From f173022b702deacbca2c8a5be689c3d248c7ab66 Mon Sep 17 00:00:00 2001 From: Frank Plowman Date: Mon, 13 Jun 2022 18:37:04 +0100 Subject: [PATCH 001/720] make style of listings 9-7 and 9-8 consistent with 9-6 --- listings/ch09-error-handling/listing-09-07/src/main.rs | 3 +-- listings/ch09-error-handling/listing-09-08/src/main.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/listings/ch09-error-handling/listing-09-07/src/main.rs b/listings/ch09-error-handling/listing-09-07/src/main.rs index f4564f670d..0295949d23 100644 --- a/listings/ch09-error-handling/listing-09-07/src/main.rs +++ b/listings/ch09-error-handling/listing-09-07/src/main.rs @@ -1,7 +1,6 @@ // ANCHOR: here use std::fs::File; -use std::io; -use std::io::Read; +use std::io::{self, Read}; fn read_username_from_file() -> Result { let mut username_file = File::open("hello.txt")?; diff --git a/listings/ch09-error-handling/listing-09-08/src/main.rs b/listings/ch09-error-handling/listing-09-08/src/main.rs index c3c6e23efc..ca672caad0 100644 --- a/listings/ch09-error-handling/listing-09-08/src/main.rs +++ b/listings/ch09-error-handling/listing-09-08/src/main.rs @@ -1,7 +1,6 @@ // ANCHOR: here use std::fs::File; -use std::io; -use std::io::Read; +use std::io::{self, Read}; fn read_username_from_file() -> Result { let mut username = String::new(); From b26046998542dc6bb2e04b9c2cba0e833b924509 Mon Sep 17 00:00:00 2001 From: Sanjyoti <78781492+thedumbsloth@users.noreply.github.com> Date: Wed, 27 Jul 2022 20:10:36 +0530 Subject: [PATCH 002/720] Edit on line no. 153. Edit on line no. 153. The adding of pub keyword to mod hosting and fn add_to_waitlist enables us to use the absolute and relative paths in the fn eat_at_restaurant according to the code specified in listing 7-7. --- ...ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index c8fb3247ff..83f45e81fe 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -150,7 +150,7 @@ and `fn add_to_waitlist` lets us call the function from `eat_at_restaurant` Now the code will compile! To see why adding the `pub` keyword lets us use -these paths in `add_to_waitlist` with respect to the privacy rules, let’s look +these paths in `eat_at_restaurant` with respect to the privacy rules, let’s look at the absolute and the relative paths. In the absolute path, we start with `crate`, the root of our crate’s module From 0e9980e4295df3462b26f8c42547d6cb906c86ab Mon Sep 17 00:00:00 2001 From: JirCep Date: Sat, 30 Jul 2022 14:38:08 +0200 Subject: [PATCH 003/720] Unnecessary import removal As per my observations crate being subject to integration tests is available for qualified reference without importing it with `use`. --- .../listing-11-13/tests/integration_test.rs | 2 -- src/ch11-03-test-organization.md | 4 ---- 2 files changed, 6 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs index e26fa71096..336c5ec54b 100644 --- a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs @@ -1,5 +1,3 @@ -use adder; - #[test] fn it_adds_two() { assert_eq!(4, adder::add_two(2)); diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index 9f26546cf4..61eda50c49 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -117,10 +117,6 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file: Listing 11-13: An integration test of a function in the `adder` crate -Each file in the `tests` directory is a separate crate, so we need to bring our -library into each test crate’s scope. For that reason we add `use adder` at the -top of the code, which we didn’t need in the unit tests. - We don’t need to annotate any code in *tests/integration_test.rs* with `#[cfg(test)]`. Cargo treats the `tests` directory specially and compiles files in this directory only when we run `cargo test`. Run `cargo test` now: From 15616bc09bd7ab6e785680a364364e962c57bb21 Mon Sep 17 00:00:00 2001 From: JirCep Date: Wed, 3 Aug 2022 22:14:44 +0200 Subject: [PATCH 004/720] `expect` is not used multitude times by this chapter --- ...2-03-improving-error-handling-and-modularity.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ch12-03-improving-error-handling-and-modularity.md b/src/ch12-03-improving-error-handling-and-modularity.md index 87e525d122..961246be62 100644 --- a/src/ch12-03-improving-error-handling-and-modularity.md +++ b/src/ch12-03-improving-error-handling-and-modularity.md @@ -23,13 +23,13 @@ example, the file could be missing, or we might not have permission to open it. Right now, regardless of the situation, we’d print the same error message for everything, which wouldn’t give the user any information! -Fourth, we use `expect` repeatedly to handle different errors, and if the user -runs our program without specifying enough arguments, they’ll get an `index out -of bounds` error from Rust that doesn’t clearly explain the problem. It would -be best if all the error-handling code were in one place so future maintainers -had only one place to consult the code if the error-handling logic needed to -change. Having all the error-handling code in one place will also ensure that -we’re printing messages that will be meaningful to our end users. +Fourth, if the user runs our program without specifying enough arguments, +they’ll get an `index out of bounds` error from Rust that doesn’t clearly +explain the problem. It would be best if all the error-handling code were +in one place so future maintainers had only one place to consult the code +if the error-handling logic needed to change. Having all the error-handling +code in one place will also ensure that we’re printing messages that +will be meaningful to our end users. Let’s address these four problems by refactoring our project. From 6c63c46817ceccb90aa5e665e56442b8d794e4c8 Mon Sep 17 00:00:00 2001 From: Alex Gotsis Date: Fri, 5 Aug 2022 00:56:52 -0700 Subject: [PATCH 005/720] Improve awkward phrasing around the kinds of closures --- src/ch13-01-closures.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch13-01-closures.md b/src/ch13-01-closures.md index f1ae324354..646204f689 100644 --- a/src/ch13-01-closures.md +++ b/src/ch13-01-closures.md @@ -329,13 +329,13 @@ Using `FnOnce` in the trait bound expresses the constraint that `unwrap_or_else` is only going to call `f` at most one time. In the body of `unwrap_or_else`, we can see that if the `Option` is `Some`, `f` won’t be called. If the `Option` is `None`, `f` will be called once. Because all -closures implement `FnOnce`, `unwrap_or_else` accepts the most different kinds -of closures and is as flexible as it can be. +closures implement `FnOnce`, `unwrap_or_else` accepts all closures and is as +flexible as it can be. > Note: Functions can implement all three of the `Fn` traits too. If what we > want to do doesn’t require capturing a value from the environment, we can use > the name of a function rather than a closure where we need something that -> implements one of the `Fn` traits. For example, on an `Option>` value, +> implements one of the `Fn` traits. For example, on an `Option>` value > we could call `unwrap_or_else(Vec::new)` to get a new, empty vector if the > value is `None`. From 3ebc3b285f01c04dcf48ef5a2363f2eaa104c8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Hern=C3=A1ndez?= Date: Thu, 1 Sep 2022 14:22:21 +0200 Subject: [PATCH 006/720] Update ch02-00-guessing-game-tutorial.md The example code converts the input into a whole number. Replace the text "convert the String the program reads as input into a real number type" to "an actual number type" as the word real might be understood as one of the number categories instead as a synonym to "actual". --- src/ch02-00-guessing-game-tutorial.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index bffbc05017..c5999daa3f 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -641,8 +641,8 @@ an `i32`, which is the type of `secret_number` unless you add type information elsewhere that would cause Rust to infer a different numerical type. The reason for the error is that Rust cannot compare a string and a number type. -Ultimately, we want to convert the `String` the program reads as input into a -real number type so we can compare it numerically to the secret number. We do so +Ultimately, we want to convert the `String` the program reads as input into an +actual number type so we can compare it numerically to the secret number. We do so by adding this line to the `main` function body: Filename: src/main.rs From 7b109240d2bfdd7caaea8eba849c5b0941ed4f05 Mon Sep 17 00:00:00 2001 From: Amit Weisbord Date: Tue, 27 Sep 2022 10:14:41 +0300 Subject: [PATCH 007/720] Clarified collection in slice definition Noticed the slice definition in the first paragraph relies on the reader recalling: * what collections are * that the reference page ended stating slices are a kind of reference I think the first paragraph should be more clear to someone who lands on it and isn't reading the rest of the documentation ATM. --- src/ch04-03-slices.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index afb6f76b10..1aae43f038 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -1,8 +1,9 @@ ## The Slice Type -*Slices* let you reference a contiguous sequence of elements in a collection -rather than the whole collection. A slice is a kind of reference, so it does -not have ownership. +*Slices* are a kind of reference, which lets you access a contiguous sub-sequence +of elements in a sequential [collection](book/src/ch08-00-common-collections.md). +Because slices are a kind of reference, they too can borrow access to memory, but +not own it. Here’s a small programming problem: write a function that takes a string of words separated by spaces and returns the first word it finds in that string. From 3a8ff9bdd272d4a60622f4ef3e2413b4170258ba Mon Sep 17 00:00:00 2001 From: Amit Weisbord Date: Tue, 27 Sep 2022 15:22:13 +0300 Subject: [PATCH 008/720] Fix broken url --- src/ch04-03-slices.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 1aae43f038..3b1b7989c1 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -1,7 +1,7 @@ ## The Slice Type *Slices* are a kind of reference, which lets you access a contiguous sub-sequence -of elements in a sequential [collection](book/src/ch08-00-common-collections.md). +of elements in a sequential [collection](ch08-00-common-collections.md). Because slices are a kind of reference, they too can borrow access to memory, but not own it. From d78fe8764aaa76ade6cc1f60f695ec9485474a08 Mon Sep 17 00:00:00 2001 From: JirCep Date: Sat, 8 Oct 2022 22:02:53 +0200 Subject: [PATCH 009/720] Minor corrections Irrefutable pattern receives warning, refutable error, when used unexpectedly. --- src/ch18-02-refutability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch18-02-refutability.md b/src/ch18-02-refutability.md index be3c31765c..29ab7ec48b 100644 --- a/src/ch18-02-refutability.md +++ b/src/ch18-02-refutability.md @@ -61,7 +61,7 @@ the code in the curly brackets, giving it a way to continue validly. Listing patterns instead of `let` We’ve given the code an out! This code is perfectly valid, although it means we -cannot use an irrefutable pattern without receiving an error. If we give `if +cannot use an irrefutable pattern without receiving a warning. If we give `if let` a pattern that will always match, such as `x`, as shown in Listing 18-10, the compiler will give a warning. From 7c9680b2861d4448d4fe82ef4ea74bd2528513f1 Mon Sep 17 00:00:00 2001 From: Marijn <40164828+MarijnRitzen@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:05:57 +0200 Subject: [PATCH 010/720] Update ch20-01-single-threaded.md Listing 20-8 is the html file --- src/ch20-01-single-threaded.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch20-01-single-threaded.md b/src/ch20-01-single-threaded.md index 993239a981..1776f05589 100644 --- a/src/ch20-01-single-threaded.md +++ b/src/ch20-01-single-threaded.md @@ -448,7 +448,7 @@ uses the `status_line` and `filename` variables. This makes it easier to see the difference between the two cases, and it means we have only one place to update the code if we want to change how the file reading and response writing work. The behavior of the code in Listing 20-9 will be the same as that in -Listing 20-8. +Listing 20-6 and 20-7. Awesome! We now have a simple web server in approximately 40 lines of Rust code that responds to one request with a page of content and responds to all other From 3e2e5214f4d2d9b605783ccb307f5dae939b01e5 Mon Sep 17 00:00:00 2001 From: JirCep Date: Sat, 22 Oct 2022 22:34:41 +0200 Subject: [PATCH 011/720] Guarded match arm exhaustivness clarification --- src/ch18-03-pattern-syntax.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/ch18-03-pattern-syntax.md b/src/ch18-03-pattern-syntax.md index aeaa766ff3..d1fd8ed4b9 100644 --- a/src/ch18-03-pattern-syntax.md +++ b/src/ch18-03-pattern-syntax.md @@ -477,8 +477,27 @@ second arm doesn’t have a match guard and therefore matches any `Some` variant There is no way to express the `if x % 2 == 0` condition within a pattern, so the match guard gives us the ability to express this logic. The downside of -this additional expressiveness is that the compiler doesn't try to check for -exhaustiveness when match guard expressions are involved. +this additional expressiveness is that the compiler is not smart enough about +arms exhaustiveness anymore when match guard expressions are involved. + +```rust +match Some(100) { + Some(_) if true => print!("Got Some"), + None => println!("Got None") +} +``` +This `match` expression involves compilation error. +```console +error[E0004]: non-exhaustive patterns: `Some(_)` not covered + --> src/main.rs:33:11 + | +33 | match Some(100) { + | ^^^^^^^^^ pattern `Some(_)` not covered + | +``` +Compilation fails even though `Some(_) if true` guarded pattern matches +any possible `Some`. Same as unguarded `Some(_)` does. + In Listing 18-11, we mentioned that we could use match guards to solve our pattern-shadowing problem. Recall that we created a new variable inside the From e4881ec331145bd0c360e1fa5b92f56b49a8814a Mon Sep 17 00:00:00 2001 From: JirCep Date: Sat, 22 Oct 2022 22:47:00 +0200 Subject: [PATCH 012/720] print! for both --- src/ch18-03-pattern-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch18-03-pattern-syntax.md b/src/ch18-03-pattern-syntax.md index d1fd8ed4b9..89b2b5a998 100644 --- a/src/ch18-03-pattern-syntax.md +++ b/src/ch18-03-pattern-syntax.md @@ -483,7 +483,7 @@ arms exhaustiveness anymore when match guard expressions are involved. ```rust match Some(100) { Some(_) if true => print!("Got Some"), - None => println!("Got None") + None => print!("Got None") } ``` This `match` expression involves compilation error. From 7f495192becde1f8fc2f09bae61d6d7120103241 Mon Sep 17 00:00:00 2001 From: JirCep Date: Sat, 22 Oct 2022 23:00:13 +0200 Subject: [PATCH 013/720] ignore,does_not_compile --- src/ch18-03-pattern-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch18-03-pattern-syntax.md b/src/ch18-03-pattern-syntax.md index 89b2b5a998..a04736d72c 100644 --- a/src/ch18-03-pattern-syntax.md +++ b/src/ch18-03-pattern-syntax.md @@ -480,7 +480,7 @@ the match guard gives us the ability to express this logic. The downside of this additional expressiveness is that the compiler is not smart enough about arms exhaustiveness anymore when match guard expressions are involved. -```rust +```rust,ignore,does_not_compile match Some(100) { Some(_) if true => print!("Got Some"), None => print!("Got None") From 64af4ed516c3007346621f12f76848bb7813ad99 Mon Sep 17 00:00:00 2001 From: Krishnakumar Gopalakrishnan Date: Wed, 9 Nov 2022 14:03:15 +0000 Subject: [PATCH 014/720] In Appendix D, adds hyperlink to Appendix E --- src/appendix-04-useful-development-tools.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/appendix-04-useful-development-tools.md b/src/appendix-04-useful-development-tools.md index 40b076153d..30249ed578 100644 --- a/src/appendix-04-useful-development-tools.md +++ b/src/appendix-04-useful-development-tools.md @@ -95,7 +95,7 @@ fn main() { The `for` loop variable is now named `_i`, and the warning no longer appears. You can also use the `cargo fix` command to transition your code between -different Rust editions. Editions are covered in Appendix E. +different Rust editions. Editions are covered in [Appendix E][editions]. ### More Lints with Clippy @@ -178,3 +178,4 @@ particular IDE. Your IDE will gain abilities such as autocompletion, jump to definition, and inline errors. [rust-analyzer]: https://rust-analyzer.github.io +[editions]: appendix-05-editions.md From a60f4316ec923a5ac2ed6a2eba6960edb832d855 Mon Sep 17 00:00:00 2001 From: Timothy Odebunmi Date: Wed, 16 Nov 2022 08:51:22 +0100 Subject: [PATCH 015/720] Fix Install MdBook command The command to install mdbook specified the version the wrong way and it failed on zsh --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 91c64ce25d..94e1a004a7 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ rust-lang/rust uses in [this file][rust-mdbook]. To get it: [rust-mdbook]: https://github.com/rust-lang/rust/blob/master/src/tools/rustbook/Cargo.toml ```bash -$ cargo install mdbook --vers [version-num] +$ cargo install mdbook --version ``` ## Building From 72b2348d78082d6a09a666a64578655efbdc17c3 Mon Sep 17 00:00:00 2001 From: SilkovAlexander Date: Sat, 19 Nov 2022 20:10:06 +0300 Subject: [PATCH 016/720] Fixed a typo --- src/ch13-03-improving-our-io-project.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch13-03-improving-our-io-project.md b/src/ch13-03-improving-our-io-project.md index b9ef0b430c..f93c5f6957 100644 --- a/src/ch13-03-improving-our-io-project.md +++ b/src/ch13-03-improving-our-io-project.md @@ -90,7 +90,7 @@ We’ve updated the signature of the `Config::build` function so the parameter `args` has a generic type with the trait bounds `impl Iterator` instead of `&[String]`. This usage of the `impl Trait` syntax we discussed in the [“Traits as Parameters”][impl-trait] section of Chapter 10 -means that `args` can be any type that implements the `Iterator` type and +means that `args` can be any type that implements the `Iterator` trait and returns `String` items. Because we’re taking ownership of `args` and we’ll be mutating `args` by From 4c8d13c52c51f1c62a80b52d7fbd7cc0b63ada43 Mon Sep 17 00:00:00 2001 From: Emanuele Gurini <33976932+EmanueleGurini@users.noreply.github.com> Date: Thu, 8 Dec 2022 11:12:39 +0100 Subject: [PATCH 017/720] FIX: IT repo updated Old repository, by Ciro Fusco, has been deleted. I opened a new one to start a new translation and I just updated the link. --- src/appendix-06-translation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appendix-06-translation.md b/src/appendix-06-translation.md index 2c57343540..7e8c68d253 100644 --- a/src/appendix-06-translation.md +++ b/src/appendix-06-translation.md @@ -11,7 +11,7 @@ For resources in languages other than English. Most are still in progress; see - [正體中文](https://github.com/rust-tw/book-tw) - [Українська](https://github.com/pavloslav/rust-book-uk-ua) - [Español](https://github.com/thecodix/book), [alternate](https://github.com/ManRR/rust-book-es) -- [Italiano](https://github.com/Ciro-Fusco/book_it) +- [Italiano](https://github.com/EmanueleGurini/book_it) - [Русский](https://github.com/rust-lang-ru/book) - [한국어](https://github.com/rinthel/rust-lang-book-ko) - [日本語](https://github.com/rust-lang-ja/book-ja) From f28554d1b216d49a4d11d05995302cf54a0f9d72 Mon Sep 17 00:00:00 2001 From: Arthur Cheek Date: Thu, 15 Dec 2022 21:54:24 +0000 Subject: [PATCH 018/720] Update -guessing-game-tutorial incorrect output `println!("x = {x} and y + 2 = {}", y + 2);` "This code would print `x = 5 and y = 12`." is incorrect. changed to "This code would print `x = 5 and y + 2 = 12`." --- src/ch02-00-guessing-game-tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index 4dac237642..4f28573333 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -291,7 +291,7 @@ let y = 10; println!("x = {x} and y + 2 = {}", y + 2); ``` -This code would print `x = 5 and y = 12`. +This code would print `x = 5 and y + 2 = 12`. ### Testing the First Part From 2bd5d42c9956369132228da6409f0e68da56c51a Mon Sep 17 00:00:00 2001 From: Theo <57922624+theo-coder@users.noreply.github.com> Date: Sun, 18 Dec 2022 16:33:56 +0100 Subject: [PATCH 019/720] fix macos installation problem when installing rust on macos just copy pasting the command throw an error about curl, on the official rust-lang website the command uses tlsv1.2 and roll backing seems to fix the issue --- src/ch01-01-installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index fa9617ad9e..87f37fab26 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -28,7 +28,7 @@ these steps should work as expected with the content of this book. If you’re using Linux or macOS, open a terminal and enter the following command: ```console -$ curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh +$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh ``` The command downloads a script and starts the installation of the `rustup` From e58e314c18d7093a609a074a5e74a823fc12d241 Mon Sep 17 00:00:00 2001 From: Vincent Esche <138017+regexident@users.noreply.github.com> Date: Wed, 4 Jan 2023 10:13:11 +0100 Subject: [PATCH 020/720] Swap inconsistent `assert_eq!` argument order in testing chapter --- .../no-listing-04-bug-in-add-two/output.txt | 4 ++-- .../no-listing-04-bug-in-add-two/src/lib.rs | 2 +- src/ch11-01-writing-tests.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt index 28e2414bef..2ee24f14c4 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt @@ -10,8 +10,8 @@ failures: ---- tests::it_adds_two stdout ---- thread 'main' panicked at 'assertion failed: `(left == right)` - left: `4`, - right: `5`', src/lib.rs:11:9 + left: `5`, + right: `4`', src/lib.rs:11:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs index f186625261..d7b4e139b8 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs @@ -10,6 +10,6 @@ mod tests { #[test] fn it_adds_two() { - assert_eq!(4, add_two(2)); + assert_eq!(add_two(2), 4); } } diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index df09aadc84..d3efa66075 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -320,7 +320,7 @@ assertion functions are called `expected` and `actual`, and the order in which we specify the arguments matters. However, in Rust, they’re called `left` and `right`, and the order in which we specify the value we expect and the value the code produces doesn’t matter. We could write the assertion in this test as -`assert_eq!(add_two(2), 4)`, which would result in the same failure message +`assert_eq!(4, add_two(2))`, which would result in the same failure message that displays `` assertion failed: `(left == right)` ``. The `assert_ne!` macro will pass if the two values we give it are not equal and From 0d5ac818bc08a41d878402d3653e760ba2771d28 Mon Sep 17 00:00:00 2001 From: "Shangdian (King) Han" Date: Sun, 8 Jan 2023 01:48:50 +0800 Subject: [PATCH 021/720] Fix incorrect interpretation of compiler error --- src/ch15-05-interior-mutability.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index 7b5e825d7e..d8f51b319d 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -191,9 +191,10 @@ However, there’s one problem with this test, as shown here: We can’t modify the `MockMessenger` to keep track of the messages, because the `send` method takes an immutable reference to `self`. We also can’t take the -suggestion from the error text to use `&mut self` instead, because then the -signature of `send` wouldn’t match the signature in the `Messenger` trait -definition (feel free to try and see what error message you get). +suggestion from the error text to use `&mut self` instead, because we are +testing an API and it's not a good idea to modify the API for the sole purpose +of testing. Usually, the test engineers do not have permission to modify the +API they're testing. Feel free to try and see what error message you get. This is a situation in which interior mutability can help! We’ll store the `sent_messages` within a `RefCell`, and then the `send` method will be From 1c0fd73e4dd775607fd3bb93c0cf28bfda42b63e Mon Sep 17 00:00:00 2001 From: abiphone <50788307+abiphone@users.noreply.github.com> Date: Thu, 8 Dec 2022 23:26:59 +0800 Subject: [PATCH 022/720] Typo Typo, filename is now file_path. --- src/ch13-03-improving-our-io-project.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch13-03-improving-our-io-project.md b/src/ch13-03-improving-our-io-project.md index b9ef0b430c..6831e540d0 100644 --- a/src/ch13-03-improving-our-io-project.md +++ b/src/ch13-03-improving-our-io-project.md @@ -28,7 +28,7 @@ we would remove them in the future. Well, that time is now! We needed `clone` here because we have a slice with `String` elements in the parameter `args`, but the `build` function doesn’t own `args`. To return ownership of a `Config` instance, we had to clone the values from the `query` -and `filename` fields of `Config` so the `Config` instance can own its values. +and `file_path` fields of `Config` so the `Config` instance can own its values. With our new knowledge about iterators, we can change the `build` function to take ownership of an iterator as its argument instead of borrowing a slice. @@ -118,7 +118,7 @@ the program. We want to ignore that and get to the next value, so first we call value we want to put in the `query` field of `Config`. If `next` returns a `Some`, we use a `match` to extract the value. If it returns `None`, it means not enough arguments were given and we return early with an `Err` value. We do -the same thing for the `filename` value. +the same thing for the `file_path` field. ### Making Code Clearer with Iterator Adaptors From 2cd1b5593d26dc6a03c20f8619187ad4b2485552 Mon Sep 17 00:00:00 2001 From: abiphone <50788307+abiphone@users.noreply.github.com> Date: Thu, 8 Dec 2022 23:49:53 +0800 Subject: [PATCH 023/720] rst restore `value` --- src/ch13-03-improving-our-io-project.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch13-03-improving-our-io-project.md b/src/ch13-03-improving-our-io-project.md index 6831e540d0..42a5be89d2 100644 --- a/src/ch13-03-improving-our-io-project.md +++ b/src/ch13-03-improving-our-io-project.md @@ -118,7 +118,7 @@ the program. We want to ignore that and get to the next value, so first we call value we want to put in the `query` field of `Config`. If `next` returns a `Some`, we use a `match` to extract the value. If it returns `None`, it means not enough arguments were given and we return early with an `Err` value. We do -the same thing for the `file_path` field. +the same thing for the `file_path` value. ### Making Code Clearer with Iterator Adaptors From f2bf90ca17c36d796cb27dc77097dc221477f720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anselm=20Sch=C3=BCler?= Date: Sun, 15 Jan 2023 01:32:18 +0100 Subject: [PATCH 024/720] Remove direction to authenticate with `cargo login {API token}` --- src/ch14-02-publishing-to-crates-io.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ch14-02-publishing-to-crates-io.md b/src/ch14-02-publishing-to-crates-io.md index c5b1ac7fc3..8349c1e8fe 100644 --- a/src/ch14-02-publishing-to-crates-io.md +++ b/src/ch14-02-publishing-to-crates-io.md @@ -273,10 +273,12 @@ in via a GitHub account. (The GitHub account is currently a requirement, but the site might support other ways of creating an account in the future.) Once you’re logged in, visit your account settings at [https://crates.io/me/](https://crates.io/me/) and retrieve your -API key. Then run the `cargo login` command with your API key, like this: +API key. Then run the `cargo login` command and paste your API key when prompted, like this: ```console -$ cargo login abcdefghijklmnopqrstuvwxyz012345 +$ cargo login +please paste the API Token found on https://crates.io/me below +abcdefghijklmnopqrstuvwxyz012345 ``` This command will inform Cargo of your API token and store it locally in From 4404cbcc354fad516c7ad9b5dea51b2ed876803a Mon Sep 17 00:00:00 2001 From: printfn Date: Sat, 21 Jan 2023 10:18:33 +0000 Subject: [PATCH 025/720] Fix broken nostarch URL --- CONTRIBUTING.md | 4 +++- README.md | 4 ++-- src/ch00-00-introduction.md | 2 +- src/title-page.md | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3c9500687d..a58ea42038 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,11 +38,13 @@ that governs all sub-projects, including this one. Please respect it! ## Expectations -Because the book is [printed](https://nostarch.com/rust), and because we want +Because the book is [printed][nostarch], and because we want to keep the online version of the book close to the print version when possible, it may take longer than you're used to for us to address your issue or pull request. +[nostarch]: https://nostarch.com/rust-programming-language-2nd-edition + So far, we've been doing a larger revision to coincide with [Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger revisions, we will only be correcting errors. If your issue or pull request diff --git a/README.md b/README.md index 94e1a004a7..f6341efc9c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository contains the source of "The Rust Programming Language" book. [The book is available in dead-tree form from No Starch Press][nostarch]. -[nostarch]: https://nostarch.com/rust +[nostarch]: https://nostarch.com/rust-programming-language-2nd-edition You can also read the book for free online. Please see the book as shipped with the latest [stable], [beta], or [nightly] Rust releases. Be aware that issues @@ -73,7 +73,7 @@ kinds of contributions we're looking for. [contrib]: https://github.com/rust-lang/book/blob/main/CONTRIBUTING.md -Because the book is [printed](https://nostarch.com/rust), and because we want +Because the book is [printed][nostarch], and because we want to keep the online version of the book close to the print version when possible, it may take longer than you're used to for us to address your issue or pull request. diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 9df8e6c882..536988cb19 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -4,7 +4,7 @@ > Language][nsprust] available in print and ebook format from [No Starch > Press][nsp]. -[nsprust]: https://nostarch.com/rust +[nsprust]: https://nostarch.com/rust-programming-language-2nd-edition [nsp]: https://nostarch.com/ Welcome to *The Rust Programming Language*, an introductory book about Rust. diff --git a/src/title-page.md b/src/title-page.md index 12d1a65987..9503861e7a 100644 --- a/src/title-page.md +++ b/src/title-page.md @@ -18,7 +18,7 @@ Press][nsprust]. [install]: ch01-01-installation.html [editions]: appendix-05-editions.html -[nsprust]: https://nostarch.com/rust +[nsprust]: https://nostarch.com/rust-programming-language-2nd-edition [translations]: appendix-06-translation.html > **🚨 Want a more interactive learning experience? Try out a different version From f2a78f64b668f63f581203c6bac509903f7c00ee Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 23 Jan 2023 13:19:32 -0500 Subject: [PATCH 026/720] Change CamelCase to UpperCamelCase Brings the terminology in line with the rest of the project, see . Connects to #2194. --- ci/dictionary.txt | 1 + src/ch10-01-syntax.md | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 9eb695d5b3..a91df4a036 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -546,6 +546,7 @@ unsafety unsized unsynchronized Unyank +UpperCamelCase URIs UsefulType username diff --git a/src/ch10-01-syntax.md b/src/ch10-01-syntax.md index c22aef7c36..431dba9667 100644 --- a/src/ch10-01-syntax.md +++ b/src/ch10-01-syntax.md @@ -33,9 +33,9 @@ the duplication by introducing a generic type parameter in a single function. To parameterize the types in a new single function, we need to name the type parameter, just as we do for the value parameters to a function. You can use any identifier as a type parameter name. But we’ll use `T` because, by -convention, type parameter names in Rust are short, often just a letter, and Rust’s -type-naming convention is CamelCase. Short for “type,” `T` is the default -choice of most Rust programmers. +convention, type parameter names in Rust are short, often just a letter, and +Rust’s type-naming convention is UpperCamelCase. Short for “type,” `T` is the +default choice of most Rust programmers. When we use a parameter in the body of the function, we have to declare the parameter name in the signature so the compiler knows what that name means. @@ -274,7 +274,7 @@ method. ### Performance of Code Using Generics You might be wondering whether there is a runtime cost when using generic type -parameters. The good news is that using generic types won't make your program run +parameters. The good news is that using generic types won't make your program run any slower than it would with concrete types. Rust accomplishes this by performing monomorphization of the code using From 4ddb4f996b8a3b942403d35b0fa4449f64d40e6b Mon Sep 17 00:00:00 2001 From: Jon Earnshaw Date: Tue, 7 Feb 2023 04:28:22 +0000 Subject: [PATCH 027/720] Update Listing 11-1 to reflect current contents --- .../ch11-writing-automated-tests/listing-11-01/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs index 1b4a90c938..7d12d9af81 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs @@ -1,8 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn it_works() { - let result = 2 + 2; + let result = add(2, 2); assert_eq!(result, 4); } } From b2365a3f087681afb477b4af58dedc7474f5b4ca Mon Sep 17 00:00:00 2001 From: Jon Earnshaw Date: Tue, 7 Feb 2023 04:43:38 +0000 Subject: [PATCH 028/720] Modify text to better refer to updated listing 11-1 --- src/ch11-01-writing-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index df09aadc84..97f13f9de3 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -62,7 +62,7 @@ cd ../../.. Listing 11-1: The test module and function generated automatically by `cargo new` -For now, let’s ignore the top two lines and focus on the function. Note the +For now, let's focus solely on the `it_works()` function. Note the `#[test]` annotation: this attribute indicates this is a test function, so the test runner knows to treat this function as a test. We might also have non-test functions in the `tests` module to help set up common scenarios or perform From bb7aa19d9dc6fd9c9a2128e9526ae861602651d9 Mon Sep 17 00:00:00 2001 From: Jon Earnshaw Date: Tue, 7 Feb 2023 04:49:10 +0000 Subject: [PATCH 029/720] Update listings subsequent to listing 11-1 to reflect current content --- .../listing-11-03/src/lib.rs | 11 +++++++++-- .../no-listing-01-changing-test-name/src/lib.rs | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs index a9ec008919..67b6552c71 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs @@ -1,11 +1,18 @@ // ANCHOR: here +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn exploration() { - assert_eq!(2 + 2, 4); + let result = add(2, 2); + assert_eq!(result, 4); } - + #[test] fn another() { panic!("Make this test fail"); diff --git a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs index 330bddf6ac..5be58b93fc 100644 --- a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs @@ -1,7 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn exploration() { - assert_eq!(2 + 2, 4); + let result = add(2, 2); + assert_eq!(result, 4); } } From bfdfb30b05560c0e25e2a4253eca8dbcf6338e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Pu=C4=8Dil?= Date: Tue, 7 Feb 2023 14:06:22 +0100 Subject: [PATCH 030/720] Fix the expected substring in ch11-01 According to Listing 11-9, the substring expected to be included is "less than or equal to 100" (not "Guess value must be less than or equal to 100" as written in the book, which is strictly speaking not the expected substring - it's almost the entire panic message except the final ", got {}." part). See https://github.com/rust-lang/book/blob/f2a78f64b668f63f581203c6bac509903f7c00ee/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs#L31: ```rust #[should_panic(expected = "less than or equal to 100")] ``` Also I think this was the only place in this chapter / in the book where I saw a string quotation in inline code additionally surrounded with single quotes `'`, so I removed them. --- src/ch11-01-writing-tests.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index df09aadc84..dc8546a936 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -497,10 +497,10 @@ This time when we run the `should_panic` test, it will fail: ``` The failure message indicates that this test did indeed panic as we expected, -but the panic message did not include the expected string `'Guess value must be -less than or equal to 100'`. The panic message that we did get in this case was -`Guess value must be greater than or equal to 1, got 200.` Now we can start -figuring out where our bug is! +but the panic message did not include the expected string `less than or equal +to 100`. The panic message that we did get in this case was `Guess value must +be greater than or equal to 1, got 200.` Now we can start figuring out where +our bug is! ### Using `Result` in Tests From f92027c68a6f0af79ce797dd0b257f8c65359611 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 10 Feb 2023 10:55:43 -0500 Subject: [PATCH 031/720] Update to Rust 1.66.1 --- .github/workflows/main.yml | 4 ++-- .../no-listing-02-without-expect/output.txt | 2 +- .../no-listing-23-statements-dont-return-values/output.txt | 2 +- listings/ch12-an-io-project/listing-12-12/output.txt | 2 +- listings/ch13-functional-features/listing-13-14/output.txt | 2 +- listings/ch15-smart-pointers/listing-15-03/output.txt | 4 ++-- listings/ch18-patterns-and-matching/listing-18-08/output.txt | 4 ++++ listings/ch18-patterns-and-matching/listing-18-10/output.txt | 2 +- listings/ch19-advanced-features/listing-19-20/output.txt | 4 ++-- rust-toolchain | 2 +- src/title-page.md | 2 +- 11 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 64ab49c515..5e00271370 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.65 -c rust-docs - rustup default 1.65 + rustup toolchain install 1.66 -c rust-docs + rustup default 1.66 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt index 8095bbd8db..c9411e514e 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt @@ -6,8 +6,8 @@ warning: unused `Result` that must be used 10 | io::stdin().read_line(&mut guess); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(unused_must_use)]` on by default = note: this `Result` may be an `Err` variant, which should be handled + = note: `#[warn(unused_must_use)]` on by default warning: `guessing_game` (bin "guessing_game") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.59s diff --git a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt index c0484ea1b4..d27a7fae28 100644 --- a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt @@ -8,7 +8,7 @@ error[E0308]: mismatched types | | | implicitly returns `()` as its body has no tail or `return` expression 8 | x + 1; - | - help: remove this semicolon + | - help: remove this semicolon to return this value For more information about this error, try `rustc --explain E0308`. error: could not compile `functions` due to previous error diff --git a/listings/ch12-an-io-project/listing-12-12/output.txt b/listings/ch12-an-io-project/listing-12-12/output.txt index c18902518e..3115c26771 100644 --- a/listings/ch12-an-io-project/listing-12-12/output.txt +++ b/listings/ch12-an-io-project/listing-12-12/output.txt @@ -6,8 +6,8 @@ warning: unused `Result` that must be used 19 | run(config); | ^^^^^^^^^^^^ | - = note: `#[warn(unused_must_use)]` on by default = note: this `Result` may be an `Err` variant, which should be handled + = note: `#[warn(unused_must_use)]` on by default warning: `minigrep` (bin "minigrep") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.71s diff --git a/listings/ch13-functional-features/listing-13-14/output.txt b/listings/ch13-functional-features/listing-13-14/output.txt index 228c764ed2..b197d5fb25 100644 --- a/listings/ch13-functional-features/listing-13-14/output.txt +++ b/listings/ch13-functional-features/listing-13-14/output.txt @@ -6,8 +6,8 @@ warning: unused `Map` that must be used 4 | v1.iter().map(|x| x + 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(unused_must_use)]` on by default = note: iterators are lazy and do nothing unless consumed + = note: `#[warn(unused_must_use)]` on by default warning: `iterators` (bin "iterators") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.47s diff --git a/listings/ch15-smart-pointers/listing-15-03/output.txt b/listings/ch15-smart-pointers/listing-15-03/output.txt index d5522cd533..04b6976fed 100644 --- a/listings/ch15-smart-pointers/listing-15-03/output.txt +++ b/listings/ch15-smart-pointers/listing-15-03/output.txt @@ -4,11 +4,11 @@ error[E0072]: recursive type `List` has infinite size --> src/main.rs:1:1 | 1 | enum List { - | ^^^^^^^^^ recursive type has infinite size + | ^^^^^^^^^ 2 | Cons(i32, List), | ---- recursive without indirection | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | 2 | Cons(i32, Box), | ++++ + diff --git a/listings/ch18-patterns-and-matching/listing-18-08/output.txt b/listings/ch18-patterns-and-matching/listing-18-08/output.txt index 0fd5373b82..db41c5ed70 100644 --- a/listings/ch18-patterns-and-matching/listing-18-08/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-08/output.txt @@ -14,6 +14,10 @@ help: you might want to use `if let` to ignore the variant that isn't matched | 3 | let x = if let Some(x) = some_option_value { x } else { todo!() }; | ++++++++++ ++++++++++++++++++++++ +help: alternatively, you might want to use let else to handle the variant that isn't matched + | +3 | let Some(x) = some_option_value else { todo!() }; + | ++++++++++++++++ For more information about this error, try `rustc --explain E0005`. error: could not compile `patterns` due to previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-10/output.txt b/listings/ch18-patterns-and-matching/listing-18-10/output.txt index 702d10a23f..6488fb29ca 100644 --- a/listings/ch18-patterns-and-matching/listing-18-10/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-10/output.txt @@ -6,9 +6,9 @@ warning: irrefutable `if let` pattern 2 | if let x = 5 { | ^^^^^^^^^ | - = note: `#[warn(irrefutable_let_patterns)]` on by default = note: this pattern will always match, so the `if let` is useless = help: consider replacing the `if let` with a `let` + = note: `#[warn(irrefutable_let_patterns)]` on by default warning: `patterns` (bin "patterns") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.39s diff --git a/listings/ch19-advanced-features/listing-19-20/output.txt b/listings/ch19-advanced-features/listing-19-20/output.txt index a3b281e3fc..5942876044 100644 --- a/listings/ch19-advanced-features/listing-19-20/output.txt +++ b/listings/ch19-advanced-features/listing-19-20/output.txt @@ -11,8 +11,8 @@ error[E0790]: cannot call associated function on trait without specifying the co | help: use the fully-qualified path to the only available implementation | -20 | println!("A baby dog is called a {}", <::Dog as Animal>::baby_name()); - | +++++++++ + +20 | println!("A baby dog is called a {}", ::baby_name()); + | +++++++ + For more information about this error, try `rustc --explain E0790`. error: could not compile `traits-example` due to previous error diff --git a/rust-toolchain b/rust-toolchain index 5b6cd6b3cd..9cf4011bde 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.65 +1.66 diff --git a/src/title-page.md b/src/title-page.md index 9503861e7a..2a8dab4501 100644 --- a/src/title-page.md +++ b/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.65 (released 2022-11-03) +This version of the text assumes you’re using Rust 1.66.1 (released 2023-01-10) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From d94e03a18a2590ed3f1c67b859cb11528d2a2d5c Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 10 Feb 2023 11:01:09 -0500 Subject: [PATCH 032/720] Update to Rust 1.67.1 --- .github/workflows/main.yml | 4 ++-- .../listing-02-04/output.txt | 1 + .../no-listing-02-without-expect/output.txt | 2 +- .../no-listing-04-cant-use-after-move/output.txt | 4 ++++ .../output.txt | 11 +++-------- .../no-listing-10-non-exhaustive-match/output.txt | 4 ++++ .../listing-07-12/output.txt | 12 ++++++------ .../ch08-common-collections/listing-08-19/output.txt | 1 - .../listing-11-03/output.txt | 2 +- .../listing-11-10/output.txt | 2 +- .../no-listing-03-introducing-a-bug/output.txt | 2 +- .../no-listing-04-bug-in-add-two/output.txt | 2 +- .../no-listing-06-greeter-with-bug/output.txt | 2 +- .../no-listing-07-custom-failure-message/output.txt | 2 +- .../output.txt | 2 +- .../output-only-01-show-output/output.txt | 2 +- listings/ch12-an-io-project/listing-12-12/output.txt | 2 +- listings/ch12-an-io-project/listing-12-16/output.txt | 2 +- .../listing-13-14/output.txt | 2 +- .../ch15-smart-pointers/listing-15-23/output.txt | 2 +- .../listing-16-14/output.txt | 3 +++ .../listing-18-08/output.txt | 4 ++++ listings/ch20-web-server/listing-20-22/output.txt | 1 + .../output.txt | 1 + rust-toolchain | 2 +- src/title-page.md | 2 +- 26 files changed, 44 insertions(+), 32 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e00271370..65574a070e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.66 -c rust-docs - rustup default 1.66 + rustup toolchain install 1.67 -c rust-docs + rustup default 1.67 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 70a0c930c2..3640c06946 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,6 +18,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: associated function defined here + --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/cmp.rs:783:8 For more information about this error, try `rustc --explain E0308`. error: could not compile `guessing_game` due to previous error diff --git a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt index c9411e514e..9517af95f0 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt @@ -4,7 +4,7 @@ warning: unused `Result` that must be used --> src/main.rs:10:5 | 10 | io::stdin().read_line(&mut guess); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default diff --git a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt index 05987f7c8d..4a53567018 100644 --- a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt @@ -12,6 +12,10 @@ error[E0382]: borrow of moved value: `s1` | ^^ value borrowed here after move | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider cloning the value if the performance cost is acceptable + | +3 | let s2 = s1.clone(); + | ++++++++ For more information about this error, try `rustc --explain E0382`. error: could not compile `ownership` due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt index d4a040e8eb..a16dc01807 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt @@ -8,15 +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 f32 as Add> - <&'a f64 as Add> - <&'a i128 as Add> - <&'a i16 as Add> - <&'a i32 as Add> - <&'a i64 as Add> <&'a i8 as Add> - <&'a isize as Add> - and 48 others + <&i8 as Add<&i8>> + > + For more information about this error, try `rustc --explain E0277`. error: could not compile `enums` due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index bec72849aa..75d056f843 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -7,6 +7,10 @@ error[E0004]: non-exhaustive patterns: `None` not covered | ^ pattern `None` not covered | note: `Option` defined here + --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:518:1 + | + = note: +/rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:522:5: not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | diff --git a/listings/ch07-managing-growing-projects/listing-07-12/output.txt b/listings/ch07-managing-growing-projects/listing-07-12/output.txt index 39b6505401..1bc89bf322 100644 --- a/listings/ch07-managing-growing-projects/listing-07-12/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-12/output.txt @@ -1,11 +1,5 @@ $ cargo build Compiling restaurant v0.1.0 (file:///projects/restaurant) -error[E0433]: failed to resolve: use of undeclared crate or module `hosting` - --> src/lib.rs:11:9 - | -11 | hosting::add_to_waitlist(); - | ^^^^^^^ use of undeclared crate or module `hosting` - warning: unused import: `crate::front_of_house::hosting` --> src/lib.rs:7:5 | @@ -14,6 +8,12 @@ warning: unused import: `crate::front_of_house::hosting` | = note: `#[warn(unused_imports)]` on by default +error[E0433]: failed to resolve: use of undeclared crate or module `hosting` + --> src/lib.rs:11:9 + | +11 | hosting::add_to_waitlist(); + | ^^^^^^^ use of undeclared crate or module `hosting` + For more information about this error, try `rustc --explain E0433`. warning: `restaurant` (lib) generated 1 warning error: could not compile `restaurant` due to previous error; 1 warning emitted diff --git a/listings/ch08-common-collections/listing-08-19/output.txt b/listings/ch08-common-collections/listing-08-19/output.txt index 95577772e1..3a682457c6 100644 --- a/listings/ch08-common-collections/listing-08-19/output.txt +++ b/listings/ch08-common-collections/listing-08-19/output.txt @@ -14,7 +14,6 @@ error[E0277]: the type `String` cannot be indexed by `{integer}` >> >> >> - > For more information about this error, try `rustc --explain E0277`. error: could not compile `collections` due to previous error diff --git a/listings/ch11-writing-automated-tests/listing-11-03/output.txt b/listings/ch11-writing-automated-tests/listing-11-03/output.txt index 2fa5cf0774..e8c31e79ec 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-03/output.txt @@ -10,7 +10,7 @@ test tests::exploration ... ok failures: ---- tests::another stdout ---- -thread 'main' panicked at 'Make this test fail', src/lib.rs:10:9 +thread 'tests::another' panicked at 'Make this test fail', src/lib.rs:10:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/listing-11-10/output.txt b/listings/ch11-writing-automated-tests/listing-11-10/output.txt index 681cfbb81a..b0d10deaa8 100644 --- a/listings/ch11-writing-automated-tests/listing-11-10/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-10/output.txt @@ -11,7 +11,7 @@ failures: ---- tests::this_test_will_fail stdout ---- I got the value 8 -thread 'main' panicked at 'assertion failed: `(left == right)` +thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)` left: `5`, right: `10`', src/lib.rs:19:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt index 7c62822f76..6fbb5e4966 100644 --- a/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt @@ -10,7 +10,7 @@ test tests::smaller_cannot_hold_larger ... ok failures: ---- tests::larger_can_hold_smaller stdout ---- -thread 'main' panicked at 'assertion failed: larger.can_hold(&smaller)', src/lib.rs:28:9 +thread 'tests::larger_can_hold_smaller' panicked at 'assertion failed: larger.can_hold(&smaller)', src/lib.rs:28:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt index 28e2414bef..00bf63fff6 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt @@ -9,7 +9,7 @@ test tests::it_adds_two ... FAILED failures: ---- tests::it_adds_two stdout ---- -thread 'main' panicked at 'assertion failed: `(left == right)` +thread 'tests::it_adds_two' panicked at 'assertion failed: `(left == right)` left: `4`, right: `5`', src/lib.rs:11:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt index 3366e3ace7..68d724f118 100644 --- a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt @@ -9,7 +9,7 @@ test tests::greeting_contains_name ... FAILED failures: ---- tests::greeting_contains_name stdout ---- -thread 'main' panicked at 'assertion failed: result.contains(\"Carol\")', src/lib.rs:12:9 +thread 'tests::greeting_contains_name' panicked at 'assertion failed: result.contains(\"Carol\")', src/lib.rs:12:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt index cebebdaee9..03d6ad7f13 100644 --- a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt @@ -9,7 +9,7 @@ test tests::greeting_contains_name ... FAILED failures: ---- tests::greeting_contains_name stdout ---- -thread 'main' panicked at 'Greeting did not contain name, value was `Hello!`', src/lib.rs:12:9 +thread 'tests::greeting_contains_name' panicked at 'Greeting did not contain name, value was `Hello!`', src/lib.rs:12:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt index c176e88b88..0b045e8be9 100644 --- a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt @@ -9,7 +9,7 @@ test tests::greater_than_100 - should panic ... FAILED failures: ---- tests::greater_than_100 stdout ---- -thread 'main' panicked at 'Guess value must be greater than or equal to 1, got 200.', src/lib.rs:13:13 +thread 'tests::greater_than_100' panicked at 'Guess value must be greater than or equal to 1, got 200.', src/lib.rs:13:13 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace note: panic did not contain expected string panic message: `"Guess value must be greater than or equal to 1, got 200."`, diff --git a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt index 4ececf245c..bc03145a18 100644 --- a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt @@ -20,7 +20,7 @@ failures: ---- tests::this_test_will_fail stdout ---- I got the value 8 -thread 'main' panicked at 'assertion failed: `(left == right)` +thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)` left: `5`, right: `10`', src/lib.rs:19:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch12-an-io-project/listing-12-12/output.txt b/listings/ch12-an-io-project/listing-12-12/output.txt index 3115c26771..9870b21255 100644 --- a/listings/ch12-an-io-project/listing-12-12/output.txt +++ b/listings/ch12-an-io-project/listing-12-12/output.txt @@ -4,7 +4,7 @@ warning: unused `Result` that must be used --> src/main.rs:19:5 | 19 | run(config); - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default diff --git a/listings/ch12-an-io-project/listing-12-16/output.txt b/listings/ch12-an-io-project/listing-12-16/output.txt index 3c34e39454..be4a97eea2 100644 --- a/listings/ch12-an-io-project/listing-12-16/output.txt +++ b/listings/ch12-an-io-project/listing-12-16/output.txt @@ -9,7 +9,7 @@ test tests::one_result ... FAILED failures: ---- tests::one_result stdout ---- -thread 'main' panicked at 'assertion failed: `(left == right)` +thread 'tests::one_result' panicked at 'assertion failed: `(left == right)` left: `["safe, fast, productive."]`, right: `[]`', src/lib.rs:44:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch13-functional-features/listing-13-14/output.txt b/listings/ch13-functional-features/listing-13-14/output.txt index b197d5fb25..9930379910 100644 --- a/listings/ch13-functional-features/listing-13-14/output.txt +++ b/listings/ch13-functional-features/listing-13-14/output.txt @@ -4,7 +4,7 @@ warning: unused `Map` that must be used --> src/main.rs:4:5 | 4 | v1.iter().map(|x| x + 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: iterators are lazy and do nothing unless consumed = note: `#[warn(unused_must_use)]` on by default diff --git a/listings/ch15-smart-pointers/listing-15-23/output.txt b/listings/ch15-smart-pointers/listing-15-23/output.txt index 3749c845cb..0ffabf7650 100644 --- a/listings/ch15-smart-pointers/listing-15-23/output.txt +++ b/listings/ch15-smart-pointers/listing-15-23/output.txt @@ -9,7 +9,7 @@ test tests::it_sends_an_over_75_percent_warning_message ... FAILED failures: ---- tests::it_sends_an_over_75_percent_warning_message stdout ---- -thread 'main' panicked at 'already borrowed: BorrowMutError', src/lib.rs:60:53 +thread 'tests::it_sends_an_over_75_percent_warning_message' panicked at 'already borrowed: BorrowMutError', src/lib.rs:60:53 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index 0634b86e52..e8cf21a736 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -22,6 +22,9 @@ note: required because it's used within this closure 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` + --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:704:8 + | + = note: required by this bound in `spawn` For more information about this error, try `rustc --explain E0277`. error: could not compile `shared-state` due to previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-08/output.txt b/listings/ch18-patterns-and-matching/listing-18-08/output.txt index db41c5ed70..52efabb5c1 100644 --- a/listings/ch18-patterns-and-matching/listing-18-08/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-08/output.txt @@ -9,6 +9,10 @@ error[E0005]: refutable pattern in local binding: `None` not covered = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html note: `Option` defined here + --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:518:1 + | + = note: +/rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:522:5: not covered = note: the matched value is of type `Option` help: you might want to use `if let` to ignore the variant that isn't matched | diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index a6c9e8d3b3..342bf9a16d 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/listings/ch20-web-server/listing-20-22/output.txt @@ -9,6 +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: this function takes ownership of the receiver `self`, which moves `worker.thread` + --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:1581:17 For more information about this error, try `rustc --explain E0507`. error: could not compile `hello` due to previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index e4c0eeb2aa..fec2377dc2 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt @@ -7,6 +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/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:1581: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/rust-toolchain b/rust-toolchain index 9cf4011bde..9ebd7af328 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.66 +1.67 diff --git a/src/title-page.md b/src/title-page.md index 2a8dab4501..5f7a7a680a 100644 --- a/src/title-page.md +++ b/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.66.1 (released 2023-01-10) +This version of the text assumes you’re using Rust 1.67.1 (released 2023-02-09) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 21a2ed14f4480dab62438dcc1130291bebc65379 Mon Sep 17 00:00:00 2001 From: Mateus Rodolfo <66533348+sourproton@users.noreply.github.com> Date: Mon, 13 Feb 2023 19:44:28 +0100 Subject: [PATCH 033/720] Removed "," typo on ch03-01 line 85 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed extra comma on line 85. We’ll cover types and type annotations in the next section, “Data Types`,`”, so don’t worry about the details right now. --- src/ch03-01-variables-and-mutability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch03-01-variables-and-mutability.md b/src/ch03-01-variables-and-mutability.md index 883a530500..058f7bb5c4 100644 --- a/src/ch03-01-variables-and-mutability.md +++ b/src/ch03-01-variables-and-mutability.md @@ -82,7 +82,7 @@ First, you aren’t allowed to use `mut` with constants. Constants aren’t just immutable by default—they’re always immutable. You declare constants using the `const` keyword instead of the `let` keyword, and the type of the value *must* be annotated. We’ll cover types and type annotations in the next section, -[“Data Types,”][data-types], so don’t worry about the details +[“Data Types”][data-types], so don’t worry about the details right now. Just know that you must always annotate the type. Constants can be declared in any scope, including the global scope, which makes From dddd193acf6f61bae33882022c5bc1ceae1d1b4a Mon Sep 17 00:00:00 2001 From: zica <59327276+zica87@users.noreply.github.com> Date: Mon, 20 Feb 2023 20:12:05 +0800 Subject: [PATCH 034/720] Replace RLS with rust-analyzer in ch00 --- src/ch00-00-introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 536988cb19..12632aa0bf 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -38,7 +38,7 @@ Rust also brings contemporary developer tools to the systems programming world: ecosystem. * The Rustfmt formatting tool ensures a consistent coding style across developers. -* The Rust Language Server powers Integrated Development Environment (IDE) +* The rust-analyzer powers Integrated Development Environment (IDE) integration for code completion and inline error messages. By using these and other tools in the Rust ecosystem, developers can be From d454a700b1648201dc90a0094acf5352fb28bb3b Mon Sep 17 00:00:00 2001 From: David Glasser Date: Fri, 10 Mar 2023 08:54:28 -0800 Subject: [PATCH 035/720] Fix em dashes When reading this section as HTML, these double hyphens stood out to me. It looks like this was introduced last year in #3135. I found other parts of the book where em dashes used standard Unicode em dash characters (rather than some Markdown representation) so I updated these to use them. (Note that I actually think this would read more clearly if it used parentheses rather than em dashes, but I figured I'd start with the smallest possible suggestion.) --- src/ch16-02-message-passing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch16-02-message-passing.md b/src/ch16-02-message-passing.md index e2f0b63c14..c468b94c33 100644 --- a/src/ch16-02-message-passing.md +++ b/src/ch16-02-message-passing.md @@ -52,7 +52,7 @@ producer for now, but we’ll add multiple producers when we get this example working. The `mpsc::channel` function returns a tuple, the first element of which is the -sending end--the transmitter--and the second element is the receiving end--the +sending end—the transmitter—and the second element is the receiving end—the receiver. The abbreviations `tx` and `rx` are traditionally used in many fields for *transmitter* and *receiver* respectively, so we name our variables as such to indicate each end. We’re using a `let` statement with a pattern that From 136d1132ed15a4fee4589c440f63ef61ad7dfa46 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Fri, 17 Mar 2023 16:38:53 +0100 Subject: [PATCH 036/720] Fix "`test` module" to "`tests` module" in ch11-03 The module is called `tests`, not `test` - see Listing 11-12: https://github.com/rust-lang/book/blob/21a2ed14f4480dab62438dcc1130291bebc65379/listings/ch11-writing-automated-tests/listing-11-12/src/lib.rs#L9-L10 --- src/ch11-03-test-organization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index 9f26546cf4..8aaa9e58a7 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -70,7 +70,7 @@ Note that the `internal_adder` function is not marked as `pub`. Tests are just Rust code, and the `tests` module is just another module. As we discussed in the [“Paths for Referring to an Item in the Module Tree”][paths] section, items in child modules can use the items in their ancestor modules. In -this test, we bring all of the `test` module’s parent’s items into scope with +this test, we bring all of the `tests` module’s parent’s items into scope with `use super::*`, and then the test can call `internal_adder`. If you don’t think private functions should be tested, there’s nothing in Rust that will compel you to do so. From 0510ca84c2ce6bf93c4ccf9248756e9e4fd00b12 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 30 Mar 2023 14:50:15 +0200 Subject: [PATCH 037/720] simplify COPYRIGHT file --- COPYRIGHT | 293 +----------------------------------------------------- 1 file changed, 3 insertions(+), 290 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index dfe614df93..0fc3ea43fe 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,290 +1,3 @@ -Short version for non-lawyers: - -The Rust Project is dual-licensed under Apache 2.0 and MIT -terms. - - -Longer version: - -The Rust Project is copyright 2010, The Rust Project -Developers. - -Licensed under the Apache License, Version 2.0 - or the MIT -license , -at your option. All files in the project carrying such -notice may not be copied, modified, or distributed except -according to those terms. - - -The Rust Project includes packages written by third parties. -The following third party packages are included, and carry -their own copyright notices and license terms: - -* The src/rt/miniz.c file, carrying an implementation of - RFC1950/RFC1951 DEFLATE, by Rich Geldreich - . All uses of this file are - permitted by the embedded "unlicense" notice - (effectively: public domain with warranty disclaimer). - -* LLVM. Code for this package is found in src/llvm. - - Copyright (c) 2003-2013 University of Illinois at - Urbana-Champaign. All rights reserved. - - Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - https://llvm.org - - Permission is hereby granted, free of charge, to any - person obtaining a copy of this software and associated - documentation files (the "Software"), to deal with the - Software without restriction, including without - limitation the rights to use, copy, modify, merge, - publish, distribute, sublicense, and/or sell copies of - the Software, and to permit persons to whom the Software - is furnished to do so, subject to the following - conditions: - - * Redistributions of source code must retain the - above copyright notice, this list of conditions - and the following disclaimers. - - * Redistributions in binary form must reproduce the - above copyright notice, this list of conditions - and the following disclaimers in the documentation - and/or other materials provided with the - distribution. - - * Neither the names of the LLVM Team, University of - Illinois at Urbana-Champaign, nor the names of its - contributors may be used to endorse or promote - products derived from this Software without - specific prior written permission. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF - ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED - TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT - SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE - FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT - OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS WITH THE SOFTWARE. - -* Additional libraries included in LLVM carry separate - BSD-compatible licenses. See src/llvm/LICENSE.txt for - details. - -* compiler-rt, in src/compiler-rt is dual licensed under - LLVM's license and MIT: - - Copyright (c) 2009-2014 by the contributors listed in - CREDITS.TXT - - All rights reserved. - - Developed by: - - LLVM Team - - University of Illinois at Urbana-Champaign - - https://llvm.org - - Permission is hereby granted, free of charge, to any - person obtaining a copy of this software and associated - documentation files (the "Software"), to deal with the - Software without restriction, including without - limitation the rights to use, copy, modify, merge, - publish, distribute, sublicense, and/or sell copies of - the Software, and to permit persons to whom the Software - is furnished to do so, subject to the following - conditions: - - * Redistributions of source code must retain the - above copyright notice, this list of conditions - and the following disclaimers. - - * Redistributions in binary form must reproduce the - above copyright notice, this list of conditions - and the following disclaimers in the documentation - and/or other materials provided with the - distribution. - - * Neither the names of the LLVM Team, University of - Illinois at Urbana-Champaign, nor the names of its - contributors may be used to endorse or promote - products derived from this Software without - specific prior written permission. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF - ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED - TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT - SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE - FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT - OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS WITH THE SOFTWARE. - - ======================================================== - - Copyright (c) 2009-2014 by the contributors listed in - CREDITS.TXT - - Permission is hereby granted, free of charge, to any - person obtaining a copy of this software and associated - documentation files (the "Software"), to deal in the - Software without restriction, including without - limitation the rights to use, copy, modify, merge, - publish, distribute, sublicense, and/or sell copies of - the Software, and to permit persons to whom the Software - is furnished to do so, subject to the following - conditions: - - The above copyright notice and this permission notice - shall be included in all copies or substantial portions - of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF - ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED - TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT - SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR - IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - -* Portions of the FFI code for interacting with the native ABI - is derived from the Clay programming language, which carries - the following license. - - Copyright (C) 2008-2010 Tachyon Technologies. - All rights reserved. - - Redistribution and use in source and binary forms, with - or without modification, are permitted provided that the - following conditions are met: - - 1. Redistributions of source code must retain the above - copyright notice, this list of conditions and the - following disclaimer. - - 2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and - the following disclaimer in the documentation and/or - other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - OF SUCH DAMAGE. - -* libbacktrace, under src/libbacktrace: - - Copyright (C) 2012-2014 Free Software Foundation, Inc. - Written by Ian Lance Taylor, Google. - - Redistribution and use in source and binary forms, with - or without modification, are permitted provided that the - following conditions are met: - - (1) Redistributions of source code must retain the - above copyright notice, this list of conditions and - the following disclaimer. - - (2) Redistributions in binary form must reproduce - the above copyright notice, this list of conditions - and the following disclaimer in the documentation - and/or other materials provided with the - distribution. - - (3) The name of the author may not be used to - endorse or promote products derived from this - software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN - NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - OF SUCH DAMAGE. */ - -* jemalloc, under src/jemalloc: - - Copyright (C) 2002-2014 Jason Evans - . All rights reserved. - Copyright (C) 2007-2012 Mozilla Foundation. - All rights reserved. - Copyright (C) 2009-2014 Facebook, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice(s), - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice(s), - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) - BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - OF SUCH DAMAGE. - -* Additional copyright may be retained by contributors other - than Mozilla, the Rust Project Developers, or the parties - enumerated in this file. Such copyright can be determined - on a case-by-case basis by examining the author of each - portion of a file in the revision-control commit records - of the project, or by consulting representative comments - claiming copyright ownership for a file. - - For example, the text: - - "Copyright (c) 2011 Google Inc." - - appears in some files, and these files thereby denote - that their author and copyright-holder is Google Inc. - - In all such cases, the absence of explicit licensing text - indicates that the contributor chose to license their work - for distribution under identical terms to those Mozilla - has chosen for the collective work, enumerated at the top - of this file. The only difference is the retention of - copyright itself, held by the contributor. +This repository is licensed under the Apache License, Version 2.0 + or the MIT +license , at your option. From c06006157b14b3d47b5c716fc392b77f3b2e21ce Mon Sep 17 00:00:00 2001 From: Vishal Lama Date: Sat, 1 Apr 2023 19:19:22 -0600 Subject: [PATCH 038/720] Fix grammar Add the word 'of' to fix the grammar. --- src/ch15-06-reference-cycles.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch15-06-reference-cycles.md b/src/ch15-06-reference-cycles.md index bef289202c..beb2bc2169 100644 --- a/src/ch15-06-reference-cycles.md +++ b/src/ch15-06-reference-cycles.md @@ -84,7 +84,7 @@ If you uncomment the last `println!` and run the program, Rust will try to print this cycle with `a` pointing to `b` pointing to `a` and so forth until it overflows the stack. -Compared to a real-world program, the consequences creating a reference cycle +Compared to a real-world program, the consequences of creating a reference cycle in this example aren’t very dire: right after we create the reference cycle, the program ends. However, if a more complex program allocated lots of memory in a cycle and held onto it for a long time, the program would use more memory From 8fa6b854d515506d825390fe0d817f5ef0c89350 Mon Sep 17 00:00:00 2001 From: Jason Walton Date: Thu, 6 Apr 2023 14:54:45 -0400 Subject: [PATCH 039/720] Update copyright in LICENSE-APACHE Looks like we forgot to fill this in when we added the license file. ;) --- LICENSE-APACHE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE-APACHE b/LICENSE-APACHE index 16fe87b06e..38634daab0 100644 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work. same "printed page" as the copyright notice for easier identification within third-party archives. -Copyright [yyyy] [name of copyright owner] +Copyright 2010 The Rust Project Developers Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From d5eb2f7a8e9c6f51b4478f9cd46f55448e2ca2c1 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Fri, 21 Apr 2023 04:28:02 +0100 Subject: [PATCH 040/720] Update MSVC instructions --- src/ch01-01-installation.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index 87f37fab26..64968f6bc7 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -59,16 +59,9 @@ the `build-essential` package. On Windows, go to [https://www.rust-lang.org/tools/install][install] and follow the instructions for installing Rust. At some point in the installation, you’ll -receive a message explaining that you’ll also need the MSVC build tools for -Visual Studio 2013 or later. - -To acquire the build tools, you’ll need to install [Visual Studio -2022][visualstudio]. When asked which workloads to install, include: - -* “Desktop Development with C++” -* The Windows 10 or 11 SDK -* The English language pack component, along with any other language pack of - your choosing +be prompted to install Visual Studio. This provides a linker and the native +libraries needed to compile programs. If you need more help with this step, see +[https://rust-lang.github.io/rustup/installation/windows-msvc.html][msvc] The rest of this book uses commands that work in both *cmd.exe* and PowerShell. If there are specific differences, we’ll explain which to use. @@ -143,5 +136,5 @@ sure what it does or how to use it, use the application programming interface [otherinstall]: https://forge.rust-lang.org/infra/other-installation-methods.html [install]: https://www.rust-lang.org/tools/install -[visualstudio]: https://visualstudio.microsoft.com/downloads/ +[msvc]: https://rust-lang.github.io/rustup/installation/windows-msvc.html [community]: https://www.rust-lang.org/community From 12a247444cce91bc5784403ae5cc54d1013b979b Mon Sep 17 00:00:00 2001 From: Ham Date: Wed, 3 May 2023 18:24:22 +0800 Subject: [PATCH 041/720] Procedure Macro: Update dependencies --- .../listing-19-31/hello_macro/hello_macro_derive/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml index aa076ac48b..ed9e917ad0 100644 --- a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml +++ b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" proc-macro = true [dependencies] -syn = "1.0" +syn = "2.0" quote = "1.0" From f1877e8db3097ed9e9607f8bdabe00df72ca89d3 Mon Sep 17 00:00:00 2001 From: Ham Date: Wed, 3 May 2023 18:33:18 +0800 Subject: [PATCH 042/720] update link to doc of syn crate --- src/ch19-06-macros.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch19-06-macros.md b/src/ch19-06-macros.md index 7731869eae..9b6ab16633 100644 --- a/src/ch19-06-macros.md +++ b/src/ch19-06-macros.md @@ -508,6 +508,6 @@ and do one more project! [tlborm]: https://veykril.github.io/tlborm/ [`syn`]: https://crates.io/crates/syn [`quote`]: https://crates.io/crates/quote -[syn-docs]: https://docs.rs/syn/1.0/syn/struct.DeriveInput.html +[syn-docs]: https://docs.rs/syn/latest/syn/struct.DeriveInput.html [quote-docs]: https://docs.rs/quote [decl]: #declarative-macros-with-macro_rules-for-general-metaprogramming From 22e4c82ab88082a7413398076b7030415cf2b1e6 Mon Sep 17 00:00:00 2001 From: Smeagol <78649849+Smeagol2069@users.noreply.github.com> Date: Tue, 9 May 2023 16:01:32 -0400 Subject: [PATCH 043/720] Parity with rustup's help When `rustup help` is run, it suggests using `rustup doc --book` rather than docs. While docs is a valid alias, I feel that both the book and the help should be the same. --- src/title-page.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/title-page.md b/src/title-page.md index 5f7a7a680a..ca5d9727ac 100644 --- a/src/title-page.md +++ b/src/title-page.md @@ -8,7 +8,7 @@ to install or update Rust. The HTML format is available online at [https://doc.rust-lang.org/stable/book/](https://doc.rust-lang.org/stable/book/) -and offline with installations of Rust made with `rustup`; run `rustup docs +and offline with installations of Rust made with `rustup`; run `rustup doc --book` to open. Several community [translations] are also available. From 3ceb9936d79c808c64d1e9934c80d51015efe5ad Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Wed, 17 May 2023 11:40:27 +0200 Subject: [PATCH 044/720] Remove hebrew niqqud in 8-14 String::from example Niqqud (hebrew diacrital system to represent vowels) is mainly used in poetry and in children's book. Israelis do not use niqqud when they write. --- listings/ch08-common-collections/listing-08-14/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch08-common-collections/listing-08-14/src/main.rs b/listings/ch08-common-collections/listing-08-14/src/main.rs index f701fd578b..bf737ab446 100644 --- a/listings/ch08-common-collections/listing-08-14/src/main.rs +++ b/listings/ch08-common-collections/listing-08-14/src/main.rs @@ -3,7 +3,7 @@ fn main() { let hello = String::from("السلام عليكم"); let hello = String::from("Dobrý den"); let hello = String::from("Hello"); - let hello = String::from("שָׁלוֹם"); + let hello = String::from("שלום"); let hello = String::from("नमस्ते"); let hello = String::from("こんにちは"); let hello = String::from("안녕하세요"); From c75ecfb5cb3595967d2f61bceede9e422c9087f4 Mon Sep 17 00:00:00 2001 From: Kris van Rens <50581423+krisvanrens@users.noreply.github.com> Date: Fri, 19 May 2023 20:35:39 +0200 Subject: [PATCH 045/720] Start note sentence with a capital --- src/ch15-02-deref.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch15-02-deref.md b/src/ch15-02-deref.md index 23c9fe8bfc..56db7c0a02 100644 --- a/src/ch15-02-deref.md +++ b/src/ch15-02-deref.md @@ -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` type we’re about to +> Note: There’s one big difference between the `MyBox` type we’re about to > build and the real `Box`: 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. From a125fc772c931aca527e26ce8b9bb5d1f1847066 Mon Sep 17 00:00:00 2001 From: Arjun Aggarwal <116913325+arjun051@users.noreply.github.com> Date: Sun, 21 May 2023 03:12:39 +0530 Subject: [PATCH 046/720] Update README.md ->It appears that you are missing a comma after the introductory phrase ideally ->The noun phrase word seems to be missing a determiner before it --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f6341efc9c..cd75900835 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ See the [releases] to download just the code of all the code listings that appea ## Requirements -Building the book requires [mdBook], ideally the same version that +Building the book requires [mdBook], ideally, the same version that rust-lang/rust uses in [this file][rust-mdbook]. To get it: [mdBook]: https://github.com/rust-lang-nursery/mdBook @@ -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). From 21cf840842bdf768a798869f06373c96c1cc5122 Mon Sep 17 00:00:00 2001 From: Shinya Fujino Date: Tue, 13 Jun 2023 00:11:49 +0900 Subject: [PATCH 047/720] Correct `i32` formatting in ch19-05 --- src/ch19-05-advanced-functions-and-closures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch19-05-advanced-functions-and-closures.md b/src/ch19-05-advanced-functions-and-closures.md index 69624f056e..88c46847d5 100644 --- a/src/ch19-05-advanced-functions-and-closures.md +++ b/src/ch19-05-advanced-functions-and-closures.md @@ -17,7 +17,7 @@ The syntax for specifying that a parameter is a function pointer is similar to that of closures, as shown in Listing 19-27, where we’ve defined a function `add_one` that adds one to its parameter. The function `do_twice` takes two parameters: a function pointer to any function that takes an `i32` parameter -and returns an `i32`, and one `i32 value`. The `do_twice` function calls the +and returns an `i32`, and one `i32` value. The `do_twice` function calls the function `f` twice, passing it the `arg` value, then adds the two function call results together. The `main` function calls `do_twice` with the arguments `add_one` and `5`. From eb0e86b49de0b0164ef70fb1cdb52a600ff07d07 Mon Sep 17 00:00:00 2001 From: Menachem Adin Date: Fri, 16 Jun 2023 00:15:10 +0300 Subject: [PATCH 048/720] Remove redundant words --- src/ch12-05-working-with-environment-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch12-05-working-with-environment-variables.md b/src/ch12-05-working-with-environment-variables.md index 4e6b40fb3b..263c80cd06 100644 --- a/src/ch12-05-working-with-environment-variables.md +++ b/src/ch12-05-working-with-environment-variables.md @@ -113,7 +113,7 @@ function, as shown in Listing 12-22. This still won’t compile yet. Finally, we need to check for the environment variable. The functions for working with environment variables are in the `env` module in the standard library, so we bring that module into scope at the top of *src/lib.rs*. Then -we’ll use the `var` function from the `env` module to check to see if any value +we’ll use the `var` function from the `env` module to check if any value has been set for an environment variable named `IGNORE_CASE`, as shown in Listing 12-23. From 668c64760b5c7ea654facb4ba5fe9faddfda27cc Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 29 Jun 2023 09:50:36 -0400 Subject: [PATCH 049/720] Remove adjective about what kind of number this is --- src/ch08-02-strings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index 9663d36ab1..f38803ee3b 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -244,7 +244,7 @@ encoded UTF-8 example strings from Listing 8-14. First, this one: In this case, `len` will be 4, which means the vector storing the string “Hola” is 4 bytes long. Each of these letters takes 1 byte when encoded in UTF-8. The following line, however, may surprise you. (Note that this string begins with -the capital Cyrillic letter Ze, not the Arabic number 3.) +the capital Cyrillic letter Ze, not the number 3.) ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-14/src/main.rs:russian}} From d7db5129d2c6b9b256e762b8a4a15bcd15927228 Mon Sep 17 00:00:00 2001 From: Rahul Rao <63695122+rahulrao0209@users.noreply.github.com> Date: Fri, 7 Jul 2023 23:45:42 +0530 Subject: [PATCH 050/720] Update ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md Editing what I think is a minor typo. The binary crate should be calling code within the library crate (instead of with the library crate) --- ...ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index c8fb3247ff..3d6d890c13 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -184,7 +184,7 @@ interested in this topic, see [The Rust API Guidelines][api-guidelines]. > well as a *src/lib.rs* library crate root, and both crates will have the > package name by default. Typically, packages with this pattern of containing > both a library and a binary crate will have just enough code in the binary -> crate to start an executable that calls code with the library crate. This +> crate to start an executable that calls code within the library crate. This > lets other projects benefit from the most functionality that the package > provides, because the library crate’s code can be shared. > From 8f79c36d976c2d58d5de9398d2f0e3d31009e5ee Mon Sep 17 00:00:00 2001 From: Joshua Goring Date: Fri, 14 Jul 2023 22:37:30 -0500 Subject: [PATCH 051/720] Fix #3703 --- src/ch18-02-refutability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch18-02-refutability.md b/src/ch18-02-refutability.md index be3c31765c..29ab7ec48b 100644 --- a/src/ch18-02-refutability.md +++ b/src/ch18-02-refutability.md @@ -61,7 +61,7 @@ the code in the curly brackets, giving it a way to continue validly. Listing patterns instead of `let` We’ve given the code an out! This code is perfectly valid, although it means we -cannot use an irrefutable pattern without receiving an error. If we give `if +cannot use an irrefutable pattern without receiving a warning. If we give `if let` a pattern that will always match, such as `x`, as shown in Listing 18-10, the compiler will give a warning. From dc16e35f98955d2a28d49ad01791dcc2c9c8178f Mon Sep 17 00:00:00 2001 From: Mike Ton Date: Wed, 19 Jul 2023 16:30:28 +0000 Subject: [PATCH 052/720] Update loop to Result: 10 --- .../ch16-fearless-concurrency/listing-16-15/src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs index 30247dd52f..a568668d56 100644 --- a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs @@ -5,7 +5,13 @@ fn main() { let counter = Arc::new(Mutex::new(0)); let mut handles = vec![]; - for _ in 0..10 { + // The chapters accompanying text states that the print should be : + // Result: 10 + // But the current code yields : + // Result: 9 + // An update to this should resolve the drift between text and code : + // 1..=10 - is a range that is inclusive of 1 and inclusive of 10 + for _ in 0..=10 { let counter = Arc::clone(&counter); let handle = thread::spawn(move || { let mut num = counter.lock().unwrap(); From a80a425f71f0849af91be3d7d19df7f6ed99cc4b Mon Sep 17 00:00:00 2001 From: Mike Ton Date: Wed, 19 Jul 2023 16:46:31 +0000 Subject: [PATCH 053/720] Comments cleaned up and removed --- .../ch16-fearless-concurrency/listing-16-15/src/main.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs index a568668d56..6e849ff117 100644 --- a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs @@ -5,12 +5,6 @@ fn main() { let counter = Arc::new(Mutex::new(0)); let mut handles = vec![]; - // The chapters accompanying text states that the print should be : - // Result: 10 - // But the current code yields : - // Result: 9 - // An update to this should resolve the drift between text and code : - // 1..=10 - is a range that is inclusive of 1 and inclusive of 10 for _ in 0..=10 { let counter = Arc::clone(&counter); let handle = thread::spawn(move || { From 4d988c795a28a076778bf1ee9a47a639255481bc Mon Sep 17 00:00:00 2001 From: Jaime Terreu Date: Thu, 3 Aug 2023 22:36:34 +0930 Subject: [PATCH 054/720] Improve sentence --- src/ch10-03-lifetime-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index 5229ab74b3..eacbbd2818 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -44,7 +44,7 @@ The outer scope declares a variable named `r` with no initial value, and the inner scope declares a variable named `x` with the initial value of 5. Inside the inner scope, we attempt to set the value of `r` as a reference to `x`. Then the inner scope ends, and we attempt to print the value in `r`. This code won’t -compile because the value `r` is referring to has gone out of scope before we +compile because what the value `r` is referring to has gone out of scope before we try to use it. Here is the error message: ```console From 66aedb4a61bf208c69d61b2f89bac25f70d6cdad Mon Sep 17 00:00:00 2001 From: Mike Krisher Date: Wed, 2 Aug 2023 15:25:31 -0400 Subject: [PATCH 055/720] Small wording changes --- src/ch10-03-lifetime-syntax.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index eacbbd2818..498f01f0b5 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -8,13 +8,13 @@ One detail we didn’t discuss in the [“References and Borrowing”][references-and-borrowing] section in Chapter 4 is that every reference in Rust has a *lifetime*, which is the scope for which that reference is valid. Most of the time, lifetimes are implicit and inferred, -just like most of the time, types are inferred. We only must annotate types +just like most of the time, types are inferred. We must only annotate types when multiple types are possible. In a similar way, we must annotate lifetimes when the lifetimes of references could be related in a few different ways. Rust requires us to annotate the relationships using generic lifetime parameters to ensure the actual references used at runtime will definitely be valid. -Annotating lifetimes is not even a concept most other programming languages +Annotating lifetimes is not a concept most other programming languages have, so this is going to feel unfamiliar. Although we won’t cover lifetimes in their entirety in this chapter, we’ll discuss common ways you might encounter lifetime syntax so you can get comfortable with the concept. From 72187f5cd0beaaa9c6f584156bcd88f921871e83 Mon Sep 17 00:00:00 2001 From: kadiwa Date: Sat, 15 Jul 2023 17:02:35 +0200 Subject: [PATCH 056/720] redirects: change link for `#![no_std]` tutorial --- redirects/using-rust-without-the-standard-library.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/redirects/using-rust-without-the-standard-library.md b/redirects/using-rust-without-the-standard-library.md index 75145429d4..0fbdfebdd6 100644 --- a/redirects/using-rust-without-the-standard-library.md +++ b/redirects/using-rust-without-the-standard-library.md @@ -7,11 +7,11 @@ --- -This particular chapter has moved to [the Unstable Book][2]. +This particular chapter has moved to [the Rustonomicon][2]. -* **[In the Unstable Rust Book: `lang_items` — Writing an executable without stdlib][2]** +* **[In the Rustonomicon: Beneath std][2]** * [In the first edition: Ch 4.12 — Using Rust without the Standard Library][1] [1]: https://doc.rust-lang.org/1.30.0/book/first-edition/using-rust-without-the-standard-library.html -[2]: ../unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib +[2]: ../nomicon/beneath-std.html From a6656c5b072dc9e283b4f16b95679e9d591915e4 Mon Sep 17 00:00:00 2001 From: Luciano Manerich Junior Date: Sat, 19 Aug 2023 17:54:19 -0300 Subject: [PATCH 057/720] Added "--" between run and args --- listings/ch12-an-io-project/listing-12-12/output.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch12-an-io-project/listing-12-12/output.txt b/listings/ch12-an-io-project/listing-12-12/output.txt index 9870b21255..3d732f6038 100644 --- a/listings/ch12-an-io-project/listing-12-12/output.txt +++ b/listings/ch12-an-io-project/listing-12-12/output.txt @@ -1,4 +1,4 @@ -$ cargo run the poem.txt +$ cargo run -- the poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) warning: unused `Result` that must be used --> src/main.rs:19:5 From 84ff595aa4cd78fb93e8ad3581b1b4b87cbb6e42 Mon Sep 17 00:00:00 2001 From: Stu <31073482+stu-h@users.noreply.github.com> Date: Wed, 20 Sep 2023 17:22:00 +0100 Subject: [PATCH 058/720] reword --- src/ch19-01-unsafe-rust.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch19-01-unsafe-rust.md b/src/ch19-01-unsafe-rust.md index 6ff229dd37..a8133ca8e5 100644 --- a/src/ch19-01-unsafe-rust.md +++ b/src/ch19-01-unsafe-rust.md @@ -34,7 +34,7 @@ include the ability to: * Call an unsafe function or method * Access or modify a mutable static variable * Implement an unsafe trait -* Access fields of `union`s +* Access fields of a `union` It’s important to understand that `unsafe` doesn’t turn off the borrow checker or disable any other of Rust’s safety checks: if you use a reference in unsafe From 08d3496982aaa197b8db8bc885f9cd82d87a6747 Mon Sep 17 00:00:00 2001 From: Matt Nield <64328730+matthewjnield@users.noreply.github.com> Date: Sun, 8 Oct 2023 01:52:28 -0400 Subject: [PATCH 059/720] Fix typo in Chapter 7 Section 3 Fix typo in Chapter 7 Section 3, changing "benefit from the most functionality" to "benefit from most of the functionality" --- ...ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index c8fb3247ff..e2e627eb75 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -185,7 +185,7 @@ interested in this topic, see [The Rust API Guidelines][api-guidelines]. > package name by default. Typically, packages with this pattern of containing > both a library and a binary crate will have just enough code in the binary > crate to start an executable that calls code with the library crate. This -> lets other projects benefit from the most functionality that the package +> lets other projects benefit from most of the functionality that the package > provides, because the library crate’s code can be shared. > > The module tree should be defined in *src/lib.rs*. Then, any public items can From 1402554da88bfaf3fe1cc33d18a5974286287408 Mon Sep 17 00:00:00 2001 From: Matt Nield <64328730+matthewjnield@users.noreply.github.com> Date: Sun, 8 Oct 2023 02:02:46 -0400 Subject: [PATCH 060/720] Fix typo in Chapter 7 Section 3 Fix typo in Chapter 7 Section 3, changing "start an executable that calls code with the library crate." to "start an executable that calls code within the library crate." --- ...ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index e2e627eb75..85fc247376 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -184,7 +184,7 @@ interested in this topic, see [The Rust API Guidelines][api-guidelines]. > well as a *src/lib.rs* library crate root, and both crates will have the > package name by default. Typically, packages with this pattern of containing > both a library and a binary crate will have just enough code in the binary -> crate to start an executable that calls code with the library crate. This +> crate to start an executable that calls code within the library crate. This > lets other projects benefit from most of the functionality that the package > provides, because the library crate’s code can be shared. > From 198010b61e645645dcbc7527a78479202ebb2e54 Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Ribera Costa <56278796+SergioRibera@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:13:48 -0400 Subject: [PATCH 061/720] add rustlanges book translation --- src/appendix-06-translation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appendix-06-translation.md b/src/appendix-06-translation.md index 7e8c68d253..a0105785c0 100644 --- a/src/appendix-06-translation.md +++ b/src/appendix-06-translation.md @@ -10,7 +10,7 @@ For resources in languages other than English. Most are still in progress; see - [简体中文](https://github.com/KaiserY/trpl-zh-cn) - [正體中文](https://github.com/rust-tw/book-tw) - [Українська](https://github.com/pavloslav/rust-book-uk-ua) -- [Español](https://github.com/thecodix/book), [alternate](https://github.com/ManRR/rust-book-es) +- [Español](https://github.com/thecodix/book), [alternate](https://github.com/ManRR/rust-book-es), [Español por RustLangES](https://github.com/RustLangES/book) - [Italiano](https://github.com/EmanueleGurini/book_it) - [Русский](https://github.com/rust-lang-ru/book) - [한국어](https://github.com/rinthel/rust-lang-book-ko) From 618a9c6eb6b528324465b20dcc9f7d71e624ea36 Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Ribera Costa <56278796+SergioRibera@users.noreply.github.com> Date: Tue, 10 Oct 2023 19:18:27 -0400 Subject: [PATCH 062/720] add words to dictionary --- ci/dictionary.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index a91df4a036..deafdd8cd3 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -159,6 +159,7 @@ Enums eprintln Erlang ErrorKind +Español eval executables ExitCode @@ -369,6 +370,7 @@ PendingReviewPost PlaceholderType polymorphism PoolCreationError +por portia powershell PowerShell @@ -431,6 +433,7 @@ rustdoc Rustonomicon rustfix rustfmt +RustLangES rustup sampleproject screenshot From 3dca2fc50b922a8efb94903b9fee8bb42ab48f38 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 19 Oct 2023 09:10:43 -0700 Subject: [PATCH 063/720] Fix cargo doc links --- src/ch02-00-guessing-game-tutorial.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index 4f28573333..5e27fb114d 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -930,8 +930,8 @@ discusses structs and method syntax, and Chapter 6 explains how enums work. [randcrate]: https://crates.io/crates/rand [semver]: http://semver.org [cratesio]: https://crates.io/ -[doccargo]: http://doc.crates.io -[doccratesio]: http://doc.crates.io/crates-io.html +[doccargo]: https://doc.rust-lang.org/cargo/ +[doccratesio]: https://doc.rust-lang.org/cargo/reference/publishing.html [match]: ch06-02-match.html [shadowing]: ch03-01-variables-and-mutability.html#shadowing [parse]: ../std/primitive.str.html#method.parse From 187b317e891a4eedfd8f1e16c773e7520e1850f2 Mon Sep 17 00:00:00 2001 From: Rafael Kraut <14234815+RafaelKr@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:30:26 +0200 Subject: [PATCH 064/720] Improve ch03-05-control-flow collection looping wording This makes it clearer, that you COULD use a `while` loop to loop a collection, but a `for` loop is the preferred way --- src/ch03-05-control-flow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch03-05-control-flow.md b/src/ch03-05-control-flow.md index 60d6b95a96..aac0e0c653 100644 --- a/src/ch03-05-control-flow.md +++ b/src/ch03-05-control-flow.md @@ -297,7 +297,7 @@ evaluates to `true`, the code runs; otherwise, it exits the loop. #### Looping Through a Collection with `for` -You can choose to use the `while` construct to loop over the elements of a +You could choose to use the `while` construct to loop over the elements of a collection, such as an array. For example, the loop in Listing 3-4 prints each element in the array `a`. From f55ac5d8fa1d070edc2374b1bcfdbd83bf66f39d Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 13 Oct 2022 15:01:58 -0400 Subject: [PATCH 065/720] Inline all format arguments The inlined format arguments are a bit easier to understand, especially for those familiar with the other languages (python, js). --- Cargo.toml | 2 +- .../listing-04-01/src/main.rs | 2 +- .../listing-04-03/src/main.rs | 4 ++-- .../listing-04-05/src/main.rs | 2 +- .../no-listing-01-can-mutate-string/src/main.rs | 4 ++-- .../no-listing-04-cant-use-after-move/src/main.rs | 2 +- .../no-listing-05-clone/src/main.rs | 2 +- .../no-listing-06-copy/src/main.rs | 2 +- .../no-listing-07-reference/src/main.rs | 2 +- .../no-listing-08-reference-with-annotations/src/main.rs | 2 +- .../no-listing-13-reference-scope-ends/src/main.rs | 4 ++-- .../no-listing-19-slice-error/src/main.rs | 2 +- .../listing-05-12/src/main.rs | 2 +- .../output-only-02-pretty-debug/src/main.rs | 2 +- .../listing-06-06/src/main.rs | 2 +- .../no-listing-09-variable-in-pattern/src/main.rs | 2 +- .../no-listing-12-if-let/src/main.rs | 2 +- .../no-listing-13-count-and-announce-match/src/main.rs | 2 +- .../src/main.rs | 2 +- .../quick-reference-example/src/main.rs | 2 +- .../ch08-common-collections/listing-08-23/src/main.rs | 2 +- .../ch08-common-collections/listing-08-24/src/main.rs | 2 +- .../ch08-common-collections/listing-08-25/src/main.rs | 2 +- listings/ch09-error-handling/listing-09-04/src/main.rs | 2 +- listings/ch09-error-handling/listing-09-05/src/main.rs | 4 ++-- listings/ch09-error-handling/listing-09-13/src/main.rs | 2 +- .../listing-10-01/src/main.rs | 2 +- .../listing-10-02/src/main.rs | 4 ++-- .../listing-10-03/src/main.rs | 4 ++-- .../listing-10-04/src/main.rs | 4 ++-- .../listing-10-05/src/main.rs | 4 ++-- .../listing-10-16/src/main.rs | 2 +- .../listing-10-17/src/main.rs | 2 +- .../listing-10-18/src/main.rs | 2 +- .../listing-10-19/src/main.rs | 2 +- .../listing-10-20/src/main.rs | 2 +- .../listing-10-21/src/main.rs | 2 +- .../listing-10-22/src/main.rs | 2 +- .../listing-10-23/output.txt | 4 ++-- .../listing-10-23/src/main.rs | 2 +- .../src/main.rs | 2 +- .../no-listing-09-unrelated-lifetime/src/main.rs | 2 +- .../no-listing-10-lifetimes-on-methods/src/main.rs | 2 +- .../src/main.rs | 4 ++-- .../ch11-writing-automated-tests/listing-11-08/src/lib.rs | 2 +- .../ch11-writing-automated-tests/listing-11-10/src/lib.rs | 2 +- .../no-listing-05-greeter/src/lib.rs | 2 +- .../no-listing-08-guess-with-bug/src/lib.rs | 2 +- .../output-only-01-show-output/src/lib.rs | 2 +- listings/ch12-an-io-project/listing-12-02/src/main.rs | 4 ++-- listings/ch12-an-io-project/listing-12-03/src/main.rs | 4 ++-- listings/ch12-an-io-project/listing-12-04/src/main.rs | 4 ++-- listings/ch12-an-io-project/listing-12-05/src/main.rs | 4 ++-- .../ch13-functional-features/listing-13-04/src/main.rs | 8 ++++---- .../ch13-functional-features/listing-13-05/src/main.rs | 4 ++-- .../ch13-functional-features/listing-13-06/src/main.rs | 4 ++-- .../ch13-functional-features/listing-13-07/src/main.rs | 2 +- .../ch13-functional-features/listing-13-08/src/main.rs | 2 +- .../ch13-functional-features/listing-13-09/src/main.rs | 2 +- .../ch13-functional-features/listing-13-11/src/main.rs | 2 +- listings/ch15-smart-pointers/listing-15-01/src/main.rs | 2 +- listings/ch15-smart-pointers/listing-15-24/src/main.rs | 6 +++--- .../ch16-fearless-concurrency/listing-16-01/src/main.rs | 4 ++-- .../ch16-fearless-concurrency/listing-16-02/src/main.rs | 4 ++-- .../ch16-fearless-concurrency/listing-16-03/output.txt | 6 +++--- .../ch16-fearless-concurrency/listing-16-03/src/main.rs | 2 +- .../ch16-fearless-concurrency/listing-16-04/src/main.rs | 2 +- .../ch16-fearless-concurrency/listing-16-05/src/main.rs | 2 +- .../ch16-fearless-concurrency/listing-16-08/src/main.rs | 2 +- .../ch16-fearless-concurrency/listing-16-09/output.txt | 4 ++-- .../ch16-fearless-concurrency/listing-16-09/src/main.rs | 4 ++-- .../ch16-fearless-concurrency/listing-16-10/src/main.rs | 2 +- .../ch16-fearless-concurrency/listing-16-11/src/main.rs | 2 +- .../ch16-fearless-concurrency/listing-16-12/src/main.rs | 2 +- .../no-listing-01-join-too-early/src/main.rs | 4 ++-- .../output-only-01-move-drop/output.txt | 4 ++-- .../output-only-01-move-drop/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-02/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-03/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-07/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-09/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-10/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-11/src/main.rs | 4 ++-- .../ch18-patterns-and-matching/listing-18-15/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-17/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-18/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-21/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-22/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-23/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-25/src/main.rs | 2 +- .../ch18-patterns-and-matching/listing-18-26/src/main.rs | 4 ++-- .../ch18-patterns-and-matching/listing-18-27/src/main.rs | 4 ++-- .../ch18-patterns-and-matching/listing-18-29/src/main.rs | 4 ++-- listings/ch19-advanced-features/listing-19-09/src/main.rs | 2 +- listings/ch19-advanced-features/listing-19-10/src/main.rs | 2 +- listings/ch19-advanced-features/listing-19-22/src/main.rs | 2 +- listings/ch19-advanced-features/listing-19-23/src/main.rs | 2 +- listings/ch19-advanced-features/listing-19-27/src/main.rs | 2 +- .../no-listing-02-impl-outlineprint-for-point/src/main.rs | 2 +- .../no-listing-03-impl-display-for-point/src/main.rs | 2 +- listings/ch20-web-server/listing-20-02/src/main.rs | 2 +- src/ch09-02-recoverable-errors-with-result.md | 4 ++-- tools/doc-to-md.sh | 2 +- tools/src/bin/link2print.rs | 4 ++-- 104 files changed, 139 insertions(+), 139 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c59425f920..60bd20b0fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "rust-book" version = "0.0.1" description = "The Rust Book" -edition = "2018" +edition = "2021" [[bin]] name = "concat_chapters" diff --git a/listings/ch04-understanding-ownership/listing-04-01/src/main.rs b/listings/ch04-understanding-ownership/listing-04-01/src/main.rs index 148ad84c97..ebcd3691be 100644 --- a/listings/ch04-understanding-ownership/listing-04-01/src/main.rs +++ b/listings/ch04-understanding-ownership/listing-04-01/src/main.rs @@ -6,4 +6,4 @@ fn main() { // do stuff with s } // this scope is now over, and s is no longer valid // ANCHOR_END: here -} \ No newline at end of file +} diff --git a/listings/ch04-understanding-ownership/listing-04-03/src/main.rs b/listings/ch04-understanding-ownership/listing-04-03/src/main.rs index b001cc5f4a..edf51a947d 100644 --- a/listings/ch04-understanding-ownership/listing-04-03/src/main.rs +++ b/listings/ch04-understanding-ownership/listing-04-03/src/main.rs @@ -14,10 +14,10 @@ fn main() { // special happens. fn takes_ownership(some_string: String) { // some_string comes into scope - println!("{}", some_string); + println!("{some_string}"); } // Here, some_string goes out of scope and `drop` is called. The backing // memory is freed. fn makes_copy(some_integer: i32) { // some_integer comes into scope - println!("{}", some_integer); + println!("{some_integer}"); } // Here, some_integer goes out of scope. Nothing special happens. diff --git a/listings/ch04-understanding-ownership/listing-04-05/src/main.rs b/listings/ch04-understanding-ownership/listing-04-05/src/main.rs index 22aee1419e..2782483a77 100644 --- a/listings/ch04-understanding-ownership/listing-04-05/src/main.rs +++ b/listings/ch04-understanding-ownership/listing-04-05/src/main.rs @@ -3,7 +3,7 @@ fn main() { let (s2, len) = calculate_length(s1); - println!("The length of '{}' is {}.", s2, len); + println!("The length of '{s2}' is {len}."); } fn calculate_length(s: String) -> (String, usize) { diff --git a/listings/ch04-understanding-ownership/no-listing-01-can-mutate-string/src/main.rs b/listings/ch04-understanding-ownership/no-listing-01-can-mutate-string/src/main.rs index b68f0f1e78..15bc9d9220 100644 --- a/listings/ch04-understanding-ownership/no-listing-01-can-mutate-string/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-01-can-mutate-string/src/main.rs @@ -4,6 +4,6 @@ fn main() { s.push_str(", world!"); // push_str() appends a literal to a String - println!("{}", s); // This will print `hello, world!` - // ANCHOR_END: here + println!("{s}"); // This will print `hello, world!` + // ANCHOR_END: here } diff --git a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/src/main.rs b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/src/main.rs index d0b9f18795..e35f6d8034 100644 --- a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/src/main.rs @@ -3,6 +3,6 @@ fn main() { let s1 = String::from("hello"); let s2 = s1; - println!("{}, world!", s1); + println!("{s1}, world!"); // ANCHOR_END: here } diff --git a/listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs b/listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs index 4e61cc1a16..0b65e5f611 100644 --- a/listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs @@ -3,6 +3,6 @@ fn main() { let s1 = String::from("hello"); let s2 = s1.clone(); - println!("s1 = {}, s2 = {}", s1, s2); + println!("s1 = {s1}, s2 = {s2}"); // ANCHOR_END: here } diff --git a/listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs b/listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs index 63a1fae248..b6fd2445d0 100644 --- a/listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs @@ -3,6 +3,6 @@ fn main() { let x = 5; let y = x; - println!("x = {}, y = {}", x, y); + println!("x = {x}, y = {y}"); // ANCHOR_END: here } diff --git a/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs b/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs index fd32a5fc95..6f6d5fb239 100644 --- a/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs @@ -6,7 +6,7 @@ fn main() { let len = calculate_length(&s1); // ANCHOR_END: here - println!("The length of '{}' is {}.", s1, len); + println!("The length of '{s1}' is {len}."); } fn calculate_length(s: &String) -> usize { diff --git a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs index 6686a801c0..964fd233f7 100644 --- a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs @@ -3,7 +3,7 @@ fn main() { let len = calculate_length(&s1); - println!("The length of '{}' is {}.", s1, len); + println!("The length of '{s1}' is {len}."); } // ANCHOR: here diff --git a/listings/ch04-understanding-ownership/no-listing-13-reference-scope-ends/src/main.rs b/listings/ch04-understanding-ownership/no-listing-13-reference-scope-ends/src/main.rs index 8619449669..c005414d8e 100644 --- a/listings/ch04-understanding-ownership/no-listing-13-reference-scope-ends/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-13-reference-scope-ends/src/main.rs @@ -4,10 +4,10 @@ fn main() { let r1 = &s; // no problem let r2 = &s; // no problem - println!("{} and {}", r1, r2); + println!("{r1} and {r2}"); // variables r1 and r2 will not be used after this point let r3 = &mut s; // no problem - println!("{}", r3); + println!("{r3}"); // ANCHOR_END: here } diff --git a/listings/ch04-understanding-ownership/no-listing-19-slice-error/src/main.rs b/listings/ch04-understanding-ownership/no-listing-19-slice-error/src/main.rs index 99e04018d2..b23e45f435 100644 --- a/listings/ch04-understanding-ownership/no-listing-19-slice-error/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-19-slice-error/src/main.rs @@ -18,6 +18,6 @@ fn main() { s.clear(); // error! - println!("the first word is: {}", word); + println!("the first word is: {word}"); } // ANCHOR_END: here diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-12/src/main.rs b/listings/ch05-using-structs-to-structure-related-data/listing-05-12/src/main.rs index 2ffc4b8e7b..67e0b92a47 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-12/src/main.rs +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-12/src/main.rs @@ -10,5 +10,5 @@ fn main() { height: 50, }; - println!("rect1 is {:?}", rect1); + println!("rect1 is {rect1:?}"); } diff --git a/listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/src/main.rs b/listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/src/main.rs index 84e32aee49..f763b50d3b 100644 --- a/listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/src/main.rs +++ b/listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/src/main.rs @@ -10,5 +10,5 @@ fn main() { height: 50, }; - println!("rect1 is {:#?}", rect1); + println!("rect1 is {rect1:#?}"); } diff --git a/listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs b/listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs index dc2bffb911..0a037517ab 100644 --- a/listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs +++ b/listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs @@ -2,7 +2,7 @@ fn main() { // ANCHOR: here let config_max = Some(3u8); match config_max { - Some(max) => println!("The maximum is configured to be {}", max), + Some(max) => println!("The maximum is configured to be {max}"), _ => (), } // ANCHOR_END: here diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs b/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs index a4d500c11c..298215d405 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs +++ b/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs @@ -19,7 +19,7 @@ fn value_in_cents(coin: Coin) -> u8 { Coin::Nickel => 5, Coin::Dime => 10, Coin::Quarter(state) => { - println!("State quarter from {:?}!", state); + println!("State quarter from {state:?}!"); 25 } } diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs b/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs index 735086d4ed..7d7254ea0f 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs +++ b/listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs @@ -2,7 +2,7 @@ fn main() { // ANCHOR: here let config_max = Some(3u8); if let Some(max) = config_max { - println!("The maximum is configured to be {}", max); + println!("The maximum is configured to be {max}"); } // ANCHOR_END: here } diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs b/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs index 12c4c0fec1..d0d7d80271 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs +++ b/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs @@ -17,7 +17,7 @@ fn main() { // ANCHOR: here let mut count = 0; match coin { - Coin::Quarter(state) => println!("State quarter from {:?}!", state), + Coin::Quarter(state) => println!("State quarter from {state:?}!"), _ => count += 1, } // ANCHOR_END: here diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs b/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs index ba7eda27b4..3bb3630350 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs +++ b/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs @@ -17,7 +17,7 @@ fn main() { // ANCHOR: here let mut count = 0; if let Coin::Quarter(state) = coin { - println!("State quarter from {:?}!", state); + println!("State quarter from {state:?}!"); } else { count += 1; } diff --git a/listings/ch07-managing-growing-projects/quick-reference-example/src/main.rs b/listings/ch07-managing-growing-projects/quick-reference-example/src/main.rs index 7a024a9a0d..0d9a0ca92f 100644 --- a/listings/ch07-managing-growing-projects/quick-reference-example/src/main.rs +++ b/listings/ch07-managing-growing-projects/quick-reference-example/src/main.rs @@ -4,5 +4,5 @@ pub mod garden; fn main() { let plant = Asparagus {}; - println!("I'm growing {:?}!", plant); + println!("I'm growing {plant:?}!"); } diff --git a/listings/ch08-common-collections/listing-08-23/src/main.rs b/listings/ch08-common-collections/listing-08-23/src/main.rs index e8684cf2b6..29025b4177 100644 --- a/listings/ch08-common-collections/listing-08-23/src/main.rs +++ b/listings/ch08-common-collections/listing-08-23/src/main.rs @@ -7,6 +7,6 @@ fn main() { scores.insert(String::from("Blue"), 10); scores.insert(String::from("Blue"), 25); - println!("{:?}", scores); + println!("{scores:?}"); // ANCHOR_END: here } diff --git a/listings/ch08-common-collections/listing-08-24/src/main.rs b/listings/ch08-common-collections/listing-08-24/src/main.rs index 3ad97b57af..013895632e 100644 --- a/listings/ch08-common-collections/listing-08-24/src/main.rs +++ b/listings/ch08-common-collections/listing-08-24/src/main.rs @@ -8,6 +8,6 @@ fn main() { scores.entry(String::from("Yellow")).or_insert(50); scores.entry(String::from("Blue")).or_insert(50); - println!("{:?}", scores); + println!("{scores:?}"); // ANCHOR_END: here } diff --git a/listings/ch08-common-collections/listing-08-25/src/main.rs b/listings/ch08-common-collections/listing-08-25/src/main.rs index f3f6aa166d..84dd1cd4ba 100644 --- a/listings/ch08-common-collections/listing-08-25/src/main.rs +++ b/listings/ch08-common-collections/listing-08-25/src/main.rs @@ -11,6 +11,6 @@ fn main() { *count += 1; } - println!("{:?}", map); + println!("{map:?}"); // ANCHOR_END: here } diff --git a/listings/ch09-error-handling/listing-09-04/src/main.rs b/listings/ch09-error-handling/listing-09-04/src/main.rs index 69da109fe4..832f57f0e6 100644 --- a/listings/ch09-error-handling/listing-09-04/src/main.rs +++ b/listings/ch09-error-handling/listing-09-04/src/main.rs @@ -5,6 +5,6 @@ fn main() { let greeting_file = match greeting_file_result { Ok(file) => file, - Err(error) => panic!("Problem opening the file: {:?}", error), + Err(error) => panic!("Problem opening the file: {error:?}"), }; } diff --git a/listings/ch09-error-handling/listing-09-05/src/main.rs b/listings/ch09-error-handling/listing-09-05/src/main.rs index 83ea01044f..e0bc55c3f1 100644 --- a/listings/ch09-error-handling/listing-09-05/src/main.rs +++ b/listings/ch09-error-handling/listing-09-05/src/main.rs @@ -9,10 +9,10 @@ fn main() { Err(error) => match error.kind() { ErrorKind::NotFound => match File::create("hello.txt") { Ok(fc) => fc, - Err(e) => panic!("Problem creating the file: {:?}", e), + Err(e) => panic!("Problem creating the file: {e:?}"), }, other_error => { - panic!("Problem opening the file: {:?}", other_error); + panic!("Problem opening the file: {other_error:?}"); } }, }; diff --git a/listings/ch09-error-handling/listing-09-13/src/main.rs b/listings/ch09-error-handling/listing-09-13/src/main.rs index 9e07c1ee25..42b7d32ef6 100644 --- a/listings/ch09-error-handling/listing-09-13/src/main.rs +++ b/listings/ch09-error-handling/listing-09-13/src/main.rs @@ -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 } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-01/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-01/src/main.rs index a4dba7ed43..c9e9bbbd21 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-01/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-01/src/main.rs @@ -10,7 +10,7 @@ fn main() { } } - println!("The largest number is {}", largest); + println!("The largest number is {largest}"); // ANCHOR_END: here assert_eq!(*largest, 100); // ANCHOR: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-02/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-02/src/main.rs index 8c523a8be3..fd43154a94 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-02/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-02/src/main.rs @@ -9,7 +9,7 @@ fn main() { } } - println!("The largest number is {}", largest); + println!("The largest number is {largest}"); let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8]; @@ -21,5 +21,5 @@ fn main() { } } - println!("The largest number is {}", largest); + println!("The largest number is {largest}"); } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-03/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-03/src/main.rs index 899222909c..1878f5aacc 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-03/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-03/src/main.rs @@ -15,7 +15,7 @@ fn main() { let number_list = vec![34, 50, 25, 100, 65]; let result = largest(&number_list); - println!("The largest number is {}", result); + println!("The largest number is {result}"); // ANCHOR_END: here assert_eq!(*result, 100); // ANCHOR: here @@ -23,7 +23,7 @@ fn main() { let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8]; let result = largest(&number_list); - println!("The largest number is {}", result); + println!("The largest number is {result}"); // ANCHOR_END: here assert_eq!(*result, 6000); // ANCHOR: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-04/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-04/src/main.rs index a47e3f232c..ac3b1f7c1e 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-04/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-04/src/main.rs @@ -27,7 +27,7 @@ fn main() { let number_list = vec![34, 50, 25, 100, 65]; let result = largest_i32(&number_list); - println!("The largest number is {}", result); + println!("The largest number is {result}"); // ANCHOR_END: here assert_eq!(*result, 100); // ANCHOR: here @@ -35,7 +35,7 @@ fn main() { let char_list = vec!['y', 'm', 'a', 'q']; let result = largest_char(&char_list); - println!("The largest char is {}", result); + println!("The largest char is {result}"); // ANCHOR_END: here assert_eq!(*result, 'y'); // ANCHOR: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/src/main.rs index df33743f78..094eb416a7 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/src/main.rs @@ -14,10 +14,10 @@ fn main() { let number_list = vec![34, 50, 25, 100, 65]; let result = largest(&number_list); - println!("The largest number is {}", result); + println!("The largest number is {result}"); let char_list = vec!['y', 'm', 'a', 'q']; let result = largest(&char_list); - println!("The largest char is {}", result); + println!("The largest char is {result}"); } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/src/main.rs index d71134ea09..773340eabc 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/src/main.rs @@ -6,5 +6,5 @@ fn main() { r = &x; } - println!("r: {}", r); + println!("r: {r}"); } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-17/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-17/src/main.rs index e8ca92328a..6679bcf31e 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-17/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-17/src/main.rs @@ -6,5 +6,5 @@ fn main() { r = &x; // | | } // -+ | // | - println!("r: {}", r); // | + println!("r: {r}"); // | } // ---------+ diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/src/main.rs index 09ae3919cd..634ff9391a 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/src/main.rs @@ -3,6 +3,6 @@ fn main() { // | let r = &x; // --+-- 'a | // | | - println!("r: {}", r); // | | + println!("r: {r}"); // | | // --+ | } // ----------+ diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/src/main.rs index 0f076a71db..8b64cd0008 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/src/main.rs @@ -3,5 +3,5 @@ fn main() { let string2 = "xyz"; let result = longest(string1.as_str(), string2); - println!("The longest string is {}", result); + println!("The longest string is {result}"); } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/src/main.rs index 6af8c9f0da..bf41acd1f1 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/src/main.rs @@ -3,7 +3,7 @@ fn main() { let string2 = "xyz"; let result = longest(string1.as_str(), string2); - println!("The longest string is {}", result); + println!("The longest string is {result}"); } // ANCHOR: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-21/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-21/src/main.rs index 09c3a0daaa..7668de1340 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-21/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-21/src/main.rs @@ -3,7 +3,7 @@ fn main() { let string2 = "xyz"; let result = longest(string1.as_str(), string2); - println!("The longest string is {}", result); + println!("The longest string is {result}"); } // ANCHOR: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-22/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-22/src/main.rs index 836ec72959..fc9ff296cf 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-22/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-22/src/main.rs @@ -5,7 +5,7 @@ fn main() { { let string2 = String::from("xyz"); let result = longest(string1.as_str(), string2.as_str()); - println!("The longest string is {}", result); + println!("The longest string is {result}"); } } // ANCHOR_END: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt index 7f31ce02c4..0cf373f8a4 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt @@ -7,8 +7,8 @@ error[E0597]: `string2` does not live long enough | ^^^^^^^^^^^^^^^^ borrowed value does not live long enough 7 | } | - `string2` dropped here while still borrowed -8 | println!("The longest string is {}", result); - | ------ borrow later used here +8 | println!("The longest string is {result}"); + | ------ borrow later used here For more information about this error, try `rustc --explain E0597`. error: could not compile `chapter10` due to previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/src/main.rs index 2a6fa5898f..f2e6338625 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/src/main.rs @@ -6,7 +6,7 @@ fn main() { let string2 = String::from("xyz"); result = longest(string1.as_str(), string2.as_str()); } - println!("The longest string is {}", result); + println!("The longest string is {result}"); } // ANCHOR_END: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-08-only-one-reference-with-lifetime/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-08-only-one-reference-with-lifetime/src/main.rs index d144305cb0..4c35d90e3a 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-08-only-one-reference-with-lifetime/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-08-only-one-reference-with-lifetime/src/main.rs @@ -3,7 +3,7 @@ fn main() { let string2 = "efghijklmnopqrstuvwxyz"; let result = longest(string1.as_str(), string2); - println!("The longest string is {}", result); + println!("The longest string is {result}"); } // ANCHOR: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/src/main.rs index aca4be0a78..4d596ec434 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/src/main.rs @@ -3,7 +3,7 @@ fn main() { let string2 = "xyz"; let result = longest(string1.as_str(), string2); - println!("The longest string is {}", result); + println!("The longest string is {result}"); } // ANCHOR: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-10-lifetimes-on-methods/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-10-lifetimes-on-methods/src/main.rs index 32ad530b51..b8222308d1 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-10-lifetimes-on-methods/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-10-lifetimes-on-methods/src/main.rs @@ -13,7 +13,7 @@ impl<'a> ImportantExcerpt<'a> { // ANCHOR: 3rd impl<'a> ImportantExcerpt<'a> { fn announce_and_return_part(&self, announcement: &str) -> &str { - println!("Attention please: {}", announcement); + println!("Attention please: {announcement}"); self.part } } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-11-generics-traits-and-lifetimes/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-11-generics-traits-and-lifetimes/src/main.rs index cfafa9a6d3..4b0201fb16 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-11-generics-traits-and-lifetimes/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-11-generics-traits-and-lifetimes/src/main.rs @@ -7,7 +7,7 @@ fn main() { string2, "Today is someone's birthday!", ); - println!("The longest string is {}", result); + println!("The longest string is {result}"); } // ANCHOR: here @@ -21,7 +21,7 @@ fn longest_with_an_announcement<'a, T>( where T: Display, { - println!("Announcement! {}", ann); + println!("Announcement! {ann}"); if x.len() > y.len() { x } else { diff --git a/listings/ch11-writing-automated-tests/listing-11-08/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-08/src/lib.rs index 9391be5b1f..54e447bb93 100644 --- a/listings/ch11-writing-automated-tests/listing-11-08/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-08/src/lib.rs @@ -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 } diff --git a/listings/ch11-writing-automated-tests/listing-11-10/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-10/src/lib.rs index 6fd76ce006..99fc06b8d6 100644 --- a/listings/ch11-writing-automated-tests/listing-11-10/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-10/src/lib.rs @@ -1,5 +1,5 @@ fn prints_and_returns_10(a: i32) -> i32 { - println!("I got the value {}", a); + println!("I got the value {a}"); 10 } diff --git a/listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs index 3ba3d8819e..433cf148ea 100644 --- a/listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs @@ -1,5 +1,5 @@ pub fn greeting(name: &str) -> String { - format!("Hello {}!", name) + format!("Hello {name}!") } #[cfg(test)] diff --git a/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/src/lib.rs index 32540ba83c..0f962fcd79 100644 --- a/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/src/lib.rs @@ -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 } diff --git a/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs b/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs index 43c4c92f9a..462d224709 100644 --- a/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs +++ b/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs @@ -1,5 +1,5 @@ pub fn prints_and_returns_10(a: i32) -> i32 { - println!("I got the value {}", a); + println!("I got the value {a}"); 10 } diff --git a/listings/ch12-an-io-project/listing-12-02/src/main.rs b/listings/ch12-an-io-project/listing-12-02/src/main.rs index ae2fa7bb1b..afc3c3c9f9 100644 --- a/listings/ch12-an-io-project/listing-12-02/src/main.rs +++ b/listings/ch12-an-io-project/listing-12-02/src/main.rs @@ -6,6 +6,6 @@ fn main() { let query = &args[1]; let file_path = &args[2]; - println!("Searching for {}", query); - println!("In file {}", file_path); + println!("Searching for {query}"); + println!("In file {file_path}"); } diff --git a/listings/ch12-an-io-project/listing-12-03/src/main.rs b/listings/ch12-an-io-project/listing-12-03/src/main.rs index ae2fa7bb1b..afc3c3c9f9 100644 --- a/listings/ch12-an-io-project/listing-12-03/src/main.rs +++ b/listings/ch12-an-io-project/listing-12-03/src/main.rs @@ -6,6 +6,6 @@ fn main() { let query = &args[1]; let file_path = &args[2]; - println!("Searching for {}", query); - println!("In file {}", file_path); + println!("Searching for {query}"); + println!("In file {file_path}"); } diff --git a/listings/ch12-an-io-project/listing-12-04/src/main.rs b/listings/ch12-an-io-project/listing-12-04/src/main.rs index 944e4300ec..f343249797 100644 --- a/listings/ch12-an-io-project/listing-12-04/src/main.rs +++ b/listings/ch12-an-io-project/listing-12-04/src/main.rs @@ -10,9 +10,9 @@ fn main() { let query = &args[1]; let file_path = &args[2]; - println!("Searching for {}", query); + println!("Searching for {query}"); // ANCHOR: here - println!("In file {}", file_path); + println!("In file {file_path}"); let contents = fs::read_to_string(file_path) .expect("Should have been able to read the file"); diff --git a/listings/ch12-an-io-project/listing-12-05/src/main.rs b/listings/ch12-an-io-project/listing-12-05/src/main.rs index 0615918338..838cacf39a 100644 --- a/listings/ch12-an-io-project/listing-12-05/src/main.rs +++ b/listings/ch12-an-io-project/listing-12-05/src/main.rs @@ -10,8 +10,8 @@ fn main() { // --snip-- // ANCHOR_END: here - println!("Searching for {}", query); - println!("In file {}", file_path); + println!("Searching for {query}"); + println!("In file {file_path}"); let contents = fs::read_to_string(file_path) .expect("Should have been able to read the file"); diff --git a/listings/ch13-functional-features/listing-13-04/src/main.rs b/listings/ch13-functional-features/listing-13-04/src/main.rs index 43b91bb30e..19f51a6f71 100644 --- a/listings/ch13-functional-features/listing-13-04/src/main.rs +++ b/listings/ch13-functional-features/listing-13-04/src/main.rs @@ -1,10 +1,10 @@ fn main() { let list = vec![1, 2, 3]; - println!("Before defining closure: {:?}", list); + println!("Before defining closure: {list:?}"); - let only_borrows = || println!("From closure: {:?}", list); + let only_borrows = || println!("From closure: {list:?}"); - println!("Before calling closure: {:?}", list); + println!("Before calling closure: {list:?}"); only_borrows(); - println!("After calling closure: {:?}", list); + println!("After calling closure: {list:?}"); } diff --git a/listings/ch13-functional-features/listing-13-05/src/main.rs b/listings/ch13-functional-features/listing-13-05/src/main.rs index 37f8130e2c..f6c2a53de6 100644 --- a/listings/ch13-functional-features/listing-13-05/src/main.rs +++ b/listings/ch13-functional-features/listing-13-05/src/main.rs @@ -1,9 +1,9 @@ fn main() { let mut list = vec![1, 2, 3]; - println!("Before defining closure: {:?}", list); + println!("Before defining closure: {list:?}"); let mut borrows_mutably = || list.push(7); borrows_mutably(); - println!("After calling closure: {:?}", list); + println!("After calling closure: {list:?}"); } diff --git a/listings/ch13-functional-features/listing-13-06/src/main.rs b/listings/ch13-functional-features/listing-13-06/src/main.rs index 2c8e18c9fd..ee9ca04570 100644 --- a/listings/ch13-functional-features/listing-13-06/src/main.rs +++ b/listings/ch13-functional-features/listing-13-06/src/main.rs @@ -2,9 +2,9 @@ use std::thread; fn main() { let list = vec![1, 2, 3]; - println!("Before defining closure: {:?}", list); + println!("Before defining closure: {list:?}"); - thread::spawn(move || println!("From thread: {:?}", list)) + thread::spawn(move || println!("From thread: {list:?}")) .join() .unwrap(); } diff --git a/listings/ch13-functional-features/listing-13-07/src/main.rs b/listings/ch13-functional-features/listing-13-07/src/main.rs index 73a25e5f91..e7ab8d3402 100644 --- a/listings/ch13-functional-features/listing-13-07/src/main.rs +++ b/listings/ch13-functional-features/listing-13-07/src/main.rs @@ -12,5 +12,5 @@ fn main() { ]; list.sort_by_key(|r| r.width); - println!("{:#?}", list); + println!("{list:#?}"); } diff --git a/listings/ch13-functional-features/listing-13-08/src/main.rs b/listings/ch13-functional-features/listing-13-08/src/main.rs index 3b9c9cbdfd..48920d39b4 100644 --- a/listings/ch13-functional-features/listing-13-08/src/main.rs +++ b/listings/ch13-functional-features/listing-13-08/src/main.rs @@ -18,5 +18,5 @@ fn main() { sort_operations.push(value); r.width }); - println!("{:#?}", list); + println!("{list:#?}"); } diff --git a/listings/ch13-functional-features/listing-13-09/src/main.rs b/listings/ch13-functional-features/listing-13-09/src/main.rs index a60d6fd3fc..f007e3c04d 100644 --- a/listings/ch13-functional-features/listing-13-09/src/main.rs +++ b/listings/ch13-functional-features/listing-13-09/src/main.rs @@ -16,5 +16,5 @@ fn main() { num_sort_operations += 1; r.width }); - println!("{:#?}, sorted in {num_sort_operations} operations", list); + println!("{list:#?}, sorted in {num_sort_operations} operations"); } diff --git a/listings/ch13-functional-features/listing-13-11/src/main.rs b/listings/ch13-functional-features/listing-13-11/src/main.rs index 712aff4085..b4e85169ab 100644 --- a/listings/ch13-functional-features/listing-13-11/src/main.rs +++ b/listings/ch13-functional-features/listing-13-11/src/main.rs @@ -5,7 +5,7 @@ fn main() { let v1_iter = v1.iter(); for val in v1_iter { - println!("Got: {}", val); + println!("Got: {val}"); } // ANCHOR_END: here } diff --git a/listings/ch15-smart-pointers/listing-15-01/src/main.rs b/listings/ch15-smart-pointers/listing-15-01/src/main.rs index 8da1d905d6..97f04f3858 100644 --- a/listings/ch15-smart-pointers/listing-15-01/src/main.rs +++ b/listings/ch15-smart-pointers/listing-15-01/src/main.rs @@ -1,4 +1,4 @@ fn main() { let b = Box::new(5); - println!("b = {}", b); + println!("b = {b}"); } diff --git a/listings/ch15-smart-pointers/listing-15-24/src/main.rs b/listings/ch15-smart-pointers/listing-15-24/src/main.rs index e225bd8620..e3dda1a196 100644 --- a/listings/ch15-smart-pointers/listing-15-24/src/main.rs +++ b/listings/ch15-smart-pointers/listing-15-24/src/main.rs @@ -18,7 +18,7 @@ fn main() { *value.borrow_mut() += 10; - println!("a after = {:?}", a); - println!("b after = {:?}", b); - println!("c after = {:?}", c); + println!("a after = {a:?}"); + println!("b after = {b:?}"); + println!("c after = {c:?}"); } diff --git a/listings/ch16-fearless-concurrency/listing-16-01/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-01/src/main.rs index 6305a98e3d..ea10ba282a 100644 --- a/listings/ch16-fearless-concurrency/listing-16-01/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-01/src/main.rs @@ -4,13 +4,13 @@ use std::time::Duration; fn main() { thread::spawn(|| { for i in 1..10 { - println!("hi number {} from the spawned thread!", i); + println!("hi number {i} from the spawned thread!"); thread::sleep(Duration::from_millis(1)); } }); for i in 1..5 { - println!("hi number {} from the main thread!", i); + println!("hi number {i} from the main thread!"); thread::sleep(Duration::from_millis(1)); } } diff --git a/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs index e37607f1d6..33bf53f400 100644 --- a/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs @@ -4,13 +4,13 @@ use std::time::Duration; fn main() { let handle = thread::spawn(|| { for i in 1..10 { - println!("hi number {} from the spawned thread!", i); + println!("hi number {i} from the spawned thread!"); thread::sleep(Duration::from_millis(1)); } }); for i in 1..5 { - println!("hi number {} from the main thread!", i); + println!("hi number {i} from the main thread!"); thread::sleep(Duration::from_millis(1)); } diff --git a/listings/ch16-fearless-concurrency/listing-16-03/output.txt b/listings/ch16-fearless-concurrency/listing-16-03/output.txt index 321bf59d70..3acd5ef098 100644 --- a/listings/ch16-fearless-concurrency/listing-16-03/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-03/output.txt @@ -5,15 +5,15 @@ error[E0373]: closure may outlive the current function, but it borrows `v`, whic | 6 | let handle = thread::spawn(|| { | ^^ may outlive borrowed value `v` -7 | println!("Here's a vector: {:?}", v); - | - `v` is borrowed here +7 | println!("Here's a vector: {v:?}"); + | - `v` is borrowed here | note: function requires argument type to outlive `'static` --> src/main.rs:6:18 | 6 | let handle = thread::spawn(|| { | __________________^ -7 | | println!("Here's a vector: {:?}", v); +7 | | println!("Here's a vector: {v:?}"); 8 | | }); | |______^ help: to force the closure to take ownership of `v` (and any other referenced variables), use the `move` keyword diff --git a/listings/ch16-fearless-concurrency/listing-16-03/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-03/src/main.rs index defc876482..b2231c5b86 100644 --- a/listings/ch16-fearless-concurrency/listing-16-03/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-03/src/main.rs @@ -4,7 +4,7 @@ fn main() { let v = vec![1, 2, 3]; let handle = thread::spawn(|| { - println!("Here's a vector: {:?}", v); + println!("Here's a vector: {v:?}"); }); handle.join().unwrap(); diff --git a/listings/ch16-fearless-concurrency/listing-16-04/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-04/src/main.rs index 0bccc5f56f..f0a9058a1c 100644 --- a/listings/ch16-fearless-concurrency/listing-16-04/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-04/src/main.rs @@ -4,7 +4,7 @@ fn main() { let v = vec![1, 2, 3]; let handle = thread::spawn(|| { - println!("Here's a vector: {:?}", v); + println!("Here's a vector: {v:?}"); }); drop(v); // oh no! diff --git a/listings/ch16-fearless-concurrency/listing-16-05/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-05/src/main.rs index a6547dc4c1..76783e6149 100644 --- a/listings/ch16-fearless-concurrency/listing-16-05/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-05/src/main.rs @@ -4,7 +4,7 @@ fn main() { let v = vec![1, 2, 3]; let handle = thread::spawn(move || { - println!("Here's a vector: {:?}", v); + println!("Here's a vector: {v:?}"); }); handle.join().unwrap(); diff --git a/listings/ch16-fearless-concurrency/listing-16-08/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-08/src/main.rs index fbba9167d4..e7ac452dcd 100644 --- a/listings/ch16-fearless-concurrency/listing-16-08/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-08/src/main.rs @@ -10,5 +10,5 @@ fn main() { }); let received = rx.recv().unwrap(); - println!("Got: {}", received); + println!("Got: {received}"); } diff --git a/listings/ch16-fearless-concurrency/listing-16-09/output.txt b/listings/ch16-fearless-concurrency/listing-16-09/output.txt index db85185372..2add0095e7 100644 --- a/listings/ch16-fearless-concurrency/listing-16-09/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-09/output.txt @@ -7,8 +7,8 @@ error[E0382]: borrow of moved value: `val` | --- move occurs because `val` has type `String`, which does not implement the `Copy` trait 9 | tx.send(val).unwrap(); | --- value moved here -10 | println!("val is {}", val); - | ^^^ value borrowed here after move +10 | println!("val is {val}"); + | ^^^ value borrowed here after move | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/listings/ch16-fearless-concurrency/listing-16-09/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-09/src/main.rs index 98a8129ab3..fe20d3474a 100644 --- a/listings/ch16-fearless-concurrency/listing-16-09/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-09/src/main.rs @@ -7,9 +7,9 @@ fn main() { thread::spawn(move || { let val = String::from("hi"); tx.send(val).unwrap(); - println!("val is {}", val); + println!("val is {val}"); }); let received = rx.recv().unwrap(); - println!("Got: {}", received); + println!("Got: {received}"); } diff --git a/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs index 82b220de45..c9702bd858 100644 --- a/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-10/src/main.rs @@ -20,6 +20,6 @@ fn main() { }); for received in rx { - println!("Got: {}", received); + println!("Got: {received}"); } } diff --git a/listings/ch16-fearless-concurrency/listing-16-11/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-11/src/main.rs index d92deab5cb..174a5d14bb 100644 --- a/listings/ch16-fearless-concurrency/listing-16-11/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-11/src/main.rs @@ -38,7 +38,7 @@ fn main() { }); for received in rx { - println!("Got: {}", received); + println!("Got: {received}"); } // --snip-- diff --git a/listings/ch16-fearless-concurrency/listing-16-12/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-12/src/main.rs index 0c0d6767ad..99ba5b489a 100644 --- a/listings/ch16-fearless-concurrency/listing-16-12/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-12/src/main.rs @@ -8,5 +8,5 @@ fn main() { *num = 6; } - println!("m = {:?}", m); + println!("m = {m:?}"); } diff --git a/listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs b/listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs index 6205e57d33..7023a90f64 100644 --- a/listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs +++ b/listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs @@ -4,7 +4,7 @@ use std::time::Duration; fn main() { let handle = thread::spawn(|| { for i in 1..10 { - println!("hi number {} from the spawned thread!", i); + println!("hi number {i} from the spawned thread!"); thread::sleep(Duration::from_millis(1)); } }); @@ -12,7 +12,7 @@ fn main() { handle.join().unwrap(); for i in 1..5 { - println!("hi number {} from the main thread!", i); + println!("hi number {i} from the main thread!"); thread::sleep(Duration::from_millis(1)); } } diff --git a/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt b/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt index 301a9a44a4..fca5abeb80 100644 --- a/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt +++ b/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt @@ -8,8 +8,8 @@ error[E0382]: use of moved value: `v` 5 | 6 | let handle = thread::spawn(move || { | ------- value moved into closure here -7 | println!("Here's a vector: {:?}", v); - | - variable moved due to use in closure +7 | println!("Here's a vector: {v:?}"); + | - variable moved due to use in closure ... 10 | drop(v); // oh no! | ^ value used here after move diff --git a/listings/ch16-fearless-concurrency/output-only-01-move-drop/src/main.rs b/listings/ch16-fearless-concurrency/output-only-01-move-drop/src/main.rs index 70f659c5f6..cc71cbab0b 100644 --- a/listings/ch16-fearless-concurrency/output-only-01-move-drop/src/main.rs +++ b/listings/ch16-fearless-concurrency/output-only-01-move-drop/src/main.rs @@ -4,7 +4,7 @@ fn main() { let v = vec![1, 2, 3]; let handle = thread::spawn(move || { - println!("Here's a vector: {:?}", v); + println!("Here's a vector: {v:?}"); }); drop(v); // oh no! diff --git a/listings/ch18-patterns-and-matching/listing-18-02/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-02/src/main.rs index 5f75a4f2db..2479d845d6 100644 --- a/listings/ch18-patterns-and-matching/listing-18-02/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-02/src/main.rs @@ -7,7 +7,7 @@ fn main() { stack.push(3); while let Some(top) = stack.pop() { - println!("{}", top); + println!("{top}"); } // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-03/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-03/src/main.rs index eb922d62cd..218c180635 100644 --- a/listings/ch18-patterns-and-matching/listing-18-03/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-03/src/main.rs @@ -3,7 +3,7 @@ fn main() { let v = vec!['a', 'b', 'c']; for (index, value) in v.iter().enumerate() { - println!("{} is at index {}", value, index); + println!("{value} is at index {index}"); } // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-07/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-07/src/main.rs index 4eccb8088c..70069424c6 100644 --- a/listings/ch18-patterns-and-matching/listing-18-07/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-07/src/main.rs @@ -1,5 +1,5 @@ fn print_coordinates(&(x, y): &(i32, i32)) { - println!("Current location: ({}, {})", x, y); + println!("Current location: ({x}, {y})"); } fn main() { diff --git a/listings/ch18-patterns-and-matching/listing-18-09/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-09/src/main.rs index d6274fc0e1..e378c37032 100644 --- a/listings/ch18-patterns-and-matching/listing-18-09/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-09/src/main.rs @@ -2,7 +2,7 @@ fn main() { let some_option_value: Option = None; // ANCHOR: here if let Some(x) = some_option_value { - println!("{}", x); + println!("{x}"); } // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-10/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-10/src/main.rs index cb81772e0c..2073948e7d 100644 --- a/listings/ch18-patterns-and-matching/listing-18-10/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-10/src/main.rs @@ -1,7 +1,7 @@ fn main() { // ANCHOR: here if let x = 5 { - println!("{}", x); + println!("{x}"); }; // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs index db942b7ac7..0552128036 100644 --- a/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs @@ -6,9 +6,9 @@ fn main() { match x { Some(50) => println!("Got 50"), Some(y) => println!("Matched, y = {y}"), - _ => println!("Default case, x = {:?}", x), + _ => println!("Default case, x = {x:?}"), } - println!("at the end: x = {:?}, y = {y}", x); + println!("at the end: x = {x:?}, y = {y}"); // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs index a3138b2277..9407cc16ab 100644 --- a/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs @@ -19,7 +19,7 @@ fn main() { println!("Text message: {text}"); } Message::ChangeColor(r, g, b) => { - println!("Change the color to red {r}, green {g}, and blue {b}",) + println!("Change the color to red {r}, green {g}, and blue {b}") } } } diff --git a/listings/ch18-patterns-and-matching/listing-18-17/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-17/src/main.rs index cf1fbe0721..7053860348 100644 --- a/listings/ch18-patterns-and-matching/listing-18-17/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-17/src/main.rs @@ -1,5 +1,5 @@ fn foo(_: i32, y: i32) { - println!("This code only uses the y parameter: {}", y); + println!("This code only uses the y parameter: {y}"); } fn main() { diff --git a/listings/ch18-patterns-and-matching/listing-18-18/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-18/src/main.rs index b776c64c42..2b8877620a 100644 --- a/listings/ch18-patterns-and-matching/listing-18-18/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-18/src/main.rs @@ -12,6 +12,6 @@ fn main() { } } - println!("setting is {:?}", setting_value); + println!("setting is {setting_value:?}"); // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-21/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-21/src/main.rs index 980610503f..320db62f5f 100644 --- a/listings/ch18-patterns-and-matching/listing-18-21/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-21/src/main.rs @@ -6,6 +6,6 @@ fn main() { println!("found a string"); } - println!("{:?}", s); + println!("{s:?}"); // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-22/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-22/src/main.rs index e2faa345bc..9df1492b29 100644 --- a/listings/ch18-patterns-and-matching/listing-18-22/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-22/src/main.rs @@ -6,6 +6,6 @@ fn main() { println!("found a string"); } - println!("{:?}", s); + println!("{s:?}"); // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-23/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-23/src/main.rs index 7a9d9bb36f..491d6c53f8 100644 --- a/listings/ch18-patterns-and-matching/listing-18-23/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-23/src/main.rs @@ -9,7 +9,7 @@ fn main() { let origin = Point { x: 0, y: 0, z: 0 }; match origin { - Point { x, .. } => println!("x is {}", x), + Point { x, .. } => println!("x is {x}"), } // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-25/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-25/src/main.rs index b90884eb9c..6c3b24b7db 100644 --- a/listings/ch18-patterns-and-matching/listing-18-25/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-25/src/main.rs @@ -3,7 +3,7 @@ fn main() { match numbers { (.., second, ..) => { - println!("Some numbers: {}", second) + println!("Some numbers: {second}") }, } } diff --git a/listings/ch18-patterns-and-matching/listing-18-26/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-26/src/main.rs index 41fce97950..2566169a7d 100644 --- a/listings/ch18-patterns-and-matching/listing-18-26/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-26/src/main.rs @@ -3,8 +3,8 @@ fn main() { let num = Some(4); match num { - Some(x) if x % 2 == 0 => println!("The number {} is even", x), - Some(x) => println!("The number {} is odd", x), + Some(x) if x % 2 == 0 => println!("The number {x} is even"), + Some(x) => println!("The number {x} is odd"), None => (), } // ANCHOR_END: here diff --git a/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs index 8386a0ab8f..06fd949964 100644 --- a/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs @@ -5,8 +5,8 @@ fn main() { match x { Some(50) => println!("Got 50"), Some(n) if n == y => println!("Matched, n = {n}"), - _ => println!("Default case, x = {:?}", x), + _ => println!("Default case, x = {x:?}"), } - println!("at the end: x = {:?}, y = {y}", x); + println!("at the end: x = {x:?}, y = {y}"); } diff --git a/listings/ch18-patterns-and-matching/listing-18-29/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-29/src/main.rs index 3514deb636..e36fda8789 100644 --- a/listings/ch18-patterns-and-matching/listing-18-29/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-29/src/main.rs @@ -9,11 +9,11 @@ fn main() { match msg { Message::Hello { id: id_variable @ 3..=7, - } => println!("Found an id in range: {}", id_variable), + } => println!("Found an id in range: {id_variable}"), Message::Hello { id: 10..=12 } => { println!("Found an id in another range") } - Message::Hello { id } => println!("Found some other id: {}", id), + Message::Hello { id } => println!("Found some other id: {id}"), } // ANCHOR_END: here } diff --git a/listings/ch19-advanced-features/listing-19-09/src/main.rs b/listings/ch19-advanced-features/listing-19-09/src/main.rs index 82a4b4219f..fda5179af7 100644 --- a/listings/ch19-advanced-features/listing-19-09/src/main.rs +++ b/listings/ch19-advanced-features/listing-19-09/src/main.rs @@ -1,5 +1,5 @@ static HELLO_WORLD: &str = "Hello, world!"; fn main() { - println!("name is: {}", HELLO_WORLD); + println!("name is: {HELLO_WORLD}"); } diff --git a/listings/ch19-advanced-features/listing-19-10/src/main.rs b/listings/ch19-advanced-features/listing-19-10/src/main.rs index e8dab68e0d..b5559fd3a5 100644 --- a/listings/ch19-advanced-features/listing-19-10/src/main.rs +++ b/listings/ch19-advanced-features/listing-19-10/src/main.rs @@ -10,6 +10,6 @@ fn main() { add_to_count(3); unsafe { - println!("COUNTER: {}", COUNTER); + println!("COUNTER: {COUNTER}"); } } diff --git a/listings/ch19-advanced-features/listing-19-22/src/main.rs b/listings/ch19-advanced-features/listing-19-22/src/main.rs index febe58b0c5..7069fef179 100644 --- a/listings/ch19-advanced-features/listing-19-22/src/main.rs +++ b/listings/ch19-advanced-features/listing-19-22/src/main.rs @@ -7,7 +7,7 @@ trait OutlinePrint: fmt::Display { let len = output.len(); println!("{}", "*".repeat(len + 4)); println!("*{}*", " ".repeat(len + 2)); - println!("* {} *", output); + println!("* {output} *"); println!("*{}*", " ".repeat(len + 2)); println!("{}", "*".repeat(len + 4)); } diff --git a/listings/ch19-advanced-features/listing-19-23/src/main.rs b/listings/ch19-advanced-features/listing-19-23/src/main.rs index eae46c92f3..f8c8366b4c 100644 --- a/listings/ch19-advanced-features/listing-19-23/src/main.rs +++ b/listings/ch19-advanced-features/listing-19-23/src/main.rs @@ -10,5 +10,5 @@ impl fmt::Display for Wrapper { fn main() { let w = Wrapper(vec![String::from("hello"), String::from("world")]); - println!("w = {}", w); + println!("w = {w}"); } diff --git a/listings/ch19-advanced-features/listing-19-27/src/main.rs b/listings/ch19-advanced-features/listing-19-27/src/main.rs index 91b2cf04bf..312df2412f 100644 --- a/listings/ch19-advanced-features/listing-19-27/src/main.rs +++ b/listings/ch19-advanced-features/listing-19-27/src/main.rs @@ -9,5 +9,5 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 { fn main() { let answer = do_twice(add_one, 5); - println!("The answer is: {}", answer); + println!("The answer is: {answer}"); } diff --git a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/src/main.rs b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/src/main.rs index a1e2fe4c46..0e45f3c283 100644 --- a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/src/main.rs +++ b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/src/main.rs @@ -6,7 +6,7 @@ trait OutlinePrint: fmt::Display { let len = output.len(); println!("{}", "*".repeat(len + 4)); println!("*{}*", " ".repeat(len + 2)); - println!("* {} *", output); + println!("* {output} *"); println!("*{}*", " ".repeat(len + 2)); println!("{}", "*".repeat(len + 4)); } diff --git a/listings/ch19-advanced-features/no-listing-03-impl-display-for-point/src/main.rs b/listings/ch19-advanced-features/no-listing-03-impl-display-for-point/src/main.rs index c7bbb6a708..fa5be1c7cf 100644 --- a/listings/ch19-advanced-features/no-listing-03-impl-display-for-point/src/main.rs +++ b/listings/ch19-advanced-features/no-listing-03-impl-display-for-point/src/main.rs @@ -4,7 +4,7 @@ trait OutlinePrint: fmt::Display { let len = output.len(); println!("{}", "*".repeat(len + 4)); println!("*{}*", " ".repeat(len + 2)); - println!("* {} *", output); + println!("* {output} *"); println!("*{}*", " ".repeat(len + 2)); println!("{}", "*".repeat(len + 4)); } diff --git a/listings/ch20-web-server/listing-20-02/src/main.rs b/listings/ch20-web-server/listing-20-02/src/main.rs index 7240c73c7f..f139846c6d 100644 --- a/listings/ch20-web-server/listing-20-02/src/main.rs +++ b/listings/ch20-web-server/listing-20-02/src/main.rs @@ -21,5 +21,5 @@ fn handle_connection(mut stream: TcpStream) { .take_while(|line| !line.is_empty()) .collect(); - println!("Request: {:#?}", http_request); + println!("Request: {http_request:#?}"); } diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 2ee006f09d..2dd864f08c 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -147,10 +147,10 @@ the missing file error. > let greeting_file = File::open("hello.txt").unwrap_or_else(|error| { > if error.kind() == ErrorKind::NotFound { > File::create("hello.txt").unwrap_or_else(|error| { -> panic!("Problem creating the file: {:?}", error); +> panic!("Problem creating the file: {error:?}"); > }) > } else { -> panic!("Problem opening the file: {:?}", error); +> panic!("Problem opening the file: {error:?}"); > } > }); > } diff --git a/tools/doc-to-md.sh b/tools/doc-to-md.sh index 8c802a71fa..2649460065 100755 --- a/tools/doc-to-md.sh +++ b/tools/doc-to-md.sh @@ -22,7 +22,7 @@ directory, so all fixes need to be made in `/src/`. unzip -o "tmp/$filename.docx" -d "tmp/$filename" # Convert to markdown with XSL. xsltproc tools/docx-to-md.xsl "tmp/$filename/word/document.xml" | \ - # Hard wrap at 80 chars at word bourdaries. + # Hard wrap at 80 chars at word boundaries. fold -w 80 -s | \ # Remove trailing whitespace and append to the file in the `nostarch` dir for comparison. sed -e "s/ *$//" >> "nostarch/$filename.md" diff --git a/tools/src/bin/link2print.rs b/tools/src/bin/link2print.rs index 1e92ecbccd..c57d788d21 100644 --- a/tools/src/bin/link2print.rs +++ b/tools/src/bin/link2print.rs @@ -71,13 +71,13 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String { Some(key) => { match key.as_str() { // `[name][]` - "" => ref_map.get(&name.to_uppercase()).unwrap_or_else(|| panic!("could not find url for the link text `{}`", name)).to_string(), + "" => ref_map.get(&name.to_uppercase()).unwrap_or_else(|| panic!("could not find url for the link text `{name}`")).to_string(), // `[name][reference]` _ => ref_map.get(&key.as_str().to_uppercase()).unwrap_or_else(|| panic!("could not find url for the link text `{}`", key.as_str())).to_string(), } } // `[name]` as reference - None => ref_map.get(&name.to_uppercase()).unwrap_or_else(|| panic!("could not find url for the link text `{}`", name)).to_string(), + None => ref_map.get(&name.to_uppercase()).unwrap_or_else(|| panic!("could not find url for the link text `{name}`")).to_string(), } } }; From a786ec4a2b602c3d8d3a0693711814b0a7d657a1 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 5 Feb 2022 21:36:35 -0500 Subject: [PATCH 066/720] Use v1.58 captured ident formatting in examples Per https://github.com/rust-lang/book/issues/3047, use captured identifiers instead of the positional ones for some examples, e.g. ```diff - println!("Worker {} got a job; executing.", id); + println!("Worker {id} got a job; executing."); ``` --- .../ch04-understanding-ownership/listing-04-05/src/main.rs | 2 +- .../no-listing-05-clone/src/main.rs | 2 +- .../no-listing-06-copy/src/main.rs | 2 +- .../no-listing-07-reference/src/main.rs | 2 +- .../no-listing-08-reference-with-annotations/src/main.rs | 2 +- .../no-listing-09-variable-in-pattern/src/main.rs | 2 +- .../no-listing-13-count-and-announce-match/src/main.rs | 2 +- .../src/main.rs | 2 +- .../no-listing-05-greeter/src/lib.rs | 2 +- .../ch16-fearless-concurrency/listing-16-01/src/main.rs | 4 ++-- .../ch16-fearless-concurrency/listing-16-02/src/main.rs | 4 ++-- .../no-listing-01-join-too-early/src/main.rs | 4 ++-- .../ch18-patterns-and-matching/listing-18-11/src/main.rs | 4 ++-- .../ch18-patterns-and-matching/listing-18-27/src/main.rs | 2 +- redirects/loops.md | 6 +++--- 15 files changed, 21 insertions(+), 21 deletions(-) diff --git a/listings/ch04-understanding-ownership/listing-04-05/src/main.rs b/listings/ch04-understanding-ownership/listing-04-05/src/main.rs index 22aee1419e..2782483a77 100644 --- a/listings/ch04-understanding-ownership/listing-04-05/src/main.rs +++ b/listings/ch04-understanding-ownership/listing-04-05/src/main.rs @@ -3,7 +3,7 @@ fn main() { let (s2, len) = calculate_length(s1); - println!("The length of '{}' is {}.", s2, len); + println!("The length of '{s2}' is {len}."); } fn calculate_length(s: String) -> (String, usize) { diff --git a/listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs b/listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs index 4e61cc1a16..0b65e5f611 100644 --- a/listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs @@ -3,6 +3,6 @@ fn main() { let s1 = String::from("hello"); let s2 = s1.clone(); - println!("s1 = {}, s2 = {}", s1, s2); + println!("s1 = {s1}, s2 = {s2}"); // ANCHOR_END: here } diff --git a/listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs b/listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs index 63a1fae248..b6fd2445d0 100644 --- a/listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs @@ -3,6 +3,6 @@ fn main() { let x = 5; let y = x; - println!("x = {}, y = {}", x, y); + println!("x = {x}, y = {y}"); // ANCHOR_END: here } diff --git a/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs b/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs index fd32a5fc95..6f6d5fb239 100644 --- a/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs @@ -6,7 +6,7 @@ fn main() { let len = calculate_length(&s1); // ANCHOR_END: here - println!("The length of '{}' is {}.", s1, len); + println!("The length of '{s1}' is {len}."); } fn calculate_length(s: &String) -> usize { diff --git a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs index 6686a801c0..964fd233f7 100644 --- a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs @@ -3,7 +3,7 @@ fn main() { let len = calculate_length(&s1); - println!("The length of '{}' is {}.", s1, len); + println!("The length of '{s1}' is {len}."); } // ANCHOR: here diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs b/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs index a4d500c11c..298215d405 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs +++ b/listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs @@ -19,7 +19,7 @@ fn value_in_cents(coin: Coin) -> u8 { Coin::Nickel => 5, Coin::Dime => 10, Coin::Quarter(state) => { - println!("State quarter from {:?}!", state); + println!("State quarter from {state:?}!"); 25 } } diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs b/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs index 12c4c0fec1..d0d7d80271 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs +++ b/listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs @@ -17,7 +17,7 @@ fn main() { // ANCHOR: here let mut count = 0; match coin { - Coin::Quarter(state) => println!("State quarter from {:?}!", state), + Coin::Quarter(state) => println!("State quarter from {state:?}!"), _ => count += 1, } // ANCHOR_END: here diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs b/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs index ba7eda27b4..3bb3630350 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs +++ b/listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs @@ -17,7 +17,7 @@ fn main() { // ANCHOR: here let mut count = 0; if let Coin::Quarter(state) = coin { - println!("State quarter from {:?}!", state); + println!("State quarter from {state:?}!"); } else { count += 1; } diff --git a/listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs index 3ba3d8819e..433cf148ea 100644 --- a/listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs @@ -1,5 +1,5 @@ pub fn greeting(name: &str) -> String { - format!("Hello {}!", name) + format!("Hello {name}!") } #[cfg(test)] diff --git a/listings/ch16-fearless-concurrency/listing-16-01/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-01/src/main.rs index 6305a98e3d..ea10ba282a 100644 --- a/listings/ch16-fearless-concurrency/listing-16-01/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-01/src/main.rs @@ -4,13 +4,13 @@ use std::time::Duration; fn main() { thread::spawn(|| { for i in 1..10 { - println!("hi number {} from the spawned thread!", i); + println!("hi number {i} from the spawned thread!"); thread::sleep(Duration::from_millis(1)); } }); for i in 1..5 { - println!("hi number {} from the main thread!", i); + println!("hi number {i} from the main thread!"); thread::sleep(Duration::from_millis(1)); } } diff --git a/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs index e37607f1d6..33bf53f400 100644 --- a/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs @@ -4,13 +4,13 @@ use std::time::Duration; fn main() { let handle = thread::spawn(|| { for i in 1..10 { - println!("hi number {} from the spawned thread!", i); + println!("hi number {i} from the spawned thread!"); thread::sleep(Duration::from_millis(1)); } }); for i in 1..5 { - println!("hi number {} from the main thread!", i); + println!("hi number {i} from the main thread!"); thread::sleep(Duration::from_millis(1)); } diff --git a/listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs b/listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs index 6205e57d33..7023a90f64 100644 --- a/listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs +++ b/listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs @@ -4,7 +4,7 @@ use std::time::Duration; fn main() { let handle = thread::spawn(|| { for i in 1..10 { - println!("hi number {} from the spawned thread!", i); + println!("hi number {i} from the spawned thread!"); thread::sleep(Duration::from_millis(1)); } }); @@ -12,7 +12,7 @@ fn main() { handle.join().unwrap(); for i in 1..5 { - println!("hi number {} from the main thread!", i); + println!("hi number {i} from the main thread!"); thread::sleep(Duration::from_millis(1)); } } diff --git a/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs index db942b7ac7..0552128036 100644 --- a/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs @@ -6,9 +6,9 @@ fn main() { match x { Some(50) => println!("Got 50"), Some(y) => println!("Matched, y = {y}"), - _ => println!("Default case, x = {:?}", x), + _ => println!("Default case, x = {x:?}"), } - println!("at the end: x = {:?}, y = {y}", x); + println!("at the end: x = {x:?}, y = {y}"); // ANCHOR_END: here } diff --git a/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs b/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs index 8386a0ab8f..d4748fb154 100644 --- a/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs +++ b/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs @@ -5,7 +5,7 @@ fn main() { match x { Some(50) => println!("Got 50"), Some(n) if n == y => println!("Matched, n = {n}"), - _ => println!("Default case, x = {:?}", x), + _ => println!("Default case, x = {x:?}"), } println!("at the end: x = {:?}, y = {y}", x); diff --git a/redirects/loops.md b/redirects/loops.md index 1686c115ee..30c7d4059f 100644 --- a/redirects/loops.md +++ b/redirects/loops.md @@ -14,17 +14,17 @@ loop { let mut number = 3; while number != 0 { - println!("{}!", number); + println!("{number}!"); number = number - 1; } let a = [10, 20, 30, 40, 50]; for element in a.iter() { - println!("the value is: {}", element); + println!("the value is: {element}"); } ``` --- You can find the latest version of this information -[here](ch03-05-control-flow.html#repetition-with-loops). \ No newline at end of file +[here](ch03-05-control-flow.html#repetition-with-loops). From 5b6c1ceaa62ecbd6caef08df39b33b3938e99deb Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 31 Oct 2023 09:22:17 +1100 Subject: [PATCH 067/720] Prepare for removal of compiler plugin support. https://github.com/rust-lang/rust/pull/116412 will remove support for compiler plugins from rustc, which includes the entry in The Rust Unstable Book. This commit removes a link to that entry so it won't be broken when that PR merges. --- redirects/compiler-plugins.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/redirects/compiler-plugins.md b/redirects/compiler-plugins.md index 66061adf5a..67187f5f6b 100644 --- a/redirects/compiler-plugins.md +++ b/redirects/compiler-plugins.md @@ -2,12 +2,5 @@ There is a new edition of the book and this is an old link. -> Compiler plugins are user-provided libraries that extend the compiler's behavior with new syntax extensions, lint checks, etc. - ---- - -This particular chapter has moved to [the Unstable Book][2]. - -* **[In the Unstable Rust Book: `plugin`][2]** - -[2]: ../unstable-book/language-features/plugin.html +> Compiler plugins were user-provided libraries that extended the compiler's behavior in certain ways. +> Support for them has been removed. From 81255e776b0daacfb65adf7c903e90e3fb7d0a24 Mon Sep 17 00:00:00 2001 From: Marcus Stollsteimer Date: Sat, 4 Nov 2023 14:32:25 +0100 Subject: [PATCH 068/720] Update panic! formatting style for Guess example --- listings/ch09-error-handling/listing-09-13/src/main.rs | 2 +- .../ch11-writing-automated-tests/listing-11-08/src/lib.rs | 2 +- .../ch11-writing-automated-tests/listing-11-09/src/lib.rs | 6 ++---- .../no-listing-08-guess-with-bug/src/lib.rs | 2 +- .../no-listing-09-guess-with-panic-msg-bug/src/lib.rs | 6 ++---- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/listings/ch09-error-handling/listing-09-13/src/main.rs b/listings/ch09-error-handling/listing-09-13/src/main.rs index 9e07c1ee25..42b7d32ef6 100644 --- a/listings/ch09-error-handling/listing-09-13/src/main.rs +++ b/listings/ch09-error-handling/listing-09-13/src/main.rs @@ -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 } diff --git a/listings/ch11-writing-automated-tests/listing-11-08/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-08/src/lib.rs index 9391be5b1f..54e447bb93 100644 --- a/listings/ch11-writing-automated-tests/listing-11-08/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-08/src/lib.rs @@ -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 } diff --git a/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs index cc1c5c35d0..1bb464137b 100644 --- a/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs @@ -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}." ); } diff --git a/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/src/lib.rs index 32540ba83c..0f962fcd79 100644 --- a/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/src/lib.rs @@ -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 } diff --git a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs index 7703dd75ae..fb5fc0e77b 100644 --- a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs @@ -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 From d0473bee36c64303989075bd61abe4ada42fed0f Mon Sep 17 00:00:00 2001 From: Marcus Stollsteimer Date: Sun, 5 Nov 2023 22:25:22 +0100 Subject: [PATCH 069/720] Fix mdBook links --- CONTRIBUTING.md | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a58ea42038..a20cb58501 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,4 +70,4 @@ a new language! We're waiting on [mdbook support] for multiple languages before we merge any in, but feel free to start! [Translations]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations -[mdbook support]: https://github.com/rust-lang-nursery/mdBook/issues/5 +[mdbook support]: https://github.com/rust-lang/mdBook/issues/5 diff --git a/README.md b/README.md index f6341efc9c..c70c85e727 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ See the [releases] to download just the code of all the code listings that appea Building the book requires [mdBook], ideally the same version that rust-lang/rust uses in [this file][rust-mdbook]. To get it: -[mdBook]: https://github.com/rust-lang-nursery/mdBook +[mdBook]: https://github.com/rust-lang/mdBook [rust-mdbook]: https://github.com/rust-lang/rust/blob/master/src/tools/rustbook/Cargo.toml ```bash @@ -93,7 +93,7 @@ a new language! We're waiting on [mdbook support] for multiple languages before we merge any in, but feel free to start! [Translations]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations -[mdbook support]: https://github.com/rust-lang-nursery/mdBook/issues/5 +[mdbook support]: https://github.com/rust-lang/mdBook/issues/5 ## Spellchecking From 44c783863ad2e587f19a8c54ace153b79e883958 Mon Sep 17 00:00:00 2001 From: Aryan Malik Date: Wed, 8 Nov 2023 00:04:02 +0530 Subject: [PATCH 070/720] Fixed 'troubleshooting' link --- src/ch01-02-hello-world.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index 8d8d754d7b..9cbbc514ca 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -102,7 +102,7 @@ first line declares a function named `main` that has no parameters and returns nothing. If there were parameters, they would go inside the parentheses `()`. The function body is wrapped in `{}`. Rust requires curly brackets around all -function bodies. It’s good style to place the opening curly bracket on the same +function bodies. It’s a good style to place the opening curly bracket on the same line as the function declaration, adding one space in between. > Note: If you want to stick to a standard style across Rust projects, you can @@ -197,5 +197,5 @@ grows, you’ll want to manage all the options and make it easy to share your code. Next, we’ll introduce you to the Cargo tool, which will help you write real-world Rust programs. -[troubleshooting]: ch01-01-installation.html#troubleshooting +[troubleshooting]: ch01-01-installation.md#troubleshooting [devtools]: appendix-04-useful-development-tools.md From 98f0eefaaa7474d645c8c3ea51a25e71851f8586 Mon Sep 17 00:00:00 2001 From: Aryan Malik Date: Wed, 8 Nov 2023 22:27:52 +0530 Subject: [PATCH 071/720] Update ch01-02-hello-world.md --- src/ch01-02-hello-world.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index 9cbbc514ca..fd4ebfce94 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -102,7 +102,7 @@ first line declares a function named `main` that has no parameters and returns nothing. If there were parameters, they would go inside the parentheses `()`. The function body is wrapped in `{}`. Rust requires curly brackets around all -function bodies. It’s a good style to place the opening curly bracket on the same +function bodies. It’s good style to place the opening curly bracket on the same line as the function declaration, adding one space in between. > Note: If you want to stick to a standard style across Rust projects, you can @@ -198,4 +198,4 @@ code. Next, we’ll introduce you to the Cargo tool, which will help you write real-world Rust programs. [troubleshooting]: ch01-01-installation.md#troubleshooting -[devtools]: appendix-04-useful-development-tools.md +[devtools]: appendix-04-useful-development-tools.html From 71352deb20727b4dda9ebfe8182709d5bf17dfea Mon Sep 17 00:00:00 2001 From: Aryan Malik Date: Wed, 8 Nov 2023 23:22:24 +0530 Subject: [PATCH 072/720] Update ch01-02-hello-world.md --- src/ch01-02-hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index fd4ebfce94..f291463799 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -197,5 +197,5 @@ grows, you’ll want to manage all the options and make it easy to share your code. Next, we’ll introduce you to the Cargo tool, which will help you write real-world Rust programs. -[troubleshooting]: ch01-01-installation.md#troubleshooting +[troubleshooting]: ch01-01-installation.html#troubleshooting [devtools]: appendix-04-useful-development-tools.html From f082dde4e5bfcef53b27b5541c63f6fb6f726c90 Mon Sep 17 00:00:00 2001 From: Marcus Stollsteimer Date: Sat, 18 Nov 2023 20:10:30 +0100 Subject: [PATCH 073/720] Small correction in ch13-01 Fix description: the example tries to count the number of times `sort_by_key` calls the closure, not how often `sort_by_key` is called. Also, use a clearer String value in the example code. --- listings/ch13-functional-features/listing-13-08/output.txt | 2 +- listings/ch13-functional-features/listing-13-08/src/main.rs | 2 +- src/ch13-01-closures.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/listings/ch13-functional-features/listing-13-08/output.txt b/listings/ch13-functional-features/listing-13-08/output.txt index a910537667..8ebb87026b 100644 --- a/listings/ch13-functional-features/listing-13-08/output.txt +++ b/listings/ch13-functional-features/listing-13-08/output.txt @@ -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| { diff --git a/listings/ch13-functional-features/listing-13-08/src/main.rs b/listings/ch13-functional-features/listing-13-08/src/main.rs index 3b9c9cbdfd..1b60f1f6ad 100644 --- a/listings/ch13-functional-features/listing-13-08/src/main.rs +++ b/listings/ch13-functional-features/listing-13-08/src/main.rs @@ -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); diff --git a/src/ch13-01-closures.md b/src/ch13-01-closures.md index f1ae324354..d9e3ac6841 100644 --- a/src/ch13-01-closures.md +++ b/src/ch13-01-closures.md @@ -382,7 +382,7 @@ compiler won’t let us use this closure with `sort_by_key`: `sort_by_key` 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 @@ -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 From 6bc227c9a4d944c7a4b5721c27738065c54a41c4 Mon Sep 17 00:00:00 2001 From: Blatko1 Date: Thu, 30 Nov 2023 22:52:39 +0100 Subject: [PATCH 074/720] improvements --- src/appendix-01-keywords.md | 10 ++++---- src/appendix-02-operators.md | 4 +-- src/appendix-03-derivable-traits.md | 10 ++++---- src/appendix-04-useful-development-tools.md | 9 +++---- src/appendix-05-editions.md | 4 +-- src/appendix-07-nightly-rust.md | 9 +++---- src/ch00-00-introduction.md | 28 ++++++++++----------- src/ch01-01-installation.md | 10 ++++---- src/ch01-02-hello-world.md | 8 +++--- 9 files changed, 45 insertions(+), 47 deletions(-) diff --git a/src/appendix-01-keywords.md b/src/appendix-01-keywords.md index b848945915..0cbaf316a5 100644 --- a/src/appendix-01-keywords.md +++ b/src/appendix-01-keywords.md @@ -2,7 +2,7 @@ The following list contains keywords that are reserved for current or future use by the Rust language. As such, they cannot be used as identifiers (except -as raw identifiers as we’ll discuss in the “[Raw +as raw identifiers, as we’ll discuss in the “[Raw Identifiers][raw-identifiers]” section). Identifiers are names of functions, variables, parameters, struct fields, modules, crates, constants, macros, static values, attributes, types, traits, or lifetimes. @@ -81,7 +81,7 @@ Rust for potential future use. ### Raw Identifiers *Raw identifiers* are the syntax that lets you use keywords where they wouldn’t -normally be allowed. You use a raw identifier by prefixing a keyword with `r#`. +usually be allowed. You use a raw identifier by prefixing a keyword with `r#`. For example, `match` is a keyword. If you try to compile the following function that uses `match` as its name: @@ -106,7 +106,7 @@ error: expected identifier, found keyword `match` The error shows that you can’t use the keyword `match` as the function identifier. To use `match` as a function name, you need to use the raw -identifier syntax, like this: +identifier syntax like this: Filename: src/main.rs @@ -121,11 +121,11 @@ fn main() { ``` This code will compile without any errors. Note the `r#` prefix on the function -name in its definition as well as where the function is called in `main`. +name in its definition, as well as where the function is called in `main`. Raw identifiers allow you to use any word you choose as an identifier, even if that word happens to be a reserved keyword. This gives us more freedom to -choose identifier names, as well as lets us integrate with programs written in +choose identifier names and lets us integrate with programs written in a language where these words aren’t keywords. In addition, raw identifiers allow you to use libraries written in a different Rust edition than your crate uses. For example, `try` isn’t a keyword in the 2015 edition but is in the 2018 diff --git a/src/appendix-02-operators.md b/src/appendix-02-operators.md index bc770c703e..eff7f1de65 100644 --- a/src/appendix-02-operators.md +++ b/src/appendix-02-operators.md @@ -87,7 +87,7 @@ locations. | `"..."` | String literal | | `r"..."`, `r#"..."#`, `r##"..."##`, etc. | Raw string literal, escape characters not processed | | `b"..."` | Byte string literal; constructs an array of bytes instead of a string | -| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, combination of raw and byte string literal | +| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, a combination of raw and byte string literal | | `'...'` | Character literal | | `b'...'` | ASCII byte literal | | |...| expr | Closure | @@ -119,7 +119,7 @@ parameters. | Symbol | Explanation | |--------|-------------| | `path<...>` | Specifies parameters to generic type in a type (e.g., `Vec`) | -| `path::<...>`, `method::<...>` | Specifies parameters to generic type, function, or method in an expression; often referred to as turbofish (e.g., `"42".parse::()`) | +| `path::<...>`, `method::<...>` | Specifies parameters to a generic type, function, or method in an expression; often referred to as turbofish (e.g., `"42".parse::()`) | | `fn ident<...> ...` | Define generic function | | `struct ident<...> ...` | Define generic structure | | `enum ident<...> ...` | Define generic enumeration | diff --git a/src/appendix-03-derivable-traits.md b/src/appendix-03-derivable-traits.md index 299796dbf7..3677281d75 100644 --- a/src/appendix-03-derivable-traits.md +++ b/src/appendix-03-derivable-traits.md @@ -21,7 +21,7 @@ for each trait for details of how to manually implement them. These traits listed here are the only ones defined by the standard library that can be implemented on your types using `derive`. Other traits defined in the standard library don’t have sensible default behavior, so it’s up to you to -implement them in the way that makes sense for what you’re trying to accomplish. +implement them in a way that makes sense for what you’re trying to accomplish. An example of a trait that can’t be derived is `Display`, which handles formatting for end users. You should always consider the appropriate way to @@ -45,7 +45,7 @@ The `Debug` trait allows you to print instances of a type for debugging purposes, so you and other programmers using your type can inspect an instance at a particular point in a program’s execution. -The `Debug` trait is required, for example, in use of the `assert_eq!` macro. +The `Debug` trait is required, for example, in using the `assert_eq!` macro. This macro prints the values of instances given as arguments if the equality assertion fails so programmers can see why the two instances weren’t equal. @@ -71,14 +71,14 @@ number types: the implementation of floating point numbers states that two instances of the not-a-number (`NaN`) value are not equal to each other. An example of when `Eq` is required is for keys in a `HashMap` so the -`HashMap` can tell whether two keys are the same. +`HashMap` can tell whether two keys are identical. ### `PartialOrd` and `Ord` for Ordering Comparisons The `PartialOrd` trait allows you to compare instances of a type for sorting purposes. A type that implements `PartialOrd` can be used with the `<`, `>`, `<=`, and `>=` operators. You can only apply the `PartialOrd` trait to types -that also implement `PartialEq`. +that implement `PartialEq`. Deriving `PartialOrd` implements the `partial_cmp` method, which returns an `Option` that will be `None` when the values given don’t produce an @@ -115,7 +115,7 @@ data. See the [“Ways Variables and Data Interact: Clone”][ways-variables-and-data-interact-clone] section in Chapter 4 for more information on `Clone`. -Deriving `Clone` implements the `clone` method, which when implemented for the +Deriving `Clone` implements the `clone` method, which, when implemented for the whole type, calls `clone` on each of the parts of the type. This means all the fields or values in the type must also implement `Clone` to derive `Clone`. diff --git a/src/appendix-04-useful-development-tools.md b/src/appendix-04-useful-development-tools.md index 40b076153d..b36ab7d950 100644 --- a/src/appendix-04-useful-development-tools.md +++ b/src/appendix-04-useful-development-tools.md @@ -1,6 +1,6 @@ ## Appendix D - Useful Development Tools -In this appendix, we talk about some useful development tools that the Rust +In this appendix, we talk about some useful development tools the Rust project provides. We’ll look at automatic formatting, quick ways to apply warning fixes, a linter, and integrating with IDEs. @@ -32,8 +32,7 @@ on `rustfmt`, see [its documentation][rustfmt]. ### Fix Your Code with `rustfix` The rustfix tool is included with Rust installations and can automatically fix -compiler warnings that have a clear way to correct the problem that’s likely -what you want. It’s likely you’ve seen compiler warnings before. For example, +compiler warnings that have a clear way to correct the problem in a way you likely want. It’s likely you’ve seen compiler warnings before. For example, consider this code: Filename: src/main.rs @@ -66,7 +65,7 @@ warning: unused variable: `i` ``` The warning suggests that we use `_i` as a name instead: the underscore -indicates that we intend for this variable to be unused. We can automatically +indicates that we intend this variable to be unused. We can automatically apply that suggestion using the `rustfix` tool by running the command `cargo fix`: @@ -138,7 +137,7 @@ error: approximate value of `f{32, 64}::consts::PI` found | = note: `#[deny(clippy::approx_constant)]` on by default = help: consider using the constant directly - = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant + = help: for further information, visit https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant ``` This error lets you know that Rust already has a more precise `PI` constant diff --git a/src/appendix-05-editions.md b/src/appendix-05-editions.md index 90828ebbaf..65ac46c554 100644 --- a/src/appendix-05-editions.md +++ b/src/appendix-05-editions.md @@ -43,9 +43,9 @@ together. Edition changes only affect the way the compiler initially parses code. Therefore, if you’re using Rust 2015 and one of your dependencies uses Rust 2018, your project will compile and be able to use that dependency. The opposite situation, where your project uses Rust 2018 and a dependency uses -Rust 2015, works as well. +Rust 2015 works as well. -To be clear: most features will be available on all editions. Developers using +To be clear, most features will be available in all editions. Developers using any Rust edition will continue to see improvements as new stable releases are made. However, in some cases, mainly when new keywords are added, some new features might only be available in later editions. You will need to switch diff --git a/src/appendix-07-nightly-rust.md b/src/appendix-07-nightly-rust.md index 46e619c815..ca72b19df5 100644 --- a/src/appendix-07-nightly-rust.md +++ b/src/appendix-07-nightly-rust.md @@ -35,8 +35,7 @@ assume that the Rust team is working on the release of Rust 1.5. That release happened in December of 2015, but it will provide us with realistic version numbers. A new feature is added to Rust: a new commit lands on the `master` branch. Each night, a new nightly version of Rust is produced. Every day is a -release day, and these releases are created by our release infrastructure -automatically. So as time passes, our releases look like this, once a night: +release day, and these releases are created automatically by our release infrastructure. So, as time passes, our releases look like this once a night: ```text nightly: * - - * - - * @@ -62,7 +61,7 @@ nightly: * - - * - - * - - * - - * beta: * ``` -Let’s say a regression is found. Good thing we had some time to test the beta +Let’s say a regression is found. It's a good thing we had some time to test the beta release before the regression snuck into a stable release! The fix is applied to `master`, so that nightly is fixed, and then the fix is backported to the `beta` branch, and a new release of beta is produced: @@ -106,7 +105,7 @@ release, you can know the date of the next one: it’s six weeks later. A nice aspect of having releases scheduled every six weeks is that the next train is coming soon. If a feature happens to miss a particular release, there’s no need to worry: another one is happening in a short time! This helps reduce pressure -to sneak possibly unpolished features in close to the release deadline. +to sneak possibly unpolished features close to the release deadline. Thanks to this process, you can always check out the next build of Rust and verify for yourself that it’s easy to upgrade to: if a beta release doesn’t @@ -176,7 +175,7 @@ have a lot of Rust projects! So how do you learn about these new features? Rust’s development model follows a *Request For Comments (RFC) process*. If you’d like an improvement in Rust, -you can write up a proposal, called an RFC. +you can write up a proposal called an RFC. Anyone can write RFCs to improve Rust, and the proposals are reviewed and discussed by the Rust team, which is comprised of many topic subteams. There’s diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 536988cb19..deed58514b 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -46,7 +46,7 @@ productive while writing systems-level code. ### Students -Rust is for students and those who are interested in learning about systems +Rust is for students and those interested in learning about systems concepts. Using Rust, many people have learned about topics like operating systems development. The community is very welcoming and happy to answer student questions. Through efforts such as this book, the Rust teams want to @@ -59,7 +59,7 @@ Hundreds of companies, large and small, use Rust in production for a variety of tasks, including command line tools, web services, DevOps tooling, embedded devices, audio and video analysis and transcoding, cryptocurrencies, bioinformatics, search engines, Internet of Things applications, machine -learning, and even major parts of the Firefox web browser. +learning, and even significant parts of the Firefox web browser. ### Open Source Developers @@ -72,7 +72,7 @@ language. Rust is for people who crave speed and stability in a language. By speed, we mean both how quickly Rust code can run and the speed at which Rust lets you write programs. The Rust compiler’s checks ensure stability through feature -additions and refactoring. This is in contrast to the brittle legacy code in +additions and refactoring. This contrasts with the brittle legacy code in languages without these checks, which developers are often afraid to modify. By striving for zero-cost abstractions, higher-level features that compile to lower-level code as fast as code written manually, Rust endeavors to make safe @@ -88,14 +88,14 @@ Rust a try and see if its choices work for you. This book assumes that you’ve written code in another programming language but doesn’t make any assumptions about which one. We’ve tried to make the material -broadly accessible to those from a wide variety of programming backgrounds. We -don’t spend a lot of time talking about what programming *is* or how to think +broadly accessible to those from various programming backgrounds. We +don’t spend much time talking about what programming *is* or how to think about it. If you’re entirely new to programming, you would be better served by reading a book that specifically provides an introduction to programming. ## How to Use This Book -In general, this book assumes that you’re reading it in sequence from front to +Generally, this book assumes that you’re reading it in sequence from front to back. Later chapters build on concepts in earlier chapters, and earlier chapters might not delve into details on a particular topic but will revisit the topic in a later chapter. @@ -123,13 +123,13 @@ enums to make custom types in Rust. In Chapter 7, you’ll learn about Rust’s module system and about privacy rules for organizing your code and its public Application Programming Interface -(API). Chapter 8 discusses some common collection data structures that the +(API). Chapter 8 discusses common collection data structures the standard library provides, such as vectors, strings, and hash maps. Chapter 9 explores Rust’s error-handling philosophy and techniques. Chapter 10 digs into generics, traits, and lifetimes, which give you the power to define code that applies to multiple types. Chapter 11 is all about testing, -which even with Rust’s safety guarantees is necessary to ensure your program’s +which, even with Rust’s safety guarantees, is necessary to ensure your program’s logic is correct. In Chapter 12, we’ll build our own implementation of a subset of functionality from the `grep` command line tool that searches for text within files. For this, we’ll use many of the concepts we discussed in the @@ -142,11 +142,11 @@ Chapter 15 discusses smart pointers that the standard library provides and the traits that enable their functionality. In Chapter 16, we’ll walk through different models of concurrent programming -and talk about how Rust helps you to program in multiple threads fearlessly. +and talk about how Rust helps you program in multiple threads fearlessly. Chapter 17 looks at how Rust idioms compare to object-oriented programming principles you might be familiar with. -Chapter 18 is a reference on patterns and pattern matching, which are powerful +Chapter 18 references patterns and pattern matching, which are powerful ways of expressing ideas throughout Rust programs. Chapter 19 contains a smorgasbord of advanced topics of interest, including unsafe Rust, macros, and more about lifetimes, traits, types, functions, and closures. @@ -159,7 +159,7 @@ more reference-like format. Appendix A covers Rust’s keywords, Appendix B covers Rust’s operators and symbols, Appendix C covers derivable traits provided by the standard library, Appendix D covers some useful development tools, and Appendix E explains Rust editions. In Appendix F, you can find -translations of the book, and in Appendix G we’ll cover how Rust is made and +translations of the book, and in Appendix G, we’ll cover how Rust is made and what nightly Rust is. There is no wrong way to read this book: if you want to skip ahead, go for it! @@ -168,13 +168,13 @@ confusion. But do whatever works for you. -An important part of the process of learning Rust is learning how to read the +An important part of learning Rust is learning how to read the error messages the compiler displays: these will guide you toward working code. -As such, we’ll provide many examples that don’t compile along with the error +As such, we’ll provide many examples that don’t compile, along with the error message the compiler will show you in each situation. Know that if you enter and run a random example, it may not compile! Make sure you read the surrounding text to see whether the example you’re trying to run is meant to -error. Ferris will also help you distinguish code that isn’t meant to work: +be an error. Ferris will also help you distinguish code that isn’t meant to work: | Ferris | Meaning | |------------------------------------------------------------------------------------------------------------------|--------------------------------------------------| diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index 87f37fab26..ca0d6a8ee7 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -11,7 +11,7 @@ The following steps install the latest stable version of the Rust compiler. Rust’s stability guarantees ensure that all the examples in the book that compile will continue to compile with newer Rust versions. The output might differ slightly between versions because Rust often improves error messages and -warnings. In other words, any newer, stable version of Rust you install using +warnings. In other words, any more recent stable version of Rust you install using these steps should work as expected with the content of this book. > ### Command Line Notation @@ -39,7 +39,7 @@ for your password. If the install is successful, the following line will appear: Rust is installed now. Great! ``` -You will also need a *linker*, which is a program that Rust uses to join its +You will also need a *linker*, which is a program Rust uses to combine its compiled outputs into one file. It is likely you already have one. If you get linker errors, you should install a C compiler, which will typically include a linker. A C compiler is also useful because some common Rust packages depend on @@ -83,14 +83,14 @@ $ rustc --version ``` You should see the version number, commit hash, and commit date for the latest -stable version that has been released, in the following format: +stable version that has been released in the following format: ```text rustc x.y.z (abcabcabc yyyy-mm-dd) ``` If you see this information, you have installed Rust successfully! If you don’t -see this information, check that Rust is in your `%PATH%` system variable as +see this information and check that Rust is in your `%PATH%` system variable as follows. In Windows CMD, use: @@ -111,7 +111,7 @@ In Linux and macOS, use: $ echo $PATH ``` -If that’s all correct and Rust still isn’t working, there are a number of +If that’s all correct and Rust still isn’t working, there are several places you can get help. Find out how to get in touch with other Rustaceans (a silly nickname we call ourselves) on [the community page][community]. diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index f291463799..93af283ce4 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -102,11 +102,11 @@ first line declares a function named `main` that has no parameters and returns nothing. If there were parameters, they would go inside the parentheses `()`. The function body is wrapped in `{}`. Rust requires curly brackets around all -function bodies. It’s good style to place the opening curly bracket on the same +function bodies. It’s a good style to place the opening curly bracket on the same line as the function declaration, adding one space in between. > Note: If you want to stick to a standard style across Rust projects, you can -> use an automatic formatter tool called `rustfmt` to format your code in a +> use an automatic formatting tool called `rustfmt` to format your code in a > particular style (more on `rustfmt` in > [Appendix D][devtools]). The Rust team has included this tool > with the standard Rust distribution, as `rustc` is, so it should already be @@ -121,7 +121,7 @@ The body of the `main` function holds the following code: This line does all the work in this little program: it prints text to the screen. There are four important details to notice here. -First, Rust style is to indent with four spaces, not a tab. +First, the Rust style is to indent with four spaces, not a tab. Second, `println!` calls a Rust macro. If it had called a function instead, it would be entered as `println` (without the `!`). We’ll discuss Rust macros in @@ -161,7 +161,7 @@ main main.rs ``` On Linux and macOS, you’ll see two files. With PowerShell on Windows, you’ll -see the same three files that you would see using CMD. With CMD on Windows, you +see the same three files you would see using CMD. With CMD on Windows, you would enter the following: ```cmd From 0fa9efb837a02e7ec425f34eb40f4ff299cd9f74 Mon Sep 17 00:00:00 2001 From: Blatko1 Date: Wed, 13 Dec 2023 11:28:05 +0100 Subject: [PATCH 075/720] changes by @StefanSalewski --- src/appendix-05-editions.md | 4 ++-- src/appendix-07-nightly-rust.md | 2 +- src/ch00-00-introduction.md | 4 ++-- src/ch01-01-installation.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/appendix-05-editions.md b/src/appendix-05-editions.md index 65ac46c554..0ddb779546 100644 --- a/src/appendix-05-editions.md +++ b/src/appendix-05-editions.md @@ -43,9 +43,9 @@ together. Edition changes only affect the way the compiler initially parses code. Therefore, if you’re using Rust 2015 and one of your dependencies uses Rust 2018, your project will compile and be able to use that dependency. The opposite situation, where your project uses Rust 2018 and a dependency uses -Rust 2015 works as well. +Rust 2015, works as well. -To be clear, most features will be available in all editions. Developers using +To be clear: most features will be available in all editions. Developers using any Rust edition will continue to see improvements as new stable releases are made. However, in some cases, mainly when new keywords are added, some new features might only be available in later editions. You will need to switch diff --git a/src/appendix-07-nightly-rust.md b/src/appendix-07-nightly-rust.md index ca72b19df5..edf9815684 100644 --- a/src/appendix-07-nightly-rust.md +++ b/src/appendix-07-nightly-rust.md @@ -175,7 +175,7 @@ have a lot of Rust projects! So how do you learn about these new features? Rust’s development model follows a *Request For Comments (RFC) process*. If you’d like an improvement in Rust, -you can write up a proposal called an RFC. +you can write up a proposal, called an RFC. Anyone can write RFCs to improve Rust, and the proposals are reviewed and discussed by the Rust team, which is comprised of many topic subteams. There’s diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index deed58514b..0b4cdb8732 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -168,8 +168,8 @@ confusion. But do whatever works for you. -An important part of learning Rust is learning how to read the -error messages the compiler displays: these will guide you toward working code. +An important aspect of mastering Rust involves understanding how to interpret the +error messages displayed by the compiler: these will guide you toward working code. As such, we’ll provide many examples that don’t compile, along with the error message the compiler will show you in each situation. Know that if you enter and run a random example, it may not compile! Make sure you read the diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index ca0d6a8ee7..b2690a9a65 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -90,7 +90,7 @@ rustc x.y.z (abcabcabc yyyy-mm-dd) ``` If you see this information, you have installed Rust successfully! If you don’t -see this information and check that Rust is in your `%PATH%` system variable as +see this information, check that Rust is in your `%PATH%` system variable as follows. In Windows CMD, use: From 521fb1cd682c389abb71b2ee19293f28cc0b4587 Mon Sep 17 00:00:00 2001 From: octavio telles teichner Date: Mon, 8 Jan 2024 16:46:37 -0300 Subject: [PATCH 076/720] Rephrase for clarity --- .../ch04-understanding-ownership/listing-04-03/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/listings/ch04-understanding-ownership/listing-04-03/src/main.rs b/listings/ch04-understanding-ownership/listing-04-03/src/main.rs index b001cc5f4a..28f5ca62cb 100644 --- a/listings/ch04-understanding-ownership/listing-04-03/src/main.rs +++ b/listings/ch04-understanding-ownership/listing-04-03/src/main.rs @@ -6,9 +6,9 @@ fn main() { let x = 5; // x comes into scope - makes_copy(x); // x would move into the function, - // but i32 is Copy, so it's okay to still - // use x afterward + makes_copy(x); // since i32 implements the Copy trait, + // x does NOT move into the function, + println!("{}", x); // so it's okay to use x afterward } // Here, x goes out of scope, then s. But because s's value was moved, nothing // special happens. From 42a052a685e57473147d32cb9d4a94ee21e20b0e Mon Sep 17 00:00:00 2001 From: Jonah Nestrick Date: Mon, 29 Jan 2024 13:36:04 -0500 Subject: [PATCH 077/720] Update README to use --locked for installing mdbook --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c70c85e727..926a3f1faf 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ rust-lang/rust uses in [this file][rust-mdbook]. To get it: [rust-mdbook]: https://github.com/rust-lang/rust/blob/master/src/tools/rustbook/Cargo.toml ```bash -$ cargo install mdbook --version +$ cargo install mdbook --locked --version ``` ## Building From fb53518114a9e637ffb024a5faf268e77091d394 Mon Sep 17 00:00:00 2001 From: Pooria Mokhtari Date: Sat, 10 Feb 2024 18:15:14 +0330 Subject: [PATCH 078/720] Update the link to the farsi translation repository --- src/appendix-06-translation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appendix-06-translation.md b/src/appendix-06-translation.md index 7e8c68d253..54d58376ee 100644 --- a/src/appendix-06-translation.md +++ b/src/appendix-06-translation.md @@ -22,7 +22,7 @@ For resources in languages other than English. Most are still in progress; see - [Esperanto](https://github.com/psychoslave/Rust-libro) - [ελληνική](https://github.com/TChatzigiannakis/rust-book-greek) - [Svenska](https://github.com/sebras/book) -- [Farsi](https://github.com/pomokhtari/rust-book-fa) +- [Farsi](https://github.com/RustFarsi/book) - [Deutsch](https://github.com/rust-lang-de/rustbook-de) - [हिंदी](https://github.com/venkatarun95/rust-book-hindi) - [ไทย](https://github.com/rust-lang-th/book-th) From 3db049bb6aac0a20331e57c048828c3ffedf888f Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 12:15:27 -0500 Subject: [PATCH 079/720] Update to Rust 1.68 --- .github/workflows/main.yml | 4 +- .../listing-02-04/output.txt | 23 +++++----- .../output.txt | 6 +++ .../output.txt | 4 +- .../listing-04-06/output.txt | 7 ++- .../output.txt | 31 +++++++------ .../listing-15-21/output.txt | 8 ++-- .../output.txt | 7 ++- .../listing-16-14/output.txt | 45 ++++++++++--------- .../listing-18-08/output.txt | 13 +----- .../output.txt | 4 +- .../ch20-web-server/listing-20-22/output.txt | 21 +++++---- .../output.txt | 21 +++++---- rust-toolchain | 2 +- src/title-page.md | 2 +- 15 files changed, 108 insertions(+), 90 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 65574a070e..5f3638cc3d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.67 -c rust-docs - rustup default 1.67 + rustup toolchain install 1.68 -c rust-docs + rustup default 1.68 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 3640c06946..d784a3dcaf 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -8,17 +8,20 @@ $ cargo build Compiling rand v0.8.5 Compiling guessing_game v0.1.0 (file:///projects/guessing_game) error[E0308]: mismatched types - --> src/main.rs:22:21 - | -22 | match guess.cmp(&secret_number) { - | --- ^^^^^^^^^^^^^^ expected struct `String`, found integer - | | - | arguments to this function are incorrect - | - = note: expected reference `&String` - found reference `&{integer}` + --> src/main.rs:22:21 + | +22 | match guess.cmp(&secret_number) { + | --- ^^^^^^^^^^^^^^ expected struct `String`, found integer + | | + | arguments to this method are incorrect + | + = note: expected reference `&String` + found reference `&{integer}` note: associated function defined here - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/cmp.rs:783:8 + --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:781:8 + | +781 | fn cmp(&self, other: &Self) -> Ordering; + | ^^^ For more information about this error, try `rustc --explain E0308`. error: could not compile `guessing_game` due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt index 31a07efc4b..c954fa78af 100644 --- a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt @@ -7,6 +7,12 @@ error[E0308]: mismatched types | ----- expected due to this value 3 | spaces = spaces.len(); | ^^^^^^^^^^^^ expected `&str`, found `usize` + | +help: try removing the method call + | +3 - spaces = spaces.len(); +3 + spaces = spaces; + | For more information about this error, try `rustc --explain E0308`. error: could not compile `variables` due to previous error diff --git a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt index 8a11cccd51..973308c53e 100644 --- a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt +++ b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt @@ -8,8 +8,8 @@ error[E0282]: type annotations needed | help: consider giving `guess` an explicit type | -2 | let guess: _ = "42".parse().expect("Not a number!"); - | +++ +2 | let guess: /* Type */ = "42".parse().expect("Not a number!"); + | ++++++++++++ For more information about this error, try `rustc --explain E0282`. error: could not compile `no_type_annotations` due to previous error diff --git a/listings/ch04-understanding-ownership/listing-04-06/output.txt b/listings/ch04-understanding-ownership/listing-04-06/output.txt index 1176f4e3ac..5fd57c96d7 100644 --- a/listings/ch04-understanding-ownership/listing-04-06/output.txt +++ b/listings/ch04-understanding-ownership/listing-04-06/output.txt @@ -3,10 +3,13 @@ $ cargo run error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&` reference --> src/main.rs:8:5 | -7 | fn change(some_string: &String) { - | ------- help: consider changing this to be a mutable reference: `&mut String` 8 | some_string.push_str(", world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +7 | fn change(some_string: &mut String) { + | ~~~~~~~~~~~ For more information about this error, try `rustc --explain E0596`. error: could not compile `ownership` due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 75d056f843..a0a046ec6a 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -1,22 +1,25 @@ $ cargo run Compiling enums v0.1.0 (file:///projects/enums) error[E0004]: non-exhaustive patterns: `None` not covered - --> src/main.rs:3:15 - | -3 | match x { - | ^ pattern `None` not covered - | + --> src/main.rs:3:15 + | +3 | match x { + | ^ pattern `None` not covered + | note: `Option` defined here - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:518:1 - | - = note: -/rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:522:5: not covered - = note: the matched value is of type `Option` + --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:566:5 + | +562 | pub enum Option { + | ------------------ +... +566 | None, + | ^^^^ not covered + = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown - | -4 ~ Some(i) => Some(i + 1), -5 ~ None => todo!(), - | + | +4 ~ Some(i) => Some(i + 1), +5 ~ None => todo!(), + | For more information about this error, try `rustc --explain E0004`. error: could not compile `enums` due to previous error diff --git a/listings/ch15-smart-pointers/listing-15-21/output.txt b/listings/ch15-smart-pointers/listing-15-21/output.txt index 6b07b66ea2..0c9ef8eb2b 100644 --- a/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/listings/ch15-smart-pointers/listing-15-21/output.txt @@ -3,11 +3,13 @@ $ cargo test error[E0596]: cannot borrow `self.sent_messages` as mutable, as it is behind a `&` reference --> src/lib.rs:58:13 | -2 | fn send(&self, msg: &str); - | ----- help: consider changing that to be a mutable reference: `&mut self` -... 58 | self.sent_messages.push(String::from(message)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing that to be a mutable reference + | +2 | fn send(&mut self, msg: &str); + | ~~~~~~~~~ For more information about this error, try `rustc --explain E0596`. error: could not compile `limit-tracker` due to previous error diff --git a/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt b/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt index 8e84746eec..d9684a6e02 100644 --- a/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt +++ b/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt @@ -3,10 +3,13 @@ $ cargo run error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> src/main.rs:3:13 | -2 | let x = 5; - | - help: consider changing this to be mutable: `mut x` 3 | let y = &mut x; | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +2 | let mut x = 5; + | +++ For more information about this error, try `rustc --explain E0596`. error: could not compile `borrowing` due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index e8cf21a736..93e6bd322b 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -1,30 +1,31 @@ $ cargo run Compiling shared-state v0.1.0 (file:///projects/shared-state) error[E0277]: `Rc>` cannot be sent between threads safely - --> src/main.rs:11:36 - | -11 | let handle = thread::spawn(move || { - | ------------- ^------ - | | | - | ______________________|_____________within this `[closure@src/main.rs:11:36: 11:43]` - | | | - | | required by a bound introduced by this call -12 | | let mut num = counter.lock().unwrap(); -13 | | -14 | | *num += 1; -15 | | }); - | |_________^ `Rc>` cannot be sent between threads safely - | - = help: within `[closure@src/main.rs:11:36: 11:43]`, the trait `Send` is not implemented for `Rc>` + --> src/main.rs:11:36 + | +11 | let handle = thread::spawn(move || { + | ------------- ^------ + | | | + | ______________________|_____________within this `[closure@src/main.rs:11:36: 11:43]` + | | | + | | required by a bound introduced by this call +12 | | let mut num = counter.lock().unwrap(); +13 | | +14 | | *num += 1; +15 | | }); + | |_________^ `Rc>` cannot be sent between threads safely + | + = help: within `[closure@src/main.rs:11:36: 11:43]`, the trait `Send` is not implemented for `Rc>` note: required because it's used within this closure - --> src/main.rs:11:36 - | -11 | let handle = thread::spawn(move || { - | ^^^^^^^ + --> src/main.rs:11:36 + | +11 | let handle = thread::spawn(move || { + | ^^^^^^^ note: required by a bound in `spawn` - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:704:8 - | - = note: required by this bound in `spawn` + --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:712:8 + | +712 | F: Send + 'static, + | ^^^^ required by this bound in `spawn` For more information about this error, try `rustc --explain E0277`. error: could not compile `shared-state` due to previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-08/output.txt b/listings/ch18-patterns-and-matching/listing-18-08/output.txt index 52efabb5c1..8e74696a03 100644 --- a/listings/ch18-patterns-and-matching/listing-18-08/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-08/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling patterns v0.1.0 (file:///projects/patterns) -error[E0005]: refutable pattern in local binding: `None` not covered +error[E0005]: refutable pattern in local binding --> src/main.rs:3:9 | 3 | let Some(x) = some_option_value; @@ -8,17 +8,8 @@ error[E0005]: refutable pattern in local binding: `None` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html -note: `Option` defined here - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:518:1 - | - = note: -/rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:522:5: not covered = note: the matched value is of type `Option` -help: you might want to use `if let` to ignore the variant that isn't matched - | -3 | let x = if let Some(x) = some_option_value { x } else { todo!() }; - | ++++++++++ ++++++++++++++++++++++ -help: alternatively, you might want to use let else to handle the variant that isn't matched +help: you might want to use `let else` to handle the variant that isn't matched | 3 | let Some(x) = some_option_value else { todo!() }; | ++++++++++++++++ diff --git a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt index 0991f10faa..f6965badd4 100644 --- a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt +++ b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt @@ -1,10 +1,10 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) error[E0277]: `Point` doesn't implement `std::fmt::Display` - --> src/main.rs:20:6 + --> src/main.rs:20:23 | 20 | impl OutlinePrint for Point {} - | ^^^^^^^^^^^^ `Point` cannot be formatted with the default formatter + | ^^^^^ `Point` cannot be formatted with the default formatter | = help: the trait `std::fmt::Display` is not implemented for `Point` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 342bf9a16d..99b6ef62a8 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/listings/ch20-web-server/listing-20-22/output.txt @@ -1,15 +1,18 @@ $ cargo check Checking hello v0.1.0 (file:///projects/hello) error[E0507]: cannot move out of `worker.thread` which is behind a mutable reference - --> src/lib.rs:52:13 - | -52 | worker.thread.join().unwrap(); - | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this method call - | | - | move occurs because `worker.thread` has type `JoinHandle<()>`, which does not implement the `Copy` trait - | -note: this function takes ownership of the receiver `self`, which moves `worker.thread` - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:1581:17 + --> src/lib.rs:52:13 + | +52 | worker.thread.join().unwrap(); + | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this method call + | | + | 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` + --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1589:17 + | +1589 | pub fn join(self) -> Result { + | ^^^^ For more information about this error, try `rustc --explain E0507`. error: could not compile `hello` due to previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index fec2377dc2..6e0132e0a8 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt @@ -1,17 +1,20 @@ $ cargo check Checking hello v0.1.0 (file:///projects/hello) error[E0599]: no method named `join` found for enum `Option` in the current scope - --> src/lib.rs:52:27 - | -52 | worker.thread.join().unwrap(); - | ^^^^ method not found in `Option>` - | + --> src/lib.rs:52:27 + | +52 | worker.thread.join().unwrap(); + | ^^^^ method not found in `Option>` + | note: the method `join` exists on the type `JoinHandle<()>` - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:1581:5 + --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1589:5 + | +1589 | pub fn join(self) -> Result { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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(); - | +++++++++++++++++ + | +52 | worker.thread.expect("REASON").join().unwrap(); + | +++++++++++++++++ error[E0308]: mismatched types --> src/lib.rs:72:22 diff --git a/rust-toolchain b/rust-toolchain index 9ebd7af328..083b97b96a 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.67 +1.68 diff --git a/src/title-page.md b/src/title-page.md index 5f7a7a680a..2f1c72d966 100644 --- a/src/title-page.md +++ b/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.67.1 (released 2023-02-09) +This version of the text assumes you’re using Rust 1.68.2 (released 2023-03-28) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From fb08e4879d6a7805c63fd1695c55554426080b6a Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 12:34:55 -0500 Subject: [PATCH 080/720] Update to Rust 1.69 --- .github/workflows/main.yml | 4 ++-- .../ch02-guessing-game-tutorial/listing-02-04/output.txt | 8 ++++---- .../no-listing-10-non-exhaustive-match/output.txt | 6 +++--- .../listing-10-16/output.txt | 2 ++ .../listing-10-23/output.txt | 2 ++ .../ch13-functional-features/listing-13-03/output.txt | 2 +- .../ch16-fearless-concurrency/listing-16-14/output.txt | 4 ++-- listings/ch20-web-server/listing-20-22/output.txt | 4 ++-- .../no-listing-02-impl-threadpool-new/output.txt | 2 +- .../no-listing-04-update-worker-definition/output.txt | 6 +++--- rust-toolchain | 2 +- src/title-page.md | 2 +- 12 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f3638cc3d..2b8b5245a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.68 -c rust-docs - rustup default 1.68 + rustup toolchain install 1.69 -c rust-docs + rustup default 1.69 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index d784a3dcaf..e64436dd75 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -11,16 +11,16 @@ error[E0308]: mismatched types --> src/main.rs:22:21 | 22 | match guess.cmp(&secret_number) { - | --- ^^^^^^^^^^^^^^ expected struct `String`, found integer + | --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}` | | | arguments to this method are incorrect | = note: expected reference `&String` found reference `&{integer}` -note: associated function defined here - --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:781:8 +note: method defined here + --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:783:8 | -781 | fn cmp(&self, other: &Self) -> Ordering; +783 | fn cmp(&self, other: &Self) -> Ordering; | ^^^ For more information about this error, try `rustc --explain E0308`. diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index a0a046ec6a..11eff13f67 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -7,12 +7,12 @@ error[E0004]: non-exhaustive patterns: `None` not covered | ^ pattern `None` not covered | note: `Option` defined here - --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:566:5 + --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:567:5 | -562 | pub enum Option { +563 | pub enum Option { | ------------------ ... -566 | None, +567 | None, | ^^^^ not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt index ad73272099..55a0ce5d38 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt @@ -3,6 +3,8 @@ $ cargo run error[E0597]: `x` does not live long enough --> src/main.rs:6:13 | +5 | let x = 5; + | - binding `x` declared here 6 | r = &x; | ^^ borrowed value does not live long enough 7 | } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt index 7f31ce02c4..0b1621e832 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt @@ -3,6 +3,8 @@ $ cargo run error[E0597]: `string2` does not live long enough --> src/main.rs:6:44 | +5 | let string2 = String::from("xyz"); + | ------- binding `string2` declared here 6 | result = longest(string1.as_str(), string2.as_str()); | ^^^^^^^^^^^^^^^^ borrowed value does not live long enough 7 | } diff --git a/listings/ch13-functional-features/listing-13-03/output.txt b/listings/ch13-functional-features/listing-13-03/output.txt index 68838deff0..fa2e06971b 100644 --- a/listings/ch13-functional-features/listing-13-03/output.txt +++ b/listings/ch13-functional-features/listing-13-03/output.txt @@ -6,7 +6,7 @@ error[E0308]: mismatched types 5 | let n = example_closure(5); | --------------- ^- help: try using a conversion method: `.to_string()` | | | - | | expected struct `String`, found integer + | | expected `String`, found integer | arguments to this function are incorrect | note: closure parameter defined here diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index 93e6bd322b..15942b400e 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -22,9 +22,9 @@ note: required because it's used within this closure 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` - --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:712:8 + --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:714:8 | -712 | F: Send + 'static, +714 | F: Send + 'static, | ^^^^ required by this bound in `spawn` For more information about this error, try `rustc --explain E0277`. diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 99b6ef62a8..5f7f30e925 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/listings/ch20-web-server/listing-20-22/output.txt @@ -9,9 +9,9 @@ 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` - --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1589:17 + --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1591:17 | -1589 | pub fn join(self) -> Result { +1591 | pub fn join(self) -> Result { | ^^^^ For more information about this error, try `rustc --explain E0507`. diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt index 44c8f3953b..593cbffcb1 100644 --- a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt +++ b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt @@ -4,7 +4,7 @@ error[E0599]: no method named `execute` found for struct `ThreadPool` in the cur --> src/main.rs:17:14 | 17 | pool.execute(|| { - | ^^^^^^^ method not found in `ThreadPool` + | -----^^^^^^^ method not found in `ThreadPool` For more information about this error, try `rustc --explain E0599`. error: could not compile `hello` due to previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 6e0132e0a8..590ba1d728 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt @@ -7,9 +7,9 @@ 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<()>` - --> /Users/carolnichols/.rustup/toolchains/1.68-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1589:5 + --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1591:5 | -1589 | pub fn join(self) -> Result { +1591 | pub fn join(self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `Option::expect` to unwrap the `JoinHandle<()>` value, panicking if the value is an `Option::None` | @@ -20,7 +20,7 @@ error[E0308]: mismatched types --> src/lib.rs:72:22 | 72 | Worker { id, thread } - | ^^^^^^ expected enum `Option`, found struct `JoinHandle` + | ^^^^^^ expected `Option>`, found `JoinHandle<_>` | = note: expected enum `Option>` found struct `JoinHandle<_>` diff --git a/rust-toolchain b/rust-toolchain index 083b97b96a..883d7d6539 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.68 +1.69 diff --git a/src/title-page.md b/src/title-page.md index 2f1c72d966..4edbdf0d9e 100644 --- a/src/title-page.md +++ b/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.68.2 (released 2023-03-28) +This version of the text assumes you’re using Rust 1.69.0 (released 2023-04-20) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 44a30761904e5dff9f444620ff7625704c5e57b6 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 13:11:07 -0500 Subject: [PATCH 081/720] Update to Rust 1.70 --- .github/workflows/main.yml | 4 ++-- .../ch02-guessing-game-tutorial/listing-02-04/output.txt | 6 +++--- .../no-listing-02-without-expect/output.txt | 4 ++++ .../no-listing-01-variables-are-immutable/output.txt | 2 +- .../no-listing-05-mut-cant-change-types/output.txt | 2 +- .../no-listing-19-statements-vs-expressions/output.txt | 2 +- .../output.txt | 2 +- .../no-listing-28-if-condition-must-be-bool/output.txt | 2 +- .../no-listing-31-arms-must-return-same-type/output.txt | 2 +- .../output-only-01-no-type-annotations/output.txt | 2 +- .../ch04-understanding-ownership/listing-04-06/output.txt | 2 +- .../no-listing-04-cant-use-after-move/output.txt | 2 +- .../no-listing-10-multiple-mut-not-allowed/output.txt | 2 +- .../output.txt | 2 +- .../no-listing-14-dangling-reference/output.txt | 2 +- .../no-listing-19-slice-error/output.txt | 2 +- .../listing-05-11/output.txt | 2 +- .../no-listing-02-reference-in-struct/output.txt | 2 +- .../output-only-01-debug/output.txt | 5 +++-- .../no-listing-07-cant-use-option-directly/output.txt | 2 +- .../no-listing-10-non-exhaustive-match/output.txt | 8 ++++---- .../listing-07-03/output.txt | 2 +- .../listing-07-05/output.txt | 2 +- .../listing-07-12/output.txt | 2 +- listings/ch08-common-collections/listing-08-06/output.txt | 4 ++-- listings/ch08-common-collections/listing-08-19/output.txt | 2 +- listings/ch09-error-handling/listing-09-10/output.txt | 2 +- .../listing-10-05/output.txt | 2 +- .../listing-10-07/output.txt | 2 +- .../listing-10-16/output.txt | 2 +- .../listing-10-20/output.txt | 2 +- .../listing-10-23/output.txt | 2 +- .../no-listing-09-unrelated-lifetime/output.txt | 2 +- listings/ch12-an-io-project/listing-12-12/output.txt | 4 ++++ .../output-only-02-missing-lifetimes/output.txt | 2 +- .../ch13-functional-features/listing-13-03/output.txt | 2 +- .../ch13-functional-features/listing-13-08/output.txt | 2 +- .../ch13-functional-features/listing-13-14/output.txt | 4 ++++ listings/ch15-smart-pointers/listing-15-03/output.txt | 2 +- listings/ch15-smart-pointers/listing-15-09/output.txt | 2 +- listings/ch15-smart-pointers/listing-15-15/output.txt | 2 +- listings/ch15-smart-pointers/listing-15-17/output.txt | 2 +- listings/ch15-smart-pointers/listing-15-21/output.txt | 2 +- .../output.txt | 2 +- .../output-only-01-comparing-to-reference/output.txt | 2 +- .../ch16-fearless-concurrency/listing-16-03/output.txt | 2 +- .../ch16-fearless-concurrency/listing-16-09/output.txt | 2 +- .../ch16-fearless-concurrency/listing-16-13/output.txt | 2 +- .../ch16-fearless-concurrency/listing-16-14/output.txt | 6 +++--- .../output-only-01-move-drop/output.txt | 2 +- listings/ch17-oop/listing-17-10/output.txt | 2 +- .../ch18-patterns-and-matching/listing-18-05/output.txt | 2 +- .../ch18-patterns-and-matching/listing-18-08/output.txt | 2 +- .../ch18-patterns-and-matching/listing-18-25/output.txt | 2 +- listings/ch19-advanced-features/listing-19-05/output.txt | 2 +- listings/ch19-advanced-features/listing-19-20/output.txt | 2 +- .../no-listing-02-impl-outlineprint-for-point/output.txt | 2 +- .../no-listing-18-returns-closure/output.txt | 2 +- .../output-only-01-missing-unsafe/output.txt | 2 +- listings/ch20-web-server/listing-20-12/output.txt | 2 +- listings/ch20-web-server/listing-20-17/output.txt | 2 +- listings/ch20-web-server/listing-20-22/output.txt | 6 +++--- .../no-listing-01-define-threadpool-struct/output.txt | 2 +- .../no-listing-02-impl-threadpool-new/output.txt | 2 +- .../no-listing-04-update-worker-definition/output.txt | 6 +++--- rust-toolchain | 2 +- src/title-page.md | 2 +- 67 files changed, 91 insertions(+), 78 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2b8b5245a7..6088036de6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.69 -c rust-docs - rustup default 1.69 + rustup toolchain install 1.70 -c rust-docs + rustup default 1.70 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index e64436dd75..97df06b875 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,10 +18,10 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:783:8 + --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:784:8 | -783 | fn cmp(&self, other: &Self) -> Ordering; +784 | fn cmp(&self, other: &Self) -> Ordering; | ^^^ For more information about this error, try `rustc --explain E0308`. -error: could not compile `guessing_game` due to previous error +error: could not compile `guessing_game` (bin "guessing_game") due to previous error diff --git a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt index 9517af95f0..c7ce1c5256 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt @@ -8,6 +8,10 @@ warning: unused `Result` that must be used | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +10 | let _ = io::stdin().read_line(&mut guess); + | +++++++ warning: `guessing_game` (bin "guessing_game") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.59s diff --git a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt index ed87cb2c87..554b764fc5 100644 --- a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt @@ -13,4 +13,4 @@ error[E0384]: cannot assign twice to immutable variable `x` | ^^^^^ cannot assign twice to immutable variable For more information about this error, try `rustc --explain E0384`. -error: could not compile `variables` due to previous error +error: could not compile `variables` (bin "variables") due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt index c954fa78af..95773d11d4 100644 --- a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt @@ -15,4 +15,4 @@ help: try removing the method call | For more information about this error, try `rustc --explain E0308`. -error: could not compile `variables` due to previous error +error: could not compile `variables` (bin "variables") due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt index 6ae56e09dc..df038b80e2 100644 --- a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt @@ -37,4 +37,4 @@ help: remove these parentheses For more information about this error, try `rustc --explain E0658`. warning: `functions` (bin "functions") generated 1 warning -error: could not compile `functions` due to 3 previous errors; 1 warning emitted +error: could not compile `functions` (bin "functions") due to 3 previous errors; 1 warning emitted diff --git a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt index d27a7fae28..337c5daf3a 100644 --- a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt @@ -11,4 +11,4 @@ error[E0308]: mismatched types | - help: remove this semicolon to return this value For more information about this error, try `rustc --explain E0308`. -error: could not compile `functions` due to previous error +error: could not compile `functions` (bin "functions") due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt index 735bfe758e..9b7296f1f5 100644 --- a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt @@ -7,4 +7,4 @@ error[E0308]: mismatched types | ^^^^^^ expected `bool`, found integer For more information about this error, try `rustc --explain E0308`. -error: could not compile `branches` due to previous error +error: could not compile `branches` (bin "branches") due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt index e922acd29c..debd0b9ca2 100644 --- a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt @@ -9,4 +9,4 @@ error[E0308]: `if` and `else` have incompatible types | expected because of this For more information about this error, try `rustc --explain E0308`. -error: could not compile `branches` due to previous error +error: could not compile `branches` (bin "branches") due to previous error diff --git a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt index 973308c53e..6cb9378af2 100644 --- a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt +++ b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt @@ -12,4 +12,4 @@ help: consider giving `guess` an explicit type | ++++++++++++ For more information about this error, try `rustc --explain E0282`. -error: could not compile `no_type_annotations` due to previous error +error: could not compile `no_type_annotations` (bin "no_type_annotations") due to previous error diff --git a/listings/ch04-understanding-ownership/listing-04-06/output.txt b/listings/ch04-understanding-ownership/listing-04-06/output.txt index 5fd57c96d7..8e6d09ed3d 100644 --- a/listings/ch04-understanding-ownership/listing-04-06/output.txt +++ b/listings/ch04-understanding-ownership/listing-04-06/output.txt @@ -12,4 +12,4 @@ help: consider changing this to be a mutable reference | ~~~~~~~~~~~ For more information about this error, try `rustc --explain E0596`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to previous error diff --git a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt index 4a53567018..17aea46a6e 100644 --- a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt @@ -18,4 +18,4 @@ help: consider cloning the value if the performance cost is acceptable | ++++++++ For more information about this error, try `rustc --explain E0382`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to previous error diff --git a/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt b/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt index 8820d2d695..1a4ea26b7a 100644 --- a/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt @@ -12,4 +12,4 @@ error[E0499]: cannot borrow `s` as mutable more than once at a time | -- first borrow later used here For more information about this error, try `rustc --explain E0499`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to previous error diff --git a/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt b/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt index d1e9db2c4b..3884c6e118 100644 --- a/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt @@ -13,4 +13,4 @@ error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immuta | -- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to previous error diff --git a/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt b/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt index b466a3dce5..72bfe4c510 100644 --- a/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt @@ -13,4 +13,4 @@ help: consider using the `'static` lifetime | +++++++ For more information about this error, try `rustc --explain E0106`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to previous error diff --git a/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt b/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt index ab0c41f4df..5adc2d0a77 100644 --- a/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt @@ -13,4 +13,4 @@ error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immuta | ---- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to previous error diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt b/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt index 7d3bfcdac4..0e008b130b 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt @@ -11,4 +11,4 @@ error[E0277]: `Rectangle` doesn't implement `std::fmt::Display` = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. -error: could not compile `rectangles` due to previous error +error: could not compile `rectangles` (bin "rectangles") due to previous error diff --git a/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt b/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt index e28da599c7..5f9344c512 100644 --- a/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt @@ -28,4 +28,4 @@ help: consider introducing a named lifetime parameter | For more information about this error, try `rustc --explain E0106`. -error: could not compile `structs` due to 2 previous errors +error: could not compile `structs` (bin "structs") due to 2 previous errors diff --git a/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt b/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt index 58cb842bfa..57bf3c7bc9 100644 --- a/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt @@ -11,8 +11,9 @@ error[E0277]: `Rectangle` doesn't implement `Debug` = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `Rectangle` with `#[derive(Debug)]` | -1 | #[derive(Debug)] +1 + #[derive(Debug)] +2 | struct Rectangle { | For more information about this error, try `rustc --explain E0277`. -error: could not compile `rectangles` due to previous error +error: could not compile `rectangles` (bin "rectangles") due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt index a16dc01807..83a6c1deac 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt @@ -14,4 +14,4 @@ error[E0277]: cannot add `Option` to `i8` For more information about this error, try `rustc --explain E0277`. -error: could not compile `enums` due to previous error +error: could not compile `enums` (bin "enums") due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 11eff13f67..79f73f7c80 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -7,12 +7,12 @@ error[E0004]: non-exhaustive patterns: `None` not covered | ^ pattern `None` not covered | note: `Option` defined here - --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:567:5 + --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:568:5 | -563 | pub enum Option { +564 | pub enum Option { | ------------------ ... -567 | None, +568 | None, | ^^^^ not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown @@ -22,4 +22,4 @@ help: ensure that all possible cases are being handled by adding a match arm wit | For more information about this error, try `rustc --explain E0004`. -error: could not compile `enums` due to previous error +error: could not compile `enums` (bin "enums") due to previous error diff --git a/listings/ch07-managing-growing-projects/listing-07-03/output.txt b/listings/ch07-managing-growing-projects/listing-07-03/output.txt index 481dcb3f74..32c0c0d346 100644 --- a/listings/ch07-managing-growing-projects/listing-07-03/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-03/output.txt @@ -25,4 +25,4 @@ note: the module `hosting` is defined here | ^^^^^^^^^^^ For more information about this error, try `rustc --explain E0603`. -error: could not compile `restaurant` due to 2 previous errors +error: could not compile `restaurant` (lib) due to 2 previous errors diff --git a/listings/ch07-managing-growing-projects/listing-07-05/output.txt b/listings/ch07-managing-growing-projects/listing-07-05/output.txt index 63eb89a146..98d8d6e2aa 100644 --- a/listings/ch07-managing-growing-projects/listing-07-05/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-05/output.txt @@ -25,4 +25,4 @@ note: the function `add_to_waitlist` is defined here | ^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0603`. -error: could not compile `restaurant` due to 2 previous errors +error: could not compile `restaurant` (lib) due to 2 previous errors diff --git a/listings/ch07-managing-growing-projects/listing-07-12/output.txt b/listings/ch07-managing-growing-projects/listing-07-12/output.txt index 1bc89bf322..a9125d04bc 100644 --- a/listings/ch07-managing-growing-projects/listing-07-12/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-12/output.txt @@ -16,4 +16,4 @@ error[E0433]: failed to resolve: use of undeclared crate or module `hosting` For more information about this error, try `rustc --explain E0433`. warning: `restaurant` (lib) generated 1 warning -error: could not compile `restaurant` due to previous error; 1 warning emitted +error: could not compile `restaurant` (lib) due to previous error; 1 warning emitted diff --git a/listings/ch08-common-collections/listing-08-06/output.txt b/listings/ch08-common-collections/listing-08-06/output.txt index 3104205f30..a38194b63b 100644 --- a/listings/ch08-common-collections/listing-08-06/output.txt +++ b/listings/ch08-common-collections/listing-08-06/output.txt @@ -10,7 +10,7 @@ error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immuta | ^^^^^^^^^ mutable borrow occurs here 7 | 8 | println!("The first element is: {first}"); - | ----- immutable borrow later used here + | ------- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `collections` due to previous error +error: could not compile `collections` (bin "collections") due to previous error diff --git a/listings/ch08-common-collections/listing-08-19/output.txt b/listings/ch08-common-collections/listing-08-19/output.txt index 3a682457c6..f6e67f3143 100644 --- a/listings/ch08-common-collections/listing-08-19/output.txt +++ b/listings/ch08-common-collections/listing-08-19/output.txt @@ -16,4 +16,4 @@ error[E0277]: the type `String` cannot be indexed by `{integer}` >> For more information about this error, try `rustc --explain E0277`. -error: could not compile `collections` due to previous error +error: could not compile `collections` (bin "collections") due to previous error diff --git a/listings/ch09-error-handling/listing-09-10/output.txt b/listings/ch09-error-handling/listing-09-10/output.txt index 75b9cf2e33..e1570745cf 100644 --- a/listings/ch09-error-handling/listing-09-10/output.txt +++ b/listings/ch09-error-handling/listing-09-10/output.txt @@ -11,4 +11,4 @@ error[E0277]: the `?` operator can only be used in a function that returns `Resu = help: the trait `FromResidual>` is not implemented for `()` For more information about this error, try `rustc --explain E0277`. -error: could not compile `error-handling` due to previous error +error: could not compile `error-handling` (bin "error-handling") due to previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt index 1a705ed570..0857a1434f 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt @@ -14,4 +14,4 @@ help: consider restricting type parameter `T` | ++++++++++++++++++++++ For more information about this error, try `rustc --explain E0369`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt index 2482c38432..ddebf76685 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt @@ -7,4 +7,4 @@ error[E0308]: mismatched types | ^^^ expected integer, found floating-point number For more information about this error, try `rustc --explain E0308`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt index 55a0ce5d38..8173b5527a 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt @@ -14,4 +14,4 @@ error[E0597]: `x` does not live long enough | - borrow later used here For more information about this error, try `rustc --explain E0597`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt index 534a984a63..36a6d83cf1 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt @@ -13,4 +13,4 @@ help: consider introducing a named lifetime parameter | ++++ ++ ++ ++ For more information about this error, try `rustc --explain E0106`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt index 0b1621e832..0f6769f998 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt @@ -13,4 +13,4 @@ error[E0597]: `string2` does not live long enough | ------ borrow later used here For more information about this error, try `rustc --explain E0597`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt index 0c628b6977..51d49e98ce 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt @@ -7,4 +7,4 @@ error[E0515]: cannot return reference to local variable `result` | ^^^^^^^^^^^^^^^ returns a reference to data owned by the current function For more information about this error, try `rustc --explain E0515`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to previous error diff --git a/listings/ch12-an-io-project/listing-12-12/output.txt b/listings/ch12-an-io-project/listing-12-12/output.txt index 9870b21255..87e131aae6 100644 --- a/listings/ch12-an-io-project/listing-12-12/output.txt +++ b/listings/ch12-an-io-project/listing-12-12/output.txt @@ -8,6 +8,10 @@ warning: unused `Result` that must be used | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +19 | let _ = run(config); + | +++++++ warning: `minigrep` (bin "minigrep") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.71s diff --git a/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt b/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt index 93116dd5ed..340c48efec 100644 --- a/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt +++ b/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt @@ -13,4 +13,4 @@ help: consider introducing a named lifetime parameter | ++++ ++ ++ ++ For more information about this error, try `rustc --explain E0106`. -error: could not compile `minigrep` due to previous error +error: could not compile `minigrep` (lib) due to previous error diff --git a/listings/ch13-functional-features/listing-13-03/output.txt b/listings/ch13-functional-features/listing-13-03/output.txt index fa2e06971b..ce35912f27 100644 --- a/listings/ch13-functional-features/listing-13-03/output.txt +++ b/listings/ch13-functional-features/listing-13-03/output.txt @@ -16,4 +16,4 @@ note: closure parameter defined here | ^ For more information about this error, try `rustc --explain E0308`. -error: could not compile `closure-example` due to previous error +error: could not compile `closure-example` (bin "closure-example") due to previous error diff --git a/listings/ch13-functional-features/listing-13-08/output.txt b/listings/ch13-functional-features/listing-13-08/output.txt index a910537667..f411d65223 100644 --- a/listings/ch13-functional-features/listing-13-08/output.txt +++ b/listings/ch13-functional-features/listing-13-08/output.txt @@ -12,4 +12,4 @@ error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` clos | ^^^^^ move occurs because `value` has type `String`, which does not implement the `Copy` trait For more information about this error, try `rustc --explain E0507`. -error: could not compile `rectangles` due to previous error +error: could not compile `rectangles` (bin "rectangles") due to previous error diff --git a/listings/ch13-functional-features/listing-13-14/output.txt b/listings/ch13-functional-features/listing-13-14/output.txt index 9930379910..53715015ed 100644 --- a/listings/ch13-functional-features/listing-13-14/output.txt +++ b/listings/ch13-functional-features/listing-13-14/output.txt @@ -8,6 +8,10 @@ warning: unused `Map` that must be used | = note: iterators are lazy and do nothing unless consumed = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +4 | let _ = v1.iter().map(|x| x + 1); + | +++++++ warning: `iterators` (bin "iterators") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.47s diff --git a/listings/ch15-smart-pointers/listing-15-03/output.txt b/listings/ch15-smart-pointers/listing-15-03/output.txt index 04b6976fed..58eada3f24 100644 --- a/listings/ch15-smart-pointers/listing-15-03/output.txt +++ b/listings/ch15-smart-pointers/listing-15-03/output.txt @@ -14,4 +14,4 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | ++++ + For more information about this error, try `rustc --explain E0072`. -error: could not compile `cons-list` due to previous error +error: could not compile `cons-list` (bin "cons-list") due to previous error diff --git a/listings/ch15-smart-pointers/listing-15-09/output.txt b/listings/ch15-smart-pointers/listing-15-09/output.txt index 75e5f1c8c4..5999bbd5fb 100644 --- a/listings/ch15-smart-pointers/listing-15-09/output.txt +++ b/listings/ch15-smart-pointers/listing-15-09/output.txt @@ -7,4 +7,4 @@ error[E0614]: type `MyBox<{integer}>` cannot be dereferenced | ^^ For more information about this error, try `rustc --explain E0614`. -error: could not compile `deref-example` due to previous error +error: could not compile `deref-example` (bin "deref-example") due to previous error diff --git a/listings/ch15-smart-pointers/listing-15-15/output.txt b/listings/ch15-smart-pointers/listing-15-15/output.txt index a38c9ccb76..16f74e29f4 100644 --- a/listings/ch15-smart-pointers/listing-15-15/output.txt +++ b/listings/ch15-smart-pointers/listing-15-15/output.txt @@ -10,4 +10,4 @@ error[E0040]: explicit use of destructor method | help: consider using `drop` function: `drop(c)` For more information about this error, try `rustc --explain E0040`. -error: could not compile `drop-example` due to previous error +error: could not compile `drop-example` (bin "drop-example") due to previous error diff --git a/listings/ch15-smart-pointers/listing-15-17/output.txt b/listings/ch15-smart-pointers/listing-15-17/output.txt index ab314d8837..9596272eb1 100644 --- a/listings/ch15-smart-pointers/listing-15-17/output.txt +++ b/listings/ch15-smart-pointers/listing-15-17/output.txt @@ -11,4 +11,4 @@ error[E0382]: use of moved value: `a` | ^ value used here after move For more information about this error, try `rustc --explain E0382`. -error: could not compile `cons-list` due to previous error +error: could not compile `cons-list` (bin "cons-list") due to previous error diff --git a/listings/ch15-smart-pointers/listing-15-21/output.txt b/listings/ch15-smart-pointers/listing-15-21/output.txt index 0c9ef8eb2b..50ad108033 100644 --- a/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/listings/ch15-smart-pointers/listing-15-21/output.txt @@ -12,5 +12,5 @@ help: consider changing that to be a mutable reference | ~~~~~~~~~ For more information about this error, try `rustc --explain E0596`. -error: could not compile `limit-tracker` due to previous error +error: could not compile `limit-tracker` (lib test) due to previous error warning: build failed, waiting for other jobs to finish... diff --git a/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt b/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt index d9684a6e02..a2e77d4d0c 100644 --- a/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt +++ b/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt @@ -12,4 +12,4 @@ help: consider changing this to be mutable | +++ For more information about this error, try `rustc --explain E0596`. -error: could not compile `borrowing` due to previous error +error: could not compile `borrowing` (bin "borrowing") due to previous error diff --git a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt index a03cc34e2e..af8af5bdc3 100644 --- a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt +++ b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt @@ -20,4 +20,4 @@ error[E0277]: can't compare `{integer}` with `&{integer}` = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. -error: could not compile `deref-example` due to previous error +error: could not compile `deref-example` (bin "deref-example") due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-03/output.txt b/listings/ch16-fearless-concurrency/listing-16-03/output.txt index 321bf59d70..c8624e2670 100644 --- a/listings/ch16-fearless-concurrency/listing-16-03/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-03/output.txt @@ -22,4 +22,4 @@ help: to force the closure to take ownership of `v` (and any other referenced va | ++++ For more information about this error, try `rustc --explain E0373`. -error: could not compile `threads` due to previous error +error: could not compile `threads` (bin "threads") due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-09/output.txt b/listings/ch16-fearless-concurrency/listing-16-09/output.txt index db85185372..3c50b48b41 100644 --- a/listings/ch16-fearless-concurrency/listing-16-09/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-09/output.txt @@ -13,4 +13,4 @@ error[E0382]: borrow of moved value: `val` = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0382`. -error: could not compile `message-passing` due to previous error +error: could not compile `message-passing` (bin "message-passing") due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-13/output.txt b/listings/ch16-fearless-concurrency/listing-16-13/output.txt index ea6963903d..a1b6af3a62 100644 --- a/listings/ch16-fearless-concurrency/listing-16-13/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-13/output.txt @@ -12,4 +12,4 @@ error[E0382]: use of moved value: `counter` | ------- use occurs due to use in closure For more information about this error, try `rustc --explain E0382`. -error: could not compile `shared-state` due to previous error +error: could not compile `shared-state` (bin "shared-state") due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index 15942b400e..d8a356b6cf 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -22,10 +22,10 @@ note: required because it's used within this closure 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` - --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:714:8 + --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:680:8 | -714 | F: Send + 'static, +680 | F: Send + 'static, | ^^^^ required by this bound in `spawn` For more information about this error, try `rustc --explain E0277`. -error: could not compile `shared-state` due to previous error +error: could not compile `shared-state` (bin "shared-state") due to previous error diff --git a/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt b/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt index 301a9a44a4..922e84d543 100644 --- a/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt +++ b/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt @@ -15,4 +15,4 @@ error[E0382]: use of moved value: `v` | ^ value used here after move For more information about this error, try `rustc --explain E0382`. -error: could not compile `threads` due to previous error +error: could not compile `threads` (bin "threads") due to previous error diff --git a/listings/ch17-oop/listing-17-10/output.txt b/listings/ch17-oop/listing-17-10/output.txt index e0a455f3b4..2192db7031 100644 --- a/listings/ch17-oop/listing-17-10/output.txt +++ b/listings/ch17-oop/listing-17-10/output.txt @@ -10,4 +10,4 @@ error[E0277]: the trait bound `String: Draw` is not satisfied = note: required for the cast from `String` to the object type `dyn Draw` For more information about this error, try `rustc --explain E0277`. -error: could not compile `gui` due to previous error +error: could not compile `gui` (bin "gui") due to previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-05/output.txt b/listings/ch18-patterns-and-matching/listing-18-05/output.txt index 57916a1f15..6c59302e73 100644 --- a/listings/ch18-patterns-and-matching/listing-18-05/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-05/output.txt @@ -12,4 +12,4 @@ error[E0308]: mismatched types found tuple `(_, _)` For more information about this error, try `rustc --explain E0308`. -error: could not compile `patterns` due to previous error +error: could not compile `patterns` (bin "patterns") due to previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-08/output.txt b/listings/ch18-patterns-and-matching/listing-18-08/output.txt index 8e74696a03..7c335384e4 100644 --- a/listings/ch18-patterns-and-matching/listing-18-08/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-08/output.txt @@ -15,4 +15,4 @@ help: you might want to use `let else` to handle the variant that isn't matched | ++++++++++++++++ For more information about this error, try `rustc --explain E0005`. -error: could not compile `patterns` due to previous error +error: could not compile `patterns` (bin "patterns") due to previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-25/output.txt b/listings/ch18-patterns-and-matching/listing-18-25/output.txt index 7e0357eac2..09255c738b 100644 --- a/listings/ch18-patterns-and-matching/listing-18-25/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-25/output.txt @@ -8,4 +8,4 @@ error: `..` can only be used once per tuple pattern | | | previously used here -error: could not compile `patterns` due to previous error +error: could not compile `patterns` (bin "patterns") due to previous error diff --git a/listings/ch19-advanced-features/listing-19-05/output.txt b/listings/ch19-advanced-features/listing-19-05/output.txt index f4b7582acc..9362fd3537 100644 --- a/listings/ch19-advanced-features/listing-19-05/output.txt +++ b/listings/ch19-advanced-features/listing-19-05/output.txt @@ -14,4 +14,4 @@ error[E0499]: cannot borrow `*values` as mutable more than once at a time | returning this value requires that `*values` is borrowed for `'1` For more information about this error, try `rustc --explain E0499`. -error: could not compile `unsafe-example` due to previous error +error: could not compile `unsafe-example` (bin "unsafe-example") due to previous error diff --git a/listings/ch19-advanced-features/listing-19-20/output.txt b/listings/ch19-advanced-features/listing-19-20/output.txt index 5942876044..19d978b8e7 100644 --- a/listings/ch19-advanced-features/listing-19-20/output.txt +++ b/listings/ch19-advanced-features/listing-19-20/output.txt @@ -15,4 +15,4 @@ help: use the fully-qualified path to the only available implementation | +++++++ + For more information about this error, try `rustc --explain E0790`. -error: could not compile `traits-example` due to previous error +error: could not compile `traits-example` (bin "traits-example") due to previous error diff --git a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt index f6965badd4..f3c90e41aa 100644 --- a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt +++ b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt @@ -15,4 +15,4 @@ note: required by a bound in `OutlinePrint` | ^^^^^^^^^^^^ required by this bound in `OutlinePrint` For more information about this error, try `rustc --explain E0277`. -error: could not compile `traits-example` due to previous error +error: could not compile `traits-example` (bin "traits-example") due to previous error diff --git a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt index 104f2cf0fe..9776e5257f 100644 --- a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt +++ b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt @@ -13,4 +13,4 @@ help: use `impl Fn(i32) -> i32` as the return type, as all return paths are of t | ~~~~~~~~~~~~~~~~~~~ For more information about this error, try `rustc --explain E0746`. -error: could not compile `functions-example` due to previous error +error: could not compile `functions-example` (lib) due to previous error diff --git a/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt b/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt index 5886bc6307..0d61d2a9b2 100644 --- a/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt +++ b/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt @@ -9,4 +9,4 @@ error[E0133]: call to unsafe function is unsafe and requires unsafe function or = note: consult the function's documentation for information on how to avoid undefined behavior For more information about this error, try `rustc --explain E0133`. -error: could not compile `unsafe-example` due to previous error +error: could not compile `unsafe-example` (bin "unsafe-example") due to previous error diff --git a/listings/ch20-web-server/listing-20-12/output.txt b/listings/ch20-web-server/listing-20-12/output.txt index 57a58b960e..a768404719 100644 --- a/listings/ch20-web-server/listing-20-12/output.txt +++ b/listings/ch20-web-server/listing-20-12/output.txt @@ -7,4 +7,4 @@ error[E0433]: failed to resolve: use of undeclared type `ThreadPool` | ^^^^^^^^^^ use of undeclared type `ThreadPool` For more information about this error, try `rustc --explain E0433`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (bin "hello") due to previous error diff --git a/listings/ch20-web-server/listing-20-17/output.txt b/listings/ch20-web-server/listing-20-17/output.txt index 8bedfecfd4..864431b0e4 100644 --- a/listings/ch20-web-server/listing-20-17/output.txt +++ b/listings/ch20-web-server/listing-20-17/output.txt @@ -10,4 +10,4 @@ error[E0382]: use of moved value: `receiver` | ^^^^^^^^ value moved here, in previous iteration of loop For more information about this error, try `rustc --explain E0382`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (lib) due to previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 5f7f30e925..ae7af472ed 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/listings/ch20-web-server/listing-20-22/output.txt @@ -9,10 +9,10 @@ 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` - --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1591:17 + --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1557:17 | -1591 | pub fn join(self) -> Result { +1557 | pub fn join(self) -> Result { | ^^^^ For more information about this error, try `rustc --explain E0507`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (lib) due to previous error diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt b/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt index fa337b8a80..70e35665da 100644 --- a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt +++ b/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt @@ -7,4 +7,4 @@ error[E0599]: no function or associated item named `new` found for struct `Threa | ^^^ function or associated item not found in `ThreadPool` For more information about this error, try `rustc --explain E0599`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (bin "hello") due to previous error diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt index 593cbffcb1..054b810cfc 100644 --- a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt +++ b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt @@ -7,4 +7,4 @@ error[E0599]: no method named `execute` found for struct `ThreadPool` in the cur | -----^^^^^^^ method not found in `ThreadPool` For more information about this error, try `rustc --explain E0599`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (bin "hello") due to previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 590ba1d728..84f4943aad 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt @@ -7,9 +7,9 @@ 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<()>` - --> /Users/carolnichols/.rustup/toolchains/1.69-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1591:5 + --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1557:5 | -1591 | pub fn join(self) -> Result { +1557 | pub fn join(self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `Option::expect` to unwrap the `JoinHandle<()>` value, panicking if the value is an `Option::None` | @@ -31,4 +31,4 @@ help: try wrapping the expression in `Some` Some errors have detailed explanations: E0308, E0599. For more information about an error, try `rustc --explain E0308`. -error: could not compile `hello` due to 2 previous errors +error: could not compile `hello` (lib) due to 2 previous errors diff --git a/rust-toolchain b/rust-toolchain index 883d7d6539..bfe79d0bdd 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.69 +1.70 diff --git a/src/title-page.md b/src/title-page.md index 4edbdf0d9e..506054aa3b 100644 --- a/src/title-page.md +++ b/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.69.0 (released 2023-04-20) +This version of the text assumes you’re using Rust 1.70.0 (released 2023-06-01) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 25d95a0580efb70f23c22cebb1c89328c8d39496 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 13:16:05 -0500 Subject: [PATCH 082/720] Update to Rust 1.71 --- .github/workflows/main.yml | 4 ++-- .../listing-02-04/output.txt | 4 ++-- .../listing-04-06/output.txt | 2 +- .../no-listing-10-non-exhaustive-match/output.txt | 6 +++--- listings/ch15-smart-pointers/listing-15-21/output.txt | 2 +- .../ch16-fearless-concurrency/listing-16-14/output.txt | 7 +++++-- listings/ch17-oop/listing-17-10/output.txt | 2 +- .../no-listing-18-returns-closure/output.txt | 10 +++++++--- listings/ch20-web-server/listing-20-22/output.txt | 4 ++-- .../no-listing-04-update-worker-definition/output.txt | 4 ++-- rust-toolchain | 2 +- src/title-page.md | 2 +- 12 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6088036de6..a1de8e319f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.70 -c rust-docs - rustup default 1.70 + rustup toolchain install 1.71 -c rust-docs + rustup default 1.71 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 97df06b875..a4a4a9ed02 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,9 +18,9 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:784:8 + --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:775:8 | -784 | fn cmp(&self, other: &Self) -> Ordering; +775 | fn cmp(&self, other: &Self) -> Ordering; | ^^^ For more information about this error, try `rustc --explain E0308`. diff --git a/listings/ch04-understanding-ownership/listing-04-06/output.txt b/listings/ch04-understanding-ownership/listing-04-06/output.txt index 8e6d09ed3d..729fd99fd7 100644 --- a/listings/ch04-understanding-ownership/listing-04-06/output.txt +++ b/listings/ch04-understanding-ownership/listing-04-06/output.txt @@ -9,7 +9,7 @@ error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&` ref help: consider changing this to be a mutable reference | 7 | fn change(some_string: &mut String) { - | ~~~~~~~~~~~ + | +++ For more information about this error, try `rustc --explain E0596`. error: could not compile `ownership` (bin "ownership") due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 79f73f7c80..21694b8df9 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -7,12 +7,12 @@ error[E0004]: non-exhaustive patterns: `None` not covered | ^ pattern `None` not covered | note: `Option` defined here - --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:568:5 + --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:567:5 | -564 | pub enum Option { +563 | pub enum Option { | ------------------ ... -568 | None, +567 | None, | ^^^^ not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown diff --git a/listings/ch15-smart-pointers/listing-15-21/output.txt b/listings/ch15-smart-pointers/listing-15-21/output.txt index 50ad108033..8e4390dde9 100644 --- a/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/listings/ch15-smart-pointers/listing-15-21/output.txt @@ -6,7 +6,7 @@ error[E0596]: cannot borrow `self.sent_messages` as mutable, as it is behind a ` 58 | self.sent_messages.push(String::from(message)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable | -help: consider changing that to be a mutable reference +help: consider changing this to be a mutable reference | 2 | fn send(&mut self, msg: &str); | ~~~~~~~~~ diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index d8a356b6cf..930fa85feb 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -22,9 +22,12 @@ note: required because it's used within this closure 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` - --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:680:8 + --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:683:8 | -680 | F: Send + 'static, +680 | pub fn spawn(f: F) -> JoinHandle + | ----- required by a bound in this function +... +683 | F: Send + 'static, | ^^^^ required by this bound in `spawn` For more information about this error, try `rustc --explain E0277`. diff --git a/listings/ch17-oop/listing-17-10/output.txt b/listings/ch17-oop/listing-17-10/output.txt index 2192db7031..25ad7efcb0 100644 --- a/listings/ch17-oop/listing-17-10/output.txt +++ b/listings/ch17-oop/listing-17-10/output.txt @@ -7,7 +7,7 @@ error[E0277]: the trait bound `String: Draw` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Draw` is not implemented for `String` | = help: the trait `Draw` is implemented for `Button` - = note: required for the cast from `String` to the object type `dyn Draw` + = note: required for the cast from `Box` to `Box` For more information about this error, try `rustc --explain E0277`. error: could not compile `gui` (bin "gui") due to previous error diff --git a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt index 9776e5257f..61349a7d0a 100644 --- a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt +++ b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt @@ -6,11 +6,15 @@ 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 | - = note: for information on `impl Trait`, see -help: use `impl Fn(i32) -> i32` as the return type, as all return paths are of type `[closure@src/lib.rs:2:5: 2:8]`, which implements `Fn(i32) -> i32` +help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type | 1 | fn returns_closure() -> impl Fn(i32) -> i32 { - | ~~~~~~~~~~~~~~~~~~~ + | ~~~~ +help: 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) + | For more information about this error, try `rustc --explain E0746`. error: could not compile `functions-example` (lib) due to previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index ae7af472ed..d7a9e5471b 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/listings/ch20-web-server/listing-20-22/output.txt @@ -9,9 +9,9 @@ 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` - --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1557:17 + --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1560:17 | -1557 | pub fn join(self) -> Result { +1560 | pub fn join(self) -> Result { | ^^^^ For more information about this error, try `rustc --explain E0507`. diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 84f4943aad..5cd0d99dd5 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt @@ -7,9 +7,9 @@ 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<()>` - --> /Users/carolnichols/.rustup/toolchains/1.70-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1557:5 + --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1560:5 | -1557 | pub fn join(self) -> Result { +1560 | pub fn join(self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `Option::expect` to unwrap the `JoinHandle<()>` value, panicking if the value is an `Option::None` | diff --git a/rust-toolchain b/rust-toolchain index bfe79d0bdd..12816e6276 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.70 +1.71 diff --git a/src/title-page.md b/src/title-page.md index 506054aa3b..de9ce7796b 100644 --- a/src/title-page.md +++ b/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.70.0 (released 2023-06-01) +This version of the text assumes you’re using Rust 1.71.1 (released 2023-08-03) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From c3613dee0c8bbf862700b5573017eeda34afafdd Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 13:19:54 -0500 Subject: [PATCH 083/720] Update to Rust 1.72 --- .github/workflows/main.yml | 4 +- .../listing-02-04/output.txt | 23 ++++------ .../output.txt | 4 +- .../output.txt | 31 ++++++------- .../listing-07-03/output.txt | 8 +++- .../listing-07-12/output.txt | 17 ++++--- .../listing-08-19/output.txt | 6 +-- .../output.txt | 10 ++-- .../listing-16-13/output.txt | 11 +++-- .../listing-16-14/output.txt | 46 ++++++++----------- .../ch20-web-server/listing-20-22/output.txt | 19 ++++---- .../output.txt | 21 ++++----- rust-toolchain | 2 +- src/title-page.md | 2 +- 14 files changed, 98 insertions(+), 106 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a1de8e319f..921af27a86 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.71 -c rust-docs - rustup default 1.71 + rustup toolchain install 1.72 -c rust-docs + rustup default 1.72 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index a4a4a9ed02..c08ccf4e50 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -8,20 +8,17 @@ $ cargo build Compiling rand v0.8.5 Compiling guessing_game v0.1.0 (file:///projects/guessing_game) error[E0308]: mismatched types - --> src/main.rs:22:21 - | -22 | match guess.cmp(&secret_number) { - | --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}` - | | - | arguments to this method are incorrect - | - = note: expected reference `&String` - found reference `&{integer}` + --> src/main.rs:22:21 + | +22 | match guess.cmp(&secret_number) { + | --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}` + | | + | arguments to this method are incorrect + | + = note: expected reference `&String` + found reference `&{integer}` note: method defined here - --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/cmp.rs:775:8 - | -775 | fn cmp(&self, other: &Self) -> Ordering; - | ^^^ + --> /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/cmp.rs:775:8 For more information about this error, try `rustc --explain E0308`. error: could not compile `guessing_game` (bin "guessing_game") due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt index 83a6c1deac..ba140f07ed 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt +++ b/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>> - > - For more information about this error, try `rustc --explain E0277`. error: could not compile `enums` (bin "enums") due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 21694b8df9..a2a443210e 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -1,25 +1,22 @@ $ cargo run Compiling enums v0.1.0 (file:///projects/enums) error[E0004]: non-exhaustive patterns: `None` not covered - --> src/main.rs:3:15 - | -3 | match x { - | ^ pattern `None` not covered - | + --> src/main.rs:3:15 + | +3 | match x { + | ^ pattern `None` not covered + | note: `Option` defined here - --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:567:5 - | -563 | pub enum Option { - | ------------------ -... -567 | None, - | ^^^^ not covered - = note: the matched value is of type `Option` + --> /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/option.rs:563:1 + ::: /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/option.rs:567:5 + | + = note: not covered + = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown - | -4 ~ Some(i) => Some(i + 1), -5 ~ None => todo!(), - | + | +4 ~ Some(i) => Some(i + 1), +5 ~ None => todo!(), + | For more information about this error, try `rustc --explain E0004`. error: could not compile `enums` (bin "enums") due to previous error diff --git a/listings/ch07-managing-growing-projects/listing-07-03/output.txt b/listings/ch07-managing-growing-projects/listing-07-03/output.txt index 32c0c0d346..2d06c7fd15 100644 --- a/listings/ch07-managing-growing-projects/listing-07-03/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-03/output.txt @@ -4,7 +4,9 @@ error[E0603]: module `hosting` is private --> src/lib.rs:9:28 | 9 | crate::front_of_house::hosting::add_to_waitlist(); - | ^^^^^^^ private module + | ^^^^^^^ --------------- function `add_to_waitlist` is not publicly re-exported + | | + | private module | note: the module `hosting` is defined here --> src/lib.rs:2:5 @@ -16,7 +18,9 @@ error[E0603]: module `hosting` is private --> src/lib.rs:12:21 | 12 | front_of_house::hosting::add_to_waitlist(); - | ^^^^^^^ private module + | ^^^^^^^ --------------- function `add_to_waitlist` is not publicly re-exported + | | + | private module | note: the module `hosting` is defined here --> src/lib.rs:2:5 diff --git a/listings/ch07-managing-growing-projects/listing-07-12/output.txt b/listings/ch07-managing-growing-projects/listing-07-12/output.txt index a9125d04bc..9e73ebf6ae 100644 --- a/listings/ch07-managing-growing-projects/listing-07-12/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-12/output.txt @@ -1,5 +1,16 @@ $ cargo build Compiling restaurant v0.1.0 (file:///projects/restaurant) +error[E0433]: failed to resolve: use of undeclared crate or module `hosting` + --> src/lib.rs:11:9 + | +11 | hosting::add_to_waitlist(); + | ^^^^^^^ use of undeclared crate or module `hosting` + | +help: consider importing this module through its public re-export + | +10 + use crate::hosting; + | + warning: unused import: `crate::front_of_house::hosting` --> src/lib.rs:7:5 | @@ -8,12 +19,6 @@ warning: unused import: `crate::front_of_house::hosting` | = note: `#[warn(unused_imports)]` on by default -error[E0433]: failed to resolve: use of undeclared crate or module `hosting` - --> src/lib.rs:11:9 - | -11 | hosting::add_to_waitlist(); - | ^^^^^^^ use of undeclared crate or module `hosting` - For more information about this error, try `rustc --explain E0433`. warning: `restaurant` (lib) generated 1 warning error: could not compile `restaurant` (lib) due to previous error; 1 warning emitted diff --git a/listings/ch08-common-collections/listing-08-19/output.txt b/listings/ch08-common-collections/listing-08-19/output.txt index f6e67f3143..bc4c679052 100644 --- a/listings/ch08-common-collections/listing-08-19/output.txt +++ b/listings/ch08-common-collections/listing-08-19/output.txt @@ -8,12 +8,12 @@ error[E0277]: the type `String` cannot be indexed by `{integer}` | = help: the trait `Index<{integer}>` is not implemented for `String` = help: the following other types implement trait `Index`: - >> > - >> + >> + >> >> + >> >> - >> For more information about this error, try `rustc --explain E0277`. error: could not compile `collections` (bin "collections") due to previous error diff --git a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt index af8af5bdc3..c4c5ee6ef6 100644 --- a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt +++ b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt @@ -8,14 +8,14 @@ error[E0277]: can't compare `{integer}` with `&{integer}` | = help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}` = help: the following other types implement trait `PartialEq`: - f32 - f64 - i128 + isize + i8 i16 i32 i64 - i8 - isize + i128 + usize + u8 and 6 others = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/listings/ch16-fearless-concurrency/listing-16-13/output.txt b/listings/ch16-fearless-concurrency/listing-16-13/output.txt index a1b6af3a62..5d0f59311b 100644 --- a/listings/ch16-fearless-concurrency/listing-16-13/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-13/output.txt @@ -1,15 +1,16 @@ $ cargo run Compiling shared-state v0.1.0 (file:///projects/shared-state) -error[E0382]: use of moved value: `counter` - --> src/main.rs:9:36 +error[E0382]: borrow of moved value: `counter` + --> src/main.rs:21:29 | 5 | let counter = Mutex::new(0); | ------- move occurs because `counter` has type `Mutex`, which does not implement the `Copy` trait ... 9 | let handle = thread::spawn(move || { - | ^^^^^^^ value moved into closure here, in previous iteration of loop -10 | let mut num = counter.lock().unwrap(); - | ------- use occurs due to use in closure + | ------- value moved into closure here, in previous iteration of loop +... +21 | println!("Result: {}", *counter.lock().unwrap()); + | ^^^^^^^^^^^^^^ value borrowed here after move For more information about this error, try `rustc --explain E0382`. error: could not compile `shared-state` (bin "shared-state") due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index 930fa85feb..7bcbdfaaa2 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -1,34 +1,28 @@ $ cargo run Compiling shared-state v0.1.0 (file:///projects/shared-state) error[E0277]: `Rc>` cannot be sent between threads safely - --> src/main.rs:11:36 - | -11 | let handle = thread::spawn(move || { - | ------------- ^------ - | | | - | ______________________|_____________within this `[closure@src/main.rs:11:36: 11:43]` - | | | - | | required by a bound introduced by this call -12 | | let mut num = counter.lock().unwrap(); -13 | | -14 | | *num += 1; -15 | | }); - | |_________^ `Rc>` cannot be sent between threads safely - | - = help: within `[closure@src/main.rs:11:36: 11:43]`, the trait `Send` is not implemented for `Rc>` + --> src/main.rs:11:36 + | +11 | let handle = thread::spawn(move || { + | ------------- ^------ + | | | + | ______________________|_____________within this `[closure@src/main.rs:11:36: 11:43]` + | | | + | | required by a bound introduced by this call +12 | | let mut num = counter.lock().unwrap(); +13 | | +14 | | *num += 1; +15 | | }); + | |_________^ `Rc>` cannot be sent between threads safely + | + = help: within `[closure@src/main.rs:11:36: 11:43]`, the trait `Send` is not implemented for `Rc>` note: required because it's used within this closure - --> src/main.rs:11:36 - | -11 | let handle = thread::spawn(move || { - | ^^^^^^^ + --> src/main.rs:11:36 + | +11 | let handle = thread::spawn(move || { + | ^^^^^^^ note: required by a bound in `spawn` - --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:683:8 - | -680 | pub fn spawn(f: F) -> JoinHandle - | ----- required by a bound in this function -... -683 | F: Send + 'static, - | ^^^^ required by this bound in `spawn` + --> /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/thread/mod.rs:680:1 For more information about this error, try `rustc --explain E0277`. error: could not compile `shared-state` (bin "shared-state") due to previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index d7a9e5471b..bea0351b3b 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/listings/ch20-web-server/listing-20-22/output.txt @@ -1,18 +1,15 @@ $ cargo check Checking hello v0.1.0 (file:///projects/hello) error[E0507]: cannot move out of `worker.thread` which is behind a mutable reference - --> src/lib.rs:52:13 - | -52 | worker.thread.join().unwrap(); - | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this method call - | | - | move occurs because `worker.thread` has type `JoinHandle<()>`, which does not implement the `Copy` trait - | + --> src/lib.rs:52:13 + | +52 | worker.thread.join().unwrap(); + | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this method call + | | + | 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` - --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1560:17 - | -1560 | pub fn join(self) -> Result { - | ^^^^ + --> /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/thread/mod.rs:1570:17 For more information about this error, try `rustc --explain E0507`. error: could not compile `hello` (lib) due to previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 5cd0d99dd5..a8716f1c4b 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt @@ -1,20 +1,17 @@ $ cargo check Checking hello v0.1.0 (file:///projects/hello) error[E0599]: no method named `join` found for enum `Option` in the current scope - --> src/lib.rs:52:27 - | -52 | worker.thread.join().unwrap(); - | ^^^^ method not found in `Option>` - | + --> src/lib.rs:52:27 + | +52 | worker.thread.join().unwrap(); + | ^^^^ method not found in `Option>` + | note: the method `join` exists on the type `JoinHandle<()>` - --> /Users/carolnichols/.rustup/toolchains/1.71-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1560:5 - | -1560 | pub fn join(self) -> Result { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + --> /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/thread/mod.rs:1570: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(); - | +++++++++++++++++ + | +52 | worker.thread.expect("REASON").join().unwrap(); + | +++++++++++++++++ error[E0308]: mismatched types --> src/lib.rs:72:22 diff --git a/rust-toolchain b/rust-toolchain index 12816e6276..cc31fcd4f5 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.71 +1.72 diff --git a/src/title-page.md b/src/title-page.md index de9ce7796b..803b913a53 100644 --- a/src/title-page.md +++ b/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.71.1 (released 2023-08-03) +This version of the text assumes you’re using Rust 1.72.1 (released 2023-09-19) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From e51e1e44572ef3f7cf026aa6fb5137e9a3277131 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 13:25:06 -0500 Subject: [PATCH 084/720] Update to Rust 1.73 --- .github/workflows/main.yml | 4 ++-- .../ch02-guessing-game-tutorial/listing-02-04/output.txt | 2 +- .../ch04-understanding-ownership/listing-04-06/output.txt | 2 +- .../no-listing-10-non-exhaustive-match/output.txt | 4 ++-- .../output-only-01-not-char-boundary/output.txt | 3 ++- listings/ch09-error-handling/listing-09-01/output.txt | 3 ++- listings/ch09-error-handling/listing-09-04/output.txt | 3 ++- .../ch09-error-handling/no-listing-01-panic/output.txt | 3 ++- .../listing-10-23/output.txt | 2 +- .../no-listing-09-unrelated-lifetime/output.txt | 7 +++++-- .../ch11-writing-automated-tests/listing-11-03/output.txt | 3 ++- .../ch11-writing-automated-tests/listing-11-10/output.txt | 7 ++++--- .../no-listing-03-introducing-a-bug/output.txt | 3 ++- .../no-listing-04-bug-in-add-two/output.txt | 7 ++++--- .../no-listing-06-greeter-with-bug/output.txt | 3 ++- .../no-listing-07-custom-failure-message/output.txt | 3 ++- .../no-listing-09-guess-with-panic-msg-bug/output.txt | 3 ++- .../output-only-01-show-output/output.txt | 7 ++++--- listings/ch12-an-io-project/listing-12-07/output.txt | 3 ++- listings/ch12-an-io-project/listing-12-08/output.txt | 3 ++- listings/ch12-an-io-project/listing-12-16/output.txt | 7 ++++--- listings/ch15-smart-pointers/listing-15-21/output.txt | 3 +-- listings/ch15-smart-pointers/listing-15-23/output.txt | 3 ++- .../ch16-fearless-concurrency/listing-16-09/output.txt | 4 ++++ .../ch16-fearless-concurrency/listing-16-13/output.txt | 2 +- .../ch16-fearless-concurrency/listing-16-14/output.txt | 2 +- listings/ch20-web-server/listing-20-17/output.txt | 8 ++++++++ listings/ch20-web-server/listing-20-22/output.txt | 2 +- .../no-listing-04-update-worker-definition/output.txt | 2 +- rust-toolchain | 2 +- src/title-page.md | 2 +- 31 files changed, 71 insertions(+), 41 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 921af27a86..b7704cf996 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.72 -c rust-docs - rustup default 1.72 + rustup toolchain install 1.73 -c rust-docs + rustup default 1.73 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index c08ccf4e50..12036e1fd5 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,7 +18,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/cmp.rs:775:8 + --> /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/cmp.rs:775:8 For more information about this error, try `rustc --explain E0308`. error: could not compile `guessing_game` (bin "guessing_game") due to previous error diff --git a/listings/ch04-understanding-ownership/listing-04-06/output.txt b/listings/ch04-understanding-ownership/listing-04-06/output.txt index 729fd99fd7..3f47171879 100644 --- a/listings/ch04-understanding-ownership/listing-04-06/output.txt +++ b/listings/ch04-understanding-ownership/listing-04-06/output.txt @@ -4,7 +4,7 @@ error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&` ref --> src/main.rs:8:5 | 8 | some_string.push_str(", world"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: consider changing this to be a mutable reference | diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index a2a443210e..4e71624c50 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/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/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/option.rs:563:1 - ::: /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/option.rs:567:5 + --> /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/option.rs:563:1 + ::: /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/option.rs:567:5 | = note: not covered = note: the matched value is of type `Option` diff --git a/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt b/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt index 35db879c9b..855d6d2f6a 100644 --- a/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt +++ b/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling collections v0.1.0 (file:///projects/collections) Finished dev [unoptimized + debuginfo] target(s) in 0.43s Running `target/debug/collections` -thread 'main' panicked at 'byte index 1 is not a char boundary; it is inside 'З' (bytes 0..2) of `Здравствуйте`', src/main.rs:4:14 +thread 'main' panicked at src/main.rs:4:19: +byte index 1 is not a char boundary; it is inside 'З' (bytes 0..2) of `Здравствуйте` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch09-error-handling/listing-09-01/output.txt b/listings/ch09-error-handling/listing-09-01/output.txt index 89aebb952f..225958320c 100644 --- a/listings/ch09-error-handling/listing-09-01/output.txt +++ b/listings/ch09-error-handling/listing-09-01/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling panic v0.1.0 (file:///projects/panic) Finished dev [unoptimized + debuginfo] target(s) in 0.27s Running `target/debug/panic` -thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5 +thread 'main' panicked at src/main.rs:4:6: +index out of bounds: the len is 3 but the index is 99 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch09-error-handling/listing-09-04/output.txt b/listings/ch09-error-handling/listing-09-04/output.txt index f776a591ce..cc135c9fa6 100644 --- a/listings/ch09-error-handling/listing-09-04/output.txt +++ b/listings/ch09-error-handling/listing-09-04/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling error-handling v0.1.0 (file:///projects/error-handling) Finished dev [unoptimized + debuginfo] target(s) in 0.73s Running `target/debug/error-handling` -thread 'main' panicked at 'Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:8:23 +thread 'main' panicked at src/main.rs:8:23: +Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" } note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch09-error-handling/no-listing-01-panic/output.txt b/listings/ch09-error-handling/no-listing-01-panic/output.txt index b25ed85d7c..d90e37e30e 100644 --- a/listings/ch09-error-handling/no-listing-01-panic/output.txt +++ b/listings/ch09-error-handling/no-listing-01-panic/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling panic v0.1.0 (file:///projects/panic) Finished dev [unoptimized + debuginfo] target(s) in 0.25s Running `target/debug/panic` -thread 'main' panicked at 'crash and burn', src/main.rs:2:5 +thread 'main' panicked at src/main.rs:2:5: +crash and burn note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt index 0f6769f998..c28b056b82 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt @@ -6,7 +6,7 @@ error[E0597]: `string2` does not live long enough 5 | let string2 = String::from("xyz"); | ------- binding `string2` declared here 6 | result = longest(string1.as_str(), string2.as_str()); - | ^^^^^^^^^^^^^^^^ borrowed value does not live long enough + | ^^^^^^^ borrowed value does not live long enough 7 | } | - `string2` dropped here while still borrowed 8 | println!("The longest string is {}", result); diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt index 51d49e98ce..fbff3e27fe 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt @@ -1,10 +1,13 @@ $ cargo run Compiling chapter10 v0.1.0 (file:///projects/chapter10) -error[E0515]: cannot return reference to local variable `result` +error[E0515]: cannot return value referencing local variable `result` --> src/main.rs:11:5 | 11 | result.as_str() - | ^^^^^^^^^^^^^^^ returns a reference to data owned by the current function + | ------^^^^^^^^^ + | | + | returns a value referencing data owned by the current function + | `result` is borrowed here For more information about this error, try `rustc --explain E0515`. error: could not compile `chapter10` (bin "chapter10") due to previous error diff --git a/listings/ch11-writing-automated-tests/listing-11-03/output.txt b/listings/ch11-writing-automated-tests/listing-11-03/output.txt index e8c31e79ec..1947556912 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-03/output.txt @@ -10,7 +10,8 @@ test tests::exploration ... ok failures: ---- tests::another stdout ---- -thread 'tests::another' panicked at 'Make this test fail', src/lib.rs:10:9 +thread 'tests::another' panicked at src/lib.rs:10:9: +Make this test fail note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/listing-11-10/output.txt b/listings/ch11-writing-automated-tests/listing-11-10/output.txt index b0d10deaa8..7a2b200ac2 100644 --- a/listings/ch11-writing-automated-tests/listing-11-10/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-10/output.txt @@ -11,9 +11,10 @@ failures: ---- tests::this_test_will_fail stdout ---- I got the value 8 -thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)` - left: `5`, - right: `10`', src/lib.rs:19:9 +thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9: +assertion `left == right` failed + left: 5 + right: 10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt index 6fbb5e4966..6e3061b9c3 100644 --- a/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt @@ -10,7 +10,8 @@ test tests::smaller_cannot_hold_larger ... ok failures: ---- tests::larger_can_hold_smaller stdout ---- -thread 'tests::larger_can_hold_smaller' panicked at 'assertion failed: larger.can_hold(&smaller)', src/lib.rs:28:9 +thread 'tests::larger_can_hold_smaller' panicked at src/lib.rs:28:9: +assertion failed: larger.can_hold(&smaller) note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt index 00bf63fff6..102479df6e 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt @@ -9,9 +9,10 @@ test tests::it_adds_two ... FAILED failures: ---- tests::it_adds_two stdout ---- -thread 'tests::it_adds_two' panicked at 'assertion failed: `(left == right)` - left: `4`, - right: `5`', src/lib.rs:11:9 +thread 'tests::it_adds_two' panicked at src/lib.rs:11:9: +assertion `left == right` failed + left: 4 + right: 5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt index 68d724f118..ca4306ca27 100644 --- a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt @@ -9,7 +9,8 @@ test tests::greeting_contains_name ... FAILED failures: ---- tests::greeting_contains_name stdout ---- -thread 'tests::greeting_contains_name' panicked at 'assertion failed: result.contains(\"Carol\")', src/lib.rs:12:9 +thread 'tests::greeting_contains_name' panicked at src/lib.rs:12:9: +assertion failed: result.contains(\"Carol\") note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt index 03d6ad7f13..e6cc739c41 100644 --- a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt @@ -9,7 +9,8 @@ test tests::greeting_contains_name ... FAILED failures: ---- tests::greeting_contains_name stdout ---- -thread 'tests::greeting_contains_name' panicked at 'Greeting did not contain name, value was `Hello!`', src/lib.rs:12:9 +thread 'tests::greeting_contains_name' panicked at src/lib.rs:12:9: +Greeting did not contain name, value was `Hello!` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt index 0b045e8be9..6e80336e5e 100644 --- a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt @@ -9,7 +9,8 @@ test tests::greater_than_100 - should panic ... FAILED failures: ---- tests::greater_than_100 stdout ---- -thread 'tests::greater_than_100' panicked at 'Guess value must be greater than or equal to 1, got 200.', src/lib.rs:13:13 +thread 'tests::greater_than_100' panicked at src/lib.rs:13:13: +Guess value must be greater than or equal to 1, got 200. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace note: panic did not contain expected string panic message: `"Guess value must be greater than or equal to 1, got 200."`, diff --git a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt index bc03145a18..b8aae1fae1 100644 --- a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt @@ -20,9 +20,10 @@ failures: ---- tests::this_test_will_fail stdout ---- I got the value 8 -thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)` - left: `5`, - right: `10`', src/lib.rs:19:9 +thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9: +assertion `left == right` failed + left: 5 + right: 10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch12-an-io-project/listing-12-07/output.txt b/listings/ch12-an-io-project/listing-12-07/output.txt index d3fa7777d5..94666c8700 100644 --- a/listings/ch12-an-io-project/listing-12-07/output.txt +++ b/listings/ch12-an-io-project/listing-12-07/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished dev [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep` -thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:27:21 +thread 'main' panicked at src/main.rs:27:21: +index out of bounds: the len is 1 but the index is 1 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch12-an-io-project/listing-12-08/output.txt b/listings/ch12-an-io-project/listing-12-08/output.txt index de2abd1afc..6d1103e4d4 100644 --- a/listings/ch12-an-io-project/listing-12-08/output.txt +++ b/listings/ch12-an-io-project/listing-12-08/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished dev [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep` -thread 'main' panicked at 'not enough arguments', src/main.rs:26:13 +thread 'main' panicked at src/main.rs:26:13: +not enough arguments note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch12-an-io-project/listing-12-16/output.txt b/listings/ch12-an-io-project/listing-12-16/output.txt index be4a97eea2..893171bc40 100644 --- a/listings/ch12-an-io-project/listing-12-16/output.txt +++ b/listings/ch12-an-io-project/listing-12-16/output.txt @@ -9,9 +9,10 @@ test tests::one_result ... FAILED failures: ---- tests::one_result stdout ---- -thread 'tests::one_result' panicked at 'assertion failed: `(left == right)` - left: `["safe, fast, productive."]`, - right: `[]`', src/lib.rs:44:9 +thread 'tests::one_result' panicked at src/lib.rs:44:9: +assertion `left == right` failed + left: ["safe, fast, productive."] + right: [] note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch15-smart-pointers/listing-15-21/output.txt b/listings/ch15-smart-pointers/listing-15-21/output.txt index 8e4390dde9..f94f72f48c 100644 --- a/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/listings/ch15-smart-pointers/listing-15-21/output.txt @@ -4,7 +4,7 @@ error[E0596]: cannot borrow `self.sent_messages` as mutable, as it is behind a ` --> src/lib.rs:58:13 | 58 | self.sent_messages.push(String::from(message)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: consider changing this to be a mutable reference | @@ -13,4 +13,3 @@ help: consider changing this to be a mutable reference For more information about this error, try `rustc --explain E0596`. error: could not compile `limit-tracker` (lib test) due to previous error -warning: build failed, waiting for other jobs to finish... diff --git a/listings/ch15-smart-pointers/listing-15-23/output.txt b/listings/ch15-smart-pointers/listing-15-23/output.txt index 0ffabf7650..5ad2087ed8 100644 --- a/listings/ch15-smart-pointers/listing-15-23/output.txt +++ b/listings/ch15-smart-pointers/listing-15-23/output.txt @@ -9,7 +9,8 @@ test tests::it_sends_an_over_75_percent_warning_message ... FAILED failures: ---- tests::it_sends_an_over_75_percent_warning_message stdout ---- -thread 'tests::it_sends_an_over_75_percent_warning_message' panicked at 'already borrowed: BorrowMutError', src/lib.rs:60:53 +thread 'tests::it_sends_an_over_75_percent_warning_message' panicked at src/lib.rs:60:53: +already borrowed: BorrowMutError note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch16-fearless-concurrency/listing-16-09/output.txt b/listings/ch16-fearless-concurrency/listing-16-09/output.txt index 3c50b48b41..a31a003e2e 100644 --- a/listings/ch16-fearless-concurrency/listing-16-09/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-09/output.txt @@ -11,6 +11,10 @@ error[E0382]: borrow of moved value: `val` | ^^^ value borrowed here after move | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider cloning the value if the performance cost is acceptable + | +9 | tx.send(val.clone()).unwrap(); + | ++++++++ For more information about this error, try `rustc --explain E0382`. error: could not compile `message-passing` (bin "message-passing") due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-13/output.txt b/listings/ch16-fearless-concurrency/listing-16-13/output.txt index 5d0f59311b..ac881aabe7 100644 --- a/listings/ch16-fearless-concurrency/listing-16-13/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-13/output.txt @@ -10,7 +10,7 @@ error[E0382]: borrow of moved value: `counter` | ------- value moved into closure here, in previous iteration of loop ... 21 | println!("Result: {}", *counter.lock().unwrap()); - | ^^^^^^^^^^^^^^ value borrowed here after move + | ^^^^^^^ value borrowed here after move For more information about this error, try `rustc --explain E0382`. error: could not compile `shared-state` (bin "shared-state") due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index 7bcbdfaaa2..b1461754bb 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/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/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/thread/mod.rs:680:1 + --> /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:680:1 For more information about this error, try `rustc --explain E0277`. error: could not compile `shared-state` (bin "shared-state") due to previous error diff --git a/listings/ch20-web-server/listing-20-17/output.txt b/listings/ch20-web-server/listing-20-17/output.txt index 864431b0e4..6272ad2898 100644 --- a/listings/ch20-web-server/listing-20-17/output.txt +++ b/listings/ch20-web-server/listing-20-17/output.txt @@ -6,8 +6,16 @@ error[E0382]: use of moved value: `receiver` 21 | let (sender, receiver) = mpsc::channel(); | -------- move occurs because `receiver` has type `std::sync::mpsc::Receiver`, which does not implement the `Copy` trait ... +25 | for id in 0..size { + | ----------------- inside of this loop 26 | workers.push(Worker::new(id, receiver)); | ^^^^^^^^ value moved here, in previous iteration of loop + | +note: consider changing this parameter type in method `new` to borrow instead if owning the value isn't necessary + --> src/lib.rs:47:33 + | +47 | fn new(id: usize, receiver: mpsc::Receiver) -> Worker { + | --- in this method ^^^^^^^^^^^^^^^^^^^ this parameter takes ownership of the value For more information about this error, try `rustc --explain E0382`. error: could not compile `hello` (lib) due to previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index bea0351b3b..87cdeb4ba3 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/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/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/thread/mod.rs:1570:17 + --> /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:1570:17 For more information about this error, try `rustc --explain E0507`. error: could not compile `hello` (lib) due to previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index a8716f1c4b..0afd1c0cbc 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/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/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/thread/mod.rs:1570:5 + --> /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:1570: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/rust-toolchain b/rust-toolchain index cc31fcd4f5..e4654bb683 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.72 +1.73 diff --git a/src/title-page.md b/src/title-page.md index 803b913a53..d17b89749d 100644 --- a/src/title-page.md +++ b/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.72.1 (released 2023-09-19) +This version of the text assumes you’re using Rust 1.73.0 (released 2023-10-05) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 551369f4b174dbb46941b2e147c51f8ab96bd26d Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 13:28:36 -0500 Subject: [PATCH 085/720] Update to Rust 1.74 --- .github/workflows/main.yml | 4 ++-- .../listing-02-04/output.txt | 2 +- .../output.txt | 19 ++----------------- .../output.txt | 4 ++-- .../listing-15-15/output.txt | 10 ++++++---- .../listing-16-14/output.txt | 6 +++--- .../ch20-web-server/listing-20-22/output.txt | 2 +- .../output.txt | 2 +- rust-toolchain | 2 +- src/title-page.md | 2 +- 10 files changed, 20 insertions(+), 33 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b7704cf996..be9b37ab12 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.73 -c rust-docs - rustup default 1.73 + rustup toolchain install 1.74 -c rust-docs + rustup default 1.74 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 12036e1fd5..e4fab67930 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,7 +18,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/cmp.rs:775:8 + --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/cmp.rs:793:8 For more information about this error, try `rustc --explain E0308`. error: could not compile `guessing_game` (bin "guessing_game") due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt index df038b80e2..33c3811911 100644 --- a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt @@ -5,22 +5,8 @@ error: expected expression, found `let` statement | 2 | let x = (let y = 6); | ^^^ - -error: expected expression, found statement (`let`) - --> src/main.rs:2:14 - | -2 | let x = (let y = 6); - | ^^^^^^^^^ - | - = note: variable declaration using `let` is a statement - -error[E0658]: `let` expressions in this position are unstable - --> src/main.rs:2:14 - | -2 | let x = (let y = 6); - | ^^^^^^^^^ | - = note: see issue #53667 for more information + = note: only supported directly in conditions of `if` and `while` expressions warning: unnecessary parentheses around assigned value --> src/main.rs:2:13 @@ -35,6 +21,5 @@ help: remove these parentheses 2 + let x = let y = 6; | -For more information about this error, try `rustc --explain E0658`. warning: `functions` (bin "functions") generated 1 warning -error: could not compile `functions` (bin "functions") due to 3 previous errors; 1 warning emitted +error: could not compile `functions` (bin "functions") due to previous error; 1 warning emitted diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 4e71624c50..e2fbaa97a6 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/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/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/option.rs:563:1 - ::: /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/option.rs:567:5 + --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/option.rs:563:1 + ::: /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/option.rs:567:5 | = note: not covered = note: the matched value is of type `Option` diff --git a/listings/ch15-smart-pointers/listing-15-15/output.txt b/listings/ch15-smart-pointers/listing-15-15/output.txt index 16f74e29f4..c7c9342cb1 100644 --- a/listings/ch15-smart-pointers/listing-15-15/output.txt +++ b/listings/ch15-smart-pointers/listing-15-15/output.txt @@ -4,10 +4,12 @@ error[E0040]: explicit use of destructor method --> src/main.rs:16:7 | 16 | c.drop(); - | --^^^^-- - | | | - | | explicit destructor calls not allowed - | help: consider using `drop` function: `drop(c)` + | ^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +16 | drop(c); + | +++++ ~ For more information about this error, try `rustc --explain E0040`. error: could not compile `drop-example` (bin "drop-example") due to previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index b1461754bb..ef657eab48 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -6,7 +6,7 @@ error[E0277]: `Rc>` cannot be sent between threads safely 11 | let handle = thread::spawn(move || { | ------------- ^------ | | | - | ______________________|_____________within this `[closure@src/main.rs:11:36: 11:43]` + | ______________________|_____________within this `{closure@src/main.rs:11:36: 11:43}` | | | | | required by a bound introduced by this call 12 | | let mut num = counter.lock().unwrap(); @@ -15,14 +15,14 @@ error[E0277]: `Rc>` cannot be sent between threads safely 15 | | }); | |_________^ `Rc>` cannot be sent between threads safely | - = help: within `[closure@src/main.rs:11:36: 11:43]`, the trait `Send` is not implemented for `Rc>` + = help: within `{closure@src/main.rs:11:36: 11:43}`, the trait `Send` is not implemented for `Rc>` note: required because it's used within this closure --> src/main.rs:11:36 | 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` - --> /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:680:1 + --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/thread/mod.rs:680:1 For more information about this error, try `rustc --explain E0277`. error: could not compile `shared-state` (bin "shared-state") due to previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 87cdeb4ba3..b0bb88e6c9 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/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/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:1570:17 + --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/thread/mod.rs:1650:17 For more information about this error, try `rustc --explain E0507`. error: could not compile `hello` (lib) due to previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 0afd1c0cbc..18d45e5114 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/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/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:1570:5 + --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/thread/mod.rs:1650: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/rust-toolchain b/rust-toolchain index e4654bb683..bc8a6589c9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.73 +1.74 diff --git a/src/title-page.md b/src/title-page.md index d17b89749d..2bbd9b3b24 100644 --- a/src/title-page.md +++ b/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.73.0 (released 2023-10-05) +This version of the text assumes you’re using Rust 1.74.1 (released 2023-12-07) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 57516ea03b61cd68c271da98687329d8a428e39d Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 13:31:52 -0500 Subject: [PATCH 086/720] Update to Rust 1.75 --- .github/workflows/main.yml | 4 ++-- .../ch02-guessing-game-tutorial/listing-02-04/output.txt | 2 +- .../output-only-01-no-type-annotations/output.txt | 7 ++++--- .../no-listing-10-non-exhaustive-match/output.txt | 4 ++-- .../no-listing-06-greeter-with-bug/output.txt | 2 +- listings/ch13-functional-features/listing-13-03/output.txt | 7 +++++++ .../ch16-fearless-concurrency/listing-16-14/output.txt | 2 +- listings/ch20-web-server/listing-20-22/output.txt | 2 +- .../no-listing-04-update-worker-definition/output.txt | 2 +- rust-toolchain | 2 +- src/title-page.md | 2 +- 11 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index be9b37ab12..0ef0ade2bd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.74 -c rust-docs - rustup default 1.74 + rustup toolchain install 1.75 -c rust-docs + rustup default 1.75 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index e4fab67930..90dc4ba829 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,7 +18,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/cmp.rs:793:8 + --> /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/cmp.rs:811:8 For more information about this error, try `rustc --explain E0308`. error: could not compile `guessing_game` (bin "guessing_game") due to previous error diff --git a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt index 6cb9378af2..1329f9d73f 100644 --- a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt +++ b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt @@ -1,15 +1,16 @@ $ cargo build Compiling no_type_annotations v0.1.0 (file:///projects/no_type_annotations) -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> src/main.rs:2:9 | 2 | let guess = "42".parse().expect("Not a number!"); - | ^^^^^ + | ^^^^^ ----- type must be known at this point | + = note: cannot satisfy `<_ as FromStr>::Err == _` help: consider giving `guess` an explicit type | 2 | let guess: /* Type */ = "42".parse().expect("Not a number!"); | ++++++++++++ -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. error: could not compile `no_type_annotations` (bin "no_type_annotations") due to previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index e2fbaa97a6..e609de51e2 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/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/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/option.rs:563:1 - ::: /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/option.rs:567:5 + --> /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:569:1 + ::: /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:573:5 | = note: not covered = note: the matched value is of type `Option` diff --git a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt index ca4306ca27..bbd42d04dc 100644 --- a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt @@ -10,7 +10,7 @@ failures: ---- tests::greeting_contains_name stdout ---- thread 'tests::greeting_contains_name' panicked at src/lib.rs:12:9: -assertion failed: result.contains(\"Carol\") +assertion failed: result.contains("Carol") note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch13-functional-features/listing-13-03/output.txt b/listings/ch13-functional-features/listing-13-03/output.txt index ce35912f27..fdc88f6388 100644 --- a/listings/ch13-functional-features/listing-13-03/output.txt +++ b/listings/ch13-functional-features/listing-13-03/output.txt @@ -9,6 +9,13 @@ error[E0308]: mismatched types | | expected `String`, found integer | arguments to this function are incorrect | +note: expected because the closure was earlier called with an argument of type `String` + --> src/main.rs:4:29 + | +4 | let s = example_closure(String::from("hello")); + | --------------- ^^^^^^^^^^^^^^^^^^^^^ expected because this argument is of type `String` + | | + | in this closure call note: closure parameter defined here --> src/main.rs:2:28 | diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index ef657eab48..a469f6e6b0 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/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/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/thread/mod.rs:680:1 + --> /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/mod.rs:682:1 For more information about this error, try `rustc --explain E0277`. error: could not compile `shared-state` (bin "shared-state") due to previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index b0bb88e6c9..da1134cd25 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/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/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/thread/mod.rs:1650:17 + --> /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/mod.rs:1652:17 For more information about this error, try `rustc --explain E0507`. error: could not compile `hello` (lib) due to previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 18d45e5114..49f7193772 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/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/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/thread/mod.rs:1650:5 + --> /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/mod.rs:1652: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/rust-toolchain b/rust-toolchain index bc8a6589c9..07cde98405 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.74 +1.75 diff --git a/src/title-page.md b/src/title-page.md index 2bbd9b3b24..6127fa3fb4 100644 --- a/src/title-page.md +++ b/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.74.1 (released 2023-12-07) +This version of the text assumes you’re using Rust 1.75.0 (released 2023-12-28) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 940fb140f5980144584f70de864fa7ca1f52247d Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 13:35:43 -0500 Subject: [PATCH 087/720] Update to Rust 1.76 --- .github/workflows/main.yml | 4 ++-- .../listing-02-02/Cargo.lock | 16 ++++++++-------- .../listing-02-04/output.txt | 4 ++-- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../listing-04-06/output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 9 +++++++-- .../no-listing-19-slice-error/output.txt | 2 +- .../listing-05-11/output.txt | 2 +- .../no-listing-05-dbg-macro/output.txt | 4 ++-- .../output-only-01-debug/output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 6 +++--- .../listing-07-12/output.txt | 2 +- .../listing-08-06/output.txt | 2 +- .../listing-08-19/output.txt | 6 +++--- .../listing-09-10/output.txt | 2 +- .../listing-10-05/output.txt | 2 +- .../listing-10-07/output.txt | 2 +- .../listing-10-16/output.txt | 2 +- .../listing-10-20/output.txt | 2 +- .../listing-10-23/output.txt | 2 +- .../output.txt | 2 +- .../listing-11-01/src/lib.rs | 8 +++++++- .../listing-12-01/output.txt | 2 +- .../output-only-01-with-args/output.txt | 2 +- .../output.txt | 2 +- .../listing-13-03/output.txt | 2 +- .../listing-13-08/output.txt | 2 +- .../add/add_one/src/lib.rs | 8 +++++++- .../listing-15-03/output.txt | 2 +- .../listing-15-09/output.txt | 2 +- .../listing-15-15/output.txt | 2 +- .../listing-15-17/output.txt | 2 +- .../listing-15-21/output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../listing-16-03/output.txt | 2 +- .../listing-16-09/output.txt | 2 +- .../listing-16-13/output.txt | 2 +- .../listing-16-14/output.txt | 4 ++-- .../output-only-01-move-drop/output.txt | 2 +- listings/ch17-oop/listing-17-10/output.txt | 2 +- .../listing-18-05/output.txt | 2 +- .../listing-18-08/output.txt | 2 +- .../listing-18-25/output.txt | 2 +- .../listing-19-05/output.txt | 2 +- .../listing-19-20/output.txt | 2 +- .../output.txt | 2 +- .../no-listing-18-returns-closure/output.txt | 2 +- .../output-only-01-missing-unsafe/output.txt | 2 +- .../ch20-web-server/listing-20-12/output.txt | 2 +- .../ch20-web-server/listing-20-17/output.txt | 2 +- .../ch20-web-server/listing-20-22/output.txt | 4 ++-- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- rust-toolchain | 2 +- src/ch03-02-data-types.md | 3 ++- src/ch05-01-defining-structs.md | 2 +- ...ch09-01-unrecoverable-errors-with-panic.md | 19 ++++++++++--------- src/ch09-02-recoverable-errors-with-result.md | 10 ++++------ src/ch15-01-box.md | 2 +- src/title-page.md | 2 +- 72 files changed, 119 insertions(+), 102 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0ef0ade2bd..ec1ab4b08a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.75 -c rust-docs - rustup default 1.75 + rustup toolchain install 1.76 -c rust-docs + rustup default 1.76 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock index edc20385bd..0fb52b33cb 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock +++ b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock @@ -10,9 +10,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -28,15 +28,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.127" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "rand" @@ -61,9 +61,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 90dc4ba829..9ae3a32d0c 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,7 +18,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/cmp.rs:811:8 + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/cmp.rs:814:8 For more information about this error, try `rustc --explain E0308`. -error: could not compile `guessing_game` (bin "guessing_game") due to previous error +error: could not compile `guessing_game` (bin "guessing_game") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt index 554b764fc5..73ca9d62fb 100644 --- a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt @@ -13,4 +13,4 @@ error[E0384]: cannot assign twice to immutable variable `x` | ^^^^^ cannot assign twice to immutable variable For more information about this error, try `rustc --explain E0384`. -error: could not compile `variables` (bin "variables") due to previous error +error: could not compile `variables` (bin "variables") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt index 95773d11d4..2ddd39ff6e 100644 --- a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt @@ -15,4 +15,4 @@ help: try removing the method call | For more information about this error, try `rustc --explain E0308`. -error: could not compile `variables` (bin "variables") due to previous error +error: could not compile `variables` (bin "variables") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt index 33c3811911..504fdd6ec7 100644 --- a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt @@ -22,4 +22,4 @@ help: remove these parentheses | warning: `functions` (bin "functions") generated 1 warning -error: could not compile `functions` (bin "functions") due to previous error; 1 warning emitted +error: could not compile `functions` (bin "functions") due to 1 previous error; 1 warning emitted diff --git a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt index 337c5daf3a..18fdfd1b41 100644 --- a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt @@ -11,4 +11,4 @@ error[E0308]: mismatched types | - help: remove this semicolon to return this value For more information about this error, try `rustc --explain E0308`. -error: could not compile `functions` (bin "functions") due to previous error +error: could not compile `functions` (bin "functions") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt index 9b7296f1f5..c9c0b0c469 100644 --- a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt @@ -7,4 +7,4 @@ error[E0308]: mismatched types | ^^^^^^ expected `bool`, found integer For more information about this error, try `rustc --explain E0308`. -error: could not compile `branches` (bin "branches") due to previous error +error: could not compile `branches` (bin "branches") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt index debd0b9ca2..7fb857f035 100644 --- a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt @@ -9,4 +9,4 @@ error[E0308]: `if` and `else` have incompatible types | expected because of this For more information about this error, try `rustc --explain E0308`. -error: could not compile `branches` (bin "branches") due to previous error +error: could not compile `branches` (bin "branches") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt index 1329f9d73f..ee6a979432 100644 --- a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt +++ b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt @@ -13,4 +13,4 @@ help: consider giving `guess` an explicit type | ++++++++++++ For more information about this error, try `rustc --explain E0284`. -error: could not compile `no_type_annotations` (bin "no_type_annotations") due to previous error +error: could not compile `no_type_annotations` (bin "no_type_annotations") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/listing-04-06/output.txt b/listings/ch04-understanding-ownership/listing-04-06/output.txt index 3f47171879..c78cd5d3de 100644 --- a/listings/ch04-understanding-ownership/listing-04-06/output.txt +++ b/listings/ch04-understanding-ownership/listing-04-06/output.txt @@ -12,4 +12,4 @@ help: consider changing this to be a mutable reference | +++ For more information about this error, try `rustc --explain E0596`. -error: could not compile `ownership` (bin "ownership") due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt index 17aea46a6e..8f9e017980 100644 --- a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt @@ -18,4 +18,4 @@ help: consider cloning the value if the performance cost is acceptable | ++++++++ For more information about this error, try `rustc --explain E0382`. -error: could not compile `ownership` (bin "ownership") due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt b/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt index 1a4ea26b7a..97be4a2586 100644 --- a/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt @@ -12,4 +12,4 @@ error[E0499]: cannot borrow `s` as mutable more than once at a time | -- first borrow later used here For more information about this error, try `rustc --explain E0499`. -error: could not compile `ownership` (bin "ownership") due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt b/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt index 3884c6e118..4548823230 100644 --- a/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt @@ -13,4 +13,4 @@ error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immuta | -- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `ownership` (bin "ownership") due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt b/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt index 72bfe4c510..70e58af8b5 100644 --- a/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt @@ -7,10 +7,15 @@ error[E0106]: missing lifetime specifier | ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from -help: consider using the `'static` lifetime +help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | 5 | fn dangle() -> &'static String { | +++++++ +help: instead, you are more likely to want to return an owned value + | +5 - fn dangle() -> &String { +5 + fn dangle() -> String { + | For more information about this error, try `rustc --explain E0106`. -error: could not compile `ownership` (bin "ownership") due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt b/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt index 5adc2d0a77..be05d65283 100644 --- a/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt @@ -13,4 +13,4 @@ error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immuta | ---- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `ownership` (bin "ownership") due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt b/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt index 0e008b130b..ee169726d0 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt @@ -11,4 +11,4 @@ error[E0277]: `Rectangle` doesn't implement `std::fmt::Display` = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. -error: could not compile `rectangles` (bin "rectangles") due to previous error +error: could not compile `rectangles` (bin "rectangles") due to 1 previous error diff --git a/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt b/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt index 2685859954..bfb88ebee6 100644 --- a/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt @@ -2,8 +2,8 @@ $ cargo run Compiling rectangles v0.1.0 (file:///projects/rectangles) Finished dev [unoptimized + debuginfo] target(s) in 0.61s Running `target/debug/rectangles` -[src/main.rs:10] 30 * scale = 60 -[src/main.rs:14] &rect1 = Rectangle { +[src/main.rs:10:16] 30 * scale = 60 +[src/main.rs:14:5] &rect1 = Rectangle { width: 60, height: 50, } diff --git a/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt b/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt index 57bf3c7bc9..71de1f7bd3 100644 --- a/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt @@ -16,4 +16,4 @@ help: consider annotating `Rectangle` with `#[derive(Debug)]` | For more information about this error, try `rustc --explain E0277`. -error: could not compile `rectangles` (bin "rectangles") due to previous error +error: could not compile `rectangles` (bin "rectangles") due to 1 previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt index ba140f07ed..fa202e6212 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt @@ -14,4 +14,4 @@ error[E0277]: cannot add `Option` to `i8` <&i8 as Add<&i8>> For more information about this error, try `rustc --explain E0277`. -error: could not compile `enums` (bin "enums") due to previous error +error: could not compile `enums` (bin "enums") due to 1 previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index e609de51e2..4ec05abf05 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/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/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:569:1 - ::: /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:573:5 + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:570:1 + ::: /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:574:5 | = note: not covered = note: the matched value is of type `Option` @@ -19,4 +19,4 @@ help: ensure that all possible cases are being handled by adding a match arm wit | For more information about this error, try `rustc --explain E0004`. -error: could not compile `enums` (bin "enums") due to previous error +error: could not compile `enums` (bin "enums") due to 1 previous error diff --git a/listings/ch07-managing-growing-projects/listing-07-12/output.txt b/listings/ch07-managing-growing-projects/listing-07-12/output.txt index 9e73ebf6ae..0eda253125 100644 --- a/listings/ch07-managing-growing-projects/listing-07-12/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-12/output.txt @@ -21,4 +21,4 @@ warning: unused import: `crate::front_of_house::hosting` For more information about this error, try `rustc --explain E0433`. warning: `restaurant` (lib) generated 1 warning -error: could not compile `restaurant` (lib) due to previous error; 1 warning emitted +error: could not compile `restaurant` (lib) due to 1 previous error; 1 warning emitted diff --git a/listings/ch08-common-collections/listing-08-06/output.txt b/listings/ch08-common-collections/listing-08-06/output.txt index a38194b63b..f98ab1cde7 100644 --- a/listings/ch08-common-collections/listing-08-06/output.txt +++ b/listings/ch08-common-collections/listing-08-06/output.txt @@ -13,4 +13,4 @@ error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immuta | ------- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `collections` (bin "collections") due to previous error +error: could not compile `collections` (bin "collections") due to 1 previous error diff --git a/listings/ch08-common-collections/listing-08-19/output.txt b/listings/ch08-common-collections/listing-08-19/output.txt index bc4c679052..de20b73edf 100644 --- a/listings/ch08-common-collections/listing-08-19/output.txt +++ b/listings/ch08-common-collections/listing-08-19/output.txt @@ -1,10 +1,10 @@ $ cargo run Compiling collections v0.1.0 (file:///projects/collections) error[E0277]: the type `String` cannot be indexed by `{integer}` - --> src/main.rs:3:13 + --> src/main.rs:3:16 | 3 | let h = s1[0]; - | ^^^^^ `String` cannot be indexed by `{integer}` + | ^ `String` cannot be indexed by `{integer}` | = help: the trait `Index<{integer}>` is not implemented for `String` = help: the following other types implement trait `Index`: @@ -16,4 +16,4 @@ error[E0277]: the type `String` cannot be indexed by `{integer}` >> For more information about this error, try `rustc --explain E0277`. -error: could not compile `collections` (bin "collections") due to previous error +error: could not compile `collections` (bin "collections") due to 1 previous error diff --git a/listings/ch09-error-handling/listing-09-10/output.txt b/listings/ch09-error-handling/listing-09-10/output.txt index e1570745cf..dbc9bb13dc 100644 --- a/listings/ch09-error-handling/listing-09-10/output.txt +++ b/listings/ch09-error-handling/listing-09-10/output.txt @@ -11,4 +11,4 @@ error[E0277]: the `?` operator can only be used in a function that returns `Resu = help: the trait `FromResidual>` is not implemented for `()` For more information about this error, try `rustc --explain E0277`. -error: could not compile `error-handling` (bin "error-handling") due to previous error +error: could not compile `error-handling` (bin "error-handling") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt index 0857a1434f..05b96ca173 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt @@ -14,4 +14,4 @@ help: consider restricting type parameter `T` | ++++++++++++++++++++++ For more information about this error, try `rustc --explain E0369`. -error: could not compile `chapter10` (bin "chapter10") due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt index ddebf76685..5f6c3f4657 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt @@ -7,4 +7,4 @@ error[E0308]: mismatched types | ^^^ expected integer, found floating-point number For more information about this error, try `rustc --explain E0308`. -error: could not compile `chapter10` (bin "chapter10") due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt index 8173b5527a..6afb5b0c2a 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt @@ -14,4 +14,4 @@ error[E0597]: `x` does not live long enough | - borrow later used here For more information about this error, try `rustc --explain E0597`. -error: could not compile `chapter10` (bin "chapter10") due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt index 36a6d83cf1..a6783b2ccd 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt @@ -13,4 +13,4 @@ help: consider introducing a named lifetime parameter | ++++ ++ ++ ++ For more information about this error, try `rustc --explain E0106`. -error: could not compile `chapter10` (bin "chapter10") due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt index c28b056b82..471347c68f 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt @@ -13,4 +13,4 @@ error[E0597]: `string2` does not live long enough | ------ borrow later used here For more information about this error, try `rustc --explain E0597`. -error: could not compile `chapter10` (bin "chapter10") due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt index fbff3e27fe..9b9ef2338c 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt @@ -10,4 +10,4 @@ error[E0515]: cannot return value referencing local variable `result` | `result` is borrowed here For more information about this error, try `rustc --explain E0515`. -error: could not compile `chapter10` (bin "chapter10") due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs index 1b4a90c938..7d12d9af81 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs @@ -1,8 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn it_works() { - let result = 2 + 2; + let result = add(2, 2); assert_eq!(result, 4); } } diff --git a/listings/ch12-an-io-project/listing-12-01/output.txt b/listings/ch12-an-io-project/listing-12-01/output.txt index 529115f8d4..7017af1ab9 100644 --- a/listings/ch12-an-io-project/listing-12-01/output.txt +++ b/listings/ch12-an-io-project/listing-12-01/output.txt @@ -2,6 +2,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished dev [unoptimized + debuginfo] target(s) in 0.61s Running `target/debug/minigrep` -[src/main.rs:5] args = [ +[src/main.rs:5:5] args = [ "target/debug/minigrep", ] diff --git a/listings/ch12-an-io-project/output-only-01-with-args/output.txt b/listings/ch12-an-io-project/output-only-01-with-args/output.txt index b48bb0e108..ef5743967e 100644 --- a/listings/ch12-an-io-project/output-only-01-with-args/output.txt +++ b/listings/ch12-an-io-project/output-only-01-with-args/output.txt @@ -2,7 +2,7 @@ $ cargo run -- needle haystack Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished dev [unoptimized + debuginfo] target(s) in 1.57s Running `target/debug/minigrep needle haystack` -[src/main.rs:5] args = [ +[src/main.rs:5:5] args = [ "target/debug/minigrep", "needle", "haystack", diff --git a/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt b/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt index 340c48efec..7e46576b4a 100644 --- a/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt +++ b/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt @@ -13,4 +13,4 @@ help: consider introducing a named lifetime parameter | ++++ ++ ++ ++ For more information about this error, try `rustc --explain E0106`. -error: could not compile `minigrep` (lib) due to previous error +error: could not compile `minigrep` (lib) due to 1 previous error diff --git a/listings/ch13-functional-features/listing-13-03/output.txt b/listings/ch13-functional-features/listing-13-03/output.txt index fdc88f6388..16716c3ac1 100644 --- a/listings/ch13-functional-features/listing-13-03/output.txt +++ b/listings/ch13-functional-features/listing-13-03/output.txt @@ -23,4 +23,4 @@ note: closure parameter defined here | ^ For more information about this error, try `rustc --explain E0308`. -error: could not compile `closure-example` (bin "closure-example") due to previous error +error: could not compile `closure-example` (bin "closure-example") due to 1 previous error diff --git a/listings/ch13-functional-features/listing-13-08/output.txt b/listings/ch13-functional-features/listing-13-08/output.txt index f411d65223..4e5b0bec30 100644 --- a/listings/ch13-functional-features/listing-13-08/output.txt +++ b/listings/ch13-functional-features/listing-13-08/output.txt @@ -12,4 +12,4 @@ error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` clos | ^^^^^ move occurs because `value` has type `String`, which does not implement the `Copy` trait For more information about this error, try `rustc --explain E0507`. -error: could not compile `rectangles` (bin "rectangles") due to previous error +error: could not compile `rectangles` (bin "rectangles") due to 1 previous error diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs index 1b4a90c938..7d12d9af81 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs @@ -1,8 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn it_works() { - let result = 2 + 2; + let result = add(2, 2); assert_eq!(result, 4); } } diff --git a/listings/ch15-smart-pointers/listing-15-03/output.txt b/listings/ch15-smart-pointers/listing-15-03/output.txt index 58eada3f24..9e54b51938 100644 --- a/listings/ch15-smart-pointers/listing-15-03/output.txt +++ b/listings/ch15-smart-pointers/listing-15-03/output.txt @@ -14,4 +14,4 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | ++++ + For more information about this error, try `rustc --explain E0072`. -error: could not compile `cons-list` (bin "cons-list") due to previous error +error: could not compile `cons-list` (bin "cons-list") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-09/output.txt b/listings/ch15-smart-pointers/listing-15-09/output.txt index 5999bbd5fb..a295d26284 100644 --- a/listings/ch15-smart-pointers/listing-15-09/output.txt +++ b/listings/ch15-smart-pointers/listing-15-09/output.txt @@ -7,4 +7,4 @@ error[E0614]: type `MyBox<{integer}>` cannot be dereferenced | ^^ For more information about this error, try `rustc --explain E0614`. -error: could not compile `deref-example` (bin "deref-example") due to previous error +error: could not compile `deref-example` (bin "deref-example") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-15/output.txt b/listings/ch15-smart-pointers/listing-15-15/output.txt index c7c9342cb1..8a53b28520 100644 --- a/listings/ch15-smart-pointers/listing-15-15/output.txt +++ b/listings/ch15-smart-pointers/listing-15-15/output.txt @@ -12,4 +12,4 @@ help: consider using `drop` function | +++++ ~ For more information about this error, try `rustc --explain E0040`. -error: could not compile `drop-example` (bin "drop-example") due to previous error +error: could not compile `drop-example` (bin "drop-example") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-17/output.txt b/listings/ch15-smart-pointers/listing-15-17/output.txt index 9596272eb1..757a65fb54 100644 --- a/listings/ch15-smart-pointers/listing-15-17/output.txt +++ b/listings/ch15-smart-pointers/listing-15-17/output.txt @@ -11,4 +11,4 @@ error[E0382]: use of moved value: `a` | ^ value used here after move For more information about this error, try `rustc --explain E0382`. -error: could not compile `cons-list` (bin "cons-list") due to previous error +error: could not compile `cons-list` (bin "cons-list") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-21/output.txt b/listings/ch15-smart-pointers/listing-15-21/output.txt index f94f72f48c..3f00da3607 100644 --- a/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/listings/ch15-smart-pointers/listing-15-21/output.txt @@ -12,4 +12,4 @@ help: consider changing this to be a mutable reference | ~~~~~~~~~ For more information about this error, try `rustc --explain E0596`. -error: could not compile `limit-tracker` (lib test) due to previous error +error: could not compile `limit-tracker` (lib test) due to 1 previous error diff --git a/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt b/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt index a2e77d4d0c..95b9b68a82 100644 --- a/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt +++ b/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt @@ -12,4 +12,4 @@ help: consider changing this to be mutable | +++ For more information about this error, try `rustc --explain E0596`. -error: could not compile `borrowing` (bin "borrowing") due to previous error +error: could not compile `borrowing` (bin "borrowing") due to 1 previous error diff --git a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt index c4c5ee6ef6..c7ed502b27 100644 --- a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt +++ b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt @@ -20,4 +20,4 @@ error[E0277]: can't compare `{integer}` with `&{integer}` = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. -error: could not compile `deref-example` (bin "deref-example") due to previous error +error: could not compile `deref-example` (bin "deref-example") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-03/output.txt b/listings/ch16-fearless-concurrency/listing-16-03/output.txt index c8624e2670..f90a9bcf4a 100644 --- a/listings/ch16-fearless-concurrency/listing-16-03/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-03/output.txt @@ -22,4 +22,4 @@ help: to force the closure to take ownership of `v` (and any other referenced va | ++++ For more information about this error, try `rustc --explain E0373`. -error: could not compile `threads` (bin "threads") due to previous error +error: could not compile `threads` (bin "threads") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-09/output.txt b/listings/ch16-fearless-concurrency/listing-16-09/output.txt index a31a003e2e..b32885752b 100644 --- a/listings/ch16-fearless-concurrency/listing-16-09/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-09/output.txt @@ -17,4 +17,4 @@ help: consider cloning the value if the performance cost is acceptable | ++++++++ For more information about this error, try `rustc --explain E0382`. -error: could not compile `message-passing` (bin "message-passing") due to previous error +error: could not compile `message-passing` (bin "message-passing") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-13/output.txt b/listings/ch16-fearless-concurrency/listing-16-13/output.txt index ac881aabe7..5405f76bcf 100644 --- a/listings/ch16-fearless-concurrency/listing-16-13/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-13/output.txt @@ -13,4 +13,4 @@ error[E0382]: borrow of moved value: `counter` | ^^^^^^^ value borrowed here after move For more information about this error, try `rustc --explain E0382`. -error: could not compile `shared-state` (bin "shared-state") due to previous error +error: could not compile `shared-state` (bin "shared-state") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index a469f6e6b0..504826c1b8 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/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/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/mod.rs:682:1 + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:678:1 For more information about this error, try `rustc --explain E0277`. -error: could not compile `shared-state` (bin "shared-state") due to previous error +error: could not compile `shared-state` (bin "shared-state") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt b/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt index 922e84d543..269f1a95e8 100644 --- a/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt +++ b/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt @@ -15,4 +15,4 @@ error[E0382]: use of moved value: `v` | ^ value used here after move For more information about this error, try `rustc --explain E0382`. -error: could not compile `threads` (bin "threads") due to previous error +error: could not compile `threads` (bin "threads") due to 1 previous error diff --git a/listings/ch17-oop/listing-17-10/output.txt b/listings/ch17-oop/listing-17-10/output.txt index 25ad7efcb0..78d7c39a32 100644 --- a/listings/ch17-oop/listing-17-10/output.txt +++ b/listings/ch17-oop/listing-17-10/output.txt @@ -10,4 +10,4 @@ error[E0277]: the trait bound `String: Draw` is not satisfied = note: required for the cast from `Box` to `Box` For more information about this error, try `rustc --explain E0277`. -error: could not compile `gui` (bin "gui") due to previous error +error: could not compile `gui` (bin "gui") due to 1 previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-05/output.txt b/listings/ch18-patterns-and-matching/listing-18-05/output.txt index 6c59302e73..8002272a72 100644 --- a/listings/ch18-patterns-and-matching/listing-18-05/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-05/output.txt @@ -12,4 +12,4 @@ error[E0308]: mismatched types found tuple `(_, _)` For more information about this error, try `rustc --explain E0308`. -error: could not compile `patterns` (bin "patterns") due to previous error +error: could not compile `patterns` (bin "patterns") due to 1 previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-08/output.txt b/listings/ch18-patterns-and-matching/listing-18-08/output.txt index 7c335384e4..6ce3dfc582 100644 --- a/listings/ch18-patterns-and-matching/listing-18-08/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-08/output.txt @@ -15,4 +15,4 @@ help: you might want to use `let else` to handle the variant that isn't matched | ++++++++++++++++ For more information about this error, try `rustc --explain E0005`. -error: could not compile `patterns` (bin "patterns") due to previous error +error: could not compile `patterns` (bin "patterns") due to 1 previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-25/output.txt b/listings/ch18-patterns-and-matching/listing-18-25/output.txt index 09255c738b..bd5e0f9d7b 100644 --- a/listings/ch18-patterns-and-matching/listing-18-25/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-25/output.txt @@ -8,4 +8,4 @@ error: `..` can only be used once per tuple pattern | | | previously used here -error: could not compile `patterns` (bin "patterns") due to previous error +error: could not compile `patterns` (bin "patterns") due to 1 previous error diff --git a/listings/ch19-advanced-features/listing-19-05/output.txt b/listings/ch19-advanced-features/listing-19-05/output.txt index 9362fd3537..44bcc09135 100644 --- a/listings/ch19-advanced-features/listing-19-05/output.txt +++ b/listings/ch19-advanced-features/listing-19-05/output.txt @@ -14,4 +14,4 @@ error[E0499]: cannot borrow `*values` as mutable more than once at a time | returning this value requires that `*values` is borrowed for `'1` For more information about this error, try `rustc --explain E0499`. -error: could not compile `unsafe-example` (bin "unsafe-example") due to previous error +error: could not compile `unsafe-example` (bin "unsafe-example") due to 1 previous error diff --git a/listings/ch19-advanced-features/listing-19-20/output.txt b/listings/ch19-advanced-features/listing-19-20/output.txt index 19d978b8e7..3cb5961a1a 100644 --- a/listings/ch19-advanced-features/listing-19-20/output.txt +++ b/listings/ch19-advanced-features/listing-19-20/output.txt @@ -15,4 +15,4 @@ help: use the fully-qualified path to the only available implementation | +++++++ + For more information about this error, try `rustc --explain E0790`. -error: could not compile `traits-example` (bin "traits-example") due to previous error +error: could not compile `traits-example` (bin "traits-example") due to 1 previous error diff --git a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt index f3c90e41aa..d5f2155f83 100644 --- a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt +++ b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt @@ -15,4 +15,4 @@ note: required by a bound in `OutlinePrint` | ^^^^^^^^^^^^ required by this bound in `OutlinePrint` For more information about this error, try `rustc --explain E0277`. -error: could not compile `traits-example` (bin "traits-example") due to previous error +error: could not compile `traits-example` (bin "traits-example") due to 1 previous error diff --git a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt index 61349a7d0a..bc736bd689 100644 --- a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt +++ b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt @@ -17,4 +17,4 @@ help: box the return type, and wrap all of the returned values in `Box::new` | For more information about this error, try `rustc --explain E0746`. -error: could not compile `functions-example` (lib) due to previous error +error: could not compile `functions-example` (lib) due to 1 previous error diff --git a/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt b/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt index 0d61d2a9b2..b2ed043a10 100644 --- a/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt +++ b/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt @@ -9,4 +9,4 @@ error[E0133]: call to unsafe function is unsafe and requires unsafe function or = note: consult the function's documentation for information on how to avoid undefined behavior For more information about this error, try `rustc --explain E0133`. -error: could not compile `unsafe-example` (bin "unsafe-example") due to previous error +error: could not compile `unsafe-example` (bin "unsafe-example") due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-12/output.txt b/listings/ch20-web-server/listing-20-12/output.txt index a768404719..0faae99204 100644 --- a/listings/ch20-web-server/listing-20-12/output.txt +++ b/listings/ch20-web-server/listing-20-12/output.txt @@ -7,4 +7,4 @@ error[E0433]: failed to resolve: use of undeclared type `ThreadPool` | ^^^^^^^^^^ use of undeclared type `ThreadPool` For more information about this error, try `rustc --explain E0433`. -error: could not compile `hello` (bin "hello") due to previous error +error: could not compile `hello` (bin "hello") due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-17/output.txt b/listings/ch20-web-server/listing-20-17/output.txt index 6272ad2898..cd06ca1b60 100644 --- a/listings/ch20-web-server/listing-20-17/output.txt +++ b/listings/ch20-web-server/listing-20-17/output.txt @@ -18,4 +18,4 @@ note: consider changing this parameter type in method `new` to borrow instead if | --- in this method ^^^^^^^^^^^^^^^^^^^ this parameter takes ownership of the value For more information about this error, try `rustc --explain E0382`. -error: could not compile `hello` (lib) due to previous error +error: could not compile `hello` (lib) due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index da1134cd25..35588617dd 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/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/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/mod.rs:1652:17 + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:1649:17 For more information about this error, try `rustc --explain E0507`. -error: could not compile `hello` (lib) due to previous error +error: could not compile `hello` (lib) due to 1 previous error diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt b/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt index 70e35665da..85ebfb8138 100644 --- a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt +++ b/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt @@ -7,4 +7,4 @@ error[E0599]: no function or associated item named `new` found for struct `Threa | ^^^ function or associated item not found in `ThreadPool` For more information about this error, try `rustc --explain E0599`. -error: could not compile `hello` (bin "hello") due to previous error +error: could not compile `hello` (bin "hello") due to 1 previous error diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt index 054b810cfc..667041862d 100644 --- a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt +++ b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt @@ -7,4 +7,4 @@ error[E0599]: no method named `execute` found for struct `ThreadPool` in the cur | -----^^^^^^^ method not found in `ThreadPool` For more information about this error, try `rustc --explain E0599`. -error: could not compile `hello` (bin "hello") due to previous error +error: could not compile `hello` (bin "hello") due to 1 previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 49f7193772..4a622de7f9 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/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/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/mod.rs:1652:5 + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:1649: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/rust-toolchain b/rust-toolchain index 07cde98405..9242d8e7ab 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.75 +1.76 diff --git a/src/ch03-02-data-types.md b/src/ch03-02-data-types.md index bedf1450cc..2cfc156e89 100644 --- a/src/ch03-02-data-types.md +++ b/src/ch03-02-data-types.md @@ -352,7 +352,8 @@ cargo run --> ```console -thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 10', src/main.rs:19:19 +thread 'main' panicked at src/main.rs:19:19: +index out of bounds: the len is 5 but the index is 10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index d258d89cc5..ffd9f1d7cc 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -278,7 +278,7 @@ implement them on any type, including unit-like structs. > | > > For more information about this error, try `rustc --explain E0106`. -> error: could not compile `structs` due to 2 previous errors +> error: could not compile `structs` (bin "structs") due to 2 previous errors > ``` > > In Chapter 10, we’ll discuss how to fix these errors so you can store diff --git a/src/ch09-01-unrecoverable-errors-with-panic.md b/src/ch09-01-unrecoverable-errors-with-panic.md index 5675fe3e76..3928f8d61a 100644 --- a/src/ch09-01-unrecoverable-errors-with-panic.md +++ b/src/ch09-01-unrecoverable-errors-with-panic.md @@ -117,24 +117,25 @@ check the backtrace number mentioned in the text below the listing ```console $ RUST_BACKTRACE=1 cargo run -thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5 +thread 'main' panicked at src/main.rs:4:6: +index out of bounds: the len is 3 but the index is 99 stack backtrace: 0: rust_begin_unwind - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:584:5 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5 1: core::panicking::panic_fmt - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:142:14 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14 2: core::panicking::panic_bounds_check - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:84:5 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:208:5 3: >::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/slice/index.rs:242:10 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/index.rs:255:10 4: core::slice::index:: for [T]>::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/slice/index.rs:18:9 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/index.rs:18:9 5: as core::ops::index::Index>::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/alloc/src/vec/mod.rs:2591:9 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/vec/mod.rs:2770:9 6: panic::main - at ./src/main.rs:4:5 + at ./src/main.rs:4:6 7: core::ops::function::FnOnce::call_once - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/ops/function.rs:248:5 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ``` diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 2ee006f09d..34c4e2061b 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -188,9 +188,8 @@ copy and paste relevant text --> ```text -thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { -code: 2, kind: NotFound, message: "No such file or directory" }', -src/main.rs:4:49 +thread 'main' panicked at src/main.rs:4:49: +called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" } ``` Similarly, the `expect` method lets us also choose the `panic!` error message. @@ -216,9 +215,8 @@ copy and paste relevant text --> ```text -thread 'main' panicked at 'hello.txt should be included in this project: Os { -code: 2, kind: NotFound, message: "No such file or directory" }', -src/main.rs:5:10 +thread 'main' panicked at src/main.rs:5:10: +hello.txt should be included in this project: Os { code: 2, kind: NotFound, message: "No such file or directory" } ``` In production-quality code, most Rustaceans choose `expect` rather than diff --git a/src/ch15-01-box.md b/src/ch15-01-box.md index 8380625527..53e829a4c3 100644 --- a/src/ch15-01-box.md +++ b/src/ch15-01-box.md @@ -193,7 +193,7 @@ after doing automatic regeneration, look at listings/ch15-smart-pointers/listing --> ```text -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | 2 | Cons(i32, Box), | ++++ + diff --git a/src/title-page.md b/src/title-page.md index 6127fa3fb4..4c9550040d 100644 --- a/src/title-page.md +++ b/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.75.0 (released 2023-12-28) +This version of the text assumes you’re using Rust 1.76.0 (released 2024-02-08) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 19c40bfd2d57641d962f3119a1c343355f1b3c5e Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Feb 2024 14:20:00 -0500 Subject: [PATCH 088/720] Add a rustc hash to spellcheck dictionary --- ci/dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index a91df4a036..013d38dcc3 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -35,6 +35,7 @@ backtraces BACKTRACE Backtraces Baz's +beefeb benchmarking bioinformatics bitand From 65cb1229a671a3475b4eab2dcbdccc42d9b45c0c Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Wed, 28 Feb 2024 21:50:35 +0000 Subject: [PATCH 089/720] Fix missing `the` in 04-03 --- src/ch04-03-slices.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 6ffb1dc114..c94fdc56f2 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -266,7 +266,7 @@ a string slice for the type of the `s` parameter If we have a string slice, we can pass that directly. If we have a `String`, we can pass a slice of the `String` or a reference to the `String`. This -flexibility takes advantage of *deref coercions*, a feature we will cover in +flexibility takes advantage of *deref coercions*, a feature we will cover in the [“Implicit Deref Coercions with Functions and Methods”][deref-coercions] section of Chapter 15. From af775b870f026141530289f7714d51174bfb0d5a Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Sat, 9 Mar 2024 02:23:59 +0000 Subject: [PATCH 090/720] Fix grammar in 07-03 --- ...ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index c8fb3247ff..e2e627eb75 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -185,7 +185,7 @@ interested in this topic, see [The Rust API Guidelines][api-guidelines]. > package name by default. Typically, packages with this pattern of containing > both a library and a binary crate will have just enough code in the binary > crate to start an executable that calls code with the library crate. This -> lets other projects benefit from the most functionality that the package +> lets other projects benefit from most of the functionality that the package > provides, because the library crate’s code can be shared. > > The module tree should be defined in *src/lib.rs*. Then, any public items can From 4e63e84c552186e5c8c18448188cced969e9a4e0 Mon Sep 17 00:00:00 2001 From: Herbert Reiter <46045854+damoasda@users.noreply.github.com> Date: Sat, 9 Mar 2024 14:40:44 +0100 Subject: [PATCH 091/720] Fix missing column separator --- src/appendix-02-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appendix-02-operators.md b/src/appendix-02-operators.md index bc770c703e..0a8dab9d61 100644 --- a/src/appendix-02-operators.md +++ b/src/appendix-02-operators.md @@ -103,7 +103,7 @@ hierarchy to an item. |--------|-------------| | `ident::ident` | Namespace path | | `::path` | Path relative to the crate root (i.e., an explicitly absolute path) | -| `self::path` | Path relative to the current module (i.e., an explicitly relative path). +| `self::path` | Path relative to the current module (i.e., an explicitly relative path). | | `super::path` | Path relative to the parent of the current module | | `type::ident`, `::ident` | Associated constants, functions, and types | | `::...` | Associated item for a type that cannot be directly named (e.g., `<&T>::...`, `<[T]>::...`, etc.) | From 41f759beb24b916e49fbb21faad913ac2dbb12ec Mon Sep 17 00:00:00 2001 From: Herbert Reiter <46045854+damoasda@users.noreply.github.com> Date: Sat, 9 Mar 2024 14:42:43 +0100 Subject: [PATCH 092/720] Update compiler message --- src/ch11-01-writing-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index df09aadc84..7c36f729eb 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -309,7 +309,7 @@ Run the tests again: ``` Our test caught the bug! The `it_adds_two` test failed, and the message tells -us that the assertion that fails was `` assertion failed: `(left == right)` `` +us that the assertion that fails was ``assertion `left == right` failed`` and what the `left` and `right` values are. This message helps us start debugging: the `left` argument was `4` but the `right` argument, where we had `add_two(2)`, was `5`. You can imagine that this would be especially helpful From bc9bdef970dd95ae73f8085a7cbfcc48de299680 Mon Sep 17 00:00:00 2001 From: Chris Jansen Date: Sat, 9 Mar 2024 13:43:17 -0500 Subject: [PATCH 093/720] Update full code reference main.rs in ch20-03 Updated the full code reference for `main.rs` at the end of Chapter 20.3 to match the code the tutorial instructs you to write. Namely: * Formats the `use` statements to match the format in the earlier code blocks * Updates the `handle_connection` function to use `BufReader` and a `match` expression per the earlier code blocks --- .../no-listing-07-final-code/src/main.rs | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/listings/ch20-web-server/no-listing-07-final-code/src/main.rs b/listings/ch20-web-server/no-listing-07-final-code/src/main.rs index 3161c2ee5c..f34f927e71 100644 --- a/listings/ch20-web-server/no-listing-07-final-code/src/main.rs +++ b/listings/ch20-web-server/no-listing-07-final-code/src/main.rs @@ -1,10 +1,11 @@ use hello::ThreadPool; -use std::fs; -use std::io::prelude::*; -use std::net::TcpListener; -use std::net::TcpStream; -use std::thread; -use std::time::Duration; +use std::{ + fs, + io::{prelude::*, BufReader}, + net::{TcpListener, TcpStream}, + thread, + time::Duration, +}; fn main() { let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); @@ -22,27 +23,25 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let mut buffer = [0; 1024]; - stream.read(&mut buffer).unwrap(); - - let get = b"GET / HTTP/1.1\r\n"; - let sleep = b"GET /sleep HTTP/1.1\r\n"; - - let (status_line, filename) = if buffer.starts_with(get) { - ("HTTP/1.1 200 OK", "hello.html") - } else if buffer.starts_with(sleep) { - thread::sleep(Duration::from_secs(5)); - ("HTTP/1.1 200 OK", "hello.html") - } else { - ("HTTP/1.1 404 NOT FOUND", "404.html") + let buf_reader = BufReader::new(&mut stream); + let request_line = buf_reader.lines().next().unwrap().unwrap(); + + let (status_line, filename) = match &request_line[..] { + "GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"), + "GET /sleep HTTP/1.1" => { + thread::sleep(Duration::from_secs(5)); + ("HTTP/1.1 200 OK", "hello.html") + } + _ => ("HTTP/1.1 404 NOT FOUND", "404.html"), }; let contents = fs::read_to_string(filename).unwrap(); + let length = contents.len(); let response = format!( "{}\r\nContent-Length: {}\r\n\r\n{}", status_line, - contents.len(), + length, contents ); From a6771cc7f5d8f2f9843ac97bb2a19b9c36603d61 Mon Sep 17 00:00:00 2001 From: Wang Qilin Date: Tue, 12 Mar 2024 15:08:02 +0800 Subject: [PATCH 094/720] Update appendix-07-nightly-rust.md to add maintenance time section Update appendix-07-nightly-rust.md add maintenance time section Signed-off-by: Wang Qilin --- src/appendix-07-nightly-rust.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/appendix-07-nightly-rust.md b/src/appendix-07-nightly-rust.md index 46e619c815..bccafb0b37 100644 --- a/src/appendix-07-nightly-rust.md +++ b/src/appendix-07-nightly-rust.md @@ -114,6 +114,12 @@ work as expected, you can report it to the team and get it fixed before the next stable release happens! Breakage in a beta release is relatively rare, but `rustc` is still a piece of software, and bugs do exist. +### Maintenance time + +The Rust project only supports the most recent stable version, which means the +maintenance time of a stable version is six weeks. When a new stable version +released, the old version reaches its EOL(end-of-life). + ### Unstable Features There’s one more catch with this release model: unstable features. Rust uses a From 62572d1b09fe69bf9420ff7ca4592e11e1849707 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 27 Mar 2024 12:19:03 -0600 Subject: [PATCH 095/720] Slight wording clarification in ch. 3.5 about for loops --- src/ch03-05-control-flow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch03-05-control-flow.md b/src/ch03-05-control-flow.md index aac0e0c653..34b8372f34 100644 --- a/src/ch03-05-control-flow.md +++ b/src/ch03-05-control-flow.md @@ -297,7 +297,7 @@ evaluates to `true`, the code runs; otherwise, it exits the loop. #### Looping Through a Collection with `for` -You could choose to use the `while` construct to loop over the elements of a +You can also use the `while` construct to loop over the elements of a collection, such as an array. For example, the loop in Listing 3-4 prints each element in the array `a`. From ff1602d3ef47460fa30a718f353bf4324149f460 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 27 Mar 2024 14:55:03 -0600 Subject: [PATCH 096/720] Tweak wording of new support timeline language --- src/appendix-07-nightly-rust.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/appendix-07-nightly-rust.md b/src/appendix-07-nightly-rust.md index bccafb0b37..ac3fbb9df9 100644 --- a/src/appendix-07-nightly-rust.md +++ b/src/appendix-07-nightly-rust.md @@ -116,9 +116,9 @@ next stable release happens! Breakage in a beta release is relatively rare, but ### Maintenance time -The Rust project only supports the most recent stable version, which means the -maintenance time of a stable version is six weeks. When a new stable version -released, the old version reaches its EOL(end-of-life). +The Rust project supports the most recent stable version. When a new stable +version is released, the old version reaches its end of life (EOL). This means +each version is supported for six weeks. ### Unstable Features From ee832a0849703a0dd0758e625fdb3b0a05dfcbde Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 1 Apr 2024 14:24:46 -0600 Subject: [PATCH 097/720] Fix a typo: remove an extra 's' from ch. 18.01 Fixes #3561 --- src/ch08-01-vectors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index 85d3bcfe41..d6d72de069 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -202,7 +202,7 @@ some of the columns in the row contain integers, some floating-point numbers, and some strings. We can define an enum whose variants will hold the different value types, and all the enum variants will be considered the same type: that of the enum. Then we can create a vector to hold that enum and so, ultimately, -holds different types. We’ve demonstrated this in Listing 8-9. +hold different types. We’ve demonstrated this in Listing 8-9. ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-09/src/main.rs:here}} From 54d5a35dfb7f9dcd7331279ee32c5817a4188597 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 3 Apr 2024 13:27:16 -0600 Subject: [PATCH 098/720] Revert extraneous comma --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd75900835..52e063ec0f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ See the [releases] to download just the code of all the code listings that appea ## Requirements -Building the book requires [mdBook], ideally, the same version that +Building the book requires [mdBook], ideally the same version that rust-lang/rust uses in [this file][rust-mdbook]. To get it: [mdBook]: https://github.com/rust-lang-nursery/mdBook From 204c6c40fd235e6eefebd9f66014f24de32a680f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 3 Apr 2024 13:42:45 -0600 Subject: [PATCH 099/720] Make Note text in ch. 20 consistent with other notes --- src/ch20-02-multithreaded.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch20-02-multithreaded.md b/src/ch20-02-multithreaded.md index 5a4a50ac01..cec2272db5 100644 --- a/src/ch20-02-multithreaded.md +++ b/src/ch20-02-multithreaded.md @@ -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. From a14b54050c7cb425ed10037d237b49e73818914c Mon Sep 17 00:00:00 2001 From: Chris Jansen Date: Wed, 3 Apr 2024 17:12:03 -0400 Subject: [PATCH 100/720] Updated listings based on `listing-20-24` Updated `main.rs` in both `listing-20-25` and `no-listing-07-final-code` based on `listing-20-24` --- .../ch20-web-server/listing-20-25/src/main.rs | 46 ++++++++----------- .../no-listing-07-final-code/src/main.rs | 9 +--- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/listings/ch20-web-server/listing-20-25/src/main.rs b/listings/ch20-web-server/listing-20-25/src/main.rs index a649ff1031..86e8d9e78c 100644 --- a/listings/ch20-web-server/listing-20-25/src/main.rs +++ b/listings/ch20-web-server/listing-20-25/src/main.rs @@ -1,10 +1,11 @@ use hello::ThreadPool; -use std::fs; -use std::io::prelude::*; -use std::net::TcpListener; -use std::net::TcpStream; -use std::thread; -use std::time::Duration; +use std::{ + fs, + io::{prelude::*, BufReader}, + net::{TcpListener, TcpStream}, + thread, + time::Duration, +}; // ANCHOR: here fn main() { @@ -24,30 +25,23 @@ fn main() { // ANCHOR_END: here fn handle_connection(mut stream: TcpStream) { - let mut buffer = [0; 1024]; - stream.read(&mut buffer).unwrap(); - - let get = b"GET / HTTP/1.1\r\n"; - let sleep = b"GET /sleep HTTP/1.1\r\n"; - - let (status_line, filename) = if buffer.starts_with(get) { - ("HTTP/1.1 200 OK", "hello.html") - } else if buffer.starts_with(sleep) { - thread::sleep(Duration::from_secs(5)); - ("HTTP/1.1 200 OK", "hello.html") - } else { - ("HTTP/1.1 404 NOT FOUND", "404.html") + let buf_reader = BufReader::new(&mut stream); + let request_line = buf_reader.lines().next().unwrap().unwrap(); + + let (status_line, filename) = match &request_line[..] { + "GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"), + "GET /sleep HTTP/1.1" => { + thread::sleep(Duration::from_secs(5)); + ("HTTP/1.1 200 OK", "hello.html") + } + _ => ("HTTP/1.1 404 NOT FOUND", "404.html"), }; let contents = fs::read_to_string(filename).unwrap(); + let length = contents.len(); - let response = format!( - "{}\r\nContent-Length: {}\r\n\r\n{}", - status_line, - contents.len(), - contents - ); + let response = + format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"); stream.write_all(response.as_bytes()).unwrap(); - stream.flush().unwrap(); } diff --git a/listings/ch20-web-server/no-listing-07-final-code/src/main.rs b/listings/ch20-web-server/no-listing-07-final-code/src/main.rs index f34f927e71..b6aa046d1b 100644 --- a/listings/ch20-web-server/no-listing-07-final-code/src/main.rs +++ b/listings/ch20-web-server/no-listing-07-final-code/src/main.rs @@ -38,13 +38,8 @@ fn handle_connection(mut stream: TcpStream) { let contents = fs::read_to_string(filename).unwrap(); let length = contents.len(); - let response = format!( - "{}\r\nContent-Length: {}\r\n\r\n{}", - status_line, - length, - contents - ); + let response = + format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"); stream.write_all(response.as_bytes()).unwrap(); - stream.flush().unwrap(); } From 4229b328985f9df8349c4c113f0ba1b5f144a1f9 Mon Sep 17 00:00:00 2001 From: Blatko1 Date: Thu, 4 Apr 2024 19:10:49 +0200 Subject: [PATCH 101/720] reverted all the changes but one --- src/appendix-01-keywords.md | 10 +++---- src/appendix-02-operators.md | 4 +-- src/appendix-03-derivable-traits.md | 8 +++--- src/appendix-04-useful-development-tools.md | 9 ++++--- src/appendix-05-editions.md | 2 +- src/appendix-07-nightly-rust.md | 7 ++--- src/ch00-00-introduction.md | 30 ++++++++++----------- src/ch01-01-installation.md | 8 +++--- src/ch01-02-hello-world.md | 8 +++--- 9 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/appendix-01-keywords.md b/src/appendix-01-keywords.md index 0cbaf316a5..b848945915 100644 --- a/src/appendix-01-keywords.md +++ b/src/appendix-01-keywords.md @@ -2,7 +2,7 @@ The following list contains keywords that are reserved for current or future use by the Rust language. As such, they cannot be used as identifiers (except -as raw identifiers, as we’ll discuss in the “[Raw +as raw identifiers as we’ll discuss in the “[Raw Identifiers][raw-identifiers]” section). Identifiers are names of functions, variables, parameters, struct fields, modules, crates, constants, macros, static values, attributes, types, traits, or lifetimes. @@ -81,7 +81,7 @@ Rust for potential future use. ### Raw Identifiers *Raw identifiers* are the syntax that lets you use keywords where they wouldn’t -usually be allowed. You use a raw identifier by prefixing a keyword with `r#`. +normally be allowed. You use a raw identifier by prefixing a keyword with `r#`. For example, `match` is a keyword. If you try to compile the following function that uses `match` as its name: @@ -106,7 +106,7 @@ error: expected identifier, found keyword `match` The error shows that you can’t use the keyword `match` as the function identifier. To use `match` as a function name, you need to use the raw -identifier syntax like this: +identifier syntax, like this: Filename: src/main.rs @@ -121,11 +121,11 @@ fn main() { ``` This code will compile without any errors. Note the `r#` prefix on the function -name in its definition, as well as where the function is called in `main`. +name in its definition as well as where the function is called in `main`. Raw identifiers allow you to use any word you choose as an identifier, even if that word happens to be a reserved keyword. This gives us more freedom to -choose identifier names and lets us integrate with programs written in +choose identifier names, as well as lets us integrate with programs written in a language where these words aren’t keywords. In addition, raw identifiers allow you to use libraries written in a different Rust edition than your crate uses. For example, `try` isn’t a keyword in the 2015 edition but is in the 2018 diff --git a/src/appendix-02-operators.md b/src/appendix-02-operators.md index eff7f1de65..bc770c703e 100644 --- a/src/appendix-02-operators.md +++ b/src/appendix-02-operators.md @@ -87,7 +87,7 @@ locations. | `"..."` | String literal | | `r"..."`, `r#"..."#`, `r##"..."##`, etc. | Raw string literal, escape characters not processed | | `b"..."` | Byte string literal; constructs an array of bytes instead of a string | -| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, a combination of raw and byte string literal | +| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, combination of raw and byte string literal | | `'...'` | Character literal | | `b'...'` | ASCII byte literal | | |...| expr | Closure | @@ -119,7 +119,7 @@ parameters. | Symbol | Explanation | |--------|-------------| | `path<...>` | Specifies parameters to generic type in a type (e.g., `Vec`) | -| `path::<...>`, `method::<...>` | Specifies parameters to a generic type, function, or method in an expression; often referred to as turbofish (e.g., `"42".parse::()`) | +| `path::<...>`, `method::<...>` | Specifies parameters to generic type, function, or method in an expression; often referred to as turbofish (e.g., `"42".parse::()`) | | `fn ident<...> ...` | Define generic function | | `struct ident<...> ...` | Define generic structure | | `enum ident<...> ...` | Define generic enumeration | diff --git a/src/appendix-03-derivable-traits.md b/src/appendix-03-derivable-traits.md index 3677281d75..8b9b3d3584 100644 --- a/src/appendix-03-derivable-traits.md +++ b/src/appendix-03-derivable-traits.md @@ -21,7 +21,7 @@ for each trait for details of how to manually implement them. These traits listed here are the only ones defined by the standard library that can be implemented on your types using `derive`. Other traits defined in the standard library don’t have sensible default behavior, so it’s up to you to -implement them in a way that makes sense for what you’re trying to accomplish. +implement them in the way that makes sense for what you’re trying to accomplish. An example of a trait that can’t be derived is `Display`, which handles formatting for end users. You should always consider the appropriate way to @@ -71,14 +71,14 @@ number types: the implementation of floating point numbers states that two instances of the not-a-number (`NaN`) value are not equal to each other. An example of when `Eq` is required is for keys in a `HashMap` so the -`HashMap` can tell whether two keys are identical. +`HashMap` can tell whether two keys are the same. ### `PartialOrd` and `Ord` for Ordering Comparisons The `PartialOrd` trait allows you to compare instances of a type for sorting purposes. A type that implements `PartialOrd` can be used with the `<`, `>`, `<=`, and `>=` operators. You can only apply the `PartialOrd` trait to types -that implement `PartialEq`. +that also implement `PartialEq`. Deriving `PartialOrd` implements the `partial_cmp` method, which returns an `Option` that will be `None` when the values given don’t produce an @@ -115,7 +115,7 @@ data. See the [“Ways Variables and Data Interact: Clone”][ways-variables-and-data-interact-clone] section in Chapter 4 for more information on `Clone`. -Deriving `Clone` implements the `clone` method, which, when implemented for the +Deriving `Clone` implements the `clone` method, which when implemented for the whole type, calls `clone` on each of the parts of the type. This means all the fields or values in the type must also implement `Clone` to derive `Clone`. diff --git a/src/appendix-04-useful-development-tools.md b/src/appendix-04-useful-development-tools.md index b36ab7d950..40b076153d 100644 --- a/src/appendix-04-useful-development-tools.md +++ b/src/appendix-04-useful-development-tools.md @@ -1,6 +1,6 @@ ## Appendix D - Useful Development Tools -In this appendix, we talk about some useful development tools the Rust +In this appendix, we talk about some useful development tools that the Rust project provides. We’ll look at automatic formatting, quick ways to apply warning fixes, a linter, and integrating with IDEs. @@ -32,7 +32,8 @@ on `rustfmt`, see [its documentation][rustfmt]. ### Fix Your Code with `rustfix` The rustfix tool is included with Rust installations and can automatically fix -compiler warnings that have a clear way to correct the problem in a way you likely want. It’s likely you’ve seen compiler warnings before. For example, +compiler warnings that have a clear way to correct the problem that’s likely +what you want. It’s likely you’ve seen compiler warnings before. For example, consider this code: Filename: src/main.rs @@ -65,7 +66,7 @@ warning: unused variable: `i` ``` The warning suggests that we use `_i` as a name instead: the underscore -indicates that we intend this variable to be unused. We can automatically +indicates that we intend for this variable to be unused. We can automatically apply that suggestion using the `rustfix` tool by running the command `cargo fix`: @@ -137,7 +138,7 @@ error: approximate value of `f{32, 64}::consts::PI` found | = note: `#[deny(clippy::approx_constant)]` on by default = help: consider using the constant directly - = help: for further information, visit https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant + = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant ``` This error lets you know that Rust already has a more precise `PI` constant diff --git a/src/appendix-05-editions.md b/src/appendix-05-editions.md index 0ddb779546..90828ebbaf 100644 --- a/src/appendix-05-editions.md +++ b/src/appendix-05-editions.md @@ -45,7 +45,7 @@ Rust 2018, your project will compile and be able to use that dependency. The opposite situation, where your project uses Rust 2018 and a dependency uses Rust 2015, works as well. -To be clear: most features will be available in all editions. Developers using +To be clear: most features will be available on all editions. Developers using any Rust edition will continue to see improvements as new stable releases are made. However, in some cases, mainly when new keywords are added, some new features might only be available in later editions. You will need to switch diff --git a/src/appendix-07-nightly-rust.md b/src/appendix-07-nightly-rust.md index edf9815684..46e619c815 100644 --- a/src/appendix-07-nightly-rust.md +++ b/src/appendix-07-nightly-rust.md @@ -35,7 +35,8 @@ assume that the Rust team is working on the release of Rust 1.5. That release happened in December of 2015, but it will provide us with realistic version numbers. A new feature is added to Rust: a new commit lands on the `master` branch. Each night, a new nightly version of Rust is produced. Every day is a -release day, and these releases are created automatically by our release infrastructure. So, as time passes, our releases look like this once a night: +release day, and these releases are created by our release infrastructure +automatically. So as time passes, our releases look like this, once a night: ```text nightly: * - - * - - * @@ -61,7 +62,7 @@ nightly: * - - * - - * - - * - - * beta: * ``` -Let’s say a regression is found. It's a good thing we had some time to test the beta +Let’s say a regression is found. Good thing we had some time to test the beta release before the regression snuck into a stable release! The fix is applied to `master`, so that nightly is fixed, and then the fix is backported to the `beta` branch, and a new release of beta is produced: @@ -105,7 +106,7 @@ release, you can know the date of the next one: it’s six weeks later. A nice aspect of having releases scheduled every six weeks is that the next train is coming soon. If a feature happens to miss a particular release, there’s no need to worry: another one is happening in a short time! This helps reduce pressure -to sneak possibly unpolished features close to the release deadline. +to sneak possibly unpolished features in close to the release deadline. Thanks to this process, you can always check out the next build of Rust and verify for yourself that it’s easy to upgrade to: if a beta release doesn’t diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 0b4cdb8732..536988cb19 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -46,7 +46,7 @@ productive while writing systems-level code. ### Students -Rust is for students and those interested in learning about systems +Rust is for students and those who are interested in learning about systems concepts. Using Rust, many people have learned about topics like operating systems development. The community is very welcoming and happy to answer student questions. Through efforts such as this book, the Rust teams want to @@ -59,7 +59,7 @@ Hundreds of companies, large and small, use Rust in production for a variety of tasks, including command line tools, web services, DevOps tooling, embedded devices, audio and video analysis and transcoding, cryptocurrencies, bioinformatics, search engines, Internet of Things applications, machine -learning, and even significant parts of the Firefox web browser. +learning, and even major parts of the Firefox web browser. ### Open Source Developers @@ -72,7 +72,7 @@ language. Rust is for people who crave speed and stability in a language. By speed, we mean both how quickly Rust code can run and the speed at which Rust lets you write programs. The Rust compiler’s checks ensure stability through feature -additions and refactoring. This contrasts with the brittle legacy code in +additions and refactoring. This is in contrast to the brittle legacy code in languages without these checks, which developers are often afraid to modify. By striving for zero-cost abstractions, higher-level features that compile to lower-level code as fast as code written manually, Rust endeavors to make safe @@ -88,14 +88,14 @@ Rust a try and see if its choices work for you. This book assumes that you’ve written code in another programming language but doesn’t make any assumptions about which one. We’ve tried to make the material -broadly accessible to those from various programming backgrounds. We -don’t spend much time talking about what programming *is* or how to think +broadly accessible to those from a wide variety of programming backgrounds. We +don’t spend a lot of time talking about what programming *is* or how to think about it. If you’re entirely new to programming, you would be better served by reading a book that specifically provides an introduction to programming. ## How to Use This Book -Generally, this book assumes that you’re reading it in sequence from front to +In general, this book assumes that you’re reading it in sequence from front to back. Later chapters build on concepts in earlier chapters, and earlier chapters might not delve into details on a particular topic but will revisit the topic in a later chapter. @@ -123,13 +123,13 @@ enums to make custom types in Rust. In Chapter 7, you’ll learn about Rust’s module system and about privacy rules for organizing your code and its public Application Programming Interface -(API). Chapter 8 discusses common collection data structures the +(API). Chapter 8 discusses some common collection data structures that the standard library provides, such as vectors, strings, and hash maps. Chapter 9 explores Rust’s error-handling philosophy and techniques. Chapter 10 digs into generics, traits, and lifetimes, which give you the power to define code that applies to multiple types. Chapter 11 is all about testing, -which, even with Rust’s safety guarantees, is necessary to ensure your program’s +which even with Rust’s safety guarantees is necessary to ensure your program’s logic is correct. In Chapter 12, we’ll build our own implementation of a subset of functionality from the `grep` command line tool that searches for text within files. For this, we’ll use many of the concepts we discussed in the @@ -142,11 +142,11 @@ Chapter 15 discusses smart pointers that the standard library provides and the traits that enable their functionality. In Chapter 16, we’ll walk through different models of concurrent programming -and talk about how Rust helps you program in multiple threads fearlessly. +and talk about how Rust helps you to program in multiple threads fearlessly. Chapter 17 looks at how Rust idioms compare to object-oriented programming principles you might be familiar with. -Chapter 18 references patterns and pattern matching, which are powerful +Chapter 18 is a reference on patterns and pattern matching, which are powerful ways of expressing ideas throughout Rust programs. Chapter 19 contains a smorgasbord of advanced topics of interest, including unsafe Rust, macros, and more about lifetimes, traits, types, functions, and closures. @@ -159,7 +159,7 @@ more reference-like format. Appendix A covers Rust’s keywords, Appendix B covers Rust’s operators and symbols, Appendix C covers derivable traits provided by the standard library, Appendix D covers some useful development tools, and Appendix E explains Rust editions. In Appendix F, you can find -translations of the book, and in Appendix G, we’ll cover how Rust is made and +translations of the book, and in Appendix G we’ll cover how Rust is made and what nightly Rust is. There is no wrong way to read this book: if you want to skip ahead, go for it! @@ -168,13 +168,13 @@ confusion. But do whatever works for you. -An important aspect of mastering Rust involves understanding how to interpret the -error messages displayed by the compiler: these will guide you toward working code. -As such, we’ll provide many examples that don’t compile, along with the error +An important part of the process of learning Rust is learning how to read the +error messages the compiler displays: these will guide you toward working code. +As such, we’ll provide many examples that don’t compile along with the error message the compiler will show you in each situation. Know that if you enter and run a random example, it may not compile! Make sure you read the surrounding text to see whether the example you’re trying to run is meant to -be an error. Ferris will also help you distinguish code that isn’t meant to work: +error. Ferris will also help you distinguish code that isn’t meant to work: | Ferris | Meaning | |------------------------------------------------------------------------------------------------------------------|--------------------------------------------------| diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index b2690a9a65..87f37fab26 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -11,7 +11,7 @@ The following steps install the latest stable version of the Rust compiler. Rust’s stability guarantees ensure that all the examples in the book that compile will continue to compile with newer Rust versions. The output might differ slightly between versions because Rust often improves error messages and -warnings. In other words, any more recent stable version of Rust you install using +warnings. In other words, any newer, stable version of Rust you install using these steps should work as expected with the content of this book. > ### Command Line Notation @@ -39,7 +39,7 @@ for your password. If the install is successful, the following line will appear: Rust is installed now. Great! ``` -You will also need a *linker*, which is a program Rust uses to combine its +You will also need a *linker*, which is a program that Rust uses to join its compiled outputs into one file. It is likely you already have one. If you get linker errors, you should install a C compiler, which will typically include a linker. A C compiler is also useful because some common Rust packages depend on @@ -83,7 +83,7 @@ $ rustc --version ``` You should see the version number, commit hash, and commit date for the latest -stable version that has been released in the following format: +stable version that has been released, in the following format: ```text rustc x.y.z (abcabcabc yyyy-mm-dd) @@ -111,7 +111,7 @@ In Linux and macOS, use: $ echo $PATH ``` -If that’s all correct and Rust still isn’t working, there are several +If that’s all correct and Rust still isn’t working, there are a number of places you can get help. Find out how to get in touch with other Rustaceans (a silly nickname we call ourselves) on [the community page][community]. diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index 93af283ce4..f291463799 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -102,11 +102,11 @@ first line declares a function named `main` that has no parameters and returns nothing. If there were parameters, they would go inside the parentheses `()`. The function body is wrapped in `{}`. Rust requires curly brackets around all -function bodies. It’s a good style to place the opening curly bracket on the same +function bodies. It’s good style to place the opening curly bracket on the same line as the function declaration, adding one space in between. > Note: If you want to stick to a standard style across Rust projects, you can -> use an automatic formatting tool called `rustfmt` to format your code in a +> use an automatic formatter tool called `rustfmt` to format your code in a > particular style (more on `rustfmt` in > [Appendix D][devtools]). The Rust team has included this tool > with the standard Rust distribution, as `rustc` is, so it should already be @@ -121,7 +121,7 @@ The body of the `main` function holds the following code: This line does all the work in this little program: it prints text to the screen. There are four important details to notice here. -First, the Rust style is to indent with four spaces, not a tab. +First, Rust style is to indent with four spaces, not a tab. Second, `println!` calls a Rust macro. If it had called a function instead, it would be entered as `println` (without the `!`). We’ll discuss Rust macros in @@ -161,7 +161,7 @@ main main.rs ``` On Linux and macOS, you’ll see two files. With PowerShell on Windows, you’ll -see the same three files you would see using CMD. With CMD on Windows, you +see the same three files that you would see using CMD. With CMD on Windows, you would enter the following: ```cmd From 83fb659d7b5698167359aa31637d72ac991ff521 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Fri, 5 Apr 2024 21:46:04 +0300 Subject: [PATCH 102/720] Fix confusing sentence --- src/ch10-03-lifetime-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index 498f01f0b5..e77be953b3 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -93,7 +93,7 @@ Here, `x` has the lifetime `'b`, which in this case is larger than `'a`. This means `r` can reference `x` because Rust knows that the reference in `r` will always be valid while `x` is valid. -Now that you know where the lifetimes of references are and how Rust analyzes +Now that you know what the lifetimes of references are and how Rust analyzes lifetimes to ensure references will always be valid, let’s explore generic lifetimes of parameters and return values in the context of functions. From 3e96c367636757e7b03133e07c9b8152e2c4cf50 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 3 Apr 2024 13:44:25 -0600 Subject: [PATCH 103/720] Correct the description of Listing 5-6 It used to have the inverse of what it was actually doing! Fixes #3488 --- src/ch05-01-defining-structs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index ffd9f1d7cc..c5db4dc74d 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -120,7 +120,7 @@ otherwise use the same values from `user1` that we created in Listing 5-2. {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-06/src/main.rs:here}} ``` -Listing 5-6: Creating a new `User` instance using one of +Listing 5-6: Creating a new `User` instance using all but one of the values from `user1` Using struct update syntax, we can achieve the same effect with less code, as From 3dd1e24614712e9c0e00753e2f1e69a5ee409dd2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 8 Apr 2024 12:55:34 -0600 Subject: [PATCH 104/720] Ch. 7: add a note about the need for `pub` in one more place Fixes #3447 --- src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 921e5cecca..f50219ea33 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -157,7 +157,8 @@ from a new scope with `pub use` Before this change, external code would have to call the `add_to_waitlist` function by using the path -`restaurant::front_of_house::hosting::add_to_waitlist()`. Now that this `pub +`restaurant::front_of_house::hosting::add_to_waitlist()`, which also would have +required the `front_of_house` module to be marked as `pub`. Now that this `pub use` has re-exported the `hosting` module from the root module, external code can now use the path `restaurant::hosting::add_to_waitlist()` instead. From 8355b06c7773636a9c4c24a06c18a97dd42d6a70 Mon Sep 17 00:00:00 2001 From: Kalle Wachsmuth Date: Mon, 8 Apr 2024 22:02:32 +0200 Subject: [PATCH 105/720] Revert "Merge pull request #3711 from miketon/main" This reverts commit 529b9e0d1a7cbf20a6f90caa0e3fbbd431680d48, reversing changes made to d1770c8bdf9f44cd69fda4a55fd72b009653cf6b. --- listings/ch16-fearless-concurrency/listing-16-15/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs index 6e849ff117..30247dd52f 100644 --- a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs @@ -5,7 +5,7 @@ fn main() { let counter = Arc::new(Mutex::new(0)); let mut handles = vec![]; - for _ in 0..=10 { + for _ in 0..10 { let counter = Arc::clone(&counter); let handle = thread::spawn(move || { let mut num = counter.lock().unwrap(); From 74b9dd2cb6df6d8f2a7e09d5575edef836786c83 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 8 Apr 2024 14:10:50 -0600 Subject: [PATCH 106/720] Use explicit 2.0, not latest, for syn docs link --- src/ch19-06-macros.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch19-06-macros.md b/src/ch19-06-macros.md index 9b6ab16633..f24a818c18 100644 --- a/src/ch19-06-macros.md +++ b/src/ch19-06-macros.md @@ -508,6 +508,6 @@ and do one more project! [tlborm]: https://veykril.github.io/tlborm/ [`syn`]: https://crates.io/crates/syn [`quote`]: https://crates.io/crates/quote -[syn-docs]: https://docs.rs/syn/latest/syn/struct.DeriveInput.html +[syn-docs]: https://docs.rs/syn/2.0/syn/struct.DeriveInput.html [quote-docs]: https://docs.rs/quote [decl]: #declarative-macros-with-macro_rules-for-general-metaprogramming From 8179f7543dc2b2f1fbd19f8f4d010f714e2be3cf Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 8 Apr 2024 13:28:11 -0600 Subject: [PATCH 107/720] Ch. 16: fix a grammar issue Fixes #3664 --- src/ch16-03-shared-state.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch16-03-shared-state.md b/src/ch16-03-shared-state.md index 918d162cf5..a5f806c5bf 100644 --- a/src/ch16-03-shared-state.md +++ b/src/ch16-03-shared-state.md @@ -128,7 +128,7 @@ We hinted that this example wouldn’t compile. Now let’s find out why! The error message states that the `counter` value was moved in the previous iteration of the loop. Rust is telling us that we can’t move the ownership -of lock `counter` into multiple threads. Let’s fix the compiler error with a +of `counter` into multiple threads. Let’s fix the compiler error with a multiple-ownership method we discussed in Chapter 15. #### Multiple Ownership with Multiple Threads From df98a0d1074914cf8e37a91a20f1c8e11e3004fb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 9 Apr 2024 09:36:49 -0600 Subject: [PATCH 108/720] Ch. 2: fix wording about `cargo update` --- src/ch02-00-guessing-game-tutorial.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index 5e27fb114d..e3d0a1194d 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -466,8 +466,8 @@ checked into source control with the rest of the code in your project. 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 +versions to the *Cargo.lock* file. In this case, 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.9.0, you would see the following if you ran `cargo update`: From a2c1496c9bd5ce4552a33b5047121323aeb1ae90 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 10 Apr 2024 13:13:44 -0600 Subject: [PATCH 109/720] Update src/ch11-01-writing-tests.md --- src/ch11-01-writing-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index 97f13f9de3..617b2dc5f3 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -62,7 +62,7 @@ cd ../../.. Listing 11-1: The test module and function generated automatically by `cargo new` -For now, let's focus solely on the `it_works()` function. Note the +For now, let’s focus solely on the `it_works()` function. Note the `#[test]` annotation: this attribute indicates this is a test function, so the test runner knows to treat this function as a test. We might also have non-test functions in the `tests` module to help set up common scenarios or perform From e58f1cabce5bd4a0b0885d5f3d685601011e67ae Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 4 Feb 2024 19:33:54 +0100 Subject: [PATCH 110/720] Fix "`Display` type" to "`Display` trait" in ch19-03 --- src/ch19-03-advanced-traits.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch19-03-advanced-traits.md b/src/ch19-03-advanced-traits.md index 6fd3e09f49..789591357b 100644 --- a/src/ch19-03-advanced-traits.md +++ b/src/ch19-03-advanced-traits.md @@ -442,7 +442,7 @@ that holds an instance of `Vec`; then we can implement `Display` on The implementation of `Display` uses `self.0` to access the inner `Vec`, because `Wrapper` is a tuple struct and `Vec` is the item at index 0 in the -tuple. Then we can use the functionality of the `Display` type on `Wrapper`. +tuple. Then we can use the functionality of the `Display` trait on `Wrapper`. The downside of using this technique is that `Wrapper` is a new type, so it doesn’t have the methods of the value it’s holding. We would have to implement From e81491c11e4d77d5e2c0cb74bccb119a71a7d580 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 15 Apr 2024 11:19:24 -0700 Subject: [PATCH 111/720] Update syn dependencies in Chapter 19 to 2.0 --- Cargo.lock | 20 +++++----- .../hello_macro/hello_macro_derive/Cargo.lock | 36 ++++++++--------- .../hello_macro/hello_macro_derive/src/lib.rs | 1 - .../hello_macro/hello_macro_derive/Cargo.lock | 36 ++++++++--------- .../hello_macro/hello_macro_derive/Cargo.toml | 2 +- .../hello_macro/hello_macro_derive/src/lib.rs | 1 - .../hello_macro/hello_macro_derive/Cargo.lock | 36 ++++++++--------- .../hello_macro/hello_macro_derive/Cargo.toml | 2 +- .../hello_macro/hello_macro_derive/src/lib.rs | 1 - .../pancakes/Cargo.lock | 40 +++++++++---------- 10 files changed, 86 insertions(+), 89 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0bbf7586c..5e9f838fe1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,18 +101,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.18" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -167,18 +167,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.137" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", @@ -193,9 +193,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.96" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ "proc-macro2", "quote", diff --git a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.lock b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.lock index 9a38c8ac26..6be987b21b 100644 --- a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.lock +++ b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.lock @@ -1,46 +1,46 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "hello_macro_derive" version = "0.1.0" dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "syn" -version = "1.0.14" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs index 11643a8d62..839ec83593 100644 --- a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs +++ b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; use quote::quote; -use syn; #[proc_macro_derive(HelloMacro)] pub fn hello_macro_derive(input: TokenStream) -> TokenStream { diff --git a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.lock b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.lock index 9a38c8ac26..6be987b21b 100644 --- a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.lock +++ b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.lock @@ -1,46 +1,46 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "hello_macro_derive" version = "0.1.0" dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "syn" -version = "1.0.14" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.toml b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.toml index aa076ac48b..ed9e917ad0 100644 --- a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.toml +++ b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" proc-macro = true [dependencies] -syn = "1.0" +syn = "2.0" quote = "1.0" diff --git a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs index dac6c98f66..ba1215f510 100644 --- a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs +++ b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; use quote::quote; -use syn; #[proc_macro_derive(HelloMacro)] pub fn hello_macro_derive(input: TokenStream) -> TokenStream { diff --git a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.lock b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.lock index 9a38c8ac26..6be987b21b 100644 --- a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.lock +++ b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.lock @@ -1,46 +1,46 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "hello_macro_derive" version = "0.1.0" dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "syn" -version = "1.0.14" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.toml b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.toml index aa076ac48b..ed9e917ad0 100644 --- a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.toml +++ b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" proc-macro = true [dependencies] -syn = "1.0" +syn = "2.0" quote = "1.0" diff --git a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs index 5e0b96c277..654b6bee56 100644 --- a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs +++ b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; use quote::quote; -use syn; #[proc_macro_derive(HelloMacro)] pub fn hello_macro_derive(input: TokenStream) -> TokenStream { diff --git a/listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.lock b/listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.lock index dee23ecf96..3849f15217 100644 --- a/listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.lock +++ b/listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "hello_macro" version = "0.1.0" @@ -8,51 +10,49 @@ version = "0.1.0" name = "hello_macro_derive" version = "0.1.0" dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "syn", ] [[package]] name = "pancakes" version = "0.1.0" dependencies = [ - "hello_macro 0.1.0", - "hello_macro_derive 0.1.0", + "hello_macro", + "hello_macro_derive", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "syn" -version = "1.0.14" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" From 38831b861960cd3530eacf941197dea1e58ea35a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 16 Apr 2024 14:30:19 -0600 Subject: [PATCH 112/720] Chapter 3: Clarify `return` vs. `break`. --- src/ch03-05-control-flow.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ch03-05-control-flow.md b/src/ch03-05-control-flow.md index 34b8372f34..ac416660d9 100644 --- a/src/ch03-05-control-flow.md +++ b/src/ch03-05-control-flow.md @@ -250,6 +250,9 @@ and then check whether the `counter` is equal to `10`. When it is, we use the semicolon to end the statement that assigns the value to `result`. Finally, we print the value in `result`, which in this case is `20`. +You can also `return` from inside a loop. While `break` only exits the current +loop, `return` always exits the current function. + #### Loop Labels to Disambiguate Between Multiple Loops If you have loops within loops, `break` and `continue` apply to the innermost From 12210967170792fc823d0e588f839c13464e7392 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Apr 2024 11:40:43 -0600 Subject: [PATCH 113/720] Ch. 14: clarify workspace dependency reuse Fixes #3141 --- src/ch14-03-cargo-workspaces.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ch14-03-cargo-workspaces.md b/src/ch14-03-cargo-workspaces.md index 7c67331b7f..cbece82335 100644 --- a/src/ch14-03-cargo-workspaces.md +++ b/src/ch14-03-cargo-workspaces.md @@ -267,10 +267,15 @@ error[E0432]: unresolved import `rand` To fix this, edit the *Cargo.toml* file for the `adder` package and indicate that `rand` is a dependency for it as well. Building the `adder` package will add `rand` to the list of dependencies for `adder` in *Cargo.lock*, but no -additional copies of `rand` will be downloaded. Cargo has ensured that every +additional copies of `rand` will be downloaded. Cargo will ensure that every crate in every package in the workspace using the `rand` package will be using -the same version, saving us space and ensuring that the crates in the workspace -will be compatible with each other. +the same version as long as they specify compatible versions of `rand`, saving +us space and ensuring that the crates in the workspace will be compatible with +each other. + +If crates in the workspace specify incompatible versions of the same dependency, +Cargo will resolve each of them, but will still try to resolve as few versions +as possible. #### Adding a Test to a Workspace From e9a58e3c8ecde44ee82c32475699a67fc35a41d8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Apr 2024 15:42:41 -0600 Subject: [PATCH 114/720] Ch. 14: remove extra text from cargo login code sample --- src/ch14-02-publishing-to-crates-io.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ch14-02-publishing-to-crates-io.md b/src/ch14-02-publishing-to-crates-io.md index 8349c1e8fe..d4d33babc4 100644 --- a/src/ch14-02-publishing-to-crates-io.md +++ b/src/ch14-02-publishing-to-crates-io.md @@ -277,7 +277,6 @@ API key. Then run the `cargo login` command and paste your API key when prompted ```console $ cargo login -please paste the API Token found on https://crates.io/me below abcdefghijklmnopqrstuvwxyz012345 ``` From ceacd6d75f9155163f6a605a2d52f9297601de8b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Apr 2024 15:57:05 -0600 Subject: [PATCH 115/720] Revert "Chapter 15-05: Fix incorrect interpretation of compiler error" --- src/ch15-05-interior-mutability.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index d8f51b319d..7b5e825d7e 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -191,10 +191,9 @@ However, there’s one problem with this test, as shown here: We can’t modify the `MockMessenger` to keep track of the messages, because the `send` method takes an immutable reference to `self`. We also can’t take the -suggestion from the error text to use `&mut self` instead, because we are -testing an API and it's not a good idea to modify the API for the sole purpose -of testing. Usually, the test engineers do not have permission to modify the -API they're testing. Feel free to try and see what error message you get. +suggestion from the error text to use `&mut self` instead, because then the +signature of `send` wouldn’t match the signature in the `Messenger` trait +definition (feel free to try and see what error message you get). This is a situation in which interior mutability can help! We’ll store the `sent_messages` within a `RefCell`, and then the `send` method will be From 2320e43bfc1dbd78d46a21961f5b96fc32f1e7ee Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Apr 2024 16:00:59 -0600 Subject: [PATCH 116/720] Ch. 17: clarify 'in order to compile' --- src/ch17-01-what-is-oo.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch17-01-what-is-oo.md b/src/ch17-01-what-is-oo.md index a47afebd93..4a11b7cc08 100644 --- a/src/ch17-01-what-is-oo.md +++ b/src/ch17-01-what-is-oo.md @@ -86,10 +86,10 @@ Because we’ve encapsulated the implementation details of the struct in the future. For instance, we could use a `HashSet` instead of a `Vec` for the `list` field. As long as the signatures of the `add`, `remove`, and `average` public methods stay the same, code using -`AveragedCollection` wouldn’t need to change. If we made `list` public instead, -this wouldn’t necessarily be the case: `HashSet` and `Vec` have -different methods for adding and removing items, so the external code would -likely have to change if it were modifying `list` directly. +`AveragedCollection` wouldn’t need to change in order to compile. If we made +`list` public instead, this wouldn’t necessarily be the case: `HashSet` and +`Vec` have different methods for adding and removing items, so the external +code would likely have to change if it were modifying `list` directly. If encapsulation is a required aspect for a language to be considered object-oriented, then Rust meets that requirement. The option to use `pub` or From d68ddcc4d579e53bd4cb42f1d3b1a87197e54d03 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Apr 2024 17:16:59 -0600 Subject: [PATCH 117/720] Ch. 20: shorter version of corrected listing --- src/ch20-01-single-threaded.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch20-01-single-threaded.md b/src/ch20-01-single-threaded.md index 1776f05589..b980856fd2 100644 --- a/src/ch20-01-single-threaded.md +++ b/src/ch20-01-single-threaded.md @@ -448,7 +448,7 @@ uses the `status_line` and `filename` variables. This makes it easier to see the difference between the two cases, and it means we have only one place to update the code if we want to change how the file reading and response writing work. The behavior of the code in Listing 20-9 will be the same as that in -Listing 20-6 and 20-7. +Listing 20-7. Awesome! We now have a simple web server in approximately 40 lines of Rust code that responds to one request with a page of content and responds to all other From 076420ce2098031d6bbad5d88768511c3ed91504 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 18 Apr 2024 12:03:45 -0600 Subject: [PATCH 118/720] Ch. 11: `use` scope tweak --- .../listing-11-13/tests/integration_test.rs | 4 +++- src/ch11-03-test-organization.md | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs index 336c5ec54b..3822d6b976 100644 --- a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs @@ -1,4 +1,6 @@ +use adder::add_two; + #[test] fn it_adds_two() { - assert_eq!(4, adder::add_two(2)); + assert_eq!(4, add_two(2)); } diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index 61eda50c49..918945780a 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -117,6 +117,11 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file: Listing 11-13: An integration test of a function in the `adder` crate +Each file in the `tests` directory is a separate crate, so we need to bring our +library into each test crate’s scope. For that reason we add `use +adder::add_two` at the top of the code, which we didn’t need in the unit +tests. + We don’t need to annotate any code in *tests/integration_test.rs* with `#[cfg(test)]`. Cargo treats the `tests` directory specially and compiles files in this directory only when we run `cargo test`. Run `cargo test` now: From 0b869eecc899caffda6a7de21a9f7464bdb244b8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 18 Apr 2024 13:55:40 -0600 Subject: [PATCH 119/720] Ch. 18: further clarify about irrefutable patterns --- src/ch18-02-refutability.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch18-02-refutability.md b/src/ch18-02-refutability.md index 29ab7ec48b..c8ca8b5766 100644 --- a/src/ch18-02-refutability.md +++ b/src/ch18-02-refutability.md @@ -60,10 +60,10 @@ the code in the curly brackets, giving it a way to continue validly. Listing Listing 18-9: Using `if let` and a block with refutable patterns instead of `let` -We’ve given the code an out! This code is perfectly valid, although it means we -cannot use an irrefutable pattern without receiving a warning. If we give `if -let` a pattern that will always match, such as `x`, as shown in Listing 18-10, -the compiler will give a warning. +We’ve given the code an out! This code is perfectly valid now. However, +if we give `if let` an irrefutable pattern (a pattern that will always +match), such as `x`, as shown in Listing 18-10, the compiler will give a +warning. ```rust {{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-10/src/main.rs:here}} From d737e4db6b34cd697195e5d7eb1ca315f2b7d8dc Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 18 Apr 2024 16:14:25 -0600 Subject: [PATCH 120/720] Revert "ch18-03: Guarded match arm exhaustivness clarification" --- src/ch18-03-pattern-syntax.md | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/ch18-03-pattern-syntax.md b/src/ch18-03-pattern-syntax.md index a04736d72c..aeaa766ff3 100644 --- a/src/ch18-03-pattern-syntax.md +++ b/src/ch18-03-pattern-syntax.md @@ -477,27 +477,8 @@ second arm doesn’t have a match guard and therefore matches any `Some` variant There is no way to express the `if x % 2 == 0` condition within a pattern, so the match guard gives us the ability to express this logic. The downside of -this additional expressiveness is that the compiler is not smart enough about -arms exhaustiveness anymore when match guard expressions are involved. - -```rust,ignore,does_not_compile -match Some(100) { - Some(_) if true => print!("Got Some"), - None => print!("Got None") -} -``` -This `match` expression involves compilation error. -```console -error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> src/main.rs:33:11 - | -33 | match Some(100) { - | ^^^^^^^^^ pattern `Some(_)` not covered - | -``` -Compilation fails even though `Some(_) if true` guarded pattern matches -any possible `Some`. Same as unguarded `Some(_)` does. - +this additional expressiveness is that the compiler doesn't try to check for +exhaustiveness when match guard expressions are involved. In Listing 18-11, we mentioned that we could use match guards to solve our pattern-shadowing problem. Recall that we created a new variable inside the From 82df41e8bda9ae8efb7b99e02ed7855e9e625a33 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 19 Apr 2024 12:46:08 -0600 Subject: [PATCH 121/720] Ch. 4: include link forward to collections Remove the additional, extraneous info from the Ch. 4. section 3 intro. --- src/ch04-03-slices.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 3b1b7989c1..e986844046 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -1,9 +1,8 @@ ## The Slice Type -*Slices* are a kind of reference, which lets you access a contiguous sub-sequence -of elements in a sequential [collection](ch08-00-common-collections.md). -Because slices are a kind of reference, they too can borrow access to memory, but -not own it. +*Slices* let you reference a contiguous sequence of elements in a +[collection](ch08-00-common-collections.md) rather than the whole collection. A +slice is a kind of reference, so it does not have ownership. Here’s a small programming problem: write a function that takes a string of words separated by spaces and returns the first word it finds in that string. From 0729f34edc67f8edf855403ec6e4deb4ed2f4c8b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 19 Apr 2024 12:56:12 -0600 Subject: [PATCH 122/720] Ch. 2: Further simplify language about numbers --- src/ch02-00-guessing-game-tutorial.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index c5999daa3f..aa73c37a59 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -641,9 +641,9 @@ an `i32`, which is the type of `secret_number` unless you add type information elsewhere that would cause Rust to infer a different numerical type. The reason for the error is that Rust cannot compare a string and a number type. -Ultimately, we want to convert the `String` the program reads as input into an -actual number type so we can compare it numerically to the secret number. We do so -by adding this line to the `main` function body: +Ultimately, we want to convert the `String` the program reads as input into a +number type so we can compare it numerically to the secret number. We do so by +adding this line to the `main` function body: Filename: src/main.rs From c5211edeec1e9a85c958a1ae738aef9abecd1399 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 8 Oct 2022 05:23:03 -0400 Subject: [PATCH 123/720] Apply clippy::uninlined_format_args fix --- tools/src/bin/convert_quotes.rs | 6 +++--- tools/src/bin/lfp.rs | 2 +- tools/src/bin/link2print.rs | 6 +++--- tools/src/bin/release_listings.rs | 2 +- tools/src/bin/remove_hidden_lines.rs | 4 ++-- tools/src/bin/remove_links.rs | 4 ++-- tools/src/bin/remove_markup.rs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/src/bin/convert_quotes.rs b/tools/src/bin/convert_quotes.rs index b4a9bdce2e..a6a8dae72b 100644 --- a/tools/src/bin/convert_quotes.rs +++ b/tools/src/bin/convert_quotes.rs @@ -8,7 +8,7 @@ fn main() { let mut buffer = String::new(); if let Err(e) = io::stdin().read_to_string(&mut buffer) { - panic!("{}", e); + panic!("{e}"); } for line in buffer.lines() { @@ -21,7 +21,7 @@ fn main() { if is_in_code_block { is_in_inline_code = false; is_in_html_tag = false; - println!("{}", line); + println!("{line}"); } else { let modified_line = &mut String::new(); let mut previous_char = std::char::REPLACEMENT_CHARACTER; @@ -72,7 +72,7 @@ fn main() { modified_line.push(char_to_push); previous_char = char_to_push; } - println!("{}", modified_line); + println!("{modified_line}"); } } } diff --git a/tools/src/bin/lfp.rs b/tools/src/bin/lfp.rs index c4d4bce036..f7b6e17f72 100644 --- a/tools/src/bin/lfp.rs +++ b/tools/src/bin/lfp.rs @@ -18,7 +18,7 @@ fn main() { .map(|entry| match entry { Ok(entry) => entry, Err(err) => { - eprintln!("{:?}", err); + eprintln!("{err:?}"); std::process::exit(911) } }) diff --git a/tools/src/bin/link2print.rs b/tools/src/bin/link2print.rs index c57d788d21..7d6def8616 100644 --- a/tools/src/bin/link2print.rs +++ b/tools/src/bin/link2print.rs @@ -14,12 +14,12 @@ fn read_md() -> String { let mut buffer = String::new(); match io::stdin().read_to_string(&mut buffer) { Ok(_) => buffer, - Err(error) => panic!("{}", error), + Err(error) => panic!("{error}"), } } fn write_md(output: String) { - print!("{}", output); + print!("{output}"); } fn parse_references(buffer: String) -> (String, HashMap) { @@ -81,7 +81,7 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String { } } }; - format!("{} at *{}*", name, val) + format!("{name} at *{val}*") } } }); diff --git a/tools/src/bin/release_listings.rs b/tools/src/bin/release_listings.rs index c371d7b308..4239a4dabf 100644 --- a/tools/src/bin/release_listings.rs +++ b/tools/src/bin/release_listings.rs @@ -149,7 +149,7 @@ fn copy_cleaned_rust_file( if !ANCHOR_OR_SNIP_COMMENTS.is_match(&line) && (item_name != "lib.rs" || !EMPTY_MAIN.is_match(&line)) { - writeln!(&mut to_buf, "{}", line)?; + writeln!(&mut to_buf, "{line}")?; } } diff --git a/tools/src/bin/remove_hidden_lines.rs b/tools/src/bin/remove_hidden_lines.rs index dc3c593570..934b64eb69 100644 --- a/tools/src/bin/remove_hidden_lines.rs +++ b/tools/src/bin/remove_hidden_lines.rs @@ -9,12 +9,12 @@ fn read_md() -> String { let mut buffer = String::new(); match io::stdin().read_to_string(&mut buffer) { Ok(_) => buffer, - Err(error) => panic!("{}", error), + Err(error) => panic!("{error}"), } } fn write_md(output: String) { - print!("{}", output); + print!("{output}"); } fn remove_hidden_lines(input: &str) -> String { diff --git a/tools/src/bin/remove_links.rs b/tools/src/bin/remove_links.rs index b3f78d70a0..042295d187 100644 --- a/tools/src/bin/remove_links.rs +++ b/tools/src/bin/remove_links.rs @@ -8,7 +8,7 @@ use std::io::Read; fn main() { let mut buffer = String::new(); if let Err(e) = io::stdin().read_to_string(&mut buffer) { - panic!("{}", e); + panic!("{e}"); } let mut refs = HashSet::new(); @@ -41,5 +41,5 @@ fn main() { caps.get(0).unwrap().as_str().to_string() }); - print!("{}", out); + print!("{out}"); } diff --git a/tools/src/bin/remove_markup.rs b/tools/src/bin/remove_markup.rs index c42e588e75..a9cc4b7f59 100644 --- a/tools/src/bin/remove_markup.rs +++ b/tools/src/bin/remove_markup.rs @@ -12,12 +12,12 @@ fn read_md() -> String { let mut buffer = String::new(); match io::stdin().read_to_string(&mut buffer) { Ok(_) => buffer, - Err(error) => panic!("{}", error), + Err(error) => panic!("{error}"), } } fn write_md(output: String) { - print!("{}", output); + print!("{output}"); } fn remove_markup(input: String) -> String { From 8264d69aa6ea27feb68dbd1f5d06c95076894e04 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 19 Apr 2024 13:31:53 -0600 Subject: [PATCH 124/720] Ch. 13: `unwrap_or_else` takes all three kinds of closures --- src/ch13-01-closures.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch13-01-closures.md b/src/ch13-01-closures.md index 646204f689..9c0b4be2a7 100644 --- a/src/ch13-01-closures.md +++ b/src/ch13-01-closures.md @@ -329,13 +329,13 @@ Using `FnOnce` in the trait bound expresses the constraint that `unwrap_or_else` is only going to call `f` at most one time. In the body of `unwrap_or_else`, we can see that if the `Option` is `Some`, `f` won’t be called. If the `Option` is `None`, `f` will be called once. Because all -closures implement `FnOnce`, `unwrap_or_else` accepts all closures and is as -flexible as it can be. +closures implement `FnOnce`, `unwrap_or_else` accepts all three kinds of +closures and is as flexible as it can be. > Note: Functions can implement all three of the `Fn` traits too. If what we > want to do doesn’t require capturing a value from the environment, we can use > the name of a function rather than a closure where we need something that -> implements one of the `Fn` traits. For example, on an `Option>` value +> implements one of the `Fn` traits. For example, on an `Option>` value, > we could call `unwrap_or_else(Vec::new)` to get a new, empty vector if the > value is `None`. From 54726034c5b4c7e865128a3047bc97eba15e8eb3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 19 Apr 2024 13:35:31 -0600 Subject: [PATCH 125/720] Ch. 12.3: be clearer about how `expect` was used --- ...2-03-improving-error-handling-and-modularity.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ch12-03-improving-error-handling-and-modularity.md b/src/ch12-03-improving-error-handling-and-modularity.md index 961246be62..1b67d63d6d 100644 --- a/src/ch12-03-improving-error-handling-and-modularity.md +++ b/src/ch12-03-improving-error-handling-and-modularity.md @@ -23,13 +23,13 @@ example, the file could be missing, or we might not have permission to open it. Right now, regardless of the situation, we’d print the same error message for everything, which wouldn’t give the user any information! -Fourth, if the user runs our program without specifying enough arguments, -they’ll get an `index out of bounds` error from Rust that doesn’t clearly -explain the problem. It would be best if all the error-handling code were -in one place so future maintainers had only one place to consult the code -if the error-handling logic needed to change. Having all the error-handling -code in one place will also ensure that we’re printing messages that -will be meaningful to our end users. +Fourth, we use `expect` to handle an error, and if the user runs our program +without specifying enough arguments, they’ll get an `index out of bounds` error +from Rust that doesn’t clearly explain the problem. It would be best if all the +error-handling code were in one place so future maintainers had only one place +to consult the code if the error-handling logic needed to change. Having all the +error-handling code in one place will also ensure that we’re printing messages +that will be meaningful to our end users. Let’s address these four problems by refactoring our project. From c13271897d849f806a27df14060cd9223e098e67 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 19 Apr 2024 15:40:41 -0400 Subject: [PATCH 126/720] Inline fmt lints for `redirects/` I couldn't find any documentation of how `redirects/` dir is being used, but fixed inlined format args for consistency --- redirects/choosing-your-guarantees.md | 2 +- redirects/iterators.md | 2 +- redirects/lifetimes.md | 2 +- redirects/mutability.md | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/redirects/choosing-your-guarantees.md b/redirects/choosing-your-guarantees.md index 3667258c66..d8a4e3a3f9 100644 --- a/redirects/choosing-your-guarantees.md +++ b/redirects/choosing-your-guarantees.md @@ -7,7 +7,7 @@ ```rust let b = Box::new(5); -println!("b = {}", b); +println!("b = {b}"); ``` --- diff --git a/redirects/iterators.md b/redirects/iterators.md index 26cb047668..d8a73dab87 100644 --- a/redirects/iterators.md +++ b/redirects/iterators.md @@ -11,7 +11,7 @@ let v1 = vec![1, 2, 3]; let v1_iter = v1.iter(); for val in v1_iter { - println!("Got: {}", val); + println!("Got: {val}"); } ``` diff --git a/redirects/lifetimes.md b/redirects/lifetimes.md index 21ddb38ce8..8a27ec1724 100644 --- a/redirects/lifetimes.md +++ b/redirects/lifetimes.md @@ -11,7 +11,7 @@ // | let r = &x; // --+--+-- 'a // | | - println!("r: {}", r); // | | + println!("r: {r}"); // | | // --+ | } // -----+ ``` diff --git a/redirects/mutability.md b/redirects/mutability.md index 89fc3b6f56..4e64953c10 100644 --- a/redirects/mutability.md +++ b/redirects/mutability.md @@ -6,9 +6,9 @@ ```rust let mut x = 5; -println!("The value of x is: {}", x); +println!("The value of x is: {x}"); x = 6; -println!("The value of x is: {}", x); +println!("The value of x is: {x}"); ``` --- From 502d012cabb7c6d4d134694c355d9ce0a1176f64 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 19 Apr 2024 13:02:17 -0600 Subject: [PATCH 127/720] Ch. 2: intentionally use `{}` at first This supports the prose in the guessing game tutorial, which uses this as a way of teaching where you can do `{foo}` and where you cannot. --- listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs b/listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs index d44e290d70..b822b89ff3 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs +++ b/listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs @@ -25,7 +25,7 @@ fn main() { // ANCHOR_END: expect // ANCHOR: print_guess - println!("You guessed: {guess}"); + println!("You guessed: {}", guess); // ANCHOR_END: print_guess } // ANCHOR: all From 0ec7296ff72026f0880b7d2fe329996294c70cdd Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Apr 2024 15:32:03 -0600 Subject: [PATCH 128/720] Create crate for The Rust Programming Language --- .gitignore | 1 + CONTRIBUTING.md | 11 +++ Cargo.lock | 7 ++ Cargo.toml | 7 ++ LICENSE-APACHE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE-MIT | 25 ++++++ README.md | 9 +++ src/lib.rs | 14 ++++ 8 files changed, 275 insertions(+) create mode 100644 .gitignore create mode 100644 CONTRIBUTING.md create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT create mode 100644 README.md create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..bd14bf21d7 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,11 @@ +# Contributing + +## 🚧 Under construction! 🚧 + +Thanks for your interesting in helping us with this! At the moment, we are not +ready for contributions, though. + +Once we stabilize the contents of the book, including the APIs we are +re-exporting here and the little bits of functionality implemented in that +crate, we will gladly take all the help we can get for maintaining this. We will +update this document once we are ready for contributions. diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000..0858db7638 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "trpl" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000..6b6ea9d5ad --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "trpl" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000000..38634daab0 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright 2010 The Rust Project Developers + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000000..25597d5838 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2010 The Rust Project Developers + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000000..ddfc445a50 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# The Rust Programming Language Book Crate + +This repository is the home of the `trpl` crate used in _The Rust Programming +Language_ book materials. + +## Requirements + + +This crate currently requires at least Rust 1.77. diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000000..7d12d9af81 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} From fcd470c4a8bcd295414eff072c107ff24955ab9c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Apr 2024 15:32:03 -0600 Subject: [PATCH 129/720] Add Tokio dependency We will primarily just be re-exporting this, though we may also have a couple cases where we choose to implement something small around it. --- Cargo.lock | 421 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 + 2 files changed, 423 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 0858db7638..826cde189c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,427 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "trpl" version = "0.1.0" +dependencies = [ + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/Cargo.toml b/Cargo.toml index 6b6ea9d5ad..fe35925a69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +tokio = { version = "1", features = ["full"] } From 3943e512f8f47050e6ca77d98a2386baa18d94d0 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Apr 2024 15:45:50 -0600 Subject: [PATCH 130/720] Re-export `tokio::main` as `trpl::async_main` and test it. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Introduce an integration tests crate. Structure it the way people *should* for large crates (although this is not that) and document why, including linking to a relevant post. 2. Add a basic integration test that verifies the re-export works as it should. (This is not exactly rocket science, but we want to make sure these things don’t just stop working on accident.) An open question that remains here: do we want some structure to the crate beyond the top level re-exports? My inclination at this moment is: no, because we don’t have any *motivation* for that, and naming things is difficult. (We cannot do `trpl::async`, for example, because `async` is a keyword!) --- src/lib.rs | 15 +-------------- tests/integration/main.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 tests/integration/main.rs diff --git a/src/lib.rs b/src/lib.rs index 7d12d9af81..766a9a7e68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} +pub use tokio::main as async_main; diff --git a/tests/integration/main.rs b/tests/integration/main.rs new file mode 100644 index 0000000000..81653f155b --- /dev/null +++ b/tests/integration/main.rs @@ -0,0 +1,24 @@ +//! Integration tests for the crate. +//! +//! These all live in a *single* integration test crate, `tests/integration`, +//! because each integration test is a dedicated binary crate which has to be +//! compiled separately. While that is not really a problem for a crate this +//! small, we have chosen to follow this “best practice” here as a good example. +//! +//! For more details on why you might prefer this pattern see [this post][post]. +//! +//! [post]: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html + +use trpl::async_main; + +#[test] +fn re_exported_macro_works() { + #[async_main] + async fn demo() -> &'static str { + let val = async { "Hello" }.await; + assert_eq!(val, "Hello", "Async is usable in async_main function"); + val + } + + assert_eq!(demo(), "Hello", "value returns correctly"); +} From e51828957d05fbb1bbd2961f122f53288d601247 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Apr 2024 16:13:12 -0600 Subject: [PATCH 131/720] Add more crate-level docs and matching README materials. --- README.md | 12 ++++++++++++ src/lib.rs | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/README.md b/README.md index ddfc445a50..a074e05a6e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,18 @@ This repository is the home of the `trpl` crate used in _The Rust Programming Language_ book materials. +This crate mostly just re-exports items from *other* crates. It exists for two +main reasons: + +1. So that as you read along in _The Rust Programming Language_, you can add + just one dependency, rather than however many we end up with, and likewise + use only one set of imports. + +2. So that we can more easily guarantee it keeps building and working. Since we + control the contents of this crate and when it changes, readers will never be + broken by upstream changes, e.g. if Tokio does a breaking 2.0 release at some + point. + ## Requirements diff --git a/src/lib.rs b/src/lib.rs index 766a9a7e68..a0fddb1b09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1 +1,15 @@ +//! A support crate for _The Rust Programming Language_. +//! +//! This crate mostly just re-exports items from *other* crates. It exists for +//! two main reasons: +//! +//! 1. So that as you read along in _The Rust Programming Language_, you can +//! add just one dependency, rather than however many we end up with, and +//! likewise use only one set of imports. +//! +//! 2. So that we can more easily guarantee it keeps building and working. Since +//! we control the contents of this crate and when it changes, readers will +//! never be broken by upstream changes, e.g. if Tokio does a breaking 2.0 +//! release at some point. + pub use tokio::main as async_main; From 608c35b52f8cc9a24b47b159eff35740e55281b9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Apr 2024 16:13:12 -0600 Subject: [PATCH 132/720] Document the first test so people can understand it. --- tests/integration/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/integration/main.rs b/tests/integration/main.rs index 81653f155b..fd232ccc7e 100644 --- a/tests/integration/main.rs +++ b/tests/integration/main.rs @@ -11,14 +11,19 @@ use trpl::async_main; +/// This test makes sure the re-exported version of the `tokio::main` macro, +/// which is applied like `#[tokio::main] async fn some_fn() { … }`, continues +/// to work. However, tests cannot use `async fn`, so to test it, we need to +/// have a non-`async` test function, which then applies the macro to an `async` +/// function in its body, and invokes *that*. #[test] fn re_exported_macro_works() { #[async_main] - async fn demo() -> &'static str { + async fn internal() -> &'static str { let val = async { "Hello" }.await; assert_eq!(val, "Hello", "Async is usable in async_main function"); val } - assert_eq!(demo(), "Hello", "value returns correctly"); + assert_eq!(internal(), "Hello", "value returns correctly"); } From 71ea12e43041c2b135dabb6a461c3c50b7eb67e1 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Apr 2024 16:27:04 -0600 Subject: [PATCH 133/720] Add CI for `main` and PRs against `main` --- .github/workflows/main.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..0642f451b8 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,23 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + integration_test: + name: Integration Tests + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose From 4255d87df5337ae1ed0e533eee4ddfc6cfacf7a2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Apr 2024 16:55:47 -0600 Subject: [PATCH 134/720] Add a CI status badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a074e05a6e..3906da15a4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # The Rust Programming Language Book Crate +![Build Status](https://github.com/chriskrycho/trpl-crate/workflows/CI/badge.svg) + This repository is the home of the `trpl` crate used in _The Rust Programming Language_ book materials. From 98165c42794698ef7f3e2ce8b3c225cbcda8eb65 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 25 Apr 2024 15:59:23 -0400 Subject: [PATCH 135/720] Backport changes from print for ch7 --- src/ch07-01-packages-and-crates.md | 25 +++++---- ...ng-modules-to-control-scope-and-privacy.md | 46 ++++++++-------- ...referring-to-an-item-in-the-module-tree.md | 55 ++++++++++--------- ...g-paths-into-scope-with-the-use-keyword.md | 28 +++++----- ...separating-modules-into-different-files.md | 22 ++++---- 5 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/ch07-01-packages-and-crates.md b/src/ch07-01-packages-and-crates.md index d9a70f773b..140a98518b 100644 --- a/src/ch07-01-packages-and-crates.md +++ b/src/ch07-01-packages-and-crates.md @@ -35,12 +35,13 @@ package also contains a library crate that the binary crate depends on. Other projects can depend on the Cargo library crate to use the same logic the Cargo command-line tool uses. -A package can contain as many binary crates as you like, but at most only one +A crate can come in one of two forms: a binary crate or a library crate. A +package can contain as many binary crates as you like, but at most only one library crate. A package must contain at least one crate, whether that’s a library or binary crate. -Let’s walk through what happens when we create a package. First, we enter the -command `cargo new`: +Let’s walk through what happens when we create a package. First we enter the +command `cargo new my-project`: ```console $ cargo new my-project @@ -52,15 +53,15 @@ $ ls my-project/src main.rs ``` -After we run `cargo new`, we use `ls` to see what Cargo creates. In the project -directory, there’s a *Cargo.toml* file, giving us a package. There’s also a -*src* directory that contains *main.rs*. Open *Cargo.toml* in your text editor, -and note there’s no mention of *src/main.rs*. Cargo follows a convention that -*src/main.rs* is the crate root of a binary crate with the same name as the -package. Likewise, Cargo knows that if the package directory contains -*src/lib.rs*, the package contains a library crate with the same name as the -package, and *src/lib.rs* is its crate root. Cargo passes the crate root files -to `rustc` to build the library or binary. +After we run `cargo new my-project`, we use `ls` to see what Cargo creates. In +the project directory, there’s a *Cargo.toml* file, giving us a package. +There’s also a *src* directory that contains *main.rs*. Open *Cargo.toml* in +your text editor, and note there’s no mention of *src/main.rs*. Cargo follows a +convention that *src/main.rs* is the crate root of a binary crate with the same +name as the package. Likewise, Cargo knows that if the package directory +contains *src/lib.rs*, the package contains a library crate with the same name +as the package, and *src/lib.rs* is its crate root. Cargo passes the crate root +files to `rustc` to build the library or binary. Here, we have a package that only contains *src/main.rs*, meaning it only contains a binary crate named `my-project`. If a package contains *src/main.rs* diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index 90776dbfea..4a25c161be 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -1,27 +1,23 @@ ## Defining Modules to Control Scope and Privacy In this section, we’ll talk about modules and other parts of the module system, -namely *paths* that allow you to name items; the `use` keyword that brings a +namely *paths*, which allow you to name items; the `use` keyword that brings a path into scope; and the `pub` keyword to make items public. We’ll also discuss the `as` keyword, external packages, and the glob operator. -First, we’re going to start with a list of rules for easy reference when you’re -organizing your code in the future. Then we’ll explain each of the rules in -detail. - ### Modules Cheat Sheet -Here we provide a quick reference on how modules, paths, the `use` keyword, and -the `pub` keyword work in the compiler, and how most developers organize their -code. We’ll be going through examples of each of these rules throughout this -chapter, but this is a great place to refer to as a reminder of how modules -work. +Before we get to the details of modules and paths, here we provide a quick +reference on how modules, paths, the `use` keyword, and the `pub` keyword work +in the compiler, and how most developers organize their code. We’ll be going +through examples of each of these rules throughout this chapter, but this is a +great place to refer to as a reminder of how modules work. - **Start from the crate root**: When compiling a crate, the compiler first looks in the crate root file (usually *src/lib.rs* for a library crate or *src/main.rs* for a binary crate) for code to compile. - **Declaring modules**: In the crate root file, you can declare new modules; -say, you declare a “garden” module with `mod garden;`. The compiler will look +say you declare a “garden” module with `mod garden;`. The compiler will look for the module’s code in these places: - Inline, within curly brackets that replace the semicolon following `mod garden` @@ -40,7 +36,7 @@ for the module’s code in these places: as the privacy rules allow, using the path to the code. For example, an `Asparagus` type in the garden vegetables module would be found at `crate::garden::vegetables::Asparagus`. -- **Private vs public**: Code within a module is private from its parent +- **Private vs. public**: Code within a module is private from its parent modules by default. To make a module public, declare it with `pub mod` instead of `mod`. To make items within a public module public as well, use `pub` before their declarations. @@ -50,8 +46,9 @@ for the module’s code in these places: crate::garden::vegetables::Asparagus;` and from then on you only need to write `Asparagus` to make use of that type in the scope. -Here we create a binary crate named `backyard` that illustrates these rules. The -crate’s directory, also named `backyard`, contains these files and directories: +Here, we create a binary crate named `backyard` that illustrates these rules. +The crate’s directory, also named `backyard`, contains these files and +directories: ```text backyard @@ -93,7 +90,7 @@ Now let’s get into the details of these rules and demonstrate them in action! ### Grouping Related Code in Modules *Modules* let us organize code within a crate for readability and easy reuse. -Modules also allow us to control the *privacy* of items, because code within a +Modules also allow us to control the *privacy* of items because code within a module is private by default. Private items are internal implementation details not available for outside use. We can choose to make modules and the items within them public, which exposes them to allow external code to use and depend @@ -101,7 +98,7 @@ on them. As an example, let’s write a library crate that provides the functionality of a restaurant. We’ll define the signatures of functions but leave their bodies -empty to concentrate on the organization of the code, rather than the +empty to concentrate on the organization of the code rather than the implementation of a restaurant. In the restaurant industry, some parts of a restaurant are referred to as @@ -113,8 +110,9 @@ administrative work. To structure our crate in this way, we can organize its functions into nested modules. Create a new library named `restaurant` by running `cargo new -restaurant --lib`; then enter the code in Listing 7-1 into *src/lib.rs* to -define some modules and function signatures. Here’s the front of house section: +restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to +define some modules and function signatures; this code is the front of house +section. Filename: src/lib.rs @@ -160,13 +158,13 @@ crate Listing 7-2: The module tree for the code in Listing 7-1 -This tree shows how some of the modules nest inside one another; for example, +This tree shows how some of the modules nest inside other modules; for example, `hosting` nests inside `front_of_house`. The tree also shows that some modules -are *siblings* to each other, meaning they’re defined in the same module; -`hosting` and `serving` are siblings defined within `front_of_house`. If module -A is contained inside module B, we say that module A is the *child* of module B -and that module B is the *parent* of module A. Notice that the entire module -tree is rooted under the implicit module named `crate`. +are *siblings*, meaning they’re defined in the same module; `hosting` and +`serving` are siblings defined within `front_of_house`. If module A is +contained inside module B, we say that module A is the *child* of module B and +that module B is the *parent* of module A. Notice that the entire module tree +is rooted under the implicit module named `crate`. The module tree might remind you of the filesystem’s directory tree on your computer; this is a very apt comparison! Just like directories in a filesystem, diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index fa85082b38..4201ea3db2 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -20,10 +20,10 @@ This is the same as asking: what’s the path of the `add_to_waitlist` function? Listing 7-3 contains Listing 7-1 with some of the modules and functions removed. -We’ll show two ways to call the `add_to_waitlist` function from a new function -`eat_at_restaurant` defined in the crate root. These paths are correct, but +We’ll show two ways to call the `add_to_waitlist` function from a new function, +`eat_at_restaurant`, defined in the crate root. These paths are correct, but there’s another problem remaining that will prevent this example from compiling -as-is. We’ll explain why in a bit. +as is. We’ll explain why in a bit. The `eat_at_restaurant` function is part of our library crate’s public API, so we mark it with the `pub` keyword. In the [“Exposing Paths with the `pub` @@ -55,19 +55,20 @@ filesystem equivalent would be using the path that the path is relative. Choosing whether to use a relative or absolute path is a decision you’ll make -based on your project, and depends on whether you’re more likely to move item -definition code separately from or together with the code that uses the item. -For example, if we move the `front_of_house` module and the `eat_at_restaurant` -function into a module named `customer_experience`, we’d need to update the -absolute path to `add_to_waitlist`, but the relative path would still be valid. -However, if we moved the `eat_at_restaurant` function separately into a module -named `dining`, the absolute path to the `add_to_waitlist` call would stay the -same, but the relative path would need to be updated. Our preference in general -is to specify absolute paths because it’s more likely we’ll want to move code -definitions and item calls independently of each other. +based on your project, and it depends on whether you’re more likely to move +item definition code separately from or together with the code that uses the +item. For example, if we moved the `front_of_house` module and the +`eat_at_restaurant` function into a module named `customer_experience`, we’d +need to update the absolute path to `add_to_waitlist`, but the relative path +would still be valid. However, if we moved the `eat_at_restaurant` function +separately into a module named `dining`, the absolute path to the +`add_to_waitlist` call would stay the same, but the relative path would need to +be updated. Our preference in general is to specify absolute paths because it’s +more likely we’ll want to move code definitions and item calls independently of +each other. Let’s try to compile Listing 7-3 and find out why it won’t compile yet! The -error we get is shown in Listing 7-4. +errors we get are shown in Listing 7-4. ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-03/output.txt}} @@ -113,8 +114,8 @@ access to the `add_to_waitlist` function in the child module, so we mark the Listing 7-5: Declaring the `hosting` module as `pub` to use it from `eat_at_restaurant` -Unfortunately, the code in Listing 7-5 still results in an error, as shown in -Listing 7-6. +Unfortunately, the code in Listing 7-5 still results in compiler errors, as +shown in Listing 7-6. ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-05/output.txt}} @@ -180,13 +181,13 @@ interested in this topic, see [The Rust API Guidelines][api-guidelines]. > #### Best Practices for Packages with a Binary and a Library > -> We mentioned a package can contain both a *src/main.rs* binary crate root as -> well as a *src/lib.rs* library crate root, and both crates will have the -> package name by default. Typically, packages with this pattern of containing -> both a library and a binary crate will have just enough code in the binary -> crate to start an executable that calls code within the library crate. This -> lets other projects benefit from most of the functionality that the package -> provides, because the library crate’s code can be shared. +> We mentioned that a package can contain both a *src/main.rs* binary crate +> root as well as a *src/lib.rs* library crate root, and both crates will have +> the package name by default. Typically, packages with this pattern of +> containing both a library and a binary crate will have just enough code in the +> binary crate to start an executable that calls code within the library crate. +> This lets other projects benefit from most of the functionality that the +> package provides because the library crate’s code can be shared. > > The module tree should be defined in *src/lib.rs*. Then, any public items can > be used in the binary crate by starting paths with the name of the package. @@ -206,14 +207,14 @@ the current module or the crate root, by using `super` at the start of the path. This is like starting a filesystem path with the `..` syntax. Using `super` allows us to reference an item that we know is in the parent module, which can make rearranging the module tree easier when the module is closely -related to the parent, but the parent might be moved elsewhere in the module +related to the parent but the parent might be moved elsewhere in the module tree someday. Consider the code in Listing 7-8 that models the situation in which a chef fixes an incorrect order and personally brings it out to the customer. The function `fix_incorrect_order` defined in the `back_of_house` module calls the function `deliver_order` defined in the parent module by specifying the path to -`deliver_order` starting with `super`: +`deliver_order`, starting with `super`. Filename: src/lib.rs @@ -236,7 +237,7 @@ code gets moved to a different module. ### Making Structs and Enums Public We can also use `pub` to designate structs and enums as public, but there are a -few details extra to the usage of `pub` with structs and enums. If we use `pub` +few extra details to the usage of `pub` with structs and enums. If we use `pub` before a struct definition, we make the struct public, but the struct’s fields will still be private. We can make each field public or not on a case-by-case basis. In Listing 7-9, we’ve defined a public `back_of_house::Breakfast` struct @@ -258,7 +259,7 @@ private fields Because the `toast` field in the `back_of_house::Breakfast` struct is public, in `eat_at_restaurant` we can write and read to the `toast` field using dot notation. Notice that we can’t use the `seasonal_fruit` field in -`eat_at_restaurant` because `seasonal_fruit` is private. Try uncommenting the +`eat_at_restaurant`, because `seasonal_fruit` is private. Try uncommenting the line modifying the `seasonal_fruit` field value to see what error you get! Also, note that because `back_of_house::Breakfast` has a private field, the diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index f50219ea33..defa950c6b 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -30,7 +30,7 @@ also check privacy, like any other paths. Note that `use` only creates the shortcut for the particular scope in which the `use` occurs. Listing 7-12 moves the `eat_at_restaurant` function into a new child module named `customer`, which is then a different scope than the `use` -statement, so the function body won’t compile: +statement, so the function body won’t compile. Filename: src/lib.rs @@ -57,7 +57,7 @@ the shortcut in the parent module with `super::hosting` within the child In Listing 7-11, you might have wondered why we specified `use crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in -`eat_at_restaurant` rather than specifying the `use` path all the way out to +`eat_at_restaurant`, rather than specifying the `use` path all the way out to the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. Filename: src/lib.rs @@ -69,9 +69,9 @@ the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. Listing 7-13: Bringing the `add_to_waitlist` function into scope with `use`, which is unidiomatic -Although both Listing 7-11 and 7-13 accomplish the same task, Listing 7-11 is -the idiomatic way to bring a function into scope with `use`. Bringing the -function’s parent module into scope with `use` means we have to specify the +Although both Listing 7-11 and Listing 7-13 accomplish the same task, Listing +7-11 is the idiomatic way to bring a function into scope with `use`. Bringing +the function’s parent module into scope with `use` means we have to specify the parent module when calling the function. Specifying the parent module when calling the function makes it clear that the function isn’t locally defined while still minimizing repetition of the full path. The code in Listing 7-13 is @@ -97,7 +97,7 @@ emerged, and folks have gotten used to reading and writing Rust code this way. The exception to this idiom is if we’re bringing two items with the same name into scope with `use` statements, because Rust doesn’t allow that. Listing 7-15 shows how to bring two `Result` types into scope that have the same name but -different parent modules and how to refer to them. +different parent modules, and how to refer to them. Filename: src/lib.rs @@ -110,7 +110,7 @@ the same scope requires using their parent modules. As you can see, using the parent modules distinguishes the two `Result` types. If instead we specified `use std::fmt::Result` and `use std::io::Result`, we’d -have two `Result` types in the same scope and Rust wouldn’t know which one we +have two `Result` types in the same scope, and Rust wouldn’t know which one we meant when we used `Result`. ### Providing New Names with the `as` Keyword @@ -139,8 +139,8 @@ considered idiomatic, so the choice is up to you! When we bring a name into scope with the `use` keyword, the name available in the new scope is private. To enable the code that calls our code to refer to that name as if it had been defined in that code’s scope, we can combine `pub` -and `use`. This technique is called *re-exporting* because we’re bringing -an item into scope but also making that item available for others to bring into +and `use`. This technique is called *re-exporting* because we’re bringing an +item into scope but also making that item available for others to bring into their scope. Listing 7-17 shows the code in Listing 7-11 with `use` in the root module @@ -160,7 +160,7 @@ function by using the path `restaurant::front_of_house::hosting::add_to_waitlist()`, which also would have required the `front_of_house` module to be marked as `pub`. Now that this `pub use` has re-exported the `hosting` module from the root module, external code -can now use the path `restaurant::hosting::add_to_waitlist()` instead. +can use the path `restaurant::hosting::add_to_waitlist()` instead. Re-exporting is useful when the internal structure of your code is different from how programmers calling your code would think about the domain. For @@ -226,10 +226,10 @@ crate. ### Using Nested Paths to Clean Up Large `use` Lists -If we’re using multiple items defined in the same crate or same module, -listing each item on its own line can take up a lot of vertical space in our -files. For example, these two `use` statements we had in the Guessing Game in -Listing 2-4 bring items from `std` into scope: +If we’re using multiple items defined in the same crate or same module, listing +each item on its own line can take up a lot of vertical space in our files. For +example, these two `use` statements we had in the guessing game in Listing 2-4 +bring items from `std` into scope: Filename: src/main.rs diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index 17e8d74526..b4cbcdbeda 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -10,7 +10,7 @@ modules defined in the crate root file. In this case, the crate root file is *src/lib.rs*, but this procedure also works with binary crates whose crate root file is *src/main.rs*. -First, we’ll extract the `front_of_house` module to its own file. Remove the +First we’ll extract the `front_of_house` module to its own file. Remove the code inside the curly brackets for the `front_of_house` module, leaving only the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code shown in Listing 7-21. Note that this won’t compile until we create the @@ -51,10 +51,10 @@ programming languages. Next, we’ll extract the `hosting` module to its own file. The process is a bit different because `hosting` is a child module of `front_of_house`, not of the root module. We’ll place the file for `hosting` in a new directory that will be -named for its ancestors in the module tree, in this case *src/front_of_house/*. +named for its ancestors in the module tree, in this case *src/front_of_house*. -To start moving `hosting`, we change *src/front_of_house.rs* to contain only the -declaration of the `hosting` module: +To start moving `hosting`, we change *src/front_of_house.rs* to contain only +the declaration of the `hosting` module: Filename: src/front_of_house.rs @@ -62,7 +62,7 @@ declaration of the `hosting` module: {{#rustdoc_include ../listings/ch07-managing-growing-projects/no-listing-02-extracting-hosting/src/front_of_house.rs}} ``` -Then we create a *src/front_of_house* directory and a file *hosting.rs* to +Then we create a *src/front_of_house* directory and a *hosting.rs* file to contain the definitions made in the `hosting` module: Filename: src/front_of_house/hosting.rs @@ -74,7 +74,7 @@ contain the definitions made in the `hosting` module: If we instead put *hosting.rs* in the *src* directory, the compiler would expect the *hosting.rs* code to be in a `hosting` module declared in the crate root, and not declared as a child of the `front_of_house` module. The -compiler’s rules for which files to check for which modules’ code means the +compiler’s rules for which files to check for which modules’ code mean the directories and files more closely match the module tree. > ### Alternate File Paths @@ -93,9 +93,9 @@ directories and files more closely match the module tree. > * *src/front_of_house/hosting.rs* (what we covered) > * *src/front_of_house/hosting/mod.rs* (older style, still supported path) > -> If you use both styles for the same module, you’ll get a compiler error. Using -> a mix of both styles for different modules in the same project is allowed, but -> might be confusing for people navigating your project. +> If you use both styles for the same module, you’ll get a compiler error. +> Using a mix of both styles for different modules in the same project is +> allowed, but might be confusing for people navigating your project. > > The main downside to the style that uses files named *mod.rs* is that your > project can end up with many files named *mod.rs*, which can get confusing @@ -114,8 +114,8 @@ that module. ## Summary -Rust lets you split a package into multiple crates and a crate into modules -so you can refer to items defined in one module from another module. You can do +Rust lets you split a package into multiple crates and a crate into modules so +you can refer to items defined in one module from another module. You can do this by specifying absolute or relative paths. These paths can be brought into scope with a `use` statement so you can use a shorter path for multiple uses of the item in that scope. Module code is private by default, but you can make From f954cb859fa3765f152b62337d8fd07dfa53f1ab Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 25 Apr 2024 16:47:51 -0400 Subject: [PATCH 136/720] Snapshot changes to generated ch7 that SHOULDN'T be sent to nostarch This snapshot contains line wrapping problems, irrelevant comments, extraneous output lines, and differences we're going to allow between the online and print version. The intention is to make this a baseline commit for chapter 7 that we can diff against to find changes to consider sending to nostarch as tiny tweaks. --- nostarch/chapter07.md | 457 +++++++++++++++++++++++------------------- 1 file changed, 254 insertions(+), 203 deletions(-) diff --git a/nostarch/chapter07.md b/nostarch/chapter07.md index 8b2dce7776..7e09e61eb1 100644 --- a/nostarch/chapter07.md +++ b/nostarch/chapter07.md @@ -20,7 +20,7 @@ optionally one library crate. As a package grows, you can extract parts into separate crates that become external dependencies. This chapter covers all these techniques. For very large projects comprising a set of interrelated packages that evolve together, Cargo provides *workspaces*, which we’ll cover -in “Cargo Workspaces” on page XX. +in the “Cargo Workspaces” section in Chapter 14. We’ll also discuss encapsulating implementation details, which lets you reuse code at a higher level: once you’ve implemented an operation, other code can @@ -43,11 +43,11 @@ organization, including which details are exposed, which details are private, and what names are in each scope in your programs. These features, sometimes collectively referred to as the *module system*, include: -* **Packages **: A Cargo feature that lets you build, test, and share crates -* **Crates**: A tree of modules that produces a library or executable -* **Modules and use**: Let you control the organization, scope, and privacy of -paths -* **Paths **: A way of naming an item, such as a struct, function, or module +* **Packages:** A Cargo feature that lets you build, test, and share crates +* **Crates:** A tree of modules that produces a library or executable +* **Modules** and **use:** Let you control the organization, scope, and + privacy of paths +* **Paths:** A way of naming an item, such as a struct, function, or module In this chapter, we’ll cover all these features, discuss how they interact, and explain how to use them to manage scope. By the end, you should have a solid @@ -59,35 +59,36 @@ The first parts of the module system we’ll cover are packages and crates. A *crate* is the smallest amount of code that the Rust compiler considers at a time. Even if you run `rustc` rather than `cargo` and pass a single source code -file (as we did all the way back in “Writing and Running a Rust Program” on -page XX), the compiler considers that file to be a crate. Crates can contain -modules, and the modules may be defined in other files that get compiled with -the crate, as we’ll see in the coming sections. +file (as we did all the way back in the “Writing and Running a Rust Program” +section of Chapter 1), the compiler considers that file to be a crate. Crates +can contain modules, and the modules may be defined in other files that get +compiled with the crate, as we’ll see in the coming sections. A crate can come in one of two forms: a binary crate or a library crate. *Binary crates* are programs you can compile to an executable that you can run, -such as a command line program or a server. Each must have a function called +such as a command-line program or a server. Each must have a function called `main` that defines what happens when the executable runs. All the crates we’ve created so far have been binary crates. *Library crates* don’t have a `main` function, and they don’t compile to an executable. Instead, they define functionality intended to be shared with -multiple projects. For example, the `rand` crate we used in Chapter 2 provides -functionality that generates random numbers. Most of the time when Rustaceans -say “crate,” they mean library crate, and they use “crate” interchangeably with -the general programming concept of a “library.” +multiple projects. For example, the `rand` crate we used in Chapter +2 provides functionality that generates random numbers. +Most of the time when Rustaceans say “crate”, they mean library crate, and they +use “crate” interchangeably with the general programming concept of a “library". The *crate root* is a source file that the Rust compiler starts from and makes -up the root module of your crate (we’ll explain modules in depth in “Defining -Modules to Control Scope and Privacy” on page XX). +up the root module of your crate (we’ll explain modules in depth in the +“Defining Modules to Control Scope and Privacy” +section). A *package* is a bundle of one or more crates that provides a set of functionality. A package contains a *Cargo.toml* file that describes how to build those crates. Cargo is actually a package that contains the binary crate -for the command line tool you’ve been using to build your code. The Cargo +for the command-line tool you’ve been using to build your code. The Cargo package also contains a library crate that the binary crate depends on. Other projects can depend on the Cargo library crate to use the same logic the Cargo -command line tool uses. +command-line tool uses. A crate can come in one of two forms: a binary crate or a library crate. A package can contain as many binary crates as you like, but at most only one @@ -123,100 +124,104 @@ and *src/lib.rs*, it has two crates: a binary and a library, both with the same name as the package. A package can have multiple binary crates by placing files in the *src/bin* directory: each file will be a separate binary crate. -> ### Modules Cheat Sheet -> -> Before we get to the details of modules and paths, here we provide a quick +## Defining Modules to Control Scope and Privacy + +In this section, we’ll talk about modules and other parts of the module system, +namely *paths*, which allow you to name items; the `use` keyword that brings a +path into scope; and the `pub` keyword to make items public. We’ll also discuss +the `as` keyword, external packages, and the glob operator. + +### Modules Cheat Sheet + +Before we get to the details of modules and paths, here we provide a quick reference on how modules, paths, the `use` keyword, and the `pub` keyword work in the compiler, and how most developers organize their code. We’ll be going through examples of each of these rules throughout this chapter, but this is a great place to refer to as a reminder of how modules work. -> -> * **Start from the crate root**: When compiling a crate, the compiler first -looks in the crate root file (usually *src/lib.rs* for a library crate or -*src/main.rs* for a binary crate) for code to compile. -> * **Declaring modules**: In the crate root file, you can declare new modules; + +- **Start from the crate root**: When compiling a crate, the compiler first + looks in the crate root file (usually *src/lib.rs* for a library crate or + *src/main.rs* for a binary crate) for code to compile. +- **Declaring modules**: In the crate root file, you can declare new modules; say you declare a “garden” module with `mod garden;`. The compiler will look for the module’s code in these places: -> -> * Inline, within curly brackets that replace the semicolon following `mod -garden` -> * In the file *src/garden.rs.* -> * In the file *src/garden/mod.rs* -> * **Declaring submodules**: In any file other than the crate root, you can -declare submodules. For example, you might declare `mod vegetables;` in -*src/garden.rs*. The compiler will look for the submodule’s code within the -directory named for the parent module in these places: -> -> * Inline, directly following `mod vegetables`, within curly brackets instead -of the semicolon -> * In the file *src/garden/vegetables.rs* -> * In the file *src/garden/vegetables/mod.rs* -> * **Paths to code in modules**: Once a module is part of your crate, you can -refer to code in that module from anywhere else in that same crate, as long as -the privacy rules allow, using the path to the code. For example, an -`Asparagus` type in the garden vegetables module would be found at -`crate::garden::vegetables::Asparagus`. -> * **Private vs. public**: Code within a module is private from its parent -modules by default. To make a module public, declare it with `pub mod` instead -of `mod`. To make items within a public module public as well, use `pub` before -their declarations. -> * **The use keyword**: Within a scope, the `use` keyword creates shortcuts to -items to reduce repetition of long paths. In any scope that can refer to -`crate::garden::vegetables::Asparagus`, you can create a shortcut with `use -crate::garden::vegetables::Asparagus;` and from then on you only need to write -`Asparagus` to make use of that type in the scope. -> -> Here, we create a binary crate named `backyard` that illustrates these rules. + - Inline, within curly brackets that replace the semicolon following `mod + garden` + - In the file *src/garden.rs* + - In the file *src/garden/mod.rs* +- **Declaring submodules**: In any file other than the crate root, you can + declare submodules. For example, you might declare `mod vegetables;` in + *src/garden.rs*. The compiler will look for the submodule’s code within the + directory named for the parent module in these places: + - Inline, directly following `mod vegetables`, within curly brackets instead + of the semicolon + - In the file *src/garden/vegetables.rs* + - In the file *src/garden/vegetables/mod.rs* +- **Paths to code in modules**: Once a module is part of your crate, you can + refer to code in that module from anywhere else in that same crate, as long + as the privacy rules allow, using the path to the code. For example, an + `Asparagus` type in the garden vegetables module would be found at + `crate::garden::vegetables::Asparagus`. +- **Private vs. public**: Code within a module is private from its parent + modules by default. To make a module public, declare it with `pub mod` + instead of `mod`. To make items within a public module public as well, use + `pub` before their declarations. +- **The `use` keyword**: Within a scope, the `use` keyword creates shortcuts to + items to reduce repetition of long paths. In any scope that can refer to + `crate::garden::vegetables::Asparagus`, you can create a shortcut with `use + crate::garden::vegetables::Asparagus;` and from then on you only need to + write `Asparagus` to make use of that type in the scope. + +Here, we create a binary crate named `backyard` that illustrates these rules. The crate’s directory, also named `backyard`, contains these files and directories: -> -> ``` -> backyard -> ├── Cargo.lock -> ├── Cargo.toml -> └── src -> ├── garden -> │ └── vegetables.rs -> ├── garden.rs -> └── main.rs -> ``` -> -> The crate root file in this case is *src/main.rs*, and it contains: -> -> ``` -> use crate::garden::vegetables::Asparagus; -> -> pub mod garden; -> -> fn main() { -> let plant = Asparagus {}; -> println!("I'm growing {:?}!", plant); -> } -> ``` -> -> The `pub mod garden;` line tells the compiler to include the code it finds in + +``` +backyard +├── Cargo.lock +├── Cargo.toml +└── src + ├── garden + │   └── vegetables.rs + ├── garden.rs + └── main.rs +``` + +The crate root file in this case is *src/main.rs*, and it contains: + +Filename: src/main.rs + +``` +use crate::garden::vegetables::Asparagus; + +pub mod garden; + +fn main() { + let plant = Asparagus {}; + println!("I'm growing {:?}!", plant); +} +``` + +The `pub mod garden;` line tells the compiler to include the code it finds in *src/garden.rs*, which is: -> -> ``` -> pub mod vegetables; -> ``` -> -> Here, `pub mod vegetables;` means the code in *src/garden/vegetables.rs* is + +Filename: src/garden.rs + +``` +pub mod vegetables; +``` + +Here, `pub mod vegetables;` means the code in *src/garden/vegetables.rs* is included too. That code is: -> -> ``` -> #[derive(Debug)] -> pub struct Asparagus {} -> ``` -> -> Now let’s get into the details of these rules and demonstrate them in action! -## Defining Modules to Control Scope and Privacy +``` +#[derive(Debug)] +pub struct Asparagus {} +``` -In this section, we’ll talk about modules and other parts of the module system, -namely *paths*, which allow you to name items; the `use` keyword that brings a -path into scope; and the `pub` keyword to make items public. We’ll also discuss -the `as` keyword, external packages, and the glob operator. +Now let’s get into the details of these rules and demonstrate them in action! + +### Grouping Related Code in Modules *Modules* let us organize code within a crate for readability and easy reuse. Modules also allow us to control the *privacy* of items because code within a @@ -263,8 +268,8 @@ mod front_of_house { } ``` -Listing 7-1: A `front_of_house` module containing other modules that then -contain functions +Listing 7-1: A `front_of_house` module containing other +modules that then contain functions We define a module with the `mod` keyword followed by the name of the module (in this case, `front_of_house`). The body of the module then goes inside curly @@ -298,7 +303,8 @@ crate └── take_payment ``` -Listing 7-2: The module tree for the code in Listing 7-1 +Listing 7-2: The module tree for the code in Listing +7-1 This tree shows how some of the modules nest inside other modules; for example, `hosting` nests inside `front_of_house`. The tree also shows that some modules @@ -321,18 +327,19 @@ know its path. A path can take two forms: -* An *absolute path* is the full path starting from a crate root; for code from -an external crate, the absolute path begins with the crate name, and for code -from the current crate, it starts with the literal `crate`. +* An *absolute path* is the full path starting from a crate root; for code + from an external crate, the absolute path begins with the crate name, and for + code from the current crate, it starts with the literal `crate`. * A *relative path* starts from the current module and uses `self`, `super`, or -an identifier in the current module. + an identifier in the current module. Both absolute and relative paths are followed by one or more identifiers separated by double colons (`::`). Returning to Listing 7-1, say we want to call the `add_to_waitlist` function. This is the same as asking: what’s the path of the `add_to_waitlist` function? -Listing 7-3 contains Listing 7-1 with some of the modules and functions removed. +Listing 7-3 contains Listing 7-1 with some of the modules and functions +removed. We’ll show two ways to call the `add_to_waitlist` function from a new function, `eat_at_restaurant`, defined in the crate root. These paths are correct, but @@ -340,8 +347,8 @@ there’s another problem remaining that will prevent this example from compilin as is. We’ll explain why in a bit. The `eat_at_restaurant` function is part of our library crate’s public API, so -we mark it with the `pub` keyword. In “Exposing Paths with the pub Keyword” on -page XX, we’ll go into more detail about `pub`. +we mark it with the `pub` keyword. In the “Exposing Paths with the `pub` +Keyword” section, we’ll go into more detail about `pub`. Filename: src/lib.rs @@ -361,8 +368,8 @@ pub fn eat_at_restaurant() { } ``` -Listing 7-3: Calling the `add_to_waitlist` function using absolute and relative -paths +Listing 7-3: Calling the `add_to_waitlist` function using +absolute and relative paths The first time we call the `add_to_waitlist` function in `eat_at_restaurant`, we use an absolute path. The `add_to_waitlist` function is defined in the same @@ -422,9 +429,13 @@ note: the module `hosting` is defined here | 2 | mod hosting { | ^^^^^^^^^^^ + +For more information about this error, try `rustc --explain E0603`. +error: could not compile `restaurant` (lib) due to 2 previous errors ``` -Listing 7-4: Compiler errors from building the code in Listing 7-3 +Listing 7-4: Compiler errors from building the code in +Listing 7-3 The error messages say that module `hosting` is private. In other words, we have the correct paths for the `hosting` module and the `add_to_waitlist` @@ -447,7 +458,7 @@ inner code you can change without breaking outer code. However, Rust does give you the option to expose inner parts of child modules’ code to outer ancestor modules by using the `pub` keyword to make an item public. -### Exposing Paths with the pub Keyword +### Exposing Paths with the `pub` Keyword Let’s return to the error in Listing 7-4 that told us the `hosting` module is private. We want the `eat_at_restaurant` function in the parent module to have @@ -463,11 +474,17 @@ mod front_of_house { } } ---snip-- +pub fn eat_at_restaurant() { + // Absolute path + crate::front_of_house::hosting::add_to_waitlist(); + + // Relative path + front_of_house::hosting::add_to_waitlist(); +} ``` -Listing 7-5: Declaring the `hosting` module as `pub` to use it from -`eat_at_restaurant` +Listing 7-5: Declaring the `hosting` module as `pub` to +use it from `eat_at_restaurant` Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. @@ -498,9 +515,13 @@ note: the function `add_to_waitlist` is defined here | 3 | fn add_to_waitlist() {} | ^^^^^^^^^^^^^^^^^^^^ + +For more information about this error, try `rustc --explain E0603`. +error: could not compile `restaurant` (lib) due to 2 previous errors ``` -Listing 7-6: Compiler errors from building the code in Listing 7-5 +Listing 7-6: Compiler errors from building the code in +Listing 7-5 What happened? Adding the `pub` keyword in front of `mod hosting` makes the module public. With this change, if we can access `front_of_house`, we can @@ -527,11 +548,18 @@ mod front_of_house { } } ---snip-- +pub fn eat_at_restaurant() { + // Absolute path + crate::front_of_house::hosting::add_to_waitlist(); + + // Relative path + front_of_house::hosting::add_to_waitlist(); +} ``` -Listing 7-7: Adding the `pub` keyword to `mod hosting` and `fn add_to_waitlist` -lets us call the function from `eat_at_restaurant`. +Listing 7-7: Adding the `pub` keyword to `mod hosting` +and `fn add_to_waitlist` lets us call the function from +`eat_at_restaurant` Now the code will compile! To see why adding the `pub` keyword lets us use these paths in `add_to_waitlist` with respect to the privacy rules, let’s look @@ -559,31 +587,31 @@ If you plan on sharing your library crate so other projects can use your code, your public API is your contract with users of your crate that determines how they can interact with your code. There are many considerations around managing changes to your public API to make it easier for people to depend on your -crate. These considerations are beyond the scope of this book; if you’re -interested in this topic, see the Rust API Guidelines at -*https://rust-lang.github.io/api-guidelines*. +crate. These considerations are out of the scope of this book; if you’re +interested in this topic, see The Rust API Guidelines at *https://rust-lang.github.io/api-guidelines/*. -> ### Best Practices for Packages with a Binary and a Library +> #### Best Practices for Packages with a Binary and a Library > > We mentioned that a package can contain both a *src/main.rs* binary crate -root as well as a *src/lib.rs* library crate root, and both crates will have -the package name by default. Typically, packages with this pattern of -containing both a library and a binary crate will have just enough code in the -binary crate to start an executable that calls code with the library crate. -This lets other projects benefit from the most functionality that the package -provides because the library crate’s code can be shared. +> root as well as a *src/lib.rs* library crate root, and both crates will have +> the package name by default. Typically, packages with this pattern of +> containing both a library and a binary crate will have just enough code in the +> binary crate to start an executable that calls code with the library crate. +> This lets other projects benefit from the most functionality that the +> package provides because the library crate’s code can be shared. > > The module tree should be defined in *src/lib.rs*. Then, any public items can -be used in the binary crate by starting paths with the name of the package. The -binary crate becomes a user of the library crate just like a completely -external crate would use the library crate: it can only use the public API. -This helps you design a good API; not only are you the author, you’re also a -client! +> be used in the binary crate by starting paths with the name of the package. +> The binary crate becomes a user of the library crate just like a completely +> external crate would use the library crate: it can only use the public API. +> This helps you design a good API; not only are you the author, you’re also a +> client! > -> In Chapter 12, we’ll demonstrate this organizational practice with a command -line program that will contain both a binary crate and a library crate. +> In Chapter 12, we’ll demonstrate this organizational +> practice with a command-line program that will contain both a binary crate +> and a library crate. -### Starting Relative Paths with super +### Starting Relative Paths with `super` We can construct relative paths that begin in the parent module, rather than the current module or the crate root, by using `super` at the start of the @@ -614,7 +642,8 @@ mod back_of_house { } ``` -Listing 7-8: Calling a function using a relative path starting with `super` +Listing 7-8: Calling a function using a relative path +starting with `super` The `fix_incorrect_order` function is in the `back_of_house` module, so we can use `super` to go to the parent module of `back_of_house`, which in this case @@ -664,14 +693,14 @@ pub fn eat_at_restaurant() { meal.toast = String::from("Wheat"); println!("I'd like {} toast please", meal.toast); - // The next line won't compile if we uncomment it; we're not - // allowed to see or modify the seasonal fruit that comes - // with the meal + // The next line won't compile if we uncomment it; we're not allowed + // to see or modify the seasonal fruit that comes with the meal // meal.seasonal_fruit = String::from("blueberries"); } ``` -Listing 7-9: A struct with some public fields and some private fields +Listing 7-9: A struct with some public fields and some +private fields Because the `toast` field in the `back_of_house::Breakfast` struct is public, in `eat_at_restaurant` we can write and read to the `toast` field using dot @@ -705,7 +734,8 @@ pub fn eat_at_restaurant() { } ``` -Listing 7-10: Designating an enum as public makes all its variants public. +Listing 7-10: Designating an enum as public makes all its +variants public Because we made the `Appetizer` enum public, we can use the `Soup` and `Salad` variants in `eat_at_restaurant`. @@ -720,7 +750,7 @@ There’s one more situation involving `pub` that we haven’t covered, and that our last module system feature: the `use` keyword. We’ll cover `use` by itself first, and then we’ll show how to combine `pub` and `use`. -## Bringing Paths into Scope with the use Keyword +## Bringing Paths into Scope with the `use` Keyword Having to write out the paths to call functions can feel inconvenient and repetitive. In Listing 7-7, whether we chose the absolute or relative path to @@ -750,7 +780,8 @@ pub fn eat_at_restaurant() { } ``` -Listing 7-11: Bringing a module into scope with `use` +Listing 7-11: Bringing a module into scope with +`use` Adding `use` and a path in a scope is similar to creating a symbolic link in the filesystem. By adding `use crate::front_of_house::hosting` in the crate @@ -781,12 +812,15 @@ mod customer { } ``` -Listing 7-12: A `use` statement only applies in the scope it’s in. +Listing 7-12: A `use` statement only applies in the scope +it’s in The compiler error shows that the shortcut no longer applies within the `customer` module: ``` +$ cargo build + Compiling restaurant v0.1.0 (file:///projects/restaurant) error[E0433]: failed to resolve: use of undeclared crate or module `hosting` --> src/lib.rs:11:9 | @@ -800,6 +834,10 @@ warning: unused import: `crate::front_of_house::hosting` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default + +For more information about this error, try `rustc --explain E0433`. +warning: `restaurant` (lib) generated 1 warning +error: could not compile `restaurant` (lib) due to 1 previous error; 1 warning emitted ``` Notice there’s also a warning that the `use` is no longer used in its scope! To @@ -807,7 +845,7 @@ fix this problem, move the `use` within the `customer` module too, or reference the shortcut in the parent module with `super::hosting` within the child `customer` module. -### Creating Idiomatic use Paths +### Creating Idiomatic `use` Paths In Listing 7-11, you might have wondered why we specified `use crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in @@ -830,8 +868,8 @@ pub fn eat_at_restaurant() { } ``` -Listing 7-13: Bringing the `add_to_waitlist` function into scope with `use`, -which is unidiomatic +Listing 7-13: Bringing the `add_to_waitlist` function +into scope with `use`, which is unidiomatic Although both Listing 7-11 and Listing 7-13 accomplish the same task, Listing 7-11 is the idiomatic way to bring a function into scope with `use`. Bringing @@ -857,7 +895,8 @@ fn main() { } ``` -Listing 7-14: Bringing `HashMap` into scope in an idiomatic way +Listing 7-14: Bringing `HashMap` into scope in an +idiomatic way There’s no strong reason behind this idiom: it’s just the convention that has emerged, and folks have gotten used to reading and writing Rust code this way. @@ -874,23 +913,23 @@ use std::fmt; use std::io; fn function1() -> fmt::Result { - --snip-- + // --snip-- } fn function2() -> io::Result<()> { - --snip-- + // --snip-- } ``` -Listing 7-15: Bringing two types with the same name into the same scope -requires using their parent modules. +Listing 7-15: Bringing two types with the same name into +the same scope requires using their parent modules. As you can see, using the parent modules distinguishes the two `Result` types. If instead we specified `use std::fmt::Result` and `use std::io::Result`, we’d have two `Result` types in the same scope, and Rust wouldn’t know which one we meant when we used `Result`. -### Providing New Names with the as Keyword +### Providing New Names with the `as` Keyword There’s another solution to the problem of bringing two types of the same name into the same scope with `use`: after the path, we can specify `as` and a new @@ -904,22 +943,23 @@ use std::fmt::Result; use std::io::Result as IoResult; fn function1() -> Result { - --snip-- + // --snip-- } fn function2() -> IoResult<()> { - --snip-- + // --snip-- } ``` -Listing 7-16: Renaming a type when it’s brought into scope with the `as` keyword +Listing 7-16: Renaming a type when it’s brought into +scope with the `as` keyword In the second `use` statement, we chose the new name `IoResult` for the `std::io::Result` type, which won’t conflict with the `Result` from `std::fmt` that we’ve also brought into scope. Listing 7-15 and Listing 7-16 are considered idiomatic, so the choice is up to you! -### Re-exporting Names with pub use +### Re-exporting Names with `pub use` When we bring a name into scope with the `use` keyword, the name available in the new scope is private. To enable the code that calls our code to refer to @@ -947,8 +987,8 @@ pub fn eat_at_restaurant() { } ``` -Listing 7-17: Making a name available for any code to use from a new scope with -`pub use` +Listing 7-17: Making a name available for any code to use +from a new scope with `pub use` Before this change, external code would have to call the `add_to_waitlist` function by using the path @@ -964,8 +1004,9 @@ probably won’t think about the parts of the restaurant in those terms. With `pub use`, we can write our code with one structure but expose a different structure. Doing so makes our library well organized for programmers working on the library and programmers calling the library. We’ll look at another example -of `pub use` and how it affects your crate’s documentation in “Exporting a -Convenient Public API with pub use” on page XX. +of `pub use` and how it affects your crate’s documentation in the “Exporting a +Convenient Public API with `pub use`” section of +Chapter 14. ### Using External Packages @@ -973,6 +1014,12 @@ In Chapter 2, we programmed a guessing game project that used an external package called `rand` to get random numbers. To use `rand` in our project, we added this line to *Cargo.toml*: + + Filename: Cargo.toml ``` @@ -980,14 +1027,14 @@ rand = "0.8.5" ``` Adding `rand` as a dependency in *Cargo.toml* tells Cargo to download the -`rand` package and any dependencies from *https://crates.io*, and make `rand` -available to our project. +`rand` package and any dependencies from crates.io at *https://crates.io/* and +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” on page -XX, we brought the `Rng` trait into scope and called the `rand::thread_rng` -function: +`use` line starting with the name of the crate, `rand`, and listed the items +we wanted to bring into scope. Recall that in the “Generating a Random +Number” section in Chapter 2, we brought the `Rng` trait +into scope and called the `rand::thread_rng` function: ``` use rand::Rng; @@ -998,9 +1045,9 @@ fn main() { ``` Members of the Rust community have made many packages available at -*https://crates.io*, and pulling any of them into your package involves these -same steps: listing them in your package’s *Cargo.toml* file and using `use` to -bring items from their crates into scope. +crates.io at *https://crates.io/*, and pulling any of them into your package +involves these same steps: listing them in your package’s *Cargo.toml* file and +using `use` to bring items from their crates into scope. Note that the standard `std` library is also a crate that’s external to our package. Because the standard library is shipped with the Rust language, we @@ -1015,7 +1062,7 @@ use std::collections::HashMap; This is an absolute path starting with `std`, the name of the standard library crate. -### Using Nested Paths to Clean Up Large use Lists +### Using Nested Paths to Clean Up Large `use` Lists If we’re using multiple items defined in the same crate or same module, listing each item on its own line can take up a lot of vertical space in our files. For @@ -1025,10 +1072,10 @@ bring items from `std` into scope: Filename: src/main.rs ``` ---snip-- +// --snip-- use std::cmp::Ordering; use std::io; ---snip-- +// --snip-- ``` Instead, we can use nested paths to bring the same items into scope in one @@ -1039,13 +1086,13 @@ differ, as shown in Listing 7-18. Filename: src/main.rs ``` ---snip-- +// --snip-- use std::{cmp::Ordering, io}; ---snip-- +// --snip-- ``` -Listing 7-18: Specifying a nested path to bring multiple items with the same -prefix into scope +Listing 7-18: Specifying a nested path to bring multiple +items with the same prefix into scope In bigger programs, bringing many items into scope from the same crate or module using nested paths can reduce the number of separate `use` statements @@ -1063,7 +1110,8 @@ use std::io; use std::io::Write; ``` -Listing 7-19: Two `use` statements where one is a subpath of the other +Listing 7-19: Two `use` statements where one is a subpath +of the other The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in @@ -1075,7 +1123,8 @@ Filename: src/lib.rs use std::io::{self, Write}; ``` -Listing 7-20: Combining the paths in Listing 7-19 into one `use` statement +Listing 7-20: Combining the paths in Listing 7-19 into +one `use` statement This line brings `std::io` and `std::io::Write` into scope. @@ -1094,9 +1143,11 @@ harder to tell what names are in scope and where a name used in your program was defined. The glob operator is often used when testing to bring everything under test -into the `tests` module; we’ll talk about that in “How to Write Tests” on page -XX. The glob operator is also sometimes used as part of the prelude pattern: -see the standard library documentation for more information on that pattern. +into the `tests` module; we’ll talk about that in the “How to Write +Tests” section in Chapter 11. The glob operator +is also sometimes used as part of the prelude pattern: see the standard +library documentation +for more information on that pattern. ## Separating Modules into Different Files @@ -1128,8 +1179,8 @@ pub fn eat_at_restaurant() { } ``` -Listing 7-21: Declaring the `front_of_house` module whose body will be in -*src/front_of_house.rs* +Listing 7-21: Declaring the `front_of_house` module whose +body will be in *src/front_of_house.rs* Next, place the code that was in the curly brackets into a new file named *src/front_of_house.rs*, as shown in Listing 7-22. The compiler knows to look @@ -1144,16 +1195,17 @@ pub mod hosting { } ``` -Listing 7-22: Definitions inside the `front_of_house` module in -*src/front_of_house.rs* +Listing 7-22: Definitions inside the `front_of_house` +module in *src/front_of_house.rs* Note that you only need to load a file using a `mod` declaration *once* in your module tree. Once the compiler knows the file is part of the project (and knows where in the module tree the code resides because of where you’ve put the `mod` statement), other files in your project should refer to the loaded file’s code -using a path to where it was declared, as covered in “Paths for Referring to an -Item in the Module Tree” on page XX. In other words, `mod` is *not* an -“include” operation that you may have seen in other programming languages. +using a path to where it was declared, as covered in the “Paths for Referring +to an Item in the Module Tree” section. In other words, +`mod` is *not* an “include” operation that you may have seen in other +programming languages. Next, we’ll extract the `hosting` module to its own file. The process is a bit different because `hosting` is a child module of `front_of_house`, not of the @@ -1187,26 +1239,26 @@ directories and files more closely match the module tree. > ### Alternate File Paths > > So far we’ve covered the most idiomatic file paths the Rust compiler uses, -but Rust also supports an older style of file path. For a module named -`front_of_house` declared in the crate root, the compiler will look for the -module’s code in: +> but Rust also supports an older style of file path. For a module named +> `front_of_house` declared in the crate root, the compiler will look for the +> module’s code in: > > * *src/front_of_house.rs* (what we covered) > * *src/front_of_house/mod.rs* (older style, still supported path) > > For a module named `hosting` that is a submodule of `front_of_house`, the -compiler will look for the module’s code in: +> compiler will look for the module’s code in: > > * *src/front_of_house/hosting.rs* (what we covered) > * *src/front_of_house/hosting/mod.rs* (older style, still supported path) > > If you use both styles for the same module, you’ll get a compiler error. -Using a mix of both styles for different modules in the same project is -allowed, but might be confusing for people navigating your project. +> Using a mix of both styles for different modules in the same project is +> allowed, but might be confusing for people navigating your project. > > The main downside to the style that uses files named *mod.rs* is that your -project can end up with many files named *mod.rs*, which can get confusing when -you have them open in your editor at the same time. +> project can end up with many files named *mod.rs*, which can get confusing +> when you have them open in your editor at the same time. We’ve moved each module’s code to a separate file, and the module tree remains the same. The function calls in `eat_at_restaurant` will work without any @@ -1230,4 +1282,3 @@ definitions public by adding the `pub` keyword. In the next chapter, we’ll look at some collection data structures in the standard library that you can use in your neatly organized code. - From cb0a24007f6a0837c65f5d19284111b49f1089cc Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 25 Apr 2024 16:53:14 -0400 Subject: [PATCH 137/720] Snapshot changes to ch7 to consider sending to nostarch --- nostarch/chapter07.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/nostarch/chapter07.md b/nostarch/chapter07.md index 7e09e61eb1..9fef53de79 100644 --- a/nostarch/chapter07.md +++ b/nostarch/chapter07.md @@ -410,7 +410,9 @@ error[E0603]: module `hosting` is private --> src/lib.rs:9:28 | 9 | crate::front_of_house::hosting::add_to_waitlist(); - | ^^^^^^^ private module + | ^^^^^^^ --------------- function `add_to_waitlist` is not publicly re-exported + | | + | private module | note: the module `hosting` is defined here --> src/lib.rs:2:5 @@ -422,7 +424,9 @@ error[E0603]: module `hosting` is private --> src/lib.rs:12:21 | 12 | front_of_house::hosting::add_to_waitlist(); - | ^^^^^^^ private module + | ^^^^^^^ --------------- function `add_to_waitlist` is not publicly re-exported + | | + | private module | note: the module `hosting` is defined here --> src/lib.rs:2:5 @@ -596,8 +600,8 @@ interested in this topic, see The Rust API Guidelines at *https://rust-lang.gith > root as well as a *src/lib.rs* library crate root, and both crates will have > the package name by default. Typically, packages with this pattern of > containing both a library and a binary crate will have just enough code in the -> binary crate to start an executable that calls code with the library crate. -> This lets other projects benefit from the most functionality that the +> binary crate to start an executable that calls code within the library crate. +> This lets other projects benefit from most of the functionality that the > package provides because the library crate’s code can be shared. > > The module tree should be defined in *src/lib.rs*. Then, any public items can @@ -826,6 +830,11 @@ error[E0433]: failed to resolve: use of undeclared crate or module `hosting` | 11 | hosting::add_to_waitlist(); | ^^^^^^^ use of undeclared crate or module `hosting` + | +help: consider importing this module through its public re-export + | +10 + use crate::hosting; + | warning: unused import: `crate::front_of_house::hosting` --> src/lib.rs:7:5 @@ -992,7 +1001,8 @@ from a new scope with `pub use` Before this change, external code would have to call the `add_to_waitlist` function by using the path -`restaurant::front_of_house::hosting::add_to_waitlist()`. Now that this `pub +`restaurant::front_of_house::hosting::add_to_waitlist()`, which also would have +required the `front_of_house` module to be marked as `pub`. Now that this `pub use` has re-exported the `hosting` module from the root module, external code can use the path `restaurant::hosting::add_to_waitlist()` instead. From da52d2ad992115c9db9d113a2dabc2e350311676 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 25 Apr 2024 16:32:47 -0600 Subject: [PATCH 138/720] Implement functionality for actual rewrite --- .gitignore | 1 + Cargo.lock | 71 ++++++++++++++++++++++++++++++++++ Cargo.toml | 9 +++++ README.md | 35 +++++++++++++++++ src/main.rs | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 223 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000..7c693fa570 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,71 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "note-handler-pulldown-cmark-test" +version = "0.1.0" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000..1102bab8fd --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "note-handler-pulldown-cmark-test" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +pulldown-cmark = { version = "0.10.3", features = ["simd"] } diff --git a/README.md b/README.md new file mode 100644 index 0000000000..5cda06669a --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# mdbook-simple-note-preprocessor + +This is a *very* simple [preprocessor][pre] for [mdBook][mdbook] which takes Markdown like this— + +```markdown +> Note: This is some material we want to provide more emphasis for, because it +> is important in some way! +``` + +—and produces output roughly like this: + +```html +
+

+ This is some material we want to provide more emphasis for, because it is + important in some way! +

+
+``` + +This allows using the relatively standard Markdown convention of (incorrectly!) using blockquotes for “callouts” or “notes” like this, while still producing semantic HTML which conveys the actual intent. + +> [!NOTE] +> This is *not* a full “admonition” preprocessor, and it is not remotely compliant with [the GitHub “alert” syntax][alerts]. It exists almost entirely for the sake of providing better semantic HTML for _The Rust Programming Language_ book with a minimum of disruption to existing workflows! +> +> You are probably better off using one of the other existing alert/admonition preprocessors: +> +> - [mdbook-alerts][mdbook-alerts] +> - [mdbook-admonish][mdbook-admonish] + +[pre]: https://rust-lang.github.io/mdBook/format/configuration/preprocessors.html +[mdbook]: https://github.com/rust-lang/mdBook +[alerts]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts +[mdbook-alerts]: https://github.com/lambdalisue/rs-mdbook-alerts +[mdbook-admonish]: https://github.com/tommilligan/mdbook-admonish diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000000..cc1ea8e882 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,107 @@ +use pulldown_cmark::{ + html::push_html, + Event::{self, *}, + Parser, Tag, TagEnd, +}; + +fn main() { + todo!("Now this as an mdbook preprocessor!"); +} + +fn rewrite(text: &str) -> String { + let parser = Parser::new(text); + + let mut events = Vec::new(); + let mut state = Default; + + for event in parser { + match (event, &mut state) { + (Start(Tag::BlockQuote), Default) => { + state = StartingBlockquote(vec![Start(Tag::BlockQuote)]); + } + + (Text(content), StartingBlockquote(blockquote_events)) => { + if content.starts_with("Note: ") { + let note_start = r#"
"#; + events.push(Html(note_start.into())); + events.push(Start(Tag::Paragraph)); + events.push(Text(content.replace("Note: ", "").into())); + state = InNote; + } else { + events.append(blockquote_events); + events.push(Text(content)); + } + } + + (Start(Tag::Paragraph), StartingBlockquote(ref mut events)) => { + events.push(Start(Tag::Paragraph)); + } + + (End(TagEnd::BlockQuote), InNote) => { + events.push(Html("
".into())); + state = Default; + } + + (event, _) => { + events.push(event); + } + } + } + + let mut buf = String::new(); + push_html(&mut buf, events.into_iter()); + buf +} + +use State::*; + +enum State<'e> { + Default, + StartingBlockquote(Vec>), + InNote, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn no_note() { + let text = "Hello, world.\n\nThis is some text."; + let processed = rewrite(text); + assert_eq!( + processed.as_str(), + "

Hello, world.

\n

This is some text.

\n" + ); + } + + #[test] + fn with_note() { + let text = "> Note: This is some text.\n> It keeps going."; + let processed = rewrite(text); + assert_eq!( + processed.as_str(), + "
\n

This is some text.\nIt keeps going.

\n
" + ); + } + + #[test] + fn regular_blockquote() { + let text = "> This is some text.\n> It keeps going."; + let processed = rewrite(text); + assert_eq!( + processed.as_str(), + "
\n

This is some text.\nIt keeps going.

\n
\n" + ); + } + + #[test] + fn combined() { + let text = "> Note: This is some text.\n> It keeps going.\n\nThis is regular text.\n\n> This is a blockquote.\n"; + let processed = rewrite(text); + assert_eq!( + processed.as_str(), + "
\n

This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" + ); + } +} From d098a33cb7d2198c659ba43e815a3281076065ec Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 25 Apr 2024 16:48:09 -0600 Subject: [PATCH 139/720] Integrate `rewrite` into an mdBook preprocessor - Rework the `rewrite` function to spit back out Markdown instead of going all the way to HTML. - Implement the `Preprocessor` type and wire up a CLI conforming to the mdBook preprocessor spec. - Add relevant deps, including for an integration test. --- Cargo.lock | 2130 ++++++++++++++++++++++++++++++++++++- Cargo.toml | 11 +- src/lib.rs | 166 +++ src/main.rs | 131 +-- tests/integration/main.rs | 22 + 5 files changed, 2336 insertions(+), 124 deletions(-) create mode 100644 src/lib.rs create mode 100644 tests/integration/main.rs diff --git a/Cargo.lock b/Cargo.lock index 7c693fa570..22db2b9632 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,52 +2,1799 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "ammonia" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e6d1c7838db705c9b756557ee27c384ce695a1c51a6fe528784cb1c6840170" +dependencies = [ + "html5ever", + "maplit", + "once_cell", + "tendril", + "url", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" + +[[package]] +name = "assert_cmd" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.52.5", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", + "terminal_size", +] + +[[package]] +name = "clap_complete" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "elasticlunr-rs" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41e83863a500656dfa214fee6682de9c5b9f03de6860fec531235ed2ae9f6571" +dependencies = [ + "regex", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" + +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys 0.52.0", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "globset" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "headers" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" +dependencies = [ + "base64", + "bytes", + "headers-core", + "http 0.2.12", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +dependencies = [ + "http 0.2.12", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http 0.2.12", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "markup5ever" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" +dependencies = [ + "log", + "phf", + "phf_codegen", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "mdbook" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c33564061c3c640bed5ace7d6a2a1b65f2c64257d1ac930c15e94ed0fb561d3" +dependencies = [ + "ammonia", + "anyhow", + "chrono", + "clap", + "clap_complete", + "elasticlunr-rs", + "env_logger", + "futures-util", + "handlebars", + "ignore", + "log", + "memchr", + "notify", + "notify-debouncer-mini", + "once_cell", + "opener", + "pathdiff", + "pulldown-cmark", + "regex", + "serde", + "serde_json", + "shlex", + "tempfile", + "tokio", + "toml", + "topological-sort", + "warp", +] + +[[package]] +name = "mdbook-simple-note-preprocessor" +version = "1.0.0" +dependencies = [ + "assert_cmd", + "clap", + "mdbook", + "pulldown-cmark", + "pulldown-cmark-to-cmark", + "serde_json", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.5.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "walkdir", + "windows-sys 0.48.0", +] + +[[package]] +name = "notify-debouncer-mini" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d40b221972a1fc5ef4d858a2f671fb34c75983eb385463dff3780eeff6a9d43" +dependencies = [ + "crossbeam-channel", + "log", + "notify", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opener" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c62dcb6174f9cb326eac248f07e955d5d559c272730b6c03e396b443b562788" +dependencies = [ + "bstr", + "normpath", + "winapi", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pest" +version = "2.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f73541b156d32197eecda1a4014d7f868fd2bcb3c550d5386087cfba442bf69c" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c35eeed0a3fab112f75165fdc026b3913f4183133f19b49be773ac9ea966e8bd" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "pest_meta" +version = "2.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2adbf29bb9776f28caece835398781ab24435585fe0d4dc1374a61db5accedca" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "predicates" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +dependencies = [ + "anstyle", + "difflib", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags 2.5.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + +[[package]] +name = "pulldown-cmark-to-cmark" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.198" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.198" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "serde_json" +version = "1.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] -name = "getopts" -version = "0.2.21" +name = "syn" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ - "unicode-width", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "memchr" -version = "2.7.2" +name = "tempfile" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] [[package]] -name = "note-handler-pulldown-cmark-test" -version = "0.1.0" +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "pulldown-cmark", + "futf", + "mac", + "utf-8", ] [[package]] -name = "pulldown-cmark" -version = "0.10.3" +name = "terminal_size" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "bitflags", - "getopts", - "memchr", - "pulldown-cmark-escape", - "unicase", + "rustix", + "windows-sys 0.48.0", ] [[package]] -name = "pulldown-cmark-escape" -version = "0.10.1" +name = "termtree" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + +[[package]] +name = "thiserror" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http 1.1.0", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "unicase" @@ -58,14 +1805,353 @@ dependencies = [ "version_check", ] +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "warp" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4378d202ff965b011c64817db11d5829506d3404edeadb61f190d111da3f231c" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "headers", + "http 0.2.12", + "hyper", + "log", + "mime", + "mime_guess", + "percent-encoding", + "pin-project", + "scoped-tls", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-tungstenite", + "tokio-util", + "tower-service", + "tracing", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.60", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/Cargo.toml b/Cargo.toml index 1102bab8fd..bfc1961406 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,16 @@ [package] -name = "note-handler-pulldown-cmark-test" -version = "0.1.0" +name = "mdbook-simple-note-preprocessor" +version = "1.0.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.5.4", features = ["derive"] } +mdbook = "0.4.37" pulldown-cmark = { version = "0.10.3", features = ["simd"] } +pulldown-cmark-to-cmark = "13.0.0" +serde_json = "1.0.116" + +[dev-dependencies] +assert_cmd = "2.0.14" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000000..50ba0cff1e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,166 @@ +use mdbook::{ + book::Book, + errors::Result, + preprocess::{Preprocessor, PreprocessorContext}, + BookItem, +}; +use pulldown_cmark::{ + Event::{self, *}, + Parser, Tag, TagEnd, +}; +use pulldown_cmark_to_cmark::cmark; + +/// A simple preprocessor for semantic notes in _The Rust Programming Language_. +/// +/// Takes in Markdown like this: +/// +/// ```markdown +/// > Note: This is a note. +/// ``` +/// +/// Spits out Markdown like this: +/// +/// ```markdown +///
+/// +/// This is a note. +/// +///
+/// ``` +pub struct SimpleNote; + +impl Preprocessor for SimpleNote { + fn name(&self) -> &str { + "simple-note-preprocessor" + } + + fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result { + book.for_each_mut(|item| { + if let BookItem::Chapter(ref mut chapter) = item { + chapter.content = rewrite(&chapter.content); + } + }); + Ok(book) + } + + fn supports_renderer(&self, renderer: &str) -> bool { + renderer == "html" + } +} + +pub fn rewrite(text: &str) -> String { + let parser = Parser::new(text); + + let mut events = Vec::new(); + let mut state = Default; + + for event in parser { + match (event, &mut state) { + (Start(Tag::BlockQuote), Default) => { + state = StartingBlockquote(vec![Start(Tag::BlockQuote)]); + } + + (Text(content), StartingBlockquote(blockquote_events)) => { + if content.starts_with("Note: ") { + // This needs the “extra” `SoftBreak`s so that when the + // final rendering pass happens, it does not end up treating + // the internal content as inline: content inside HTML + // blocks is only rendered as Markdown when it is separated + // from the block HTML elements: otherwise it gets treated + // as inline HTML and *not* rendered. + events.extend([ + Html(r#"
"#.into()), + SoftBreak, + SoftBreak, + Start(Tag::Paragraph), + Text(content.replace("Note: ", "").into()), + ]); + state = InNote; + } else { + events.append(blockquote_events); + events.push(Text(content)); + } + } + + (Start(Tag::Paragraph), StartingBlockquote(ref mut events)) => { + events.push(Start(Tag::Paragraph)); + } + + (End(TagEnd::BlockQuote), InNote) => { + // As with the start of the block HTML, the closing HTML must be + // separated from the Markdown text by two newlines. + events.extend([SoftBreak, SoftBreak, Html("
".into())]); + state = Default; + } + + (event, _) => { + events.push(event); + } + } + } + + let mut buf = String::new(); + cmark(events.into_iter(), &mut buf).unwrap(); + buf +} + +use State::*; + +#[derive(Debug)] +enum State<'e> { + Default, + StartingBlockquote(Vec>), + InNote, +} + +#[cfg(test)] +mod tests { + use super::*; + + fn render_markdown(text: &str) -> String { + let parser = Parser::new(text); + let mut buf = String::new(); + pulldown_cmark::html::push_html(&mut buf, parser); + buf + } + + #[test] + fn no_note() { + let text = "Hello, world.\n\nThis is some text."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "

Hello, world.

\n

This is some text.

\n" + ); + } + + #[test] + fn with_note() { + let text = "> Note: This is some text.\n> It keeps going."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

This is some text.\nIt keeps going.

\n
" + ); + } + + #[test] + fn regular_blockquote() { + let text = "> This is some text.\n> It keeps going."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

This is some text.\nIt keeps going.

\n
\n" + ); + } + + #[test] + fn combined() { + let text = "> Note: This is some text.\n> It keeps going.\n\nThis is regular text.\n\n> This is a blockquote.\n"; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" + ); + } +} diff --git a/src/main.rs b/src/main.rs index cc1ea8e882..d5166bf4a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,107 +1,38 @@ -use pulldown_cmark::{ - html::push_html, - Event::{self, *}, - Parser, Tag, TagEnd, -}; - -fn main() { - todo!("Now this as an mdbook preprocessor!"); -} - -fn rewrite(text: &str) -> String { - let parser = Parser::new(text); - - let mut events = Vec::new(); - let mut state = Default; - - for event in parser { - match (event, &mut state) { - (Start(Tag::BlockQuote), Default) => { - state = StartingBlockquote(vec![Start(Tag::BlockQuote)]); - } - - (Text(content), StartingBlockquote(blockquote_events)) => { - if content.starts_with("Note: ") { - let note_start = r#"
"#; - events.push(Html(note_start.into())); - events.push(Start(Tag::Paragraph)); - events.push(Text(content.replace("Note: ", "").into())); - state = InNote; - } else { - events.append(blockquote_events); - events.push(Text(content)); - } - } - - (Start(Tag::Paragraph), StartingBlockquote(ref mut events)) => { - events.push(Start(Tag::Paragraph)); - } - - (End(TagEnd::BlockQuote), InNote) => { - events.push(Html("
".into())); - state = Default; - } - - (event, _) => { - events.push(event); - } - } +use std::io; + +use clap::{self, Parser, Subcommand}; +use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; + +use mdbook_simple_note_preprocessor::SimpleNote; + +fn main() -> Result<(), String> { + let cli = Cli::parse(); + let simple_note = SimpleNote; + if let Some(Command::Supports { renderer }) = cli.command { + return if simple_note.supports_renderer(&renderer) { + Ok(()) + } else { + Err(format!("Renderer '{renderer}' is unsupported")) + }; } - let mut buf = String::new(); - push_html(&mut buf, events.into_iter()); - buf + let (ctx, book) = + CmdPreprocessor::parse_input(io::stdin()).map_err(|e| format!("blah: {e}"))?; + let processed = simple_note.run(&ctx, book).map_err(|e| format!("{e}"))?; + serde_json::to_writer(io::stdout(), &processed).map_err(|e| format!("{e}")) } -use State::*; - -enum State<'e> { - Default, - StartingBlockquote(Vec>), - InNote, +/// A simple preprocessor for semantic notes in _The Rust Programming Language_. +#[derive(Parser, Debug)] +struct Cli { + #[command(subcommand)] + command: Option, } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn no_note() { - let text = "Hello, world.\n\nThis is some text."; - let processed = rewrite(text); - assert_eq!( - processed.as_str(), - "

Hello, world.

\n

This is some text.

\n" - ); - } - - #[test] - fn with_note() { - let text = "> Note: This is some text.\n> It keeps going."; - let processed = rewrite(text); - assert_eq!( - processed.as_str(), - "
\n

This is some text.\nIt keeps going.

\n
" - ); - } - - #[test] - fn regular_blockquote() { - let text = "> This is some text.\n> It keeps going."; - let processed = rewrite(text); - assert_eq!( - processed.as_str(), - "
\n

This is some text.\nIt keeps going.

\n
\n" - ); - } - - #[test] - fn combined() { - let text = "> Note: This is some text.\n> It keeps going.\n\nThis is regular text.\n\n> This is a blockquote.\n"; - let processed = rewrite(text); - assert_eq!( - processed.as_str(), - "
\n

This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" - ); - } +#[derive(Subcommand, Debug)] +enum Command { + /// Is the renderer supported? + /// + /// All renderers are supported! This is the contract for mdBook. + Supports { renderer: String }, } diff --git a/tests/integration/main.rs b/tests/integration/main.rs new file mode 100644 index 0000000000..6944fae693 --- /dev/null +++ b/tests/integration/main.rs @@ -0,0 +1,22 @@ +use assert_cmd::Command; + +#[test] +fn supports_html_renderer() { + let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) + .unwrap() + .args(["supports", "html"]) + .ok(); + assert!(cmd.is_ok()); +} + +#[test] +fn errors_for_other_renderers() { + let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) + .unwrap() + .args(["supports", "total-nonsense"]) + .ok(); + assert!(cmd.is_err()); +} + +// It would be nice to add an actual fixture for an mdbook, but doing *that* is +// going to be a bit of a pain, and what I have should cover it for now. From 077b0c98b4db635d7e955a65eabfce6c8c0d09b4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 12:54:52 -0600 Subject: [PATCH 140/720] Rename to `mdbook-simple-note`. No need to be so verbose! --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22db2b9632..47ae25e539 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -941,7 +941,7 @@ dependencies = [ ] [[package]] -name = "mdbook-simple-note-preprocessor" +name = "mdbook-simple-note" version = "1.0.0" dependencies = [ "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index bfc1961406..eb01df2cc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mdbook-simple-note-preprocessor" +name = "mdbook-simple-note" version = "1.0.0" edition = "2021" diff --git a/src/main.rs b/src/main.rs index d5166bf4a2..d7c03e8fdc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::io; use clap::{self, Parser, Subcommand}; use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; -use mdbook_simple_note_preprocessor::SimpleNote; +use mdbook_simple_note::SimpleNote; fn main() -> Result<(), String> { let cli = Cli::parse(); From 563d52bcc570050065898ae0fd501d58b101f588 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 13:05:54 -0600 Subject: [PATCH 141/720] Add support for headings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This kind of thing works now: ```markdown > ## Something Big > > Here is the content! ``` The book does a lot of that (not just `> Note: …`). 😅 --- src/lib.rs | 84 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 50ba0cff1e..0460a45434 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,6 +82,16 @@ pub fn rewrite(text: &str) -> String { } } + (heading @ Start(Tag::Heading { .. }), StartingBlockquote(_blockquote_events)) => { + events.extend([ + Html(r#"
"#.into()), + SoftBreak, + SoftBreak, + heading, + ]); + state = InNote; + } + (Start(Tag::Paragraph), StartingBlockquote(ref mut events)) => { events.push(Start(Tag::Paragraph)); } @@ -117,13 +127,6 @@ enum State<'e> { mod tests { use super::*; - fn render_markdown(text: &str) -> String { - let parser = Parser::new(text); - let mut buf = String::new(); - pulldown_cmark::html::push_html(&mut buf, parser); - buf - } - #[test] fn no_note() { let text = "Hello, world.\n\nThis is some text."; @@ -163,4 +166,71 @@ mod tests { "
\n

This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" ); } + + #[test] + fn with_h1() { + let text = "> # Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
" + ); + } + + #[test] + fn with_h2() { + let text = "> ## Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
" + ); + } + + #[test] + fn with_h3() { + let text = "> ### Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
" + ); + } + + #[test] + fn with_h4() { + let text = "> #### Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
" + ); + } + + #[test] + fn with_h5() { + let text = "> ##### Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n
Header
\n

And then some note content.

\n
" + ); + } + + #[test] + fn with_h6() { + let text = "> ###### Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n
Header
\n

And then some note content.

\n
" + ); + } + + fn render_markdown(text: &str) -> String { + let parser = Parser::new(text); + let mut buf = String::new(); + pulldown_cmark::html::push_html(&mut buf, parser); + buf + } } From 301c7048a3966fcc43807b83336b3ea9fa32eb0d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 14:02:56 -0600 Subject: [PATCH 142/720] Rename to `mdbook-trpl-note`. This is *very* specific. --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 30 +++++++++++++++++++++++------- src/lib.rs | 4 ++-- src/main.rs | 4 ++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 47ae25e539..e65c10b0e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -941,7 +941,7 @@ dependencies = [ ] [[package]] -name = "mdbook-simple-note" +name = "mdbook-trpl-note" version = "1.0.0" dependencies = [ "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index eb01df2cc2..a070661fec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mdbook-simple-note" +name = "mdbook-trpl-note" version = "1.0.0" edition = "2021" diff --git a/README.md b/README.md index 5cda06669a..5195fde0f3 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,36 @@ -# mdbook-simple-note-preprocessor +# mdbook-trpl-note -This is a *very* simple [preprocessor][pre] for [mdBook][mdbook] which takes Markdown like this— +This is a *very* simple [preprocessor][pre] for [mdBook][mdbook], focused specifically on the content of _The Rust Programming Language_ book. This preprocessor takes Markdown like this— ```markdown > Note: This is some material we want to provide more emphasis for, because it > is important in some way! + +Some text. + +> ## Some subject +> +> Here is all the important things to know about that particular subject. ``` -—and produces output roughly like this: +—and rewrites the Markdown to this: ```html
-

- This is some material we want to provide more emphasis for, because it is - important in some way! -

+ +This is some material we want to provide more emphasis for, because it is +important in some way! + +
+ +Some text. + +
+ +## Some subject + +Here is all the important things to know about that particular subject. +
``` diff --git a/src/lib.rs b/src/lib.rs index 0460a45434..da48aeee5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,9 +27,9 @@ use pulldown_cmark_to_cmark::cmark; /// ///
/// ``` -pub struct SimpleNote; +pub struct TrplNote; -impl Preprocessor for SimpleNote { +impl Preprocessor for TrplNote { fn name(&self) -> &str { "simple-note-preprocessor" } diff --git a/src/main.rs b/src/main.rs index d7c03e8fdc..8649432f82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,11 @@ use std::io; use clap::{self, Parser, Subcommand}; use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; -use mdbook_simple_note::SimpleNote; +use mdbook_trpl_note::TrplNote; fn main() -> Result<(), String> { let cli = Cli::parse(); - let simple_note = SimpleNote; + let simple_note = TrplNote; if let Some(Command::Supports { renderer }) = cli.command { return if simple_note.supports_renderer(&renderer) { Ok(()) From 5f19f77fdf303b9648ccdc1b939e4b1716c63f6f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 14:07:36 -0600 Subject: [PATCH 143/720] Invert the order of the pattern match for readability. Trying to make changes to this made my head hurt: the fundamental split is on the state, *not* on the tag. So flip it. --- src/lib.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index da48aeee5f..fbfb68d7e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,19 +55,23 @@ pub fn rewrite(text: &str) -> String { let mut state = Default; for event in parser { - match (event, &mut state) { - (Start(Tag::BlockQuote), Default) => { + match (&mut state, event) { + (Default, Start(Tag::BlockQuote)) => { state = StartingBlockquote(vec![Start(Tag::BlockQuote)]); } - (Text(content), StartingBlockquote(blockquote_events)) => { + (StartingBlockquote(blockquote_events), Text(content)) => { if content.starts_with("Note: ") { - // This needs the “extra” `SoftBreak`s so that when the - // final rendering pass happens, it does not end up treating - // the internal content as inline: content inside HTML - // blocks is only rendered as Markdown when it is separated - // from the block HTML elements: otherwise it gets treated - // as inline HTML and *not* rendered. + // This needs the "extra" `SoftBreak`s so that when the final rendering pass + // happens, it does not end up treating the internal content as inline *or* + // treating the HTML tags as inline tags: + // + // - Content inside HTML blocks is only rendered as Markdown when it is + // separated from the block HTML elements: otherwise it gets treated as inline + // HTML and *not* rendered. + // - Along the same lines, an HTML tag that happens to be directly adjacent to + // the end of a previous Markdown block will end up being rendered as part of + // that block. events.extend([ Html(r#"
"#.into()), SoftBreak, @@ -82,7 +86,7 @@ pub fn rewrite(text: &str) -> String { } } - (heading @ Start(Tag::Heading { .. }), StartingBlockquote(_blockquote_events)) => { + (StartingBlockquote(_blockquote_events), heading @ Start(Tag::Heading { .. })) => { events.extend([ Html(r#"
"#.into()), SoftBreak, @@ -92,18 +96,18 @@ pub fn rewrite(text: &str) -> String { state = InNote; } - (Start(Tag::Paragraph), StartingBlockquote(ref mut events)) => { + (StartingBlockquote(ref mut events), Start(Tag::Paragraph)) => { events.push(Start(Tag::Paragraph)); } - (End(TagEnd::BlockQuote), InNote) => { + (InNote, End(TagEnd::BlockQuote)) => { // As with the start of the block HTML, the closing HTML must be // separated from the Markdown text by two newlines. events.extend([SoftBreak, SoftBreak, Html("
".into())]); state = Default; } - (event, _) => { + (_, event) => { events.push(event); } } From 804a6ad7683dccc5a29c42df0acb8c7d5c53d57a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 14:07:36 -0600 Subject: [PATCH 144/720] =?UTF-8?q?Do=20*not*=20remove=20the=20leading=20?= =?UTF-8?q?=E2=80=9CNote:=20=E2=80=9D=20from=20notes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fbfb68d7e8..0e993371c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,7 @@ pub fn rewrite(text: &str) -> String { SoftBreak, SoftBreak, Start(Tag::Paragraph), - Text(content.replace("Note: ", "").into()), + Text(content), ]); state = InNote; } else { @@ -147,7 +147,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

This is some text.\nIt keeps going.

\n
" + "
\n

Note: This is some text.\nIt keeps going.

\n
" ); } @@ -167,7 +167,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" + "
\n

Note: This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" ); } From 215420ab4275b642944c01de8251d794099df898 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 14:07:36 -0600 Subject: [PATCH 145/720] Rename header tests for clarity (prep for adding more tests!). --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0e993371c6..d72325facd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -172,7 +172,7 @@ mod tests { } #[test] - fn with_h1() { + fn with_h1_note() { let text = "> # Header\n > And then some note content."; let processed = rewrite(text); assert_eq!( @@ -182,7 +182,7 @@ mod tests { } #[test] - fn with_h2() { + fn with_h2_note() { let text = "> ## Header\n > And then some note content."; let processed = rewrite(text); assert_eq!( @@ -192,7 +192,7 @@ mod tests { } #[test] - fn with_h3() { + fn with_h3_note() { let text = "> ### Header\n > And then some note content."; let processed = rewrite(text); assert_eq!( @@ -202,7 +202,7 @@ mod tests { } #[test] - fn with_h4() { + fn with_h4_note() { let text = "> #### Header\n > And then some note content."; let processed = rewrite(text); assert_eq!( @@ -212,7 +212,7 @@ mod tests { } #[test] - fn with_h5() { + fn with_h5_note() { let text = "> ##### Header\n > And then some note content."; let processed = rewrite(text); assert_eq!( @@ -222,7 +222,7 @@ mod tests { } #[test] - fn with_h6() { + fn with_h6_note() { let text = "> ###### Header\n > And then some note content."; let processed = rewrite(text); assert_eq!( From 8c899a3bee1c36f4252b7c0a894ef20e985e5756 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 14:07:36 -0600 Subject: [PATCH 146/720] Correctly handle adjacent quotes and notes. In a scenario like this: ```markdown > This is a quote. > Note: this is a note ``` The result should be this output: ```markdown > This is a quote.
Note: this is a note
``` The same goes for heading-type notes, and for the inverted flow. --- src/lib.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index d72325facd..4a46644e2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,8 @@ pub fn rewrite(text: &str) -> String { // the end of a previous Markdown block will end up being rendered as part of // that block. events.extend([ + SoftBreak, + SoftBreak, Html(r#"
"#.into()), SoftBreak, SoftBreak, @@ -83,11 +85,14 @@ pub fn rewrite(text: &str) -> String { } else { events.append(blockquote_events); events.push(Text(content)); + state = Default; } } (StartingBlockquote(_blockquote_events), heading @ Start(Tag::Heading { .. })) => { events.extend([ + SoftBreak, + SoftBreak, Html(r#"
"#.into()), SoftBreak, SoftBreak, @@ -171,6 +176,26 @@ mod tests { ); } + #[test] + fn blockquote_then_note() { + let text = "> This is quoted.\n\n> Note: This is noted."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

This is quoted.

\n
\n
\n

Note: This is noted.

\n
" + ); + } + + #[test] + fn note_then_blockquote() { + let text = "> Note: This is noted.\n\n> This is quoted."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Note: This is noted.

\n
\n
\n

This is quoted.

\n
\n" + ); + } + #[test] fn with_h1_note() { let text = "> # Header\n > And then some note content."; @@ -231,6 +256,26 @@ mod tests { ); } + #[test] + fn h1_then_blockquote() { + let text = "> # Header\n > And then some note content.\n\n> This is quoted."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
\n
\n

This is quoted.

\n
\n" + ); + } + + #[test] + fn blockquote_then_h1_note() { + let text = "> This is quoted.\n\n> # Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

This is quoted.

\n
\n
\n

Header

\n

And then some note content.

\n
" + ); + } + fn render_markdown(text: &str) -> String { let parser = Parser::new(text); let mut buf = String::new(); From 2eabe4eb1d51453c7b0f1f2af535a17107182524 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 14:49:57 -0600 Subject: [PATCH 147/720] Remove `aria-label` from `
`s. My inspiration for these included the `aria-label` because the notes did not have a label like `Note: ` or a heading on them; these do, though. Keep the `aria-role` so screen readers present notes distinctively the same way the visual presentation is set off. Fix README: remove `aria-label` from there as well --- README.md | 4 ++-- src/lib.rs | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5195fde0f3..1ef5e64788 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Some text. —and rewrites the Markdown to this: ```html -
+
This is some material we want to provide more emphasis for, because it is important in some way! @@ -25,7 +25,7 @@ important in some way! Some text. -
+
## Some subject diff --git a/src/lib.rs b/src/lib.rs index 4a46644e2c..7a671be1ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ use pulldown_cmark_to_cmark::cmark; /// Spits out Markdown like this: /// /// ```markdown -///
+///
/// /// This is a note. /// @@ -75,7 +75,7 @@ pub fn rewrite(text: &str) -> String { events.extend([ SoftBreak, SoftBreak, - Html(r#"
"#.into()), + Html(r#"
"#.into()), SoftBreak, SoftBreak, Start(Tag::Paragraph), @@ -93,7 +93,7 @@ pub fn rewrite(text: &str) -> String { events.extend([ SoftBreak, SoftBreak, - Html(r#"
"#.into()), + Html(r#"
"#.into()), SoftBreak, SoftBreak, heading, @@ -152,7 +152,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

Note: This is some text.\nIt keeps going.

\n
" + "
\n

Note: This is some text.\nIt keeps going.

\n
" ); } @@ -172,7 +172,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

Note: This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" + "
\n

Note: This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" ); } @@ -182,7 +182,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

This is quoted.

\n
\n
\n

Note: This is noted.

\n
" + "
\n

This is quoted.

\n
\n
\n

Note: This is noted.

\n
" ); } @@ -192,7 +192,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

Note: This is noted.

\n
\n
\n

This is quoted.

\n
\n" + "
\n

Note: This is noted.

\n
\n
\n

This is quoted.

\n
\n" ); } @@ -202,7 +202,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
" + "
\n

Header

\n

And then some note content.

\n
" ); } @@ -212,7 +212,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
" + "
\n

Header

\n

And then some note content.

\n
" ); } @@ -222,7 +222,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
" + "
\n

Header

\n

And then some note content.

\n
" ); } @@ -232,7 +232,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
" + "
\n

Header

\n

And then some note content.

\n
" ); } @@ -242,7 +242,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n
Header
\n

And then some note content.

\n
" + "
\n
Header
\n

And then some note content.

\n
" ); } @@ -252,7 +252,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n
Header
\n

And then some note content.

\n
" + "
\n
Header
\n

And then some note content.

\n
" ); } @@ -262,7 +262,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
\n
\n

This is quoted.

\n
\n" + "
\n

Header

\n

And then some note content.

\n
\n
\n

This is quoted.

\n
\n" ); } @@ -272,7 +272,7 @@ mod tests { let processed = rewrite(text); assert_eq!( render_markdown(&processed), - "
\n

This is quoted.

\n
\n
\n

Header

\n

And then some note content.

\n
" + "
\n

This is quoted.

\n
\n
\n

Header

\n

And then some note content.

\n
" ); } From 1787086b5fc6c48ec12497b2cf31400f5274d0f7 Mon Sep 17 00:00:00 2001 From: Luke Franceschini Date: Mon, 29 Apr 2024 06:16:49 -0400 Subject: [PATCH 148/720] [ch10-03] Fix wording change about mandatory type annotation The wording change in 66aedb4 made this sentence flow more nicely, but is a misleading because it implies types can't be annotated if there is only one possible type. This changes it back to it's previous order, but replaces "must" with "have to" to keep it's correctness while still flowing more naturally. Technically it's still incorrect because types have to be annotated in type signatures even if there is only one possible type. Maybe the word "only" in this sentence should be removed? --- src/ch10-03-lifetime-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index e77be953b3..197e2c6f59 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -8,7 +8,7 @@ One detail we didn’t discuss in the [“References and Borrowing”][references-and-borrowing] section in Chapter 4 is that every reference in Rust has a *lifetime*, which is the scope for which that reference is valid. Most of the time, lifetimes are implicit and inferred, -just like most of the time, types are inferred. We must only annotate types +just like most of the time, types are inferred. We only have to annotate types when multiple types are possible. In a similar way, we must annotate lifetimes when the lifetimes of references could be related in a few different ways. Rust requires us to annotate the relationships using generic lifetime parameters to From 303206849b359aebf7f8b326d59d4d4d4aebf29b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Apr 2024 16:00:09 -0600 Subject: [PATCH 149/720] Prepare to merge into TRPL repo In the destination, this will be part of a Cargo workspace, and should *not* be in the root, where a merge will conflict with the workspace Cargo config etc. --- Cargo.lock => packages/mdbook-trpl-note/Cargo.lock | 0 Cargo.toml => packages/mdbook-trpl-note/Cargo.toml | 0 README.md => packages/mdbook-trpl-note/README.md | 0 {src => packages/mdbook-trpl-note/src}/lib.rs | 0 {src => packages/mdbook-trpl-note/src}/main.rs | 0 {tests => packages/mdbook-trpl-note/tests}/integration/main.rs | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename Cargo.lock => packages/mdbook-trpl-note/Cargo.lock (100%) rename Cargo.toml => packages/mdbook-trpl-note/Cargo.toml (100%) rename README.md => packages/mdbook-trpl-note/README.md (100%) rename {src => packages/mdbook-trpl-note/src}/lib.rs (100%) rename {src => packages/mdbook-trpl-note/src}/main.rs (100%) rename {tests => packages/mdbook-trpl-note/tests}/integration/main.rs (100%) diff --git a/Cargo.lock b/packages/mdbook-trpl-note/Cargo.lock similarity index 100% rename from Cargo.lock rename to packages/mdbook-trpl-note/Cargo.lock diff --git a/Cargo.toml b/packages/mdbook-trpl-note/Cargo.toml similarity index 100% rename from Cargo.toml rename to packages/mdbook-trpl-note/Cargo.toml diff --git a/README.md b/packages/mdbook-trpl-note/README.md similarity index 100% rename from README.md rename to packages/mdbook-trpl-note/README.md diff --git a/src/lib.rs b/packages/mdbook-trpl-note/src/lib.rs similarity index 100% rename from src/lib.rs rename to packages/mdbook-trpl-note/src/lib.rs diff --git a/src/main.rs b/packages/mdbook-trpl-note/src/main.rs similarity index 100% rename from src/main.rs rename to packages/mdbook-trpl-note/src/main.rs diff --git a/tests/integration/main.rs b/packages/mdbook-trpl-note/tests/integration/main.rs similarity index 100% rename from tests/integration/main.rs rename to packages/mdbook-trpl-note/tests/integration/main.rs From f48b281275f78badbbb3a219bb279d97877025b2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 29 Apr 2024 08:05:04 -0600 Subject: [PATCH 150/720] Convert to a workspace This will let us pull in, and work directly on, things like the `mdbook-trpl-notes` preprocessor. --- Cargo.lock | 181 +++++++++++++++--- Cargo.toml | 43 +---- packages/tools/Cargo.toml | 46 +++++ .../tools}/src/bin/concat_chapters.rs | 0 .../tools}/src/bin/convert_quotes.rs | 0 {tools => packages/tools}/src/bin/lfp.rs | 0 .../tools}/src/bin/link2print.rs | 0 .../tools}/src/bin/release_listings.rs | 0 .../tools}/src/bin/remove_hidden_lines.rs | 0 .../tools}/src/bin/remove_links.rs | 0 .../tools}/src/bin/remove_markup.rs | 0 11 files changed, 202 insertions(+), 68 deletions(-) create mode 100644 packages/tools/Cargo.toml rename {tools => packages/tools}/src/bin/concat_chapters.rs (100%) rename {tools => packages/tools}/src/bin/convert_quotes.rs (100%) rename {tools => packages/tools}/src/bin/lfp.rs (100%) rename {tools => packages/tools}/src/bin/link2print.rs (100%) rename {tools => packages/tools}/src/bin/release_listings.rs (100%) rename {tools => packages/tools}/src/bin/remove_hidden_lines.rs (100%) rename {tools => packages/tools}/src/bin/remove_links.rs (100%) rename {tools => packages/tools}/src/bin/remove_markup.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 5e9f838fe1..d54e8284e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "0.7.18" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -23,6 +23,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + [[package]] name = "cfg-if" version = "1.0.0" @@ -31,9 +37,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ "cfg-if", ] @@ -50,23 +56,33 @@ dependencies = [ "strsim", ] +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "filetime" -version = "0.2.16" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", "redox_syscall", - "winapi", + "windows-sys", ] [[package]] name = "flate2" -version = "1.0.24" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -80,21 +96,27 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "miniz_oxide" -version = "0.5.3" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", ] @@ -119,18 +141,30 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "regex" -version = "1.5.6" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -139,12 +173,12 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.26" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] -name = "rust-book" +name = "rust-book-tools" version = "0.0.1" dependencies = [ "docopt", @@ -156,6 +190,19 @@ dependencies = [ "walkdir", ] +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "same-file" version = "1.0.6" @@ -204,9 +251,9 @@ dependencies = [ [[package]] name = "tar" -version = "0.4.38" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" dependencies = [ "filetime", "libc", @@ -221,12 +268,11 @@ checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" [[package]] name = "walkdir" -version = "2.3.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", - "winapi", "winapi-util", ] @@ -261,11 +307,86 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + [[package]] name = "xattr" -version = "0.2.3" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" +checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f" dependencies = [ "libc", + "linux-raw-sys", + "rustix", ] diff --git a/Cargo.toml b/Cargo.toml index 60bd20b0fd..79af0bfa28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,42 +1,9 @@ -[package] -name = "rust-book" -version = "0.0.1" -description = "The Rust Book" -edition = "2021" +[workspace] +members = ["packages/*"] +default-members = ["packages/*"] +resolver = "2" -[[bin]] -name = "concat_chapters" -path = "tools/src/bin/concat_chapters.rs" - -[[bin]] -name = "convert_quotes" -path = "tools/src/bin/convert_quotes.rs" - -[[bin]] -name = "lfp" -path = "tools/src/bin/lfp.rs" - -[[bin]] -name = "link2print" -path = "tools/src/bin/link2print.rs" - -[[bin]] -name = "release_listings" -path = "tools/src/bin/release_listings.rs" - -[[bin]] -name = "remove_hidden_lines" -path = "tools/src/bin/remove_hidden_lines.rs" - -[[bin]] -name = "remove_links" -path = "tools/src/bin/remove_links.rs" - -[[bin]] -name = "remove_markup" -path = "tools/src/bin/remove_markup.rs" - -[dependencies] +[workspace.dependencies] walkdir = "2.3.1" docopt = "1.1.0" serde = "1.0" diff --git a/packages/tools/Cargo.toml b/packages/tools/Cargo.toml new file mode 100644 index 0000000000..95dda7a18b --- /dev/null +++ b/packages/tools/Cargo.toml @@ -0,0 +1,46 @@ +[package] +name = "rust-book-tools" +version = "0.0.1" +description = "The Rust Book" +edition = "2021" + +[[bin]] +name = "concat_chapters" +path = "src/bin/concat_chapters.rs" + +[[bin]] +name = "convert_quotes" +path = "src/bin/convert_quotes.rs" + +[[bin]] +name = "lfp" +path = "src/bin/lfp.rs" + +[[bin]] +name = "link2print" +path = "src/bin/link2print.rs" + +[[bin]] +name = "release_listings" +path = "src/bin/release_listings.rs" + +[[bin]] +name = "remove_hidden_lines" +path = "src/bin/remove_hidden_lines.rs" + +[[bin]] +name = "remove_links" +path = "src/bin/remove_links.rs" + +[[bin]] +name = "remove_markup" +path = "src/bin/remove_markup.rs" + +[dependencies] +walkdir = { workspace = true } +docopt = { workspace = true } +serde = { workspace = true } +regex = { workspace = true } +lazy_static = { workspace = true } +flate2 = { workspace = true } +tar = { workspace = true } diff --git a/tools/src/bin/concat_chapters.rs b/packages/tools/src/bin/concat_chapters.rs similarity index 100% rename from tools/src/bin/concat_chapters.rs rename to packages/tools/src/bin/concat_chapters.rs diff --git a/tools/src/bin/convert_quotes.rs b/packages/tools/src/bin/convert_quotes.rs similarity index 100% rename from tools/src/bin/convert_quotes.rs rename to packages/tools/src/bin/convert_quotes.rs diff --git a/tools/src/bin/lfp.rs b/packages/tools/src/bin/lfp.rs similarity index 100% rename from tools/src/bin/lfp.rs rename to packages/tools/src/bin/lfp.rs diff --git a/tools/src/bin/link2print.rs b/packages/tools/src/bin/link2print.rs similarity index 100% rename from tools/src/bin/link2print.rs rename to packages/tools/src/bin/link2print.rs diff --git a/tools/src/bin/release_listings.rs b/packages/tools/src/bin/release_listings.rs similarity index 100% rename from tools/src/bin/release_listings.rs rename to packages/tools/src/bin/release_listings.rs diff --git a/tools/src/bin/remove_hidden_lines.rs b/packages/tools/src/bin/remove_hidden_lines.rs similarity index 100% rename from tools/src/bin/remove_hidden_lines.rs rename to packages/tools/src/bin/remove_hidden_lines.rs diff --git a/tools/src/bin/remove_links.rs b/packages/tools/src/bin/remove_links.rs similarity index 100% rename from tools/src/bin/remove_links.rs rename to packages/tools/src/bin/remove_links.rs diff --git a/tools/src/bin/remove_markup.rs b/packages/tools/src/bin/remove_markup.rs similarity index 100% rename from tools/src/bin/remove_markup.rs rename to packages/tools/src/bin/remove_markup.rs From da9e96e876bb03bad43116841df9932e04d81ba2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 29 Apr 2024 09:21:19 -0600 Subject: [PATCH 151/720] Modernize tools package contents --- packages/tools/src/bin/concat_chapters.rs | 4 +--- packages/tools/src/bin/lfp.rs | 5 +++-- packages/tools/src/bin/link2print.rs | 3 ++- packages/tools/src/bin/release_listings.rs | 7 +++---- packages/tools/src/bin/remove_links.rs | 2 -- packages/tools/src/bin/remove_markup.rs | 5 ++--- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/tools/src/bin/concat_chapters.rs b/packages/tools/src/bin/concat_chapters.rs index 79ffec9b70..046870edb0 100644 --- a/packages/tools/src/bin/concat_chapters.rs +++ b/packages/tools/src/bin/concat_chapters.rs @@ -1,6 +1,3 @@ -#[macro_use] -extern crate lazy_static; - use std::collections::BTreeMap; use std::env; use std::fs::{create_dir, read_dir, File}; @@ -9,6 +6,7 @@ use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use std::process::exit; +use lazy_static::lazy_static; use regex::Regex; static PATTERNS: &[(&str, &str)] = &[ diff --git a/packages/tools/src/bin/lfp.rs b/packages/tools/src/bin/lfp.rs index f7b6e17f72..ee7f39c3c8 100644 --- a/packages/tools/src/bin/lfp.rs +++ b/packages/tools/src/bin/lfp.rs @@ -1,11 +1,12 @@ // We have some long regex literals, so: // ignore-tidy-linelength -use docopt::Docopt; -use serde::Deserialize; use std::io::BufRead; use std::{fs, io, path}; +use docopt::Docopt; +use serde::Deserialize; + fn main() { let args: Args = Docopt::new(USAGE) .and_then(|d| d.deserialize()) diff --git a/packages/tools/src/bin/link2print.rs b/packages/tools/src/bin/link2print.rs index 7d6def8616..09edd84bdb 100644 --- a/packages/tools/src/bin/link2print.rs +++ b/packages/tools/src/bin/link2print.rs @@ -1,11 +1,12 @@ // FIXME: we have some long lines that could be refactored, but it's not a big deal. // ignore-tidy-linelength -use regex::{Captures, Regex}; use std::collections::HashMap; use std::io; use std::io::Read; +use regex::{Captures, Regex}; + fn main() { write_md(parse_links(parse_references(read_md()))); } diff --git a/packages/tools/src/bin/release_listings.rs b/packages/tools/src/bin/release_listings.rs index 4239a4dabf..c9a2f45974 100644 --- a/packages/tools/src/bin/release_listings.rs +++ b/packages/tools/src/bin/release_listings.rs @@ -1,7 +1,3 @@ -#[macro_use] -extern crate lazy_static; - -use regex::Regex; use std::error::Error; use std::fs; use std::fs::File; @@ -9,6 +5,9 @@ use std::io::prelude::*; use std::io::{BufReader, BufWriter}; use std::path::{Path, PathBuf}; +use lazy_static::lazy_static; +use regex::Regex; + fn main() -> Result<(), Box> { // Get all listings from the `listings` directory let listings_dir = Path::new("listings"); diff --git a/packages/tools/src/bin/remove_links.rs b/packages/tools/src/bin/remove_links.rs index 042295d187..ebb46e2c25 100644 --- a/packages/tools/src/bin/remove_links.rs +++ b/packages/tools/src/bin/remove_links.rs @@ -1,5 +1,3 @@ -extern crate regex; - use regex::{Captures, Regex}; use std::collections::HashSet; use std::io; diff --git a/packages/tools/src/bin/remove_markup.rs b/packages/tools/src/bin/remove_markup.rs index a9cc4b7f59..cda6ebaa3b 100644 --- a/packages/tools/src/bin/remove_markup.rs +++ b/packages/tools/src/bin/remove_markup.rs @@ -1,9 +1,8 @@ -extern crate regex; - -use regex::{Captures, Regex}; use std::io; use std::io::Read; +use regex::{Captures, Regex}; + fn main() { write_md(remove_markup(read_md())); } From 33fb62e92f3fda26a196629e2ae67c537b506b02 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 29 Apr 2024 09:00:30 -0600 Subject: [PATCH 152/720] Make mdbook a workspace root dependency --- Cargo.lock | 2146 ++++++++++++++++++++++++-- Cargo.toml | 1 + packages/mdbook-trpl-note/Cargo.toml | 2 +- 3 files changed, 2001 insertions(+), 148 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d54e8284e1..3fbf7d04a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,280 +2,2057 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "ammonia" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e6d1c7838db705c9b756557ee27c384ce695a1c51a6fe528784cb1c6840170" +dependencies = [ + "html5ever", + "maplit", + "once_cell", + "tendril", + "url", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" + +[[package]] +name = "assert_cmd" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.52.5", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.11.1", + "terminal_size", +] + +[[package]] +name = "clap_complete" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.59", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "docopt" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" +dependencies = [ + "lazy_static", + "regex", + "serde", + "strsim 0.10.0", +] + +[[package]] +name = "elasticlunr-rs" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41e83863a500656dfa214fee6682de9c5b9f03de6860fec531235ed2ae9f6571" +dependencies = [ + "regex", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", +] + +[[package]] +name = "flate2" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.59", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "globset" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "headers" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" +dependencies = [ + "base64", + "bytes", + "headers-core", + "http 0.2.12", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +dependencies = [ + "http 0.2.12", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http 0.2.12", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "markup5ever" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" +dependencies = [ + "log", + "phf", + "phf_codegen", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "mdbook" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c33564061c3c640bed5ace7d6a2a1b65f2c64257d1ac930c15e94ed0fb561d3" +dependencies = [ + "ammonia", + "anyhow", + "chrono", + "clap", + "clap_complete", + "elasticlunr-rs", + "env_logger", + "futures-util", + "handlebars", + "ignore", + "log", + "memchr", + "notify", + "notify-debouncer-mini", + "once_cell", + "opener", + "pathdiff", + "pulldown-cmark", + "regex", + "serde", + "serde_json", + "shlex", + "tempfile", + "tokio", + "toml", + "topological-sort", + "warp", +] + +[[package]] +name = "mdbook-trpl-note" +version = "1.0.0" +dependencies = [ + "assert_cmd", + "clap", + "mdbook", + "pulldown-cmark", + "pulldown-cmark-to-cmark", + "serde_json", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.5.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "walkdir", + "windows-sys 0.48.0", +] + +[[package]] +name = "notify-debouncer-mini" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d40b221972a1fc5ef4d858a2f671fb34c75983eb385463dff3780eeff6a9d43" +dependencies = [ + "crossbeam-channel", + "log", + "notify", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opener" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c62dcb6174f9cb326eac248f07e955d5d559c272730b6c03e396b443b562788" +dependencies = [ + "bstr", + "normpath", + "winapi", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.1", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pest" +version = "2.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f73541b156d32197eecda1a4014d7f868fd2bcb3c550d5386087cfba442bf69c" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c35eeed0a3fab112f75165fdc026b3913f4183133f19b49be773ac9ea966e8bd" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.59", +] + +[[package]] +name = "pest_meta" +version = "2.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2adbf29bb9776f28caece835398781ab24435585fe0d4dc1374a61db5accedca" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.59", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "predicates" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +dependencies = [ + "anstyle", + "difflib", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro2" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags 2.5.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + +[[package]] +name = "pulldown-cmark-to-cmark" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.5.0", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rust-book-tools" +version = "0.0.1" +dependencies = [ + "docopt", + "flate2", + "lazy_static", + "regex", + "serde", + "tar", + "walkdir", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.59", +] + +[[package]] +name = "serde_json" +version = "1.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tar" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +dependencies = [ + "filetime", + "libc", + "xattr", +] [[package]] -name = "aho-corasick" -version = "1.1.3" +name = "tempfile" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ - "memchr", + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", ] [[package]] -name = "bitflags" -version = "1.3.2" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] [[package]] -name = "bitflags" -version = "2.5.0" +name = "terminal_size" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix", + "windows-sys 0.48.0", +] [[package]] -name = "cfg-if" -version = "1.0.0" +name = "termtree" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] -name = "crc32fast" -version = "1.4.0" +name = "thiserror" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ - "cfg-if", + "thiserror-impl", ] [[package]] -name = "docopt" -version = "1.1.1" +name = "thiserror-impl" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ - "lazy_static", - "regex", - "serde", - "strsim", + "proc-macro2", + "quote", + "syn 2.0.59", ] [[package]] -name = "errno" -version = "0.3.8" +name = "tinyvec" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ - "libc", - "windows-sys", + "tinyvec_macros", ] [[package]] -name = "filetime" -version = "0.2.23" +name = "tinyvec_macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ - "cfg-if", + "backtrace", + "bytes", "libc", - "redox_syscall", - "windows-sys", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", ] [[package]] -name = "flate2" -version = "1.0.30" +name = "tokio-macros" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ - "crc32fast", - "miniz_oxide", + "proc-macro2", + "quote", + "syn 2.0.59", ] [[package]] -name = "lazy_static" -version = "1.4.0" +name = "tokio-tungstenite" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] [[package]] -name = "libc" -version = "0.2.153" +name = "tokio-util" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] [[package]] -name = "linux-raw-sys" -version = "0.4.13" +name = "toml" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] [[package]] -name = "memchr" -version = "2.7.2" +name = "topological-sort" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "tower-service" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] -name = "proc-macro2" -version = "1.0.80" +name = "tracing" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "unicode-ident", + "log", + "pin-project-lite", + "tracing-core", ] [[package]] -name = "quote" -version = "1.0.36" +name = "tracing-core" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ - "proc-macro2", + "once_cell", ] [[package]] -name = "redox_syscall" -version = "0.4.1" +name = "try-lock" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" dependencies = [ - "bitflags 1.3.2", + "byteorder", + "bytes", + "data-encoding", + "http 1.1.0", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", ] [[package]] -name = "regex" -version = "1.10.4" +name = "typenum" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", + "version_check", ] [[package]] -name = "regex-automata" -version = "0.4.6" +name = "unicode-bidi" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", + "tinyvec", ] [[package]] -name = "regex-syntax" -version = "0.8.3" +name = "unicode-width" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] -name = "rust-book-tools" -version = "0.0.1" +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ - "docopt", - "flate2", - "lazy_static", - "regex", - "serde", - "tar", - "walkdir", + "form_urlencoded", + "idna", + "percent-encoding", ] [[package]] -name = "rustix" -version = "0.38.34" +name = "utf-8" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" dependencies = [ - "bitflags 2.5.0", - "errno", "libc", - "linux-raw-sys", - "windows-sys", ] [[package]] -name = "same-file" -version = "1.0.6" +name = "walkdir" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ + "same-file", "winapi-util", ] [[package]] -name = "serde" -version = "1.0.197" +name = "want" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "serde_derive", + "try-lock", ] [[package]] -name = "serde_derive" -version = "1.0.197" +name = "warp" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "4378d202ff965b011c64817db11d5829506d3404edeadb61f190d111da3f231c" dependencies = [ - "proc-macro2", - "quote", - "syn", + "bytes", + "futures-channel", + "futures-util", + "headers", + "http 0.2.12", + "hyper", + "log", + "mime", + "mime_guess", + "percent-encoding", + "pin-project", + "scoped-tls", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-tungstenite", + "tokio-util", + "tower-service", + "tracing", ] [[package]] -name = "strsim" -version = "0.10.0" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "syn" -version = "2.0.59" +name = "wasm-bindgen" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "cfg-if", + "wasm-bindgen-macro", ] [[package]] -name = "tar" -version = "0.4.40" +name = "wasm-bindgen-backend" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ - "filetime", - "libc", - "xattr", + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.59", + "wasm-bindgen-shared", ] [[package]] -name = "unicode-ident" -version = "1.0.0" +name = "wasm-bindgen-macro" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] [[package]] -name = "walkdir" -version = "2.5.0" +name = "wasm-bindgen-macro-support" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ - "same-file", - "winapi-util", + "proc-macro2", + "quote", + "syn 2.0.59", + "wasm-bindgen-backend", + "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + [[package]] name = "winapi" version = "0.3.9" @@ -307,13 +2084,46 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -322,28 +2132,46 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -356,24 +2184,48 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.5" diff --git a/Cargo.toml b/Cargo.toml index 79af0bfa28..989dc84332 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ resolver = "2" [workspace.dependencies] walkdir = "2.3.1" docopt = "1.1.0" +mdbook = "0.4.37" serde = "1.0" regex = "1.3.3" lazy_static = "1.4.0" diff --git a/packages/mdbook-trpl-note/Cargo.toml b/packages/mdbook-trpl-note/Cargo.toml index a070661fec..5834b96675 100644 --- a/packages/mdbook-trpl-note/Cargo.toml +++ b/packages/mdbook-trpl-note/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] clap = { version = "4.5.4", features = ["derive"] } -mdbook = "0.4.37" +mdbook = { workspace = true } pulldown-cmark = { version = "0.10.3", features = ["simd"] } pulldown-cmark-to-cmark = "13.0.0" serde_json = "1.0.116" From da7a20f2fc5c7e2bf9028c7677314b5067510723 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 25 Apr 2024 13:06:39 -0600 Subject: [PATCH 153/720] Emit semantic HTML instead of blockquotes for notes Use the newly-introduced `mdbook-trpl-note` to render accessible and semantic HTML for the notes/callouts in the book. This currently applies to the nostarch version as well, so a follow-on change will update the build process to undo that. Add CSS so the new note rendering matches the existing rendering of blockquotes. (We might want to change that at some point, but for now the goal is to maximizing continuity.) --- book.toml | 4 +++- theme/semantic-notes.css | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 theme/semantic-notes.css diff --git a/book.toml b/book.toml index 31419fde8d..1a24b3cdcb 100644 --- a/book.toml +++ b/book.toml @@ -3,6 +3,8 @@ title = "The Rust Programming Language" authors = ["Steve Klabnik", "Carol Nichols", "Contributions from the Rust Community"] [output.html] -additional-css = ["ferris.css", "theme/2018-edition.css"] +additional-css = ["ferris.css", "theme/2018-edition.css", "theme/semantic-notes.css"] additional-js = ["ferris.js"] git-repository-url = "https://github.com/rust-lang/book" + +[preprocessor.trpl-note] diff --git a/theme/semantic-notes.css b/theme/semantic-notes.css new file mode 100644 index 0000000000..7e68eb371d --- /dev/null +++ b/theme/semantic-notes.css @@ -0,0 +1,13 @@ +/* + This is copied directly from the styles for blockquotes, because notes were + historically rendered *as* blockquotes. This keeps the presentation of them + identical while updating the presentation. +*/ +.note { + margin: 20px 0; + padding: 0 20px; + color: var(--fg); + background-color: var(--quote-bg); + border-block-start: 0.1em solid var(--quote-border); + border-block-end: 0.1em solid var(--quote-border); +} From 593ec2af6ace59147f6f2c988c8018ed0eefb3c8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 29 Apr 2024 12:24:49 -0600 Subject: [PATCH 154/720] Do not apply semantic note handling to nostarch Introduce a `book.toml` in the `nostarch` directory, which matches the existing `book.toml` except for specifying the correct relative input and output directories and disabling the `trpl-note` preprocessor. This also lets us simplify the invocation in the `nostarch.sh` script a bit, by providing the configuration directly in the file. --- book.toml | 4 ++++ nostarch/book.toml | 12 ++++++++++++ tools/nostarch.sh | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 nostarch/book.toml diff --git a/book.toml b/book.toml index 1a24b3cdcb..416f2190fb 100644 --- a/book.toml +++ b/book.toml @@ -1,3 +1,6 @@ +# Sync any changes to this *other than where explicitly specified* with the copy +# in `nostarch/book.toml`! + [book] title = "The Rust Programming Language" authors = ["Steve Klabnik", "Carol Nichols", "Contributions from the Rust Community"] @@ -7,4 +10,5 @@ additional-css = ["ferris.css", "theme/2018-edition.css", "theme/semantic-notes. additional-js = ["ferris.js"] git-repository-url = "https://github.com/rust-lang/book" +# Do not sync this preprocessor; it is for the HTML renderer only. [preprocessor.trpl-note] diff --git a/nostarch/book.toml b/nostarch/book.toml new file mode 100644 index 0000000000..4c31179335 --- /dev/null +++ b/nostarch/book.toml @@ -0,0 +1,12 @@ +[book] +title = "The Rust Programming Language" +authors = ["Steve Klabnik", "Carol Nichols", "Contributions from the Rust Community"] +src = "../src" # needs to be explicit (it is implicit in `/book.toml`). + +[output.html] +additional-css = ["../ferris.css", "../theme/2018-edition.css", "../theme/semantic-notes.css"] +additional-js = ["../ferris.js"] +git-repository-url = "https://github.com/rust-lang/book" + +[build] +build-dir = "../tmp" \ No newline at end of file diff --git a/tools/nostarch.sh b/tools/nostarch.sh index eec0ac5ea1..430b0809a3 100755 --- a/tools/nostarch.sh +++ b/tools/nostarch.sh @@ -9,7 +9,7 @@ rm -rf tmp/*.md rm -rf tmp/markdown # Render the book as Markdown to include all the code listings -MDBOOK_OUTPUT__MARKDOWN=1 mdbook build -d tmp +MDBOOK_OUTPUT__MARKDOWN=1 mdbook build nostarch # Get all the Markdown files find tmp/markdown -name "${1:-\"\"}*.md" -print0 | \ From 427f7d3b8f61a63c2af1604792f6a1839d0e32dc Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 29 Apr 2024 12:48:20 -0600 Subject: [PATCH 155/720] Update CI config for workspace and mdbook-trpl-note - Add building `mdbook-trpl-note` to the relevant workflow. - Explicitly exclude `linkcheck` from new workspace. --- .github/workflows/main.yml | 2 ++ Cargo.toml | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ec1ab4b08a..db70f67da2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -43,6 +43,8 @@ jobs: mkdir bin curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.21/mdbook-v0.4.21-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin echo "$(pwd)/bin" >> ${GITHUB_PATH} + - name: Install mdbook-trpl-note + run: cargo install --path packages/mdbook-trpl-note - name: Install aspell run: sudo apt-get install aspell - name: Install shellcheck diff --git a/Cargo.toml b/Cargo.toml index 989dc84332..dd7b0e4fac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = ["packages/*"] default-members = ["packages/*"] resolver = "2" +exclude = ["linkchecker"] # part of the CI workflow [workspace.dependencies] walkdir = "2.3.1" From 7c40849115d92e165c37609d0251f1b12945cb0b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 16 Apr 2024 15:36:29 -0600 Subject: [PATCH 156/720] Add new Chapter 17: Async and Await --- src/SUMMARY.md | 42 ++++++++++--------- src/ch17-00-async-await.md | 2 + src/{ch17-00-oop.md => ch18-00-oop.md} | 0 ...01-what-is-oo.md => ch18-01-what-is-oo.md} | 0 ...it-objects.md => ch18-02-trait-objects.md} | 0 ...terns.md => ch18-03-oo-design-patterns.md} | 0 ...h18-00-patterns.md => ch19-00-patterns.md} | 0 ...=> ch19-01-all-the-places-for-patterns.md} | 0 ...efutability.md => ch19-02-refutability.md} | 0 ...rn-syntax.md => ch19-03-pattern-syntax.md} | 0 ...atures.md => ch20-00-advanced-features.md} | 0 ...-unsafe-rust.md => ch20-01-unsafe-rust.md} | 0 ...d-traits.md => ch20-03-advanced-traits.md} | 0 ...ced-types.md => ch20-04-advanced-types.md} | 0 ...h20-05-advanced-functions-and-closures.md} | 0 src/{ch19-06-macros.md => ch20-06-macros.md} | 0 ... => ch21-00-final-project-a-web-server.md} | 0 ...threaded.md => ch21-01-single-threaded.md} | 0 ...tithreaded.md => ch21-02-multithreaded.md} | 0 ... ch21-03-graceful-shutdown-and-cleanup.md} | 0 20 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 src/ch17-00-async-await.md rename src/{ch17-00-oop.md => ch18-00-oop.md} (100%) rename src/{ch17-01-what-is-oo.md => ch18-01-what-is-oo.md} (100%) rename src/{ch17-02-trait-objects.md => ch18-02-trait-objects.md} (100%) rename src/{ch17-03-oo-design-patterns.md => ch18-03-oo-design-patterns.md} (100%) rename src/{ch18-00-patterns.md => ch19-00-patterns.md} (100%) rename src/{ch18-01-all-the-places-for-patterns.md => ch19-01-all-the-places-for-patterns.md} (100%) rename src/{ch18-02-refutability.md => ch19-02-refutability.md} (100%) rename src/{ch18-03-pattern-syntax.md => ch19-03-pattern-syntax.md} (100%) rename src/{ch19-00-advanced-features.md => ch20-00-advanced-features.md} (100%) rename src/{ch19-01-unsafe-rust.md => ch20-01-unsafe-rust.md} (100%) rename src/{ch19-03-advanced-traits.md => ch20-03-advanced-traits.md} (100%) rename src/{ch19-04-advanced-types.md => ch20-04-advanced-types.md} (100%) rename src/{ch19-05-advanced-functions-and-closures.md => ch20-05-advanced-functions-and-closures.md} (100%) rename src/{ch19-06-macros.md => ch20-06-macros.md} (100%) rename src/{ch20-00-final-project-a-web-server.md => ch21-00-final-project-a-web-server.md} (100%) rename src/{ch20-01-single-threaded.md => ch21-01-single-threaded.md} (100%) rename src/{ch20-02-multithreaded.md => ch21-02-multithreaded.md} (100%) rename src/{ch20-03-graceful-shutdown-and-cleanup.md => ch21-03-graceful-shutdown-and-cleanup.md} (100%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index b4b58afdee..a004483b1e 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -101,29 +101,31 @@ - [Shared-State Concurrency](ch16-03-shared-state.md) - [Extensible Concurrency with the `Sync` and `Send` Traits](ch16-04-extensible-concurrency-sync-and-send.md) -- [Object Oriented Programming Features of Rust](ch17-00-oop.md) - - [Characteristics of Object-Oriented Languages](ch17-01-what-is-oo.md) - - [Using Trait Objects That Allow for Values of Different Types](ch17-02-trait-objects.md) - - [Implementing an Object-Oriented Design Pattern](ch17-03-oo-design-patterns.md) +- [Async and Await](ch17-00-async-await.md) + +- [Object Oriented Programming Features of Rust](ch18-00-oop.md) + - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) + - [Using Trait Objects That Allow for Values of Different Types](ch18-02-trait-objects.md) + - [Implementing an Object-Oriented Design Pattern](ch18-03-oo-design-patterns.md) ## Advanced Topics -- [Patterns and Matching](ch18-00-patterns.md) - - [All the Places Patterns Can Be Used](ch18-01-all-the-places-for-patterns.md) - - [Refutability: Whether a Pattern Might Fail to Match](ch18-02-refutability.md) - - [Pattern Syntax](ch18-03-pattern-syntax.md) - -- [Advanced Features](ch19-00-advanced-features.md) - - [Unsafe Rust](ch19-01-unsafe-rust.md) - - [Advanced Traits](ch19-03-advanced-traits.md) - - [Advanced Types](ch19-04-advanced-types.md) - - [Advanced Functions and Closures](ch19-05-advanced-functions-and-closures.md) - - [Macros](ch19-06-macros.md) - -- [Final Project: Building a Multithreaded Web Server](ch20-00-final-project-a-web-server.md) - - [Building a Single-Threaded Web Server](ch20-01-single-threaded.md) - - [Turning Our Single-Threaded Server into a Multithreaded Server](ch20-02-multithreaded.md) - - [Graceful Shutdown and Cleanup](ch20-03-graceful-shutdown-and-cleanup.md) +- [Patterns and Matching](ch19-00-patterns.md) + - [All the Places Patterns Can Be Used](ch19-01-all-the-places-for-patterns.md) + - [Refutability: Whether a Pattern Might Fail to Match](ch19-02-refutability.md) + - [Pattern Syntax](ch19-03-pattern-syntax.md) + +- [Advanced Features](ch20-00-advanced-features.md) + - [Unsafe Rust](ch20-01-unsafe-rust.md) + - [Advanced Traits](ch20-03-advanced-traits.md) + - [Advanced Types](ch20-04-advanced-types.md) + - [Advanced Functions and Closures](ch20-05-advanced-functions-and-closures.md) + - [Macros](ch20-06-macros.md) + +- [Final Project: Building a Multithreaded Web Server](ch21-00-final-project-a-web-server.md) + - [Building a Single-Threaded Web Server](ch21-01-single-threaded.md) + - [Turning Our Single-Threaded Server into a Multithreaded Server](ch21-02-multithreaded.md) + - [Graceful Shutdown and Cleanup](ch21-03-graceful-shutdown-and-cleanup.md) - [Appendix](appendix-00.md) - [A - Keywords](appendix-01-keywords.md) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md new file mode 100644 index 0000000000..7f216e6f3a --- /dev/null +++ b/src/ch17-00-async-await.md @@ -0,0 +1,2 @@ +## Async and Await + diff --git a/src/ch17-00-oop.md b/src/ch18-00-oop.md similarity index 100% rename from src/ch17-00-oop.md rename to src/ch18-00-oop.md diff --git a/src/ch17-01-what-is-oo.md b/src/ch18-01-what-is-oo.md similarity index 100% rename from src/ch17-01-what-is-oo.md rename to src/ch18-01-what-is-oo.md diff --git a/src/ch17-02-trait-objects.md b/src/ch18-02-trait-objects.md similarity index 100% rename from src/ch17-02-trait-objects.md rename to src/ch18-02-trait-objects.md diff --git a/src/ch17-03-oo-design-patterns.md b/src/ch18-03-oo-design-patterns.md similarity index 100% rename from src/ch17-03-oo-design-patterns.md rename to src/ch18-03-oo-design-patterns.md diff --git a/src/ch18-00-patterns.md b/src/ch19-00-patterns.md similarity index 100% rename from src/ch18-00-patterns.md rename to src/ch19-00-patterns.md diff --git a/src/ch18-01-all-the-places-for-patterns.md b/src/ch19-01-all-the-places-for-patterns.md similarity index 100% rename from src/ch18-01-all-the-places-for-patterns.md rename to src/ch19-01-all-the-places-for-patterns.md diff --git a/src/ch18-02-refutability.md b/src/ch19-02-refutability.md similarity index 100% rename from src/ch18-02-refutability.md rename to src/ch19-02-refutability.md diff --git a/src/ch18-03-pattern-syntax.md b/src/ch19-03-pattern-syntax.md similarity index 100% rename from src/ch18-03-pattern-syntax.md rename to src/ch19-03-pattern-syntax.md diff --git a/src/ch19-00-advanced-features.md b/src/ch20-00-advanced-features.md similarity index 100% rename from src/ch19-00-advanced-features.md rename to src/ch20-00-advanced-features.md diff --git a/src/ch19-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md similarity index 100% rename from src/ch19-01-unsafe-rust.md rename to src/ch20-01-unsafe-rust.md diff --git a/src/ch19-03-advanced-traits.md b/src/ch20-03-advanced-traits.md similarity index 100% rename from src/ch19-03-advanced-traits.md rename to src/ch20-03-advanced-traits.md diff --git a/src/ch19-04-advanced-types.md b/src/ch20-04-advanced-types.md similarity index 100% rename from src/ch19-04-advanced-types.md rename to src/ch20-04-advanced-types.md diff --git a/src/ch19-05-advanced-functions-and-closures.md b/src/ch20-05-advanced-functions-and-closures.md similarity index 100% rename from src/ch19-05-advanced-functions-and-closures.md rename to src/ch20-05-advanced-functions-and-closures.md diff --git a/src/ch19-06-macros.md b/src/ch20-06-macros.md similarity index 100% rename from src/ch19-06-macros.md rename to src/ch20-06-macros.md diff --git a/src/ch20-00-final-project-a-web-server.md b/src/ch21-00-final-project-a-web-server.md similarity index 100% rename from src/ch20-00-final-project-a-web-server.md rename to src/ch21-00-final-project-a-web-server.md diff --git a/src/ch20-01-single-threaded.md b/src/ch21-01-single-threaded.md similarity index 100% rename from src/ch20-01-single-threaded.md rename to src/ch21-01-single-threaded.md diff --git a/src/ch20-02-multithreaded.md b/src/ch21-02-multithreaded.md similarity index 100% rename from src/ch20-02-multithreaded.md rename to src/ch21-02-multithreaded.md diff --git a/src/ch20-03-graceful-shutdown-and-cleanup.md b/src/ch21-03-graceful-shutdown-and-cleanup.md similarity index 100% rename from src/ch20-03-graceful-shutdown-and-cleanup.md rename to src/ch21-03-graceful-shutdown-and-cleanup.md From c1a0d1434e304b2673cc2729598cfc19e922b60a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 16 Apr 2024 15:36:29 -0600 Subject: [PATCH 157/720] Ch. 17: introduction section --- src/ch17-00-async-await.md | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 7f216e6f3a..219fbeecca 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -1,2 +1,48 @@ ## Async and Await +In Chapter 16, we saw one of Rust’s approaches to concurrency: using threads. +Since Rust 1.39, there has been another option for concurrency: the async-await +model. + +In the async-await model, concurrent operations do not require their own +threads. Instead, they can run on *tasks*. A task is a bit like a thread, but +instead of being managed by the operating system, it is managed by a runtime. +The job of a runtime is to schedule Some languages, including Go, Kotlin, +Erlang, and Swift, ship runtimes with the language. In Rust, there are many +different runtimes, because the things a runtime for a high-throughput web +server should do are very different from the things a runtime for a +microcontroller should do. + +In the rest of chapter, we will: + +* see how to use Rust’s `async` and `.await` syntax +* explore how to use the async-await model to solve some of the same challenges + we looked at in Chapter 16 +* look at how multithreading and async provide complementary solutions, which + you can even use together in many cases + +First, though, let’s explore what async-await gives us. + +### Why async-await + +Many operations we ask the computer to do can take a while to finish. For +example, if you used a video editor to create a video of a family celebration, +exporting it could take anywhere from minutes to hours. Similarly, when you +upload that video to some service to share it with your family, that upload +process might take a long time. + +It would be nice if we could do something else while we are waiting for those +long-running processes to complete. + +As we saw in the previous chapter, threads provide one approach to concurrency, +and they let us solve some of these issues. However, they also have some +tradeoffs. On many operating systems, they use a fair bit of memory for each +thread, and they come with some overhead for starting up and shutting down. +Threads are also only an option when your operating system and hardware support +multiple threads. While mainstream desktop and mobile operating systems have all +had threading for many years, many embedded operating systems used on +microcontrollers do not. + + + +The async-await model provides a different, complementary set of tradeoffs. From d17c7129822a689b9a23472c9019836235dd56c9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 19 Apr 2024 15:45:51 -0600 Subject: [PATCH 158/720] Ch. 17: Expand introduction and add stub for tasks chapter --- src/ch17-00-async-await.md | 75 ++++++++++++++++++++++++++------------ src/ch17-01-tasks.md | 21 +++++++++++ 2 files changed, 73 insertions(+), 23 deletions(-) create mode 100644 src/ch17-01-tasks.md diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 219fbeecca..94a0c3b04c 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -4,22 +4,13 @@ In Chapter 16, we saw one of Rust’s approaches to concurrency: using threads. Since Rust 1.39, there has been another option for concurrency: the async-await model. -In the async-await model, concurrent operations do not require their own -threads. Instead, they can run on *tasks*. A task is a bit like a thread, but -instead of being managed by the operating system, it is managed by a runtime. -The job of a runtime is to schedule Some languages, including Go, Kotlin, -Erlang, and Swift, ship runtimes with the language. In Rust, there are many -different runtimes, because the things a runtime for a high-throughput web -server should do are very different from the things a runtime for a -microcontroller should do. - In the rest of chapter, we will: * see how to use Rust’s `async` and `.await` syntax * explore how to use the async-await model to solve some of the same challenges we looked at in Chapter 16 -* look at how multithreading and async provide complementary solutions, which - you can even use together in many cases +* look at how multithreading and async-await provide complementary solutions, + which you can even use together in many cases First, though, let’s explore what async-await gives us. @@ -29,20 +20,58 @@ Many operations we ask the computer to do can take a while to finish. For example, if you used a video editor to create a video of a family celebration, exporting it could take anywhere from minutes to hours. Similarly, when you upload that video to some service to share it with your family, that upload -process might take a long time. +process might take a long time. It would be nice if we could do something else +while we are waiting for those long-running processes to complete. + +In the previous chapter we treated parallelism and concurrency as +interchangeable. Now we need to distinguish between the two a little more: + +* *Parallelism* is when operations can happen simultaneously. + +* *Concurrency* is when operations can make progress without having to wait for + all other operations to complete. + +On a machine with multiple CPU cores, we can actually do work in parallel. One +core can be doing thing while another core does something completely unrelated, +and those actually happen at the same time. On a machine with a single CPU core, +the CPU can only do one operation at a time, but we can still have concurrency. +Using tools like threads, processes, and async-await, the computer can pause one +activity and switch to others before eventually cycling back to that first +activity again. So all parallel operations are also concurrent, but not all +concurrent operations happen in parallel! + +> Note: When working with async-await in Rust, we need to think in terms of +> *concurrency*. Depending on the hardware, the operating system, and the async +> runtime we are using, that concurrency may use some degree of parallelism +> under the hood, or it may not. -It would be nice if we could do something else while we are waiting for those -long-running processes to complete. +One common analogy for thinking about the difference between concurrency and +parallelism is cooking in a kitchen. Parallelism is like having two cooks: one +working on cooking eggs, and the other working on preparing fruit bowls. Those +can happen at the same time, without either affecting the other. Concurrency is +like having a single cook who can start cooking some eggs, start dicing up some +vegetables to use in the omelette, adding seasoning and whatever vegetables are +ready to the eggs at certain points, and switching back and forth between those +tasks. -As we saw in the previous chapter, threads provide one approach to concurrency, -and they let us solve some of these issues. However, they also have some -tradeoffs. On many operating systems, they use a fair bit of memory for each -thread, and they come with some overhead for starting up and shutting down. -Threads are also only an option when your operating system and hardware support -multiple threads. While mainstream desktop and mobile operating systems have all -had threading for many years, many embedded operating systems used on -microcontrollers do not. +(This analogy breaks down if you think about it too hard. The eggs keep cooking +while the cook is chopping up the vegetables, after all. That is parallelism, +not concurrency! The focus of the analogy is the *cook*, not the food, though, +and as long as you keep that in mind, it mostly works.) +Consider again the examples of exporting a video file and waiting on the video +file to finish uploading. The video export will use as much CPU and GPU power as +it can. If you only had one CPU core, and your operating system never paused +that export until it completed, you could not do anything else on your computer +while it was running. That would be a pretty frustrating experience, though, so +instead your computer could invisibly interrupt the export often enough to let +you get other small amounts of work done along the way. +The file upload is different. That does not take up that much CPU time. Mostly, +you are waiting on data to transfer across the network. -The async-await model provides a different, complementary set of tradeoffs. +A big difference between the cooking analogy and Rust’s async-await model for +concurrency is that in the cooking example, the cook makes the decision about +when to switch tasks. In Rust’s async-await model, the tasks are in control of +that. To see how, let’s look at diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md new file mode 100644 index 0000000000..bef9b40cba --- /dev/null +++ b/src/ch17-01-tasks.md @@ -0,0 +1,21 @@ +## Tasks + +As we saw in the previous chapter, threads provide one approach to concurrency, +and they let us solve some of these issues. However, they also have some +tradeoffs. On many operating systems, they use a fair bit of memory for each +thread, and they come with some overhead for starting up and shutting down. +Threads are also only an option when your operating system and hardware support +multiple threads. While mainstream desktop and mobile operating systems have all +had threading for many years, many embedded operating systems used on +microcontrollers do not. + +The async-await model provides a different, complementary set of tradeoffs. + +In the async-await model, concurrent operations do not require their own +threads. Instead, they can run on *tasks*. A task is a bit like a thread, but +instead of being managed by the operating system, it is managed by a runtime. +The job of a runtime is to schedule Some languages, including Go, Kotlin, +Erlang, and Swift, ship runtimes with the language. In Rust, there are many +different runtimes, because the things a runtime for a high-throughput web +server should do are very different from the things a runtime for a +microcontroller should do. From 4ce722d6ca8a95c4c709c55fb80818145fa535bb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 19 Apr 2024 16:39:59 -0600 Subject: [PATCH 159/720] Ch. 17: Fix a couple typos and incomplete sentences --- src/ch17-00-async-await.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 94a0c3b04c..0f6c7e9980 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -32,13 +32,13 @@ interchangeable. Now we need to distinguish between the two a little more: all other operations to complete. On a machine with multiple CPU cores, we can actually do work in parallel. One -core can be doing thing while another core does something completely unrelated, -and those actually happen at the same time. On a machine with a single CPU core, -the CPU can only do one operation at a time, but we can still have concurrency. -Using tools like threads, processes, and async-await, the computer can pause one -activity and switch to others before eventually cycling back to that first -activity again. So all parallel operations are also concurrent, but not all -concurrent operations happen in parallel! +core can be doing one thing while another core does something completely +unrelated, and those actually happen at the same time. On a machine with a +single CPU core, the CPU can only do one operation at a time, but we can still +have concurrency. Using tools like threads, processes, and async-await, the +computer can pause one activity and switch to others before eventually cycling +back to that first activity again. So all parallel operations are also +concurrent, but not all concurrent operations happen in parallel! > Note: When working with async-await in Rust, we need to think in terms of > *concurrency*. Depending on the hardware, the operating system, and the async @@ -56,8 +56,8 @@ tasks. (This analogy breaks down if you think about it too hard. The eggs keep cooking while the cook is chopping up the vegetables, after all. That is parallelism, -not concurrency! The focus of the analogy is the *cook*, not the food, though, -and as long as you keep that in mind, it mostly works.) +not just concurrency! The focus of the analogy is the *cook*, not the food, +though, and as long as you keep that in mind, it mostly works.) Consider again the examples of exporting a video file and waiting on the video file to finish uploading. The video export will use as much CPU and GPU power as @@ -74,4 +74,4 @@ here --> A big difference between the cooking analogy and Rust’s async-await model for concurrency is that in the cooking example, the cook makes the decision about when to switch tasks. In Rust’s async-await model, the tasks are in control of -that. To see how, let’s look at +that. To see how, let’s look at how Rust actually uses async-await. From 71d92ecc1a9e870a3b12f3559e7ad565753a06f5 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 22 Apr 2024 12:08:04 -0600 Subject: [PATCH 160/720] Ch. 17: Add some introductory material about async/await MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 17.00: Introduction to the conceptual machinery. This is very nascent but has some decent bones. - 17.01: Trying to get at the foundations for tasks, laziness, etc.; this is *especially* incomplete. - 17.02: Just a paragraph I do not want to lose, which I think *will* be useful… eventually. --- src/ch16-01-threads.md | 3 +- src/ch17-00-async-await.md | 52 ++++---- src/ch17-01-tasks.md | 239 +++++++++++++++++++++++++++++++++++-- src/ch17-02.md | 4 + 4 files changed, 270 insertions(+), 28 deletions(-) create mode 100644 src/ch17-02.md diff --git a/src/ch16-01-threads.md b/src/ch16-01-threads.md index cfdd0c7066..a26a18dc03 100644 --- a/src/ch16-01-threads.md +++ b/src/ch16-01-threads.md @@ -30,7 +30,8 @@ operating systems provide an API the language can call for creating new threads. The Rust standard library uses a *1:1* model of thread implementation, whereby a program uses one operating system thread per one language thread. There are crates that implement other models of threading that make different -tradeoffs to the 1:1 model. +tradeoffs to the 1:1 model. (Rust’s async-await system, which we will see in the +next chapter, provides another approach to concurrency as well.) ### Creating a New Thread with `spawn` diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 0f6c7e9980..a5bd2eb6e4 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -31,20 +31,6 @@ interchangeable. Now we need to distinguish between the two a little more: * *Concurrency* is when operations can make progress without having to wait for all other operations to complete. -On a machine with multiple CPU cores, we can actually do work in parallel. One -core can be doing one thing while another core does something completely -unrelated, and those actually happen at the same time. On a machine with a -single CPU core, the CPU can only do one operation at a time, but we can still -have concurrency. Using tools like threads, processes, and async-await, the -computer can pause one activity and switch to others before eventually cycling -back to that first activity again. So all parallel operations are also -concurrent, but not all concurrent operations happen in parallel! - -> Note: When working with async-await in Rust, we need to think in terms of -> *concurrency*. Depending on the hardware, the operating system, and the async -> runtime we are using, that concurrency may use some degree of parallelism -> under the hood, or it may not. - One common analogy for thinking about the difference between concurrency and parallelism is cooking in a kitchen. Parallelism is like having two cooks: one working on cooking eggs, and the other working on preparing fruit bowls. Those @@ -59,17 +45,43 @@ while the cook is chopping up the vegetables, after all. That is parallelism, not just concurrency! The focus of the analogy is the *cook*, not the food, though, and as long as you keep that in mind, it mostly works.) +On a machine with multiple CPU cores, we can actually do work in parallel. One +core can be doing one thing while another core does something completely +unrelated, and those actually happen at the same time. On a machine with a +single CPU core, the CPU can only do one operation at a time, but we can still +have concurrency. Using tools like threads, processes, and async-await, the +computer can pause one activity and switch to others before eventually cycling +back to that first activity again. So all parallel operations are also +concurrent, but not all concurrent operations happen in parallel! + +> Note: When working with async-await in Rust, we need to think in terms of +> *concurrency*. Depending on the hardware, the operating system, and the async +> runtime we are using, that concurrency may use some degree of parallelism +> under the hood, or it may not. More about async runtimes in a later section! + Consider again the examples of exporting a video file and waiting on the video file to finish uploading. The video export will use as much CPU and GPU power as it can. If you only had one CPU core, and your operating system never paused that export until it completed, you could not do anything else on your computer while it was running. That would be a pretty frustrating experience, though, so -instead your computer could invisibly interrupt the export often enough to let -you get other small amounts of work done along the way. - -The file upload is different. That does not take up that much CPU time. Mostly, -you are waiting on data to transfer across the network. +instead your computer can (and does!) invisibly interrupt the export often +enough to let you get other small amounts of work done along the way. + +The file upload is different. It does not take up very much CPU time. Instead, +you are mostly waiting on data to transfer across the network. If you only have +a single CPU core, you might write a bunch of data to a network socket and then +wait for it to finish getting sent by the network controller. You could choose +to wait for all the data to get “flushed” from the socket and actually sent over +the network, but if there is a busy network connection, you might be waiting for +a while… with your CPU doing not much! Thus, even if you make a blocking call to +write to a socket, your computer probably does other things while the network +operation is happening. + +In both of these cases, it might be useful for *your program* to participate in +the same kind of concurrency the computer is providing for the rest of the +system. One way to do this is the approach we saw last chapter: using threads, +which are provided and managed by the operating system. Another way to get +access to concurrency is using language-specific capabilities—like async-await. A big difference between the cooking analogy and Rust’s async-await model for concurrency is that in the cooking example, the cook makes the decision about diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index bef9b40cba..701a720bb1 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -1,4 +1,6 @@ -## Tasks +## Futures and the Async-Await Syntax + +### Tasks As we saw in the previous chapter, threads provide one approach to concurrency, and they let us solve some of these issues. However, they also have some @@ -9,13 +11,236 @@ multiple threads. While mainstream desktop and mobile operating systems have all had threading for many years, many embedded operating systems used on microcontrollers do not. -The async-await model provides a different, complementary set of tradeoffs. +The async-await model provides a different, complementary set of tradeoffs. In + + In the async-await model, concurrent operations do not require their own threads. Instead, they can run on *tasks*. A task is a bit like a thread, but instead of being managed by the operating system, it is managed by a runtime. -The job of a runtime is to schedule Some languages, including Go, Kotlin, -Erlang, and Swift, ship runtimes with the language. In Rust, there are many -different runtimes, because the things a runtime for a high-throughput web -server should do are very different from the things a runtime for a -microcontroller should do. + + + +### + +Like many other languages with first-class support for the async-await +programming model, Rust uses the `async` and `await` keywords—though with some +important differences from other languages like C# or JavaScript. Blocks and +functions can be marked `async`, and you can wait on the result of an `async` +function or block to resolve using the `await` keyword. + +Let’s write our first async function: + +```rust +fn main() { + hello_async(); +} + +async fn hello_async() { + println!("Hello, async!"); +} +``` + +If we compile and run this… nothing happens, and we get a compiler warning: + +```console +$ cargo run +warning: unused implementer of `Future` that must be used + --> src/main.rs:2:5 + | +2 | hello_async(); + | ^^^^^^^^^^^^^ + | + = note: futures do nothing unless you `.await` or poll them + = note: `#[warn(unused_must_use)]` on by default + +warning: `hello-async` (bin "hello-async") generated 1 warning + Finished dev [unoptimized + debuginfo] target(s) in 1.50s + Running `target/debug/hello-async` +``` + +The warning tells us why nothing happened. Calling `hello_async()` itself was +not enough: we need to `.await`or poll the “future” it returns. That might be a +bit surprising: we did not write a return type on the function. However, we +*did* mark it as an `async fn`. In Rust, `async fn` is equivalent to writing a +function which returns a *future* of the return type, using the `impl Trait` +syntax we discussed back in the [“Traits as Parameters”][impl-trait] section in +Chapter 10. So these two are roughly equivalent: + + +```rust +fn hello_async() -> impl Future { + println!("Hello, async!"); +} +``` + +```rust +async fn hello_async() { + println!("Hello, async!"); +} +``` + +That explains why we got the `unused_must_use` warning. The other part of the +warning was the note that we need to `.await` or poll the future. Rust's `await` +keyword is a postfix keyword, meaning it goes *after* the expression you are +awaiting. (As of now, `await` is the only postfix keyword in the language.) +Let’s try that here: + +```rust +fn main() { + hello_async().await; +} +``` + +Now we actually have a compiler error! + +```text +error[E0728]: `await` is only allowed inside `async` functions and blocks + --> src/main.rs:2:19 + | +1 | fn main() { + | ---- this is not `async` +2 | hello_async().await; + | ^^^^^ only allowed inside `async` functions and blocks +``` + +Okay, so we cannot actually use `.await` in `main`, because it is not an `async` +function itself—and it cannot be. To understand why, we need to pause to see +what a `Future` actually is and why it needs to be `.await`-ed or polled to do +anything. + +### Understanding `Future` + +Since `async fn` compiles to a return type with `impl Future`, we +know that `Future` is a trait, with an associated type `Output`. The other part +of the trait is its one method: `poll`. The `poll` method returns a fairly +simple type: + +```rust +enum Poll { + Ready(T), + Pending +} +``` + +(You might have noticed that this `Poll` type is a lot like an `Option`. Having +a dedicated type lets Rust treat `Poll` differently from `Option`, though, which +is important since they have very different meanings!) + +Under the hood, when you call `.await`, Rust compiles that to code which calls +`poll` instead, kind of like this: + + +```rust +match hello_async().poll() { + Ready(_) => { + // We’re done! + } + Pending => { + // But what goes here? + } +} +``` + +As you can see from this sample, though, there is a question: what happens when +the `Future` is still `Pending`? We need some way to try again. We would need to +have something like this instead: + + +```rust +let hello_async_fut = hello_async(); +loop { + match hello_async_fut.poll() { + Ready(_) => { + break; + } + Pending => { + // continue + } + } +} +``` + +If we wrote that code, though, we would block the computer from doing anything +else, though—the opposite of what we were going for. It also wouldn’t compile +for three other reasons, though: + +1. The `poll` method actually requires an argument: a `Context` that carries + along a way to say when to call it again, to avoid exactly the problem of + blocking other operations from making progress. + +2. The `Future` returned by our `async fn` is not actually ready to use here, + because `poll` requires that the future be “pinned”—guaranteed not to get + moved around in memory, so that any references to the future can be checked + for memory safety. + +3. Even if we pinned the future, this code would move `hello_async_fut` in the + first iteration through the `loop`. After the first time through the loop, we + would not be able to call it again. + +When we use the `async fn` form with `.await`, Rust compiles it to something +smarter than the `loop` above, in conjunction with a *runtime* responsible for +executing that loop. + +Some languages, including Go, Kotlin, Erlang, and Swift, ship runtimes with the +language. In Rust, there are many different runtimes, because the things a +runtime for a high-throughput web server with dozens of CPU cores and terabytes +of RAM should do are very different from the things a runtime for a +microcontroller with a single core and one gigabyte of RAM should do. + + + +The other thing to notice here is that futures in Rust are *lazy*. They do not +do anything until you explicitly ask them to—whether by calling `poll` or by +using `.await` to do so. This is different from the behavior we saw when using +`thread::spawn` in the previous chapter, and it is different from how many other +languages approach async-await. This allows Rust to avoid running async code +unless it is actually needed, and supports some of the memory safety features +Rust brings to async-await. (The details are beyond the scope of this book, but +are well worth digging into.) + +### Running Async Code + + + +Going back to `main`, this explains why we cannot have an `async fn main`: what +would execute the async code? We need to pick a runtime and executor. We can get +started with that easily by using the simple one that comes bundled with the +`futures` crate, an official home for Rust experimentation for async code. Since +we will be using a bunch of tools from that crate for the rest of the chapter, +let’s go ahead and add it to the dependencies for our test project: + +``` +cargo add futures@0.3 +``` + +Now we can use the executor which comes with `futures` to run the code. The +`futures::executor::block_on` function takes in a `Future` and runs it until it +completes. + +```rust +use futures::executor; + +fn main() { + executor::block_on(hello_async()); +} + +async fn hello_async() { + println!("Hello, async!"); +} +``` + +Now when we run this, we get the behavior we might have expected initially: + +```console +$ cargo run + Compiling hello-async v0.1.0 (/Users/chris/dev/chriskrycho/async-trpl-fun/hello-async) + Finished dev [unoptimized + debuginfo] target(s) in 4.89s + Running `target/debug/hello-async` +Hello, async! +``` + +Now, that’s a lot of work to just print a string, but we have laid some key +foundations for working with async and await in Rust. + +[impl-trait]: ch10-02-traits.html#traits-as-parameters diff --git a/src/ch17-02.md b/src/ch17-02.md new file mode 100644 index 0000000000..75d4dcaa65 --- /dev/null +++ b/src/ch17-02.md @@ -0,0 +1,4 @@ +The executor from `futures` we used in the previous section is intentionally +quite limited. It works well, but if you are going to build a real-world +application, you will want to use the executor from one of the *other* runtimes +in the Rust ecosystem. From fdb3794e2af67a037493e54259be98442b908f59 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 23 Apr 2024 17:26:07 -0600 Subject: [PATCH 161/720] Ch. 17: Introduce runtimes and the `trpl` crate Add a fair bit more material about the `futures` executor and why we might prefer to use something else. With that motivation in place, have the readers add our `trpl` crate. (We can of course rename that crate, but it does the job for now.) Use it to get the equivalent of `#[tokio::main]` equivalent and incorporate it into an example. --- src/ch17-01-tasks.md | 3 ++- src/ch17-02.md | 51 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 701a720bb1..70ed2f2647 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -241,6 +241,7 @@ Hello, async! ``` Now, that’s a lot of work to just print a string, but we have laid some key -foundations for working with async and await in Rust. +foundations for working with async-await in Rust! Now that you know the basics +of how futures work, and the [impl-trait]: ch10-02-traits.html#traits-as-parameters diff --git a/src/ch17-02.md b/src/ch17-02.md index 75d4dcaa65..80c1a6f582 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -1,4 +1,49 @@ The executor from `futures` we used in the previous section is intentionally -quite limited. It works well, but if you are going to build a real-world -application, you will want to use the executor from one of the *other* runtimes -in the Rust ecosystem. +quite limited. It works quite well, but if you are going to build a real-world +application, you will likely want to use the executor from one of the *other* +runtimes in the Rust ecosystem. + +For the rest of the chapter, we will be using [Tokio][tokio], which is the most +widely used async runtime, especially (but not only!) for web applications. + +> Note: There are other great options out there, too, and they may be more +> suitable for your purposes, so this is not at all saying Tokio is better than +> the alternatives. + +To keep this chapter focused on learning async-await, rather than juggling parts +of the ecosystem, we have created the `trpl` crate. (`trpl` is short for “The +Rust Programming Language”). It re-exports all the types, traits, and functions +you will need, and in a couple cases wires up a few things for you which are +less relevant to the subject of the book. There is no magic involved, though! If +you want to understand what the crate does, we encourage you to check out [its +source code][crate-source]. You will be able to see what crate each re-export +comes from, and we have left extensive comments explaining what the handful of +helper functions we supply are doing. + +For now, go ahead and add the dependency to your `hello-async` project: + +```console +$ cargo add trpl +``` + +Okay, now let’s start exploring . Going forward, we will use a new `async_main` +macro so that we can use `async fn` with a `main` function. Under the hood, this +little utility macro from Tokio sets up the Tokio runtime and wires up a call +kind of like we saw with `futures::executor::block_on` in the previous section. + +```rust +use trpl::async_main; + +#[async_main] +async fn main() { + async { + println!("Hello, world!"); + }.await; +} +``` + +Now we can use `async` blocks directly in `main` and not worry about wiring up +the runtime ourselves. + +[tokio]: https://tokio.rs +[crate-source]: TODO From cf00f054baeda0b0fd43fa3905129eec5da5f76e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 1 May 2024 10:07:55 -0600 Subject: [PATCH 162/720] =?UTF-8?q?Use=20=E2=80=9Casynchronous=20programmi?= =?UTF-8?q?ng=E2=80=9D=20or=20=E2=80=9Casync=E2=80=9D,=20not=20=E2=80=9Cas?= =?UTF-8?q?ync-await=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch16-01-threads.md | 12 ++++++------ src/ch17-00-async-await.md | 34 +++++++++++++++++----------------- src/ch17-01-tasks.md | 32 ++++++++++++++++---------------- src/ch17-02.md | 12 ++++++------ 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/ch16-01-threads.md b/src/ch16-01-threads.md index a26a18dc03..f3cdbff907 100644 --- a/src/ch16-01-threads.md +++ b/src/ch16-01-threads.md @@ -26,12 +26,12 @@ a code structure that is different from that in programs running in a single thread. Programming languages implement threads in a few different ways, and many -operating systems provide an API the language can call for creating new -threads. The Rust standard library uses a *1:1* model of thread implementation, -whereby a program uses one operating system thread per one language thread. -There are crates that implement other models of threading that make different -tradeoffs to the 1:1 model. (Rust’s async-await system, which we will see in the -next chapter, provides another approach to concurrency as well.) +operating systems provide an API the language can call for creating new threads. +The Rust standard library uses a *1:1* model of thread implementation, whereby a +program uses one operating system thread per one language thread. There are +crates that implement other models of threading that make different tradeoffs to +the 1:1 model. (Rust’s async system, which we will see in the next chapter, +provides another approach to concurrency as well.) ### Creating a New Thread with `spawn` diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index a5bd2eb6e4..f34caf2e66 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -1,20 +1,20 @@ ## Async and Await In Chapter 16, we saw one of Rust’s approaches to concurrency: using threads. -Since Rust 1.39, there has been another option for concurrency: the async-await -model. +Since Rust 1.39, there has been another option for concurrency: asynchronous +programming, or *async*. In the rest of chapter, we will: * see how to use Rust’s `async` and `.await` syntax -* explore how to use the async-await model to solve some of the same challenges - we looked at in Chapter 16 -* look at how multithreading and async-await provide complementary solutions, - which you can even use together in many cases +* explore how to use the async model to solve some of the same challenges we + looked at in Chapter 16 +* look at how multithreading and async provide complementary solutions, which + you can even use together in many cases -First, though, let’s explore what async-await gives us. +First, though, let’s explore what async gives us. -### Why async-await +### Why Async? Many operations we ask the computer to do can take a while to finish. For example, if you used a video editor to create a video of a family celebration, @@ -49,12 +49,12 @@ On a machine with multiple CPU cores, we can actually do work in parallel. One core can be doing one thing while another core does something completely unrelated, and those actually happen at the same time. On a machine with a single CPU core, the CPU can only do one operation at a time, but we can still -have concurrency. Using tools like threads, processes, and async-await, the -computer can pause one activity and switch to others before eventually cycling -back to that first activity again. So all parallel operations are also -concurrent, but not all concurrent operations happen in parallel! +have concurrency. Using tools like threads, processes, and async, the computer +can pause one activity and switch to others before eventually cycling back to +that first activity again. So all parallel operations are also concurrent, but +not all concurrent operations happen in parallel! -> Note: When working with async-await in Rust, we need to think in terms of +> Note: When working with async in Rust, we need to think in terms of > *concurrency*. Depending on the hardware, the operating system, and the async > runtime we are using, that concurrency may use some degree of parallelism > under the hood, or it may not. More about async runtimes in a later section! @@ -81,9 +81,9 @@ In both of these cases, it might be useful for *your program* to participate in the same kind of concurrency the computer is providing for the rest of the system. One way to do this is the approach we saw last chapter: using threads, which are provided and managed by the operating system. Another way to get -access to concurrency is using language-specific capabilities—like async-await. +access to concurrency is using language-specific capabilities—like async. -A big difference between the cooking analogy and Rust’s async-await model for +A big difference between the cooking analogy and Rust’s async model for concurrency is that in the cooking example, the cook makes the decision about -when to switch tasks. In Rust’s async-await model, the tasks are in control of -that. To see how, let’s look at how Rust actually uses async-await. +when to switch tasks. In Rust’s async model, the tasks are in control of that. +To see how, let’s look at how Rust actually uses async. diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 70ed2f2647..632638d60d 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -1,4 +1,4 @@ -## Futures and the Async-Await Syntax +## Futures and the Async Syntax ### Tasks @@ -11,23 +11,23 @@ multiple threads. While mainstream desktop and mobile operating systems have all had threading for many years, many embedded operating systems used on microcontrollers do not. -The async-await model provides a different, complementary set of tradeoffs. In +The async model provides a different, complementary set of tradeoffs. In -In the async-await model, concurrent operations do not require their own -threads. Instead, they can run on *tasks*. A task is a bit like a thread, but -instead of being managed by the operating system, it is managed by a runtime. +In the async model, concurrent operations do not require their own threads. +Instead, they can run on *tasks*. A task is a bit like a thread, but instead of +being managed by the operating system, it is managed by a runtime. ### -Like many other languages with first-class support for the async-await -programming model, Rust uses the `async` and `await` keywords—though with some -important differences from other languages like C# or JavaScript. Blocks and -functions can be marked `async`, and you can wait on the result of an `async` -function or block to resolve using the `await` keyword. +Like many other languages with first-class support for the async programming +model, Rust uses the `async` and `await` keywords—though with some important +differences from other languages like C# or JavaScript. Blocks and functions can +be marked `async`, and you can wait on the result of an `async` function or +block to resolve using the `await` keyword. Let’s write our first async function: @@ -194,10 +194,10 @@ The other thing to notice here is that futures in Rust are *lazy*. They do not do anything until you explicitly ask them to—whether by calling `poll` or by using `.await` to do so. This is different from the behavior we saw when using `thread::spawn` in the previous chapter, and it is different from how many other -languages approach async-await. This allows Rust to avoid running async code -unless it is actually needed, and supports some of the memory safety features -Rust brings to async-await. (The details are beyond the scope of this book, but -are well worth digging into.) +languages approach async. This allows Rust to avoid running async code unless it +is actually needed, and supports some of the memory safety features Rust brings +to async. (The details are beyond the scope of this book, but are well worth +digging into.) ### Running Async Code @@ -241,7 +241,7 @@ Hello, async! ``` Now, that’s a lot of work to just print a string, but we have laid some key -foundations for working with async-await in Rust! Now that you know the basics -of how futures work, and the +foundations for working with async in Rust! Now that you know the basics of how +futures work, and the [impl-trait]: ch10-02-traits.html#traits-as-parameters diff --git a/src/ch17-02.md b/src/ch17-02.md index 80c1a6f582..c1cff2e869 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -10,12 +10,12 @@ widely used async runtime, especially (but not only!) for web applications. > suitable for your purposes, so this is not at all saying Tokio is better than > the alternatives. -To keep this chapter focused on learning async-await, rather than juggling parts -of the ecosystem, we have created the `trpl` crate. (`trpl` is short for “The -Rust Programming Language”). It re-exports all the types, traits, and functions -you will need, and in a couple cases wires up a few things for you which are -less relevant to the subject of the book. There is no magic involved, though! If -you want to understand what the crate does, we encourage you to check out [its +To keep this chapter focused on learning async, rather than juggling parts of +the ecosystem, we have created the `trpl` crate. (`trpl` is short for “The Rust +Programming Language”). It re-exports all the types, traits, and functions you +will need, and in a couple cases wires up a few things for you which are less +relevant to the subject of the book. There is no magic involved, though! If you +want to understand what the crate does, we encourage you to check out [its source code][crate-source]. You will be able to see what crate each re-export comes from, and we have left extensive comments explaining what the handful of helper functions we supply are doing. From 02b0bd195ce3306f85749dbdb72a3e70b7911e55 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 1 May 2024 10:12:48 -0600 Subject: [PATCH 163/720] Add note about Async Book ch. 4: Pinning --- src/ch17-01-tasks.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 632638d60d..c20bb5bdb8 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -197,7 +197,8 @@ using `.await` to do so. This is different from the behavior we saw when using languages approach async. This allows Rust to avoid running async code unless it is actually needed, and supports some of the memory safety features Rust brings to async. (The details are beyond the scope of this book, but are well worth -digging into.) +digging into. In particular, see [Chapter 4: Pinning][pinning] in the official +[_Asynchronous Programming in Rust_][async-book] book.) ### Running Async Code @@ -245,3 +246,5 @@ foundations for working with async in Rust! Now that you know the basics of how futures work, and the [impl-trait]: ch10-02-traits.html#traits-as-parameters +[pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html +[async-book]: https://rust-lang.github.io/async-book/ From 94d95c6e6bffe8f6976e3cd8a2d0e7a9b9da0a2d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 1 May 2024 10:18:23 -0600 Subject: [PATCH 164/720] Ch. 17: Explain what `Poll::Pending` and `Poll::Ready(T)` mean. --- src/ch17-01-tasks.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index c20bb5bdb8..13ceb1b960 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -123,9 +123,17 @@ enum Poll { } ``` -(You might have noticed that this `Poll` type is a lot like an `Option`. Having -a dedicated type lets Rust treat `Poll` differently from `Option`, though, which -is important since they have very different meanings!) +You might have noticed that this `Poll` type is a lot like an `Option`. Having a +dedicated type lets Rust treat `Poll` differently from `Option`, though, which +is important since they have very different meanings! The `Pending` variant +indicates that the future still has work to do, so the caller will need to check +again later. The `Ready` variant indicates that the `Future` has finished its +work and the `T` value is available. + +> Note: With most future, the caller should not call `poll()` again after the +> future has returned `Ready`. Many futures will panic if polled after becoming +> ready! Futures which are safe to poll again will say so explicitly in their +> documentation. Under the hood, when you call `.await`, Rust compiles that to code which calls `poll` instead, kind of like this: From b4bcb2cb3e431199ad6013723519dbfcefeeed83 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 1 May 2024 11:02:42 -0600 Subject: [PATCH 165/720] Ch. 17: add a TODO for the `async fn` desugaring --- src/ch17-01-tasks.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 13ceb1b960..561a5a10eb 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -67,15 +67,17 @@ function which returns a *future* of the return type, using the `impl Trait` syntax we discussed back in the [“Traits as Parameters”][impl-trait] section in Chapter 10. So these two are roughly equivalent: - ```rust -fn hello_async() -> impl Future { +async fn hello_async() { println!("Hello, async!"); } ``` + + + ```rust -async fn hello_async() { +fn hello_async() -> impl Future { println!("Hello, async!"); } ``` @@ -171,7 +173,7 @@ loop { If we wrote that code, though, we would block the computer from doing anything else, though—the opposite of what we were going for. It also wouldn’t compile -for three other reasons, though: +for three other reasons: 1. The `poll` method actually requires an argument: a `Context` that carries along a way to say when to call it again, to avoid exactly the problem of From 36d9cfc0ad39bef22c26b9f7d10bd10a7d3960f8 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 3 May 2024 16:56:04 -0400 Subject: [PATCH 166/720] Backport changes to chapter 8 --- src/ch08-00-common-collections.md | 2 +- src/ch08-01-vectors.md | 36 +++++++------ src/ch08-02-strings.md | 67 ++++++++++++------------ src/ch08-03-hash-maps.md | 85 ++++++++++++++++--------------- 4 files changed, 95 insertions(+), 95 deletions(-) diff --git a/src/ch08-00-common-collections.md b/src/ch08-00-common-collections.md index cf66e18854..c9de36be1d 100644 --- a/src/ch08-00-common-collections.md +++ b/src/ch08-00-common-collections.md @@ -13,7 +13,7 @@ collections that are used very often in Rust programs: * A *vector* allows you to store a variable number of values next to each other. * A *string* is a collection of characters. We’ve mentioned the `String` type previously, but in this chapter we’ll talk about it in depth. -* A *hash map* allows you to associate a value with a particular key. It’s a +* A *hash map* allows you to associate a value with a specific key. It’s a particular implementation of the more general data structure called a *map*. To learn about the other kinds of collections provided by the standard library, diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index d6d72de069..ece5d59dce 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -65,7 +65,7 @@ we don’t need the `Vec` annotation. ### Reading Elements of Vectors -There are two ways to reference a value stored in a vector: via indexing or +There are two ways to reference a value stored in a vector: via indexing or by using the `get` method. In the following examples, we’ve annotated the types of the values that are returned from these functions for extra clarity. @@ -76,8 +76,8 @@ syntax and the `get` method. {{#rustdoc_include ../listings/ch08-common-collections/listing-08-04/src/main.rs:here}} ``` -Listing 8-4: Using indexing syntax or the `get` method to -access an item in a vector +Listing 8-4: Using indexing syntax and using the `get` +method to access an item in a vector Note a few details here. We use the index value of `2` to get the third element because vectors are indexed by number, starting at zero. Using `&` and `[]` @@ -85,11 +85,11 @@ gives us a reference to the element at the index value. When we use the `get` method with the index passed as an argument, we get an `Option<&T>` that we can use with `match`. -The reason Rust provides these two ways to reference an element is so you can -choose how the program behaves when you try to use an index value outside the -range of existing elements. As an example, let’s see what happens when we have -a vector of five elements and then we try to access an element at index 100 -with each technique, as shown in Listing 8-5. +Rust provides these two ways to reference an element so you can choose how the +program behaves when you try to use an index value outside the range of +existing elements. As an example, let’s see what happens when we have a vector +of five elements and then we try to access an element at index 100 with each +technique, as shown in Listing 8-5. ```rust,should_panic,panics {{#rustdoc_include ../listings/ch08-common-collections/listing-08-05/src/main.rs:here}} @@ -121,8 +121,7 @@ rule that states you can’t have mutable and immutable references in the same scope. That rule applies in Listing 8-6, where we hold an immutable reference to the first element in a vector and try to add an element to the end. This program won’t work if we also try to refer to that element later in the -function: - +function. ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch08-common-collections/listing-08-06/src/main.rs:here}} @@ -133,7 +132,6 @@ while holding a reference to an item Compiling this code will result in this error: - ```console {{#include ../listings/ch08-common-collections/listing-08-06/output.txt}} ``` @@ -151,7 +149,7 @@ ending up in that situation. > Note: For more on the implementation details of the `Vec` type, see [“The > Rustonomicon”][nomicon]. -### Iterating over the Values in a Vector +### Iterating Over the Values in a Vector To access each element in a vector in turn, we would iterate through all of the elements rather than use indices to access one at a time. Listing 8-7 shows how @@ -183,7 +181,7 @@ Pointer to the Value with the Dereference Operator”][deref] section of Chapter 15. Iterating over a vector, whether immutably or mutably, is safe because of the -borrow checker's rules. If we attempted to insert or remove items in the `for` +borrow checker’s rules. If we attempted to insert or remove items in the `for` loop bodies in Listing 8-7 and Listing 8-8, we would get a compiler error similar to the one we got with the code in Listing 8-6. The reference to the vector that the `for` loop holds prevents simultaneous modification of the @@ -191,11 +189,11 @@ whole vector. ### Using an Enum to Store Multiple Types -Vectors can only store values that are the same type. This can be inconvenient; -there are definitely use cases for needing to store a list of items of -different types. Fortunately, the variants of an enum are defined under the -same enum type, so when we need one type to represent elements of different -types, we can define and use an enum! +Vectors can only store values that are of the same type. This can be +inconvenient; there are definitely use cases for needing to store a list of +items of different types. Fortunately, the variants of an enum are defined +under the same enum type, so when we need one type to represent elements of +different types, we can define and use an enum! For example, say we want to get values from a row in a spreadsheet in which some of the columns in the row contain integers, some floating-point numbers, @@ -224,7 +222,7 @@ store in a vector, the enum technique won’t work. Instead, you can use a trait object, which we’ll cover in Chapter 17. Now that we’ve discussed some of the most common ways to use vectors, be sure -to review [the API documentation][vec-api] for all the many +to review [the API documentation][vec-api] for all of the many useful methods defined on `Vec` by the standard library. For example, in addition to `push`, a `pop` method removes and returns the last element. diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index f38803ee3b..be0c874748 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -36,7 +36,7 @@ are UTF-8 encoded. ### Creating a New String Many of the same operations available with `Vec` are available with `String` -as well, because `String` is actually implemented as a wrapper around a vector +as well because `String` is actually implemented as a wrapper around a vector of bytes with some extra guarantees, restrictions, and capabilities. An example of a function that works the same way with `Vec` and `String` is the `new` function to create an instance, shown in Listing 8-11. @@ -47,9 +47,9 @@ function to create an instance, shown in Listing 8-11. Listing 8-11: Creating a new, empty `String` -This line creates a new empty string called `s`, which we can then load data -into. Often, we’ll have some initial data that we want to start the string -with. For that, we use the `to_string` method, which is available on any type +This line creates a new, empty string called `s`, into which we can then load +data. Often, we’ll have some initial data with which we want to start the +string. For that, we use the `to_string` method, which is available on any type that implements the `Display` trait, as string literals do. Listing 8-12 shows two examples. @@ -63,7 +63,7 @@ two examples. This code creates a string containing `initial contents`. We can also use the function `String::from` to create a `String` from a string -literal. The code in Listing 8-13 is equivalent to the code from Listing 8-12 +literal. The code in Listing 8-13 is equivalent to the code in Listing 8-12 that uses `to_string`. ```rust @@ -76,7 +76,7 @@ a `String` from a string literal Because strings are used for so many things, we can use many different generic APIs for strings, providing us with a lot of options. Some of them can seem redundant, but they all have their place! In this case, `String::from` and -`to_string` do the same thing, so which you choose is a matter of style and +`to_string` do the same thing, so which one you choose is a matter of style and readability. Remember that strings are UTF-8 encoded, so we can include any properly encoded @@ -125,7 +125,7 @@ If the `push_str` method took ownership of `s2`, we wouldn’t be able to print its value on the last line. However, this code works as we’d expect! The `push` method takes a single character as a parameter and adds it to the -`String`. Listing 8-17 adds the letter “l” to a `String` using the `push` +`String`. Listing 8-17 adds the letter *l* to a `String` using the `push` method. ```rust @@ -159,11 +159,11 @@ this: fn add(self, s: &str) -> String { ``` -In the standard library, you'll see `add` defined using generics and associated +In the standard library, you’ll see `add` defined using generics and associated types. Here, we’ve substituted in concrete types, which is what happens when we call this method with `String` values. We’ll discuss generics in Chapter 10. -This signature gives us the clues we need to understand the tricky bits of the -`+` operator. +This signature gives us the clues we need in order to understand the tricky +bits of the `+` operator. First, `s2` has an `&`, meaning that we’re adding a *reference* of the second string to the first string. This is because of the `s` parameter in the `add` @@ -178,13 +178,13 @@ We’ll discuss deref coercion in more depth in Chapter 15. Because `add` does not take ownership of the `s` parameter, `s2` will still be a valid `String` after this operation. -Second, we can see in the signature that `add` takes ownership of `self`, +Second, we can see in the signature that `add` takes ownership of `self` because `self` does *not* have an `&`. This means `s1` in Listing 8-18 will be -moved into the `add` call and will no longer be valid after that. So although +moved into the `add` call and will no longer be valid after that. So, although `let s3 = s1 + &s2;` looks like it will copy both strings and create a new one, this statement actually takes ownership of `s1`, appends a copy of the contents of `s2`, and then returns ownership of the result. In other words, it looks -like it’s making a lot of copies but isn’t; the implementation is more +like it’s making a lot of copies, but it isn’t; the implementation is more efficient than copying. If we need to concatenate multiple strings, the behavior of the `+` operator @@ -195,8 +195,8 @@ gets unwieldy: ``` At this point, `s` will be `tic-tac-toe`. With all of the `+` and `"` -characters, it’s difficult to see what’s going on. For more complicated string -combining, we can instead use the `format!` macro: +characters, it’s difficult to see what’s going on. For combining strings in +more complicated ways, we can instead use the `format!` macro: ```rust {{#rustdoc_include ../listings/ch08-common-collections/no-listing-02-format/src/main.rs:here}} @@ -241,20 +241,21 @@ encoded UTF-8 example strings from Listing 8-14. First, this one: {{#rustdoc_include ../listings/ch08-common-collections/listing-08-14/src/main.rs:spanish}} ``` -In this case, `len` will be 4, which means the vector storing the string “Hola” -is 4 bytes long. Each of these letters takes 1 byte when encoded in UTF-8. The -following line, however, may surprise you. (Note that this string begins with -the capital Cyrillic letter Ze, not the number 3.) +In this case, `len` will be `4`, which means the vector storing the string +`"Hola"` is 4 bytes long. Each of these letters takes one byte when encoded in +UTF-8. The following line, however, may surprise you (note that this string +begins with the capital Cyrillic letter *Ze*, not the number 3): ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-14/src/main.rs:russian}} ``` -Asked how long the string is, you might say 12. In fact, Rust’s answer is 24: -that’s the number of bytes it takes to encode “Здравствуйте” in UTF-8, because -each Unicode scalar value in that string takes 2 bytes of storage. Therefore, -an index into the string’s bytes will not always correlate to a valid Unicode -scalar value. To demonstrate, consider this invalid Rust code: +If you were asked how long the string is, you might say 12. In fact, Rust’s +answer is 24: that’s the number of bytes it takes to encode “Здравствуйте” in +UTF-8, because each Unicode scalar value in that string takes 2 bytes of +storage. Therefore, an index into the string’s bytes will not always correlate +to a valid Unicode scalar value. To demonstrate, consider this invalid Rust +code: ```rust,ignore,does_not_compile let hello = "Здравствуйте"; @@ -331,8 +332,8 @@ let hello = "Здравствуйте"; let s = &hello[0..4]; ``` -Here, `s` will be a `&str` that contains the first 4 bytes of the string. -Earlier, we mentioned that each of these characters was 2 bytes, which means +Here, `s` will be a `&str` that contains the first four bytes of the string. +Earlier, we mentioned that each of these characters was two bytes, which means `s` will be `Зд`. If we were to try to slice only part of a character’s bytes with something like @@ -343,15 +344,15 @@ index were accessed in a vector: {{#include ../listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt}} ``` -You should use ranges to create string slices with caution, because doing so -can crash your program. +You should use caution when creating string slices with ranges, because doing +so can crash your program. ### Methods for Iterating Over Strings The best way to operate on pieces of strings is to be explicit about whether you want characters or bytes. For individual Unicode scalar values, use the -`chars` method. Calling `chars` on “Зд” separates out and returns two values -of type `char`, and you can iterate over the result to access each element: +`chars` method. Calling `chars` on “Зд” separates out and returns two values of +type `char`, and you can iterate over the result to access each element: ```rust for c in "Зд".chars() { @@ -385,9 +386,9 @@ This code will print the four bytes that make up this string: ``` But be sure to remember that valid Unicode scalar values may be made up of more -than 1 byte. +than one byte. -Getting grapheme clusters from strings as with the Devanagari script is +Getting grapheme clusters from strings, as with the Devanagari script, is complex, so this functionality is not provided by the standard library. Crates are available on [crates.io](https://crates.io/) if this is the functionality you need. @@ -398,7 +399,7 @@ To summarize, strings are complicated. Different programming languages make different choices about how to present this complexity to the programmer. Rust has chosen to make the correct handling of `String` data the default behavior for all Rust programs, which means programmers have to put more thought into -handling UTF-8 data upfront. This trade-off exposes more of the complexity of +handling UTF-8 data up front. This trade-off exposes more of the complexity of strings than is apparent in other programming languages, but it prevents you from having to handle errors involving non-ASCII characters later in your development life cycle. diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index 6322f1324d..72331e5b91 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -1,11 +1,11 @@ ## Storing Keys with Associated Values in Hash Maps The last of our common collections is the *hash map*. The type `HashMap` -stores a mapping of keys of type `K` to values of type `V` using a -*hashing function*, which determines how it places these keys and values into -memory. Many programming languages support this kind of data structure, but -they often use a different name, such as hash, map, object, hash table, -dictionary, or associative array, just to name a few. +stores a mapping of keys of type `K` to values of type `V` using a *hashing +function*, which determines how it places these keys and values into memory. +Many programming languages support this kind of data structure, but they often +use a different name, such as *hash*, *map*, *object*, *hash table*, +*dictionary*, or *associative array*, just to name a few. Hash maps are useful when you want to look up data not by using an index, as you can with vectors, but by using a key that can be of any type. For example, @@ -19,7 +19,7 @@ As always, check the standard library documentation for more information. ### Creating a New Hash Map -One way to create an empty hash map is using `new` and adding elements with +One way to create an empty hash map is to use `new` and to add elements with `insert`. In Listing 8-20, we’re keeping track of the scores of two teams whose names are *Blue* and *Yellow*. The Blue team starts with 10 points, and the Yellow team starts with 50. @@ -39,8 +39,8 @@ standard library; there’s no built-in macro to construct them, for example. Just like vectors, hash maps store their data on the heap. This `HashMap` has keys of type `String` and values of type `i32`. Like vectors, hash maps are -homogeneous: all of the keys must have the same type as each other, and all of -the values must have the same type. +homogeneous: all of the keys must have the same type, and all of the values +must have the same type. ### Accessing Values in a Hash Map @@ -58,10 +58,10 @@ Here, `score` will have the value that’s associated with the Blue team, and th result will be `10`. The `get` method returns an `Option<&V>`; if there’s no value for that key in the hash map, `get` will return `None`. This program handles the `Option` by calling `copied` to get an `Option` rather than an -`Option<&i32>`, then `unwrap_or` to set `score` to zero if `scores` doesn't +`Option<&i32>`, then `unwrap_or` to set `score` to zero if `scores` doesn’t have an entry for the key. -We can iterate over each key/value pair in a hash map in a similar manner as we +We can iterate over each key–value pair in a hash map in a similar manner as we do with vectors, using a `for` loop: ```rust @@ -102,8 +102,8 @@ Chapter 10. Although the number of key and value pairs is growable, each unique key can only have one value associated with it at a time (but not vice versa: for -example, both the Blue team and the Yellow team could have value 10 stored in -the `scores` hash map). +example, both the Blue team and the Yellow team could have the value `10` +stored in the `scores` hash map). When you want to change the data in a hash map, you have to decide how to handle the case when a key already has a value assigned. You could replace the @@ -117,7 +117,7 @@ new value. Let’s look at how to do each of these! If we insert a key and a value into a hash map and then insert that same key with a different value, the value associated with that key will be replaced. Even though the code in Listing 8-23 calls `insert` twice, the hash map will -only contain one key/value pair because we’re inserting the value for the Blue +only contain one key–value pair because we’re inserting the value for the Blue team’s key both times. ```rust @@ -136,15 +136,15 @@ overwritten. #### Adding a Key and Value Only If a Key Isn’t Present It’s common to check whether a particular key already exists in the hash map -with a value then take the following actions: if the key does exist in the hash -map, the existing value should remain the way it is. If the key doesn’t exist, -insert it and a value for it. +with a value and then to take the following actions: if the key does exist in +the hash map, the existing value should remain the way it is; if the key +doesn’t exist, insert it and a value for it. Hash maps have a special API for this called `entry` that takes the key you want to check as a parameter. The return value of the `entry` method is an enum called `Entry` that represents a value that might or might not exist. Let’s say we want to check whether the key for the Yellow team has a value associated -with it. If it doesn’t, we want to insert the value 50, and the same for the +with it. If it doesn’t, we want to insert the value `50`, and the same for the Blue team. Using the `entry` API, the code looks like Listing 8-24. ```rust @@ -155,16 +155,16 @@ Blue team. Using the `entry` API, the code looks like Listing 8-24. the key does not already have a value The `or_insert` method on `Entry` is defined to return a mutable reference to -the value for the corresponding `Entry` key if that key exists, and if not, +the value for the corresponding `Entry` key if that key exists, and if not, it inserts the parameter as the new value for this key and returns a mutable reference to the new value. This technique is much cleaner than writing the logic ourselves and, in addition, plays more nicely with the borrow checker. Running the code in Listing 8-24 will print `{"Yellow": 50, "Blue": 10}`. The first call to `entry` will insert the key for the Yellow team with the value -50 because the Yellow team doesn’t have a value already. The second call to +`50` because the Yellow team doesn’t have a value already. The second call to `entry` will not change the hash map because the Blue team already has the -value 10. +value `10`. #### Updating a Value Based on the Old Value @@ -173,7 +173,7 @@ update it based on the old value. For instance, Listing 8-25 shows code that counts how many times each word appears in some text. We use a hash map with the words as keys and increment the value to keep track of how many times we’ve seen that word. If it’s the first time we’ve seen a word, we’ll first insert -the value 0. +the value `0`. ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-25/src/main.rs:here}} @@ -183,13 +183,13 @@ the value 0. map that stores words and counts This code will print `{"world": 2, "hello": 1, "wonderful": 1}`. You might see -the same key/value pairs printed in a different order: recall from the +the same key–value pairs printed in a different order: recall from the [“Accessing Values in a Hash Map”][access] section that iterating over a hash map happens in an arbitrary order. -The `split_whitespace` method returns an iterator over sub-slices, separated by +The `split_whitespace` method returns an iterator over subslices, separated by whitespace, of the value in `text`. The `or_insert` method returns a mutable -reference (`&mut V`) to the value for the specified key. Here we store that +reference (`&mut V`) to the value for the specified key. Here, we store that mutable reference in the `count` variable, so in order to assign to that value, we must first dereference `count` using the asterisk (`*`). The mutable reference goes out of scope at the end of the `for` loop, so all of these @@ -198,17 +198,17 @@ changes are safe and allowed by the borrowing rules. ### Hashing Functions By default, `HashMap` uses a hashing function called *SipHash* that can provide -resistance to Denial of Service (DoS) attacks involving hash +resistance to denial-of-service (DoS) attacks involving hash tables[^siphash]. This is not the fastest hashing algorithm available, but the trade-off for better security that comes with the drop in performance is worth it. If you profile your code and find that the default hash function is too slow for your purposes, you can switch to another function by specifying a different hasher. A *hasher* is a type that implements the `BuildHasher` trait. We’ll talk about traits and how to implement them in -Chapter 10. You don’t necessarily have to implement your own hasher from -scratch; [crates.io](https://crates.io/) has libraries shared by -other Rust users that provide hashers implementing many common hashing -algorithms. +[Chapter 10][traits]. You don’t necessarily have to implement +your own hasher from scratch; [crates.io](https://crates.io/) +has libraries shared by other Rust users that provide hashers implementing many +common hashing algorithms. [^siphash]: [https://en.wikipedia.org/wiki/SipHash](https://en.wikipedia.org/wiki/SipHash) @@ -218,25 +218,26 @@ Vectors, strings, and hash maps will provide a large amount of functionality necessary in programs when you need to store, access, and modify data. Here are some exercises you should now be equipped to solve: -* Given a list of integers, use a vector and return the median (when sorted, - the value in the middle position) and mode (the value that occurs most often; - a hash map will be helpful here) of the list. -* Convert strings to pig latin. The first consonant of each word is moved to - the end of the word and “ay” is added, so “first” becomes “irst-fay.” Words - that start with a vowel have “hay” added to the end instead (“apple” becomes - “apple-hay”). Keep in mind the details about UTF-8 encoding! -* Using a hash map and vectors, create a text interface to allow a user to add - employee names to a department in a company. For example, “Add Sally to - Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all - people in a department or all people in the company by department, sorted - alphabetically. +1. Given a list of integers, use a vector and return the median (when sorted, + the value in the middle position) and mode (the value that occurs most + often; a hash map will be helpful here) of the list. +1. Convert strings to pig latin. The first consonant of each word is moved to + the end of the word and *ay* is added, so *first* becomes *irst-fay*. Words + that start with a vowel have *hay* added to the end instead (*apple* becomes + *apple-hay*). Keep in mind the details about UTF-8 encoding! +1. Using a hash map and vectors, create a text interface to allow a user to add + employee names to a department in a company; for example, “Add Sally to + Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all + people in a department or all people in the company by department, sorted + alphabetically. The standard library API documentation describes methods that vectors, strings, and hash maps have that will be helpful for these exercises! -We’re getting into more complex programs in which operations can fail, so, it’s +We’re getting into more complex programs in which operations can fail, so it’s a perfect time to discuss error handling. We’ll do that next! [validating-references-with-lifetimes]: ch10-03-lifetime-syntax.html#validating-references-with-lifetimes [access]: #accessing-values-in-a-hash-map +[traits]: ch10-02-traits.html From d1e3925a96c0cdc40cadaef9c66059fef7d189ee Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 7 May 2024 13:20:48 -0400 Subject: [PATCH 167/720] Snapshot changes to generated ch8 that SHOULDN'T be sent to nostarch --- nostarch/chapter08.md | 470 +++++++++++++++++++++++------------------- 1 file changed, 256 insertions(+), 214 deletions(-) diff --git a/nostarch/chapter08.md b/nostarch/chapter08.md index c44ebd8f7b..49e37098ca 100644 --- a/nostarch/chapter08.md +++ b/nostarch/chapter08.md @@ -20,12 +20,12 @@ collections that are used very often in Rust programs: * A *vector* allows you to store a variable number of values next to each other. * A *string* is a collection of characters. We’ve mentioned the `String` type -previously, but in this chapter we’ll talk about it in depth. + previously, but in this chapter we’ll talk about it in depth. * A *hash map* allows you to associate a value with a specific key. It’s a -particular implementation of the more general data structure called a *map*. + particular implementation of the more general data structure called a *map*. To learn about the other kinds of collections provided by the standard library, -see the documentation at *https://doc.rust-lang.org/std/collections/index.html*. +see the documentation at *../std/collections/index.html*. We’ll discuss how to create and update vectors, strings, and hash maps, as well as what makes each special. @@ -44,10 +44,11 @@ To create a new empty vector, we call the `Vec::new` function, as shown in Listing 8-1. ``` -let v: Vec = Vec::new(); + let v: Vec = Vec::new(); ``` -Listing 8-1: Creating a new, empty vector to hold values of type `i32` +Listing 8-1: Creating a new, empty vector to hold values +of type `i32` Note that we added a type annotation here. Because we aren’t inserting any values into this vector, Rust doesn’t know what kind of elements we intend to @@ -63,14 +64,15 @@ the type of value you want to store, so you rarely need to do this type annotation. Rust conveniently provides the `vec!` macro, which will create a new vector that holds the values you give it. Listing 8-2 creates a new `Vec` that holds the values `1`, `2`, and `3`. The integer type is `i32` -because that’s the default integer type, as we discussed in “Data Types” on -page XX. +because that’s the default integer type, as we discussed in the “Data +Types” section of Chapter 3. ``` -let v = vec![1, 2, 3]; + let v = vec![1, 2, 3]; ``` -Listing 8-2: Creating a new vector containing values +Listing 8-2: Creating a new vector containing +values Because we’ve given initial `i32` values, Rust can infer that the type of `v` is `Vec`, and the type annotation isn’t necessary. Next, we’ll look at how @@ -82,15 +84,16 @@ To create a vector and then add elements to it, we can use the `push` method, as shown in Listing 8-3. ``` -let mut v = Vec::new(); + let mut v = Vec::new(); -v.push(5); -v.push(6); -v.push(7); -v.push(8); + v.push(5); + v.push(6); + v.push(7); + v.push(8); ``` -Listing 8-3: Using the `push` method to add values to a vector +Listing 8-3: Using the `push` method to add values to a +vector As with any variable, if we want to be able to change its value, we need to make it mutable using the `mut` keyword, as discussed in Chapter 3. The numbers @@ -107,26 +110,26 @@ Listing 8-4 shows both methods of accessing a value in a vector, with indexing syntax and the `get` method. ``` -let v = vec![1, 2, 3, 4, 5]; + let v = vec![1, 2, 3, 4, 5]; -1 let third: &i32 = &v[2]; -println!("The third element is {third}"); + let third: &i32 = &v[2]; + println!("The third element is {third}"); -2 let third: Option<&i32> = v.get(2); -match third { - Some(third) => println!("The third element is {third}"), - None => println!("There is no third element."), -} + let third: Option<&i32> = v.get(2); + match third { + Some(third) => println!("The third element is {third}"), + None => println!("There is no third element."), + } ``` -Listing 8-4: Using indexing syntax and using the `get` method to access an item -in a vector +Listing 8-4: Using indexing syntax and using the `get` +method to access an item in a vector Note a few details here. We use the index value of `2` to get the third element -[1] because vectors are indexed by number, starting at zero. Using `&` and `[]` +because vectors are indexed by number, starting at zero. Using `&` and `[]` gives us a reference to the element at the index value. When we use the `get` -method with the index passed as an argument [2], we get an `Option<&T>` that we -can use with `match`. +method with the index passed as an argument, we get an `Option<&T>` that we can +use with `match`. Rust provides these two ways to reference an element so you can choose how the program behaves when you try to use an index value outside the range of @@ -135,14 +138,14 @@ of five elements and then we try to access an element at index 100 with each technique, as shown in Listing 8-5. ``` -let v = vec![1, 2, 3, 4, 5]; + let v = vec![1, 2, 3, 4, 5]; -let does_not_exist = &v[100]; -let does_not_exist = v.get(100); + let does_not_exist = &v[100]; + let does_not_exist = v.get(100); ``` -Listing 8-5: Attempting to access the element at index 100 in a vector -containing five elements +Listing 8-5: Attempting to access the element at index +100 in a vector containing five elements When we run this code, the first `[]` method will cause the program to panic because it references a nonexistent element. This method is best used when you @@ -170,23 +173,24 @@ program won’t work if we also try to refer to that element later in the function. ``` -let mut v = vec![1, 2, 3, 4, 5]; + let mut v = vec![1, 2, 3, 4, 5]; -let first = &v[0]; + let first = &v[0]; -v.push(6); + v.push(6); -println!("The first element is: {first}"); + println!("The first element is: {first}"); ``` -Listing 8-6: Attempting to add an element to a vector while holding a reference -to an item +Listing 8-6: Attempting to add an element to a vector +while holding a reference to an item Compiling this code will result in this error: ``` -error[E0502]: cannot borrow `v` as mutable because it is also borrowed as -immutable +$ cargo run + Compiling collections v0.1.0 (file:///projects/collections) +error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable --> src/main.rs:6:5 | 4 | let first = &v[0]; @@ -196,7 +200,10 @@ immutable | ^^^^^^^^^ mutable borrow occurs here 7 | 8 | println!("The first element is: {first}"); - | ----- immutable borrow later used here + | ------- immutable borrow later used here + +For more information about this error, try `rustc --explain E0502`. +error: could not compile `collections` (bin "collections") due to 1 previous error ``` The code in Listing 8-6 might look like it should work: why should a reference @@ -210,7 +217,7 @@ pointing to deallocated memory. The borrowing rules prevent programs from ending up in that situation. > Note: For more on the implementation details of the `Vec` type, see “The -Rustonomicon” at *https://doc.rust-lang.org/nomicon/vec/vec.html*. +> Rustonomicon” at *../nomicon/vec/vec.html*. ### Iterating Over the Values in a Vector @@ -220,32 +227,34 @@ to use a `for` loop to get immutable references to each element in a vector of `i32` values and print them. ``` -let v = vec![100, 32, 57]; -for i in &v { - println!("{i}"); -} + let v = vec![100, 32, 57]; + for i in &v { + println!("{i}"); + } ``` -Listing 8-7: Printing each element in a vector by iterating over the elements -using a `for` loop +Listing 8-7: Printing each element in a vector by +iterating over the elements using a `for` loop We can also iterate over mutable references to each element in a mutable vector in order to make changes to all the elements. The `for` loop in Listing 8-8 will add `50` to each element. ``` -let mut v = vec![100, 32, 57]; -for i in &mut v { - *i += 50; -} + let mut v = vec![100, 32, 57]; + for i in &mut v { + *i += 50; + } ``` -Listing 8-8: Iterating over mutable references to elements in a vector +Listing 8-8: Iterating over mutable references to +elements in a vector To change the value that the mutable reference refers to, we have to use the `*` dereference operator to get to the value in `i` before we can use the `+=` -operator. We’ll talk more about the dereference operator in “Following the -Pointer to the Value” on page XX. +operator. We’ll talk more about the dereference operator in the “Following the +Pointer to the Value with the Dereference Operator” +section of Chapter 15. Iterating over a vector, whether immutably or mutably, is safe because of the borrow checker’s rules. If we attempted to insert or remove items in the `for` @@ -270,20 +279,21 @@ of the enum. Then we can create a vector to hold that enum and so, ultimately, holds different types. We’ve demonstrated this in Listing 8-9. ``` -enum SpreadsheetCell { - Int(i32), - Float(f64), - Text(String), -} + enum SpreadsheetCell { + Int(i32), + Float(f64), + Text(String), + } -let row = vec![ - SpreadsheetCell::Int(3), - SpreadsheetCell::Text(String::from("blue")), - SpreadsheetCell::Float(10.12), -]; + let row = vec![ + SpreadsheetCell::Int(3), + SpreadsheetCell::Text(String::from("blue")), + SpreadsheetCell::Float(10.12), + ]; ``` -Listing 8-9: Defining an `enum` to store values of different types in one vector +Listing 8-9: Defining an `enum` to store values of +different types in one vector Rust needs to know what types will be in the vector at compile time so it knows exactly how much memory on the heap will be needed to store each element. We @@ -298,9 +308,9 @@ store in a vector, the enum technique won’t work. Instead, you can use a trait object, which we’ll cover in Chapter 17. Now that we’ve discussed some of the most common ways to use vectors, be sure -to review the API documentation for all of the many useful methods defined on -`Vec` by the standard library. For example, in addition to `push`, a `pop` -method removes and returns the last element. +to review the API documentation for all of the many +useful methods defined on `Vec` by the standard library. For example, in +addition to `push`, a `pop` method removes and returns the last element. ### Dropping a Vector Drops Its Elements @@ -308,14 +318,15 @@ Like any other `struct`, a vector is freed when it goes out of scope, as annotated in Listing 8-10. ``` -{ - let v = vec![1, 2, 3, 4]; + { + let v = vec![1, 2, 3, 4]; - // do stuff with v -} // <- v goes out of scope and is freed here + // do stuff with v + } // <- v goes out of scope and is freed here ``` -Listing 8-10: Showing where the vector and its elements are dropped +Listing 8-10: Showing where the vector and its elements +are dropped When the vector gets dropped, all of its contents are also dropped, meaning the integers it holds will be cleaned up. The borrow checker ensures that any @@ -368,7 +379,7 @@ of a function that works the same way with `Vec` and `String` is the `new` function to create an instance, shown in Listing 8-11. ``` -let mut s = String::new(); + let mut s = String::new(); ``` Listing 8-11: Creating a new, empty `String` @@ -380,16 +391,16 @@ that implements the `Display` trait, as string literals do. Listing 8-12 shows two examples. ``` -let data = "initial contents"; + let data = "initial contents"; -let s = data.to_string(); + let s = data.to_string(); -// the method also works on a literal directly: -let s = "initial contents".to_string(); + // the method also works on a literal directly: + let s = "initial contents".to_string(); ``` -Listing 8-12: Using the `to_string` method to create a `String` from a string -literal +Listing 8-12: Using the `to_string` method to create a +`String` from a string literal This code creates a string containing `initial contents`. @@ -398,11 +409,11 @@ literal. The code in Listing 8-13 is equivalent to the code in Listing 8-12 that uses `to_string`. ``` -let s = String::from("initial contents"); + let s = String::from("initial contents"); ``` -Listing 8-13: Using the `String::from` function to create a `String` from a -string literal +Listing 8-13: Using the `String::from` function to create +a `String` from a string literal Because strings are used for so many things, we can use many different generic APIs for strings, providing us with a lot of options. Some of them can seem @@ -414,20 +425,21 @@ Remember that strings are UTF-8 encoded, so we can include any properly encoded data in them, as shown in Listing 8-14. ``` -let hello = String::from("السلام عليكم"); -let hello = String::from("Dobrý den"); -let hello = String::from("Hello"); -let hello = String::from("שָׁלוֹם"); -let hello = String::from("नमस्ते"); -let hello = String::from("こんにちは"); -let hello = String::from("안녕하세요"); -let hello = String::from("你好"); -let hello = String::from("Olá"); -let hello = String::from("Здравствуйте"); -let hello = String::from("Hola"); + let hello = String::from("السلام عليكم"); + let hello = String::from("Dobrý den"); + let hello = String::from("Hello"); + let hello = String::from("שלום"); + let hello = String::from("नमस्ते"); + let hello = String::from("こんにちは"); + let hello = String::from("안녕하세요"); + let hello = String::from("你好"); + let hello = String::from("Olá"); + let hello = String::from("Здравствуйте"); + let hello = String::from("Hola"); ``` -Listing 8-14: Storing greetings in different languages in strings +Listing 8-14: Storing greetings in different languages in +strings All of these are valid `String` values. @@ -437,17 +449,18 @@ A `String` can grow in size and its contents can change, just like the contents of a `Vec`, if you push more data into it. In addition, you can conveniently use the `+` operator or the `format!` macro to concatenate `String` values. -#### Appending to a String with push_str and push +#### Appending to a String with `push_str` and `push` We can grow a `String` by using the `push_str` method to append a string slice, as shown in Listing 8-15. ``` -let mut s = String::from("foo"); -s.push_str("bar"); + let mut s = String::from("foo"); + s.push_str("bar"); ``` -Listing 8-15: Appending a string slice to a `String` using the `push_str` method +Listing 8-15: Appending a string slice to a `String` +using the `push_str` method After these two lines, `s` will contain `foobar`. The `push_str` method takes a string slice because we don’t necessarily want to take ownership of the @@ -455,13 +468,14 @@ parameter. For example, in the code in Listing 8-16, we want to be able to use `s2` after appending its contents to `s1`. ``` -let mut s1 = String::from("foo"); -let s2 = "bar"; -s1.push_str(s2); -println!("s2 is {s2}"); + let mut s1 = String::from("foo"); + let s2 = "bar"; + s1.push_str(s2); + println!("s2 is {s2}"); ``` -Listing 8-16: Using a string slice after appending its contents to a `String` +Listing 8-16: Using a string slice after appending its +contents to a `String` If the `push_str` method took ownership of `s2`, we wouldn’t be able to print its value on the last line. However, this code works as we’d expect! @@ -471,27 +485,28 @@ The `push` method takes a single character as a parameter and adds it to the method. ``` -let mut s = String::from("lo"); -s.push('l'); + let mut s = String::from("lo"); + s.push('l'); ``` -Listing 8-17: Adding one character to a `String` value using `push` +Listing 8-17: Adding one character to a `String` value +using `push` As a result, `s` will contain `lol`. -#### Concatenation with the + Operator or the format! Macro +#### Concatenation with the `+` Operator or the `format!` Macro Often, you’ll want to combine two existing strings. One way to do so is to use the `+` operator, as shown in Listing 8-18. ``` -let s1 = String::from("Hello, "); -let s2 = String::from("world!"); -let s3 = s1 + &s2; // note s1 has been moved here and can no longer be used + let s1 = String::from("Hello, "); + let s2 = String::from("world!"); + let s3 = s1 + &s2; // note s1 has been moved here and can no longer be used ``` -Listing 8-18: Using the `+` operator to combine two `String` values into a new -`String` value +Listing 8-18: Using the `+` operator to combine two +`String` values into a new `String` value The string `s3` will contain `Hello, world!`. The reason `s1` is no longer valid after the addition, and the reason we used a reference to `s2`, has to do @@ -535,11 +550,11 @@ If we need to concatenate multiple strings, the behavior of the `+` operator gets unwieldy: ``` -let s1 = String::from("tic"); -let s2 = String::from("tac"); -let s3 = String::from("toe"); + let s1 = String::from("tic"); + let s2 = String::from("tac"); + let s3 = String::from("toe"); -let s = s1 + "-" + &s2 + "-" + &s3; + let s = s1 + "-" + &s2 + "-" + &s3; ``` At this point, `s` will be `tic-tac-toe`. With all of the `+` and `"` @@ -547,11 +562,11 @@ characters, it’s difficult to see what’s going on. For combining strings in more complicated ways, we can instead use the `format!` macro: ``` -let s1 = String::from("tic"); -let s2 = String::from("tac"); -let s3 = String::from("toe"); + let s1 = String::from("tic"); + let s2 = String::from("tac"); + let s3 = String::from("toe"); -let s = format!("{s1}-{s2}-{s3}"); + let s = format!("{s1}-{s2}-{s3}"); ``` This code also sets `s` to `tic-tac-toe`. The `format!` macro works like @@ -568,23 +583,35 @@ if you try to access parts of a `String` using indexing syntax in Rust, you’ll get an error. Consider the invalid code in Listing 8-19. ``` -let s1 = String::from("hello"); -let h = s1[0]; + let s1 = String::from("hello"); + let h = s1[0]; ``` -Listing 8-19: Attempting to use indexing syntax with a `String` +Listing 8-19: Attempting to use indexing syntax with a +String This code will result in the following error: ``` +$ cargo run + Compiling collections v0.1.0 (file:///projects/collections) error[E0277]: the type `String` cannot be indexed by `{integer}` - --> src/main.rs:3:13 + --> src/main.rs:3:16 | 3 | let h = s1[0]; - | ^^^^^ `String` cannot be indexed by `{integer}` + | ^ `String` cannot be indexed by `{integer}` | - = help: the trait `Index<{integer}>` is not implemented for -`String` + = help: the trait `Index<{integer}>` is not implemented for `String` + = help: the following other types implement trait `Index`: + > + >> + >> + >> + >> + >> + +For more information about this error, try `rustc --explain E0277`. +error: could not compile `collections` (bin "collections") due to 1 previous error ``` The error and the note tell the story: Rust strings don’t support indexing. But @@ -597,16 +624,16 @@ A `String` is a wrapper over a `Vec`. Let’s look at some of our properly encoded UTF-8 example strings from Listing 8-14. First, this one: ``` -let hello = String::from("Hola"); + let hello = String::from("Hola"); ``` In this case, `len` will be `4`, which means the vector storing the string `"Hola"` is 4 bytes long. Each of these letters takes one byte when encoded in UTF-8. The following line, however, may surprise you (note that this string -begins with the capital Cyrillic letter *Ze*, not the Arabic number 3): +begins with the capital Cyrillic letter *Ze*, not the number 3): ``` -let hello = String::from("Здравствуйте"); + let hello = String::from("Здравствуйте"); ``` If you were asked how long the string is, you might say 12. In fact, Rust’s @@ -644,8 +671,8 @@ If we look at the Hindi word “नमस्ते” written in the Devanagari stored as a vector of `u8` values that looks like this: ``` -[224, 164, 168, 224, 164, 174, 224, 164, 184, 224, 165, 141, 224, -164, 164, 224, 165, 135] +[224, 164, 168, 224, 164, 174, 224, 164, 184, 224, 165, 141, 224, 164, 164, +224, 165, 135] ``` That’s 18 bytes and is how computers ultimately store this data. If we look at @@ -700,8 +727,13 @@ If we were to try to slice only part of a character’s bytes with something lik index were accessed in a vector: ``` -thread 'main' panicked at 'byte index 1 is not a char boundary; -it is inside 'З' (bytes 0..2) of `Здравствуйте`', src/main.rs:4:14 +$ cargo run + Compiling collections v0.1.0 (file:///projects/collections) + Finished dev [unoptimized + debuginfo] target(s) in 0.43s + Running `target/debug/collections` +thread 'main' panicked at src/main.rs:4:19: +byte index 1 is not a char boundary; it is inside 'З' (bytes 0..2) of `Здравствуйте` +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` You should use caution when creating string slices with ranges, because doing @@ -750,7 +782,8 @@ than one byte. Getting grapheme clusters from strings, as with the Devanagari script, is complex, so this functionality is not provided by the standard library. Crates -are available at *https://crates.io* if this is the functionality you need. +are available on crates.io if this is the +functionality you need. ### Strings Are Not So Simple @@ -798,15 +831,16 @@ names are *Blue* and *Yellow*. The Blue team starts with 10 points, and the Yellow team starts with 50. ``` -use std::collections::HashMap; + use std::collections::HashMap; -let mut scores = HashMap::new(); + let mut scores = HashMap::new(); -scores.insert(String::from("Blue"), 10); -scores.insert(String::from("Yellow"), 50); + scores.insert(String::from("Blue"), 10); + scores.insert(String::from("Yellow"), 50); ``` -Listing 8-20: Creating a new hash map and inserting some keys and values +Listing 8-20: Creating a new hash map and inserting some +keys and values Note that we need to first `use` the `HashMap` from the collections portion of the standard library. Of our three common collections, this one is the least @@ -825,18 +859,19 @@ We can get a value out of the hash map by providing its key to the `get` method, as shown in Listing 8-21. ``` -use std::collections::HashMap; + use std::collections::HashMap; -let mut scores = HashMap::new(); + let mut scores = HashMap::new(); -scores.insert(String::from("Blue"), 10); -scores.insert(String::from("Yellow"), 50); + scores.insert(String::from("Blue"), 10); + scores.insert(String::from("Yellow"), 50); -let team_name = String::from("Blue"); -let score = scores.get(&team_name).copied().unwrap_or(0); + let team_name = String::from("Blue"); + let score = scores.get(&team_name).copied().unwrap_or(0); ``` -Listing 8-21: Accessing the score for the Blue team stored in the hash map +Listing 8-21: Accessing the score for the Blue team +stored in the hash map Here, `score` will have the value that’s associated with the Blue team, and the result will be `10`. The `get` method returns an `Option<&V>`; if there’s no @@ -849,16 +884,16 @@ We can iterate over each key–value pair in a hash map in a similar manner as w do with vectors, using a `for` loop: ``` -use std::collections::HashMap; + use std::collections::HashMap; -let mut scores = HashMap::new(); + let mut scores = HashMap::new(); -scores.insert(String::from("Blue"), 10); -scores.insert(String::from("Yellow"), 50); + scores.insert(String::from("Blue"), 10); + scores.insert(String::from("Yellow"), 50); -for (key, value) in &scores { - println!("{key}: {value}"); -} + for (key, value) in &scores { + println!("{key}: {value}"); + } ``` This code will print each pair in an arbitrary order: @@ -875,19 +910,19 @@ into the hash map. For owned values like `String`, the values will be moved and the hash map will be the owner of those values, as demonstrated in Listing 8-22. ``` -use std::collections::HashMap; + use std::collections::HashMap; -let field_name = String::from("Favorite color"); -let field_value = String::from("Blue"); + let field_name = String::from("Favorite color"); + let field_value = String::from("Blue"); -let mut map = HashMap::new(); -map.insert(field_name, field_value); -// field_name and field_value are invalid at this point, try -// using them and see what compiler error you get! + let mut map = HashMap::new(); + map.insert(field_name, field_value); + // field_name and field_value are invalid at this point, try using them and + // see what compiler error you get! ``` -Listing 8-22: Showing that keys and values are owned by the hash map once -they’re inserted +Listing 8-22: Showing that keys and values are owned by +the hash map once they’re inserted We aren’t able to use the variables `field_name` and `field_value` after they’ve been moved into the hash map with the call to `insert`. @@ -895,7 +930,9 @@ they’ve been moved into the hash map with the call to `insert`. If we insert references to values into the hash map, the values won’t be moved into the hash map. The values that the references point to must be valid for at least as long as the hash map is valid. We’ll talk more about these issues in -“Validating References with Lifetimes” on page XX. +the “Validating References with +Lifetimes” section in +Chapter 10. ### Updating a Hash Map @@ -920,21 +957,25 @@ only contain one key–value pair because we’re inserting the value for the Bl team’s key both times. ``` -use std::collections::HashMap; + use std::collections::HashMap; -let mut scores = HashMap::new(); + let mut scores = HashMap::new(); -scores.insert(String::from("Blue"), 10); -scores.insert(String::from("Blue"), 25); + scores.insert(String::from("Blue"), 10); + scores.insert(String::from("Blue"), 25); -println!("{:?}", scores); + println!("{scores:?}"); ``` -Listing 8-23: Replacing a value stored with a particular key +Listing 8-23: Replacing a value stored with a particular +key This code will print `{"Blue": 25}`. The original value of `10` has been overwritten. + + + #### Adding a Key and Value Only If a Key Isn’t Present It’s common to check whether a particular key already exists in the hash map @@ -950,19 +991,19 @@ with it. If it doesn’t, we want to insert the value `50`, and the same for the Blue team. Using the `entry` API, the code looks like Listing 8-24. ``` -use std::collections::HashMap; + use std::collections::HashMap; -let mut scores = HashMap::new(); -scores.insert(String::from("Blue"), 10); + let mut scores = HashMap::new(); + scores.insert(String::from("Blue"), 10); -scores.entry(String::from("Yellow")).or_insert(50); -scores.entry(String::from("Blue")).or_insert(50); + scores.entry(String::from("Yellow")).or_insert(50); + scores.entry(String::from("Blue")).or_insert(50); -println!("{:?}", scores); + println!("{scores:?}"); ``` -Listing 8-24: Using the `entry` method to only insert if the key does not -already have a value +Listing 8-24: Using the `entry` method to only insert if +the key does not already have a value The `or_insert` method on `Entry` is defined to return a mutable reference to the value for the corresponding `Entry` key if that key exists, and if not, it @@ -986,27 +1027,27 @@ seen that word. If it’s the first time we’ve seen a word, we’ll first inse the value `0`. ``` -use std::collections::HashMap; + use std::collections::HashMap; -let text = "hello world wonderful world"; + let text = "hello world wonderful world"; -let mut map = HashMap::new(); + let mut map = HashMap::new(); -for word in text.split_whitespace() { - let count = map.entry(word).or_insert(0); - *count += 1; -} + for word in text.split_whitespace() { + let count = map.entry(word).or_insert(0); + *count += 1; + } -println!("{:?}", map); + println!("{map:?}"); ``` -Listing 8-25: Counting occurrences of words using a hash map that stores words -and counts +Listing 8-25: Counting occurrences of words using a hash +map that stores words and counts This code will print `{"world": 2, "hello": 1, "wonderful": 1}`. You might see -the same key–value pairs printed in a different order: recall from “Accessing -Values in a Hash Map” on page XX that iterating over a hash map happens in an -arbitrary order. +the same key–value pairs printed in a different order: recall from the +“Accessing Values in a Hash Map” section that +iterating over a hash map happens in an arbitrary order. The `split_whitespace` method returns an iterator over subslices, separated by whitespace, of the value in `text`. The `or_insert` method returns a mutable @@ -1019,16 +1060,18 @@ changes are safe and allowed by the borrowing rules. ### Hashing Functions By default, `HashMap` uses a hashing function called *SipHash* that can provide -resistance to denial-of-service (DoS) attacks involving hash tables. This is -not the fastest hashing algorithm available, but the trade-off for better -security that comes with the drop in performance is worth it. If you profile -your code and find that the default hash function is too slow for your -purposes, you can switch to another function by specifying a different hasher. -A *hasher* is a type that implements the `BuildHasher` trait. We’ll talk about -traits and how to implement them in Chapter 10. You don’t necessarily have to -implement your own hasher from scratch; *https://crates.io* has libraries -shared by other Rust users that provide hashers implementing many common -hashing algorithms. +resistance to denial-of-service (DoS) attacks involving hash +tables^siphash at *[https://en.wikipedia.org/wiki/SipHash](https://en.wikipedia.org/wiki/SipHash)*. This is not the fastest hashing algorithm +available, but the trade-off for better security that comes with the drop in +performance is worth it. If you profile your code and find that the default +hash function is too slow for your purposes, you can switch to another function +by specifying a different hasher. A *hasher* is a type that implements the +`BuildHasher` trait. We’ll talk about traits and how to implement them in +Chapter 10. You don’t necessarily have to implement +your own hasher from scratch; crates.io +has libraries shared by other Rust users that provide hashers implementing many +common hashing algorithms. + ## Summary @@ -1037,21 +1080,20 @@ necessary in programs when you need to store, access, and modify data. Here are some exercises you should now be equipped to solve: 1. Given a list of integers, use a vector and return the median (when sorted, -the value in the middle position) and mode (the value that occurs most often; a -hash map will be helpful here) of the list. + the value in the middle position) and mode (the value that occurs most + often; a hash map will be helpful here) of the list. 1. Convert strings to pig latin. The first consonant of each word is moved to -the end of the word and *ay* is added, so *first* becomes *irst-fay*. Words -that start with a vowel have *hay* added to the end instead (*apple* becomes -*apple-hay*). Keep in mind the details about UTF-8 encoding! + the end of the word and *ay* is added, so *first* becomes *irst-fay*. Words + that start with a vowel have *hay* added to the end instead (*apple* becomes + *apple-hay*). Keep in mind the details about UTF-8 encoding! 1. Using a hash map and vectors, create a text interface to allow a user to add -employee names to a department in a company; for example, “Add Sally to -Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all -people in a department or all people in the company by department, sorted -alphabetically. + employee names to a department in a company; for example, “Add Sally to + Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all + people in a department or all people in the company by department, sorted + alphabetically. The standard library API documentation describes methods that vectors, strings, and hash maps have that will be helpful for these exercises! We’re getting into more complex programs in which operations can fail, so it’s a perfect time to discuss error handling. We’ll do that next! - From b04c03d01af0dba8c72b7510739632912d3fb010 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 7 May 2024 13:21:30 -0400 Subject: [PATCH 168/720] Snapshot changes to ch8 to consider sending to nostarch --- nostarch/chapter08.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nostarch/chapter08.md b/nostarch/chapter08.md index 49e37098ca..fd1cd93085 100644 --- a/nostarch/chapter08.md +++ b/nostarch/chapter08.md @@ -276,7 +276,7 @@ some of the columns in the row contain integers, some floating-point numbers, and some strings. We can define an enum whose variants will hold the different value types, and all the enum variants will be considered the same type: that of the enum. Then we can create a vector to hold that enum and so, ultimately, -holds different types. We’ve demonstrated this in Listing 8-9. +hold different types. We’ve demonstrated this in Listing 8-9. ``` enum SpreadsheetCell { From 93a7176c9ae0e3267786b837b137b924816321df Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 7 May 2024 13:31:16 -0400 Subject: [PATCH 169/720] Add subslices to the dictionary --- ci/dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 013d38dcc3..e54b164f19 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -489,6 +489,7 @@ Submodules submodule’s suboptimal subpath +subslices substring subteams subtree From d4c69fd881df411c450a2fc58c2ce039af80a82c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 9 May 2024 12:38:42 -0600 Subject: [PATCH 170/720] Fix workspace behavior by excluding `listings` At some point we may want to include these in the workspace, but for now they need to be excluded so `cargo build` and `rust-analyzer` work correctly with the workspace layout. --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dd7b0e4fac..0a24b0da02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,10 @@ members = ["packages/*"] default-members = ["packages/*"] resolver = "2" -exclude = ["linkchecker"] # part of the CI workflow +exclude = [ + "linkchecker", # linkchecker is part of the CI workflow + "listings", # these are intentionally distinct from the workspace +] [workspace.dependencies] walkdir = "2.3.1" From 63baf226c424ba265220eee6ab66e679d20f8c6f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 1 May 2024 11:32:15 -0600 Subject: [PATCH 171/720] Ch. 17: fix a misplaced period --- src/ch17-02.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-02.md b/src/ch17-02.md index c1cff2e869..57b002d415 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -11,7 +11,7 @@ widely used async runtime, especially (but not only!) for web applications. > the alternatives. To keep this chapter focused on learning async, rather than juggling parts of -the ecosystem, we have created the `trpl` crate. (`trpl` is short for “The Rust +the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust Programming Language”). It re-exports all the types, traits, and functions you will need, and in a couple cases wires up a few things for you which are less relevant to the subject of the book. There is no magic involved, though! If you From c31d308f1836a69d6784bc623b68603c52d919bd Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 1 May 2024 11:32:15 -0600 Subject: [PATCH 172/720] Ch. 17: get to working async code sooner Move up the installation of the futures crate: get the initial example compiling as soon as possible (even though it is just "Hello, world!") and *then* explain what was going on. --- src/ch17-01-tasks.md | 143 ++++++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 62 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 561a5a10eb..32f8bf3120 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -7,11 +7,12 @@ and they let us solve some of these issues. However, they also have some tradeoffs. On many operating systems, they use a fair bit of memory for each thread, and they come with some overhead for starting up and shutting down. Threads are also only an option when your operating system and hardware support -multiple threads. While mainstream desktop and mobile operating systems have all -had threading for many years, many embedded operating systems used on -microcontrollers do not. +them! While mainstream desktop and mobile operating systems have all had +threading for many years, many embedded operating systems, like those used on +some microcontrollers, do not. -The async model provides a different, complementary set of tradeoffs. In +The async model provides a different—and ultimately complementary—set of +tradeoffs. In @@ -65,7 +66,10 @@ bit surprising: we did not write a return type on the function. However, we *did* mark it as an `async fn`. In Rust, `async fn` is equivalent to writing a function which returns a *future* of the return type, using the `impl Trait` syntax we discussed back in the [“Traits as Parameters”][impl-trait] section in -Chapter 10. So these two are roughly equivalent: +Chapter 10, and an `async` block compiles to an anonymous struct which +implements the `Future` trait. + +So these two are roughly equivalent: ```rust async fn hello_async() { @@ -73,28 +77,41 @@ async fn hello_async() { } ``` - - - ```rust fn hello_async() -> impl Future { - println!("Hello, async!"); + async { + println!("Hello, async!"); + } } ``` -That explains why we got the `unused_must_use` warning. The other part of the -warning was the note that we need to `.await` or poll the future. Rust's `await` -keyword is a postfix keyword, meaning it goes *after* the expression you are -awaiting. (As of now, `await` is the only postfix keyword in the language.) -Let’s try that here: - + + +That explains why we got the `unused_must_use` warning: writing `async fn` meant +we were actually returning an anonymous `Future`. Just like with `Result`, Rust +will let us know if we don’t use a `Future`. It is often a mistake to ignore an +error in an operation your program performed. With a `Future`, it is even more +significant. To see why, let’s look at the other part of the warning. It told us +that “futures do nothing unless you `.await` or poll them”. That is, futures are +*lazy*: they don’t do anything until you ask them to. The compiler is telling us +that ignoring a `Future` makes it completely useless! We will see why that is +later on. For now, let’s start by awaiting the future returned by `hello_async` +to actually have it run. + +> Note: Rust’s `await` keyword goes *after* the expression you are awaiting—that +> is, it is a *postfix keyword*. This is different from what you might be used +> to if you have used async in languages like JavaScript or C#. Rust chose this +> because it makes chains of async and non-async methods much nicer to work +> with. As of now, `await` is the only postfix keyword in the language. + + ```rust fn main() { hello_async().await; } ``` -Now we actually have a compiler error! +Oh no! We have gone from a compiler warning ton an actual error: ```text error[E0728]: `await` is only allowed inside `async` functions and blocks @@ -106,12 +123,48 @@ error[E0728]: `await` is only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks ``` -Okay, so we cannot actually use `.await` in `main`, because it is not an `async` -function itself—and it cannot be. To understand why, we need to pause to see -what a `Future` actually is and why it needs to be `.await`-ed or polled to do -anything. +This time, the compiler is informing us we cannot actually use `.await` in +`main`, because `main` is not an `async` function. As of today, it cannot be +without some extra help: it needs a *runtime* to execute the asynchronous code. +For now, we can solve that by adding the runtime built into the `futures` crate, +an official home for Rust experimentation for async code. Since we will be using +a bunch of tools from that crate for the rest of the chapter, let’s go ahead and +add it to the dependencies for our test project: + +``` +cargo add futures@0.3 +``` + +Now we can use the executor which comes with `futures` to run the code. The +`futures::executor::block_on` function takes in a `Future` and runs it until it +completes. + +```rust +use futures::executor; + +fn main() { + executor::block_on(hello_async()); +} + +async fn hello_async() { + println!("Hello, async!"); +} +``` + +Now when we run this, we get the behavior we might have expected initially: + +```console +$ cargo run + Compiling hello-async v0.1.0 (/Users/chris/dev/chriskrycho/async-trpl-fun/hello-async) + Finished dev [unoptimized + debuginfo] target(s) in 4.89s + Running `target/debug/hello-async` +Hello, async! +``` + +Phew: we finally have some working async code! To understand why we needed this, +let’s dig in a little more into what a `Future` actually is. -### Understanding `Future` +### Futures and runtimes Since `async fn` compiles to a return type with `impl Future`, we know that `Future` is a trait, with an associated type `Output`. The other part @@ -132,7 +185,7 @@ indicates that the future still has work to do, so the caller will need to check again later. The `Ready` variant indicates that the `Future` has finished its work and the `T` value is available. -> Note: With most future, the caller should not call `poll()` again after the +> Note: With most futures, the caller should not call `poll()` again after the > future has returned `Ready`. Many futures will panic if polled after becoming > ready! Futures which are safe to poll again will say so explicitly in their > documentation. @@ -192,11 +245,11 @@ When we use the `async fn` form with `.await`, Rust compiles it to something smarter than the `loop` above, in conjunction with a *runtime* responsible for executing that loop. -Some languages, including Go, Kotlin, Erlang, and Swift, ship runtimes with the -language. In Rust, there are many different runtimes, because the things a -runtime for a high-throughput web server with dozens of CPU cores and terabytes -of RAM should do are very different from the things a runtime for a -microcontroller with a single core and one gigabyte of RAM should do. +> Note: Some languages, including Go, Kotlin, Erlang, and Swift, ship runtimes +> with the language. In Rust, there are many different runtimes, because a +> runtime might need to do very different things to support a high-throughput +> web server with dozens of CPU cores and terabytes of RAM than it would for a +> microcontroller with a single core and one gigabyte of RAM should do. @@ -215,41 +268,7 @@ digging into. In particular, see [Chapter 4: Pinning][pinning] in the official Going back to `main`, this explains why we cannot have an `async fn main`: what -would execute the async code? We need to pick a runtime and executor. We can get -started with that easily by using the simple one that comes bundled with the -`futures` crate, an official home for Rust experimentation for async code. Since -we will be using a bunch of tools from that crate for the rest of the chapter, -let’s go ahead and add it to the dependencies for our test project: - -``` -cargo add futures@0.3 -``` - -Now we can use the executor which comes with `futures` to run the code. The -`futures::executor::block_on` function takes in a `Future` and runs it until it -completes. - -```rust -use futures::executor; - -fn main() { - executor::block_on(hello_async()); -} - -async fn hello_async() { - println!("Hello, async!"); -} -``` - -Now when we run this, we get the behavior we might have expected initially: - -```console -$ cargo run - Compiling hello-async v0.1.0 (/Users/chris/dev/chriskrycho/async-trpl-fun/hello-async) - Finished dev [unoptimized + debuginfo] target(s) in 4.89s - Running `target/debug/hello-async` -Hello, async! -``` +would execute the async code? We need to pick a runtime and executor. Now, that’s a lot of work to just print a string, but we have laid some key foundations for working with async in Rust! Now that you know the basics of how From dee72208b8384ec164642e43fe76fba25a3b9112 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 9 May 2024 16:35:28 -0600 Subject: [PATCH 173/720] Ch. 17: add to table of contents so `mdbook serve` is useful --- src/SUMMARY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index a004483b1e..daa9a07af7 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -102,6 +102,8 @@ - [Extensible Concurrency with the `Sync` and `Send` Traits](ch16-04-extensible-concurrency-sync-and-send.md) - [Async and Await](ch17-00-async-await.md) + - [Futures and the Async Syntax](ch17-01-tasks.md) + - [something something tokio?!?](ch17-02.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) From 5b3c27eb4ac60291e808b9f90798cf39709b86ef Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 9 May 2024 16:51:16 -0600 Subject: [PATCH 174/720] Ch. 17: clarify language about Tokio --- src/ch17-02.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch17-02.md b/src/ch17-02.md index 57b002d415..bb0306ff2f 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -7,8 +7,8 @@ For the rest of the chapter, we will be using [Tokio][tokio], which is the most widely used async runtime, especially (but not only!) for web applications. > Note: There are other great options out there, too, and they may be more -> suitable for your purposes, so this is not at all saying Tokio is better than -> the alternatives. +> suitable for your purposes. We are using Tokio because it is the most widely +> used runtime—not as a judgment call on whether it is the *best* runtime! To keep this chapter focused on learning async, rather than juggling parts of the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust From ebebf8c166ad7026ab4d3840fea455283b8837f9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 9 May 2024 16:54:09 -0600 Subject: [PATCH 175/720] Ch. 17: use `trpl`, not `futures`, even for initial code samples - Update the instructions to install `trpl` instead of `futures`, and move the introductory text there. - Update the note about Tokio in 17.02 to describe both `futures` and `tokio`. --- src/ch17-01-tasks.md | 30 ++++++++++++++++++------------ src/ch17-02.md | 40 ++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 32f8bf3120..be642fcec2 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -126,24 +126,29 @@ error[E0728]: `await` is only allowed inside `async` functions and blocks This time, the compiler is informing us we cannot actually use `.await` in `main`, because `main` is not an `async` function. As of today, it cannot be without some extra help: it needs a *runtime* to execute the asynchronous code. -For now, we can solve that by adding the runtime built into the `futures` crate, -an official home for Rust experimentation for async code. Since we will be using -a bunch of tools from that crate for the rest of the chapter, let’s go ahead and -add it to the dependencies for our test project: -``` -cargo add futures@0.3 +To keep this chapter focused on learning async, rather than juggling parts of +the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust +Programming Language”). It re-exports all the types, traits, and functions you +will need, and in a couple cases wires up a few things for you which are less +relevant to the subject of the book. There is no magic involved, though! If you +want to understand what the crate does, we encourage you to check out [its +source code][crate-source]. You will be able to see what crate each re-export +comes from, and we have left extensive comments explaining what the handful of +helper functions we supply are doing. + +For now, go ahead and add the dependency to your `hello-async` project: + +```console +$ cargo add trpl ``` -Now we can use the executor which comes with `futures` to run the code. The -`futures::executor::block_on` function takes in a `Future` and runs it until it -completes. +Now we can get our code working by using the `trpl::block_on` function, which +takes in a `Future` and runs it until it completes. ```rust -use futures::executor; - fn main() { - executor::block_on(hello_async()); + trpl::block_on(hello_async()); } async fn hello_async() { @@ -153,6 +158,7 @@ async fn hello_async() { Now when we run this, we get the behavior we might have expected initially: + ```console $ cargo run Compiling hello-async v0.1.0 (/Users/chris/dev/chriskrycho/async-trpl-fun/hello-async) diff --git a/src/ch17-02.md b/src/ch17-02.md index bb0306ff2f..fc650165df 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -3,30 +3,21 @@ quite limited. It works quite well, but if you are going to build a real-world application, you will likely want to use the executor from one of the *other* runtimes in the Rust ecosystem. -For the rest of the chapter, we will be using [Tokio][tokio], which is the most -widely used async runtime, especially (but not only!) for web applications. - -> Note: There are other great options out there, too, and they may be more -> suitable for your purposes. We are using Tokio because it is the most widely -> used runtime—not as a judgment call on whether it is the *best* runtime! - -To keep this chapter focused on learning async, rather than juggling parts of -the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust -Programming Language”). It re-exports all the types, traits, and functions you -will need, and in a couple cases wires up a few things for you which are less -relevant to the subject of the book. There is no magic involved, though! If you -want to understand what the crate does, we encourage you to check out [its -source code][crate-source]. You will be able to see what crate each re-export -comes from, and we have left extensive comments explaining what the handful of -helper functions we supply are doing. - -For now, go ahead and add the dependency to your `hello-async` project: - -```console -$ cargo add trpl -``` - -Okay, now let’s start exploring . Going forward, we will use a new `async_main` +> ### The `futures` and `tokio` Crates +> +> Whenever you see code from the `trpl` crate throughout the rest of the +> chapter, it will be re-exporting code from the `futures` and [`tokio`][tokio] crates. +> +> - The `futures` crate is an official home for Rust experimentation for async +> code, and is actually where the `Future` type was originally designed. +> +> - Tokio is the most widely used async runtime in Rust today, especially (but +> not only!) for web applications. There are other great options out there, +> too, and they may be more suitable for your purposes. We are using Tokio +> because it is the most widely-used runtime—not as a judgment call on whether +> it is the *best* runtime! + +Okay, now let’s start exploring. Going forward, we will use a new `async_main` macro so that we can use `async fn` with a `main` function. Under the hood, this little utility macro from Tokio sets up the Tokio runtime and wires up a call kind of like we saw with `futures::executor::block_on` in the previous section. @@ -45,5 +36,6 @@ async fn main() { Now we can use `async` blocks directly in `main` and not worry about wiring up the runtime ourselves. + [tokio]: https://tokio.rs [crate-source]: TODO From ee0704d4736c9aebb2f7808f2c5816504312de38 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 9 May 2024 16:54:09 -0600 Subject: [PATCH 176/720] Ch. 17: text/code ordering fix in 17.02 --- src/ch17-02.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch17-02.md b/src/ch17-02.md index fc650165df..9dfa186927 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -21,6 +21,8 @@ Okay, now let’s start exploring. Going forward, we will use a new `async_main` macro so that we can use `async fn` with a `main` function. Under the hood, this little utility macro from Tokio sets up the Tokio runtime and wires up a call kind of like we saw with `futures::executor::block_on` in the previous section. +Now we can use `async` blocks directly in `main` and not worry about wiring up +the runtime ourselves: ```rust use trpl::async_main; @@ -33,8 +35,6 @@ async fn main() { } ``` -Now we can use `async` blocks directly in `main` and not worry about wiring up -the runtime ourselves. [tokio]: https://tokio.rs From 40df04923b9750ae2e72132898759460f2eb482f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Apr 2024 16:57:00 -0600 Subject: [PATCH 177/720] Prepare to integrate into TRPL repo --- CONTRIBUTING.md => packages/trpl/CONTRIBUTING.md | 0 Cargo.lock => packages/trpl/Cargo.lock | 0 Cargo.toml => packages/trpl/Cargo.toml | 0 LICENSE-APACHE => packages/trpl/LICENSE-APACHE | 0 LICENSE-MIT => packages/trpl/LICENSE-MIT | 0 README.md => packages/trpl/README.md | 0 {src => packages/trpl/src}/lib.rs | 0 {tests => packages/trpl/tests}/integration/main.rs | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename CONTRIBUTING.md => packages/trpl/CONTRIBUTING.md (100%) rename Cargo.lock => packages/trpl/Cargo.lock (100%) rename Cargo.toml => packages/trpl/Cargo.toml (100%) rename LICENSE-APACHE => packages/trpl/LICENSE-APACHE (100%) rename LICENSE-MIT => packages/trpl/LICENSE-MIT (100%) rename README.md => packages/trpl/README.md (100%) rename {src => packages/trpl/src}/lib.rs (100%) rename {tests => packages/trpl/tests}/integration/main.rs (100%) diff --git a/CONTRIBUTING.md b/packages/trpl/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to packages/trpl/CONTRIBUTING.md diff --git a/Cargo.lock b/packages/trpl/Cargo.lock similarity index 100% rename from Cargo.lock rename to packages/trpl/Cargo.lock diff --git a/Cargo.toml b/packages/trpl/Cargo.toml similarity index 100% rename from Cargo.toml rename to packages/trpl/Cargo.toml diff --git a/LICENSE-APACHE b/packages/trpl/LICENSE-APACHE similarity index 100% rename from LICENSE-APACHE rename to packages/trpl/LICENSE-APACHE diff --git a/LICENSE-MIT b/packages/trpl/LICENSE-MIT similarity index 100% rename from LICENSE-MIT rename to packages/trpl/LICENSE-MIT diff --git a/README.md b/packages/trpl/README.md similarity index 100% rename from README.md rename to packages/trpl/README.md diff --git a/src/lib.rs b/packages/trpl/src/lib.rs similarity index 100% rename from src/lib.rs rename to packages/trpl/src/lib.rs diff --git a/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs similarity index 100% rename from tests/integration/main.rs rename to packages/trpl/tests/integration/main.rs From 7e28bd7d73f75709237d2c03e530de641983b120 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 10 May 2024 08:37:33 -0600 Subject: [PATCH 178/720] infra: run package tests With the introduction of the workspace, we were missing coverage for the supporting packages. --- .github/workflows/main.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index db70f67da2..04b855e8c8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,6 +26,21 @@ jobs: mdbook --version - name: Run tests run: mdbook test + package_tests: + name: Run package tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Update rustup + run: rustup self update + - name: Install Rust + run: | + rustup set profile minimal + rustup toolchain install 1.76 -c rust-docs + rustup default 1.76 + - name: Run package tests + run: | + cargo test lint: name: Run lints runs-on: ubuntu-latest From 8f6bcc72404a121c51f2bf9636fa3d917f6a8198 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 10 May 2024 09:09:43 -0600 Subject: [PATCH 179/720] Ch. 17: expand, clarify, and restructure 17.01 - Explicitly section out the discussions of async functions and blocks and the associated `async` and `.await` syntax from defining `Future` and explaining how it works. - Also a bunch of small phrasing tweaks. --- src/ch17-01-tasks.md | 49 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index be642fcec2..9c379c45fb 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -1,7 +1,5 @@ ## Futures and the Async Syntax -### Tasks - As we saw in the previous chapter, threads provide one approach to concurrency, and they let us solve some of these issues. However, they also have some tradeoffs. On many operating systems, they use a fair bit of memory for each @@ -22,15 +20,12 @@ being managed by the operating system, it is managed by a runtime. -### - -Like many other languages with first-class support for the async programming -model, Rust uses the `async` and `await` keywords—though with some important -differences from other languages like C# or JavaScript. Blocks and functions can -be marked `async`, and you can wait on the result of an `async` function or -block to resolve using the `await` keyword. +Like other languages with async, Rust uses the `async` and `await` +keywords—though with some important differences, as we will see. Blocks and +functions can be marked `async`, and you can wait on the result of an `async` +function or block to resolve using the `await` keyword. -Let’s write our first async function: +Let’s write our first async function, and call it: ```rust fn main() { @@ -60,16 +55,21 @@ warning: `hello-async` (bin "hello-async") generated 1 warning Running `target/debug/hello-async` ``` -The warning tells us why nothing happened. Calling `hello_async()` itself was -not enough: we need to `.await`or poll the “future” it returns. That might be a -bit surprising: we did not write a return type on the function. However, we -*did* mark it as an `async fn`. In Rust, `async fn` is equivalent to writing a -function which returns a *future* of the return type, using the `impl Trait` -syntax we discussed back in the [“Traits as Parameters”][impl-trait] section in -Chapter 10, and an `async` block compiles to an anonymous struct which -implements the `Future` trait. +The warning tells us that just calling `hello_async()` was not enough: we also +need to `.await` or poll the future it returns. This raises two important +questions: + +- Given there is no return type on the function, how is it returning a future? +- What is a future? + +### Async functions + +In Rust, `async fn` is equivalent to writing a function which returns a +future of the return type, using the `impl Trait` syntax we discussed back in +the [“Traits as Parameters”][impl-trait] section in Chapter 10. An `async` +block compiles to an anonymous struct which implements the `Future` trait. -So these two are roughly equivalent: +That means these two are roughly equivalent: ```rust async fn hello_async() { @@ -137,7 +137,7 @@ source code][crate-source]. You will be able to see what crate each re-export comes from, and we have left extensive comments explaining what the handful of helper functions we supply are doing. -For now, go ahead and add the dependency to your `hello-async` project: +For now, go ahead and add the `trpl` crate to your `hello-async` project: ```console $ cargo add trpl @@ -167,10 +167,11 @@ $ cargo run Hello, async! ``` -Phew: we finally have some working async code! To understand why we needed this, -let’s dig in a little more into what a `Future` actually is. +Phew: we finally have some working async code! Now we can answer that second +question: what is a future anyway? That will also help us understand why we need +a runtime to make this work. -### Futures and runtimes +### Futures Since `async fn` compiles to a return type with `impl Future`, we know that `Future` is a trait, with an associated type `Output`. The other part @@ -184,7 +185,7 @@ enum Poll { } ``` -You might have noticed that this `Poll` type is a lot like an `Option`. Having a +You may notice that this `Poll` type is a lot like an `Option`. Having a dedicated type lets Rust treat `Poll` differently from `Option`, though, which is important since they have very different meanings! The `Pending` variant indicates that the future still has work to do, so the caller will need to check From 03178db51d776c57cc678e8c20a3997cf03375c3 Mon Sep 17 00:00:00 2001 From: Herbert Reiter <46045854+damoasda@users.noreply.github.com> Date: Sun, 12 May 2024 12:13:45 +0200 Subject: [PATCH 180/720] Update explanation according to code listing --- src/ch05-02-example-structs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch05-02-example-structs.md b/src/ch05-02-example-structs.md index b2416b743b..1e7c9f7e9b 100644 --- a/src/ch05-02-example-structs.md +++ b/src/ch05-02-example-structs.md @@ -141,7 +141,7 @@ If we continue reading the errors, we’ll find this helpful note: ``` Let’s try it! The `println!` macro call will now look like `println!("rect1 is -{:?}", rect1);`. Putting the specifier `:?` inside the curly brackets tells +{rect1:?}");`. Putting the specifier `:?` inside the curly brackets tells `println!` we want to use an output format called `Debug`. The `Debug` trait enables us to print our struct in a way that is useful for developers so we can see its value while we’re debugging our code. From 000b3d03e1d39ed834bb33ec36e4b440db104f31 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 13 May 2024 12:27:13 -0600 Subject: [PATCH 181/720] Create a repo for listing preprocessor --- .gitignore | 1 + Cargo.lock | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 10 +++++++ 3 files changed, 89 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000..7e092ffbf3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,78 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "listing-preprocessor" +version = "0.1.0" +dependencies = [ + "pulldown-cmark", + "xmlparser", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-width" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "xmlparser" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000..24e35707dd --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "listing-preprocessor" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +pulldown-cmark = { version = "0.10.3", features = ["simd"] } +xmlparser = "0.13.6" From e07789118bbb7b9572848865451f3842a92623f8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 13 May 2024 12:27:13 -0600 Subject: [PATCH 182/720] Implement an mdBook preprocessor for ``s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of requiring a bunch of `` wrangling, add a custom tag, ``, whose attributes get rewritten into the desired output format, using `
` and `
` for improved semantic HTML. Support both a default (nice and fancy) HTML output mode and a “simple” mode to make it so we get the desired output format for the NoStarch input files as well. --- Cargo.lock | 2201 ++++++++++++++++++++++++++++++++++++- Cargo.toml | 11 +- src/lib.rs | 641 +++++++++++ src/main.rs | 37 + tests/integration/main.rs | 22 + 5 files changed, 2888 insertions(+), 24 deletions(-) create mode 100644 src/lib.rs create mode 100644 src/main.rs create mode 100644 tests/integration/main.rs diff --git a/Cargo.lock b/Cargo.lock index 7e092ffbf3..c967a690ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,53 +2,1860 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "ammonia" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e6d1c7838db705c9b756557ee27c384ce695a1c51a6fe528784cb1c6840170" +dependencies = [ + "html5ever", + "maplit", + "once_cell", + "tendril", + "url", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" + +[[package]] +name = "assert_cmd" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.52.5", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", + "terminal_size", +] + +[[package]] +name = "clap_complete" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "elasticlunr-rs" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41e83863a500656dfa214fee6682de9c5b9f03de6860fec531235ed2ae9f6571" +dependencies = [ + "regex", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "globset" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "headers" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" +dependencies = [ + "base64", + "bytes", + "headers-core", + "http 0.2.12", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +dependencies = [ + "http 0.2.12", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http 0.2.12", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "markup5ever" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" +dependencies = [ + "log", + "phf", + "phf_codegen", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "mdbook" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c33564061c3c640bed5ace7d6a2a1b65f2c64257d1ac930c15e94ed0fb561d3" +dependencies = [ + "ammonia", + "anyhow", + "chrono", + "clap", + "clap_complete", + "elasticlunr-rs", + "env_logger", + "futures-util", + "handlebars", + "ignore", + "log", + "memchr", + "notify", + "notify-debouncer-mini", + "once_cell", + "opener", + "pathdiff", + "pulldown-cmark", + "regex", + "serde", + "serde_json", + "shlex", + "tempfile", + "tokio", + "toml 0.5.11", + "topological-sort", + "warp", +] + +[[package]] +name = "mdbook-trpl-listing" +version = "0.1.0" +dependencies = [ + "assert_cmd", + "clap", + "mdbook", + "pulldown-cmark", + "pulldown-cmark-to-cmark", + "serde_json", + "thiserror", + "toml 0.8.12", + "xmlparser", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.5.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "walkdir", + "windows-sys 0.48.0", +] + +[[package]] +name = "notify-debouncer-mini" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d40b221972a1fc5ef4d858a2f671fb34c75983eb385463dff3780eeff6a9d43" +dependencies = [ + "crossbeam-channel", + "log", + "notify", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opener" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c62dcb6174f9cb326eac248f07e955d5d559c272730b6c03e396b443b562788" +dependencies = [ + "bstr", + "normpath", + "winapi", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.1", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pest" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "pest_meta" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "predicates" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +dependencies = [ + "anstyle", + "difflib", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags 2.5.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + +[[package]] +name = "pulldown-cmark-to-cmark" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.5.0", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.201" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.201" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix", + "windows-sys 0.48.0", +] [[package]] -name = "getopts" -version = "0.2.21" +name = "termtree" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + +[[package]] +name = "thiserror" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ - "unicode-width", + "thiserror-impl", ] [[package]] -name = "listing-preprocessor" -version = "0.1.0" +name = "thiserror-impl" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ - "pulldown-cmark", - "xmlparser", + "proc-macro2", + "quote", + "syn 2.0.63", ] [[package]] -name = "memchr" -version = "2.7.2" +name = "tinyvec" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] [[package]] -name = "pulldown-cmark" -version = "0.10.3" +name = "tinyvec_macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ - "bitflags", - "getopts", - "memchr", - "pulldown-cmark-escape", - "unicase", + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", ] [[package]] -name = "pulldown-cmark-escape" -version = "0.10.1" +name = "tokio-macros" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http 1.1.0", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "unicase" @@ -59,18 +1866,366 @@ dependencies = [ "version_check", ] +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "warp" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4378d202ff965b011c64817db11d5829506d3404edeadb61f190d111da3f231c" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "headers", + "http 0.2.12", + "hyper", + "log", + "mime", + "mime_guess", + "percent-encoding", + "pin-project", + "scoped-tls", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-tungstenite", + "tokio-util", + "tower-service", + "tracing", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.63", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "winnow" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" +dependencies = [ + "memchr", +] + [[package]] name = "xmlparser" version = "0.13.6" diff --git a/Cargo.toml b/Cargo.toml index 24e35707dd..414b2a7a71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,19 @@ [package] -name = "listing-preprocessor" +name = "mdbook-trpl-listing" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.5.4", features = ["derive"] } +mdbook = { version = "0.4.37" } pulldown-cmark = { version = "0.10.3", features = ["simd"] } +pulldown-cmark-to-cmark = "13.0.0" +serde_json = "1.0.117" +thiserror = "1.0.60" +toml = "0.8.12" xmlparser = "0.13.6" + +[dev-dependencies] +assert_cmd = "2.0.14" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000000..72d9b86dcb --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,641 @@ +use mdbook::{ + book::Book, + errors::Result, + preprocess::{Preprocessor, PreprocessorContext}, + BookItem, +}; +use pulldown_cmark::{html, Event, Parser}; +use pulldown_cmark_to_cmark::cmark; +use xmlparser::{Token, Tokenizer}; + +/// A preprocessor for rendering listings more elegantly. +/// +/// Given input like this: +/// +/// ````markdown +/// +/// +/// ```rust +/// fn main() {} +/// ``` +/// +/// +/// +/// ```` +/// +/// With no configuration, or with `output-mode = "default"`, it renders the +/// following Markdown to be further preprocessed or rendered to HTML: +/// +/// ````markdown +///
+/// Filename: src/main.rs +/// +/// ```rust +/// fn main() {} +/// ``` +/// +///
Listing 1-2: Some text, yeah?
+/// +///
+/// ```` +/// +/// When `output-mode = "simple"` in the configuration, it instead emits: +/// +/// ````markdown +/// Filename: src/main.rs +/// +/// ```rust +/// fn main() {} +/// ``` +/// +/// Listing 1-2: Some *text*, yeah? +/// ```` +pub struct TrplListing; + +impl Preprocessor for TrplListing { + fn name(&self) -> &str { + "trpl-listing" + } + + fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result { + let config = ctx + .config + .get_preprocessor(self.name()) + .ok_or(Error::NoConfig)?; + + let key = String::from("output-mode"); + let mode = config + .get(&key) + .map(|value| match value.as_str() { + Some(s) => Mode::try_from(s).map_err(|_| Error::BadValue { + key, + value: value.to_string(), + }), + None => Err(Error::BadValue { + key, + value: value.to_string(), + }), + }) + .transpose()? + .unwrap_or(Mode::Default); + + let mut errors: Vec = vec![]; + book.for_each_mut(|item| { + if let BookItem::Chapter(ref mut chapter) = item { + match rewrite_listing(&chapter.content, mode) { + Ok(rewritten) => chapter.content = rewritten, + Err(reason) => errors.push(reason), + } + } + }); + + if errors.is_empty() { + Ok(book) + } else { + Err(CompositeError(errors.join("\n")).into()) + } + } + + fn supports_renderer(&self, renderer: &str) -> bool { + renderer == "html" + } +} + +#[derive(Debug, thiserror::Error)] +enum Error { + #[error("No config for trpl-listing")] + NoConfig, + + #[error("Bad config value '{value}' for key '{key}'")] + BadValue { key: String, value: String }, +} + +#[derive(Debug, thiserror::Error)] +#[error("Error(s) rewriting input: {0}")] +struct CompositeError(String); + +#[derive(Debug, Clone, Copy)] +enum Mode { + Default, + Simple, +} + +/// Trivial marker struct to indicate an internal error. +/// +/// The caller has enough info to do what it needs without passing data around. +struct ParseErr; + +impl TryFrom<&str> for Mode { + type Error = ParseErr; + + fn try_from(value: &str) -> std::prelude::v1::Result { + match value { + "default" => Ok(Mode::Default), + "simple" => Ok(Mode::Simple), + _ => Err(ParseErr), + } + } +} + +fn rewrite_listing(src: &str, mode: Mode) -> Result { + let parser = Parser::new(src); + + struct State<'e> { + current_listing: Option, + events: Vec, String>>, + } + + let final_state = parser.fold( + State { + current_listing: None, + events: vec![], + }, + |mut state, ev| { + match ev { + Event::Html(tag) => { + if tag.starts_with(" match local.as_str() { + "number" => builder.with_number(value.as_str()), + "caption" => builder.with_caption(value.as_str()), + "file-name" => builder.with_file_name(value.as_str()), + _ => builder, // TODO: error on extra attrs? + }, + _ => builder, + }) + .build(); + + match listing_result { + Ok(listing) => { + let opening_event = match mode { + Mode::Default => { + let opening_html = listing.opening_html(); + Event::Html(opening_html.into()) + } + Mode::Simple => { + let opening_text = listing.opening_text(); + Event::Text(opening_text.into()) + } + }; + + state.current_listing = Some(listing); + state.events.push(Ok(opening_event)); + } + Err(reason) => state.events.push(Err(reason)), + } + } else if tag.as_ref() == "" { + match state.current_listing { + Some(listing) => { + let closing_event = match mode { + Mode::Default => { + let closing_html = listing.closing_html(); + Event::Html(closing_html.into()) + } + Mode::Simple => { + let closing_text = listing.closing_text(); + Event::Text(closing_text.into()) + } + }; + + state.current_listing = None; + state.events.push(Ok(closing_event)); + } + None => state.events.push(Err(String::from( + "Closing `
` without opening tag.", + ))), + } + } else { + state.events.push(Ok(Event::Html(tag))); + } + } + ev => state.events.push(Ok(ev)), + }; + state + }, + ); + + if final_state.current_listing.is_some() { + return Err("Unclosed listing".into()); + } + + let (events, errors): (Vec<_>, Vec<_>) = + final_state.events.into_iter().partition(|e| e.is_ok()); + + if !errors.is_empty() { + return Err(errors + .into_iter() + .map(|e| e.unwrap_err()) + .collect::>() + .join("\n")); + } + + let mut buf = String::with_capacity(src.len() * 2); + cmark(events.into_iter().map(|ok| ok.unwrap()), &mut buf).map_err(|e| format!("{e}"))?; + Ok(buf) +} + +#[derive(Debug)] +struct Listing { + number: String, + caption: String, + file_name: String, +} + +impl Listing { + fn opening_html(&self) -> String { + format!( + r#"
+Filename: {file_name} +"#, + file_name = self.file_name + ) + } + + fn closing_html(&self) -> String { + format!( + r#"
Listing {number}: {caption}
+
"#, + number = self.number, + caption = self.caption + ) + } + + fn opening_text(&self) -> String { + format!("\nFilename: {file_name}\n", file_name = self.file_name) + } + + fn closing_text(&self) -> String { + format!( + "Listing {number}: {caption}", + number = self.number, + caption = self.caption + ) + } +} + +struct ListingBuilder<'a> { + number: Option<&'a str>, + caption: Option<&'a str>, + file_name: Option<&'a str>, +} + +impl<'a> ListingBuilder<'a> { + fn new() -> ListingBuilder<'a> { + ListingBuilder { + number: None, + caption: None, + file_name: None, + } + } + + fn with_number(mut self, value: &'a str) -> Self { + self.number = Some(value); + self + } + + fn with_caption(mut self, value: &'a str) -> Self { + self.caption = Some(value); + self + } + + fn with_file_name(mut self, value: &'a str) -> Self { + self.file_name = Some(value); + self + } + + fn build(self) -> Result { + let number = self + .number + .ok_or_else(|| String::from("Missing number"))? + .to_owned(); + + let caption = self + .caption + .map(|caption_source| { + let events = Parser::new(caption_source); + let mut buf = String::with_capacity(caption_source.len() * 2); + html::push_html(&mut buf, events); + + // This is not particularly principled, but since the only + // place it is used is here, for caption source handling, it + // is “fine”. + buf.replace("

", "").replace("

", "").replace('\n', "") + }) + .ok_or_else(|| String::from("Missing caption"))? + .to_owned(); + + let file_name = self + .file_name + .ok_or_else(|| String::from("Missing file-name"))? + .to_owned(); + + Ok(Listing { + number, + caption, + file_name, + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// Note: This inserts an additional backtick around the re-emitted code. + /// It is not clear *why*, but that seems to be an artifact of the rendering + /// done by the `pulldown_cmark_to_cmark` crate. + #[test] + fn default_mode_works() { + let result = rewrite_listing( + r#"+ +```rust +fn main() {} +``` + +"#, + Mode::Default, + ); + + assert_eq!( + &result.unwrap(), + r#"
+Filename: src/main.rs + +````rust +fn main() {} +```` + +
Listing 1-2: A write-up which might include inline Markdown like code etc.
+
"# + ); + } + + #[test] + fn simple_mode_works() { + let result = rewrite_listing( + r#"+ +```rust +fn main() {} +``` + +"#, + Mode::Simple, + ); + + assert_eq!( + &result.unwrap(), + r#" +Filename: src/main.rs + +````rust +fn main() {} +```` + +Listing 1-2: A write-up which might include inline Markdown like code etc."# + ); + } + + /// Check that the config options are correctly handled. + /// + /// Note: none of these tests particularly exercise the *wiring*. They just + /// assume that the config itself is done correctly. This is a small enough + /// chunk of code that it easy to verify by hand at present. If it becomes + /// more complex in the future, it would be good to revisit and integrate + /// the same kinds of tests as the unit tests above here. + #[cfg(test)] + mod config { + use super::*; + + // TODO: what *should* the behavior here be? I *think* it should error, + // in that there is a problem if it is invoked without that info. + #[test] + fn no_config() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": {} + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_err()); + let err = result.unwrap_err(); + assert_eq!(format!("{err}"), "No config for trpl-listing"); + } + + #[test] + fn empty_config() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": { + "trpl-listing": {} + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_ok()); + } + + #[test] + fn specify_default() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": { + "trpl-listing": { + "output-mode": "default" + } + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_ok()); + } + + #[test] + fn specify_simple() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": { + "trpl-listing": { + "output-mode": "simple" + } + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_ok()); + } + + #[test] + fn specify_invalid() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": { + "trpl-listing": { + "output-mode": "nonsense" + } + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_err()); + let err = result.unwrap_err(); + assert_eq!( + format!("{err}"), + "Bad config value '\"nonsense\"' for key 'output-mode'" + ); + } + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000000..3792b46fa4 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,37 @@ +use std::io; + +use clap::{self, Parser, Subcommand}; +use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; + +use mdbook_trpl_listing::TrplListing; + +fn main() -> Result<(), String> { + let cli = Cli::parse(); + if let Some(Command::Supports { renderer }) = cli.command { + return if TrplListing.supports_renderer(&renderer) { + Ok(()) + } else { + Err(format!("Renderer '{renderer}' is unsupported")) + }; + } + + let (ctx, book) = CmdPreprocessor::parse_input(io::stdin()).map_err(|e| format!("{e}"))?; + let processed = TrplListing.run(&ctx, book).map_err(|e| format!("{e}"))?; + serde_json::to_writer(io::stdout(), &processed).map_err(|e| format!("{e}")) +} + +/// A simple preprocessor for semantic markup for code listings in _The Rust +/// Programming Language_. +#[derive(Parser, Debug)] +struct Cli { + #[command(subcommand)] + command: Option, +} + +#[derive(Subcommand, Debug)] +enum Command { + /// Is the renderer supported? + /// + /// All renderers are supported! This is the contract for mdBook. + Supports { renderer: String }, +} diff --git a/tests/integration/main.rs b/tests/integration/main.rs new file mode 100644 index 0000000000..6944fae693 --- /dev/null +++ b/tests/integration/main.rs @@ -0,0 +1,22 @@ +use assert_cmd::Command; + +#[test] +fn supports_html_renderer() { + let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) + .unwrap() + .args(["supports", "html"]) + .ok(); + assert!(cmd.is_ok()); +} + +#[test] +fn errors_for_other_renderers() { + let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) + .unwrap() + .args(["supports", "total-nonsense"]) + .ok(); + assert!(cmd.is_err()); +} + +// It would be nice to add an actual fixture for an mdbook, but doing *that* is +// going to be a bit of a pain, and what I have should cover it for now. From dad2b61a69877c1bda32dbe248bb9a095d363a3c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 13 May 2024 16:54:56 -0600 Subject: [PATCH 183/720] Prepare to integrate into TRPL repo --- Cargo.toml | 19 - packages/mdbook-trpl-listing/Cargo.lock | 2142 +++++++++++++++++ packages/mdbook-trpl-listing/Cargo.toml | 23 + .../mdbook-trpl-listing/src}/lib.rs | 0 .../mdbook-trpl-listing/src}/main.rs | 0 5 files changed, 2165 insertions(+), 19 deletions(-) delete mode 100644 Cargo.toml create mode 100644 packages/mdbook-trpl-listing/Cargo.lock create mode 100644 packages/mdbook-trpl-listing/Cargo.toml rename {src => packages/mdbook-trpl-listing/src}/lib.rs (100%) rename {src => packages/mdbook-trpl-listing/src}/main.rs (100%) diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 414b2a7a71..0000000000 --- a/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "mdbook-trpl-listing" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -clap = { version = "4.5.4", features = ["derive"] } -mdbook = { version = "0.4.37" } -pulldown-cmark = { version = "0.10.3", features = ["simd"] } -pulldown-cmark-to-cmark = "13.0.0" -serde_json = "1.0.117" -thiserror = "1.0.60" -toml = "0.8.12" -xmlparser = "0.13.6" - -[dev-dependencies] -assert_cmd = "2.0.14" diff --git a/packages/mdbook-trpl-listing/Cargo.lock b/packages/mdbook-trpl-listing/Cargo.lock new file mode 100644 index 0000000000..3d53f92f54 --- /dev/null +++ b/packages/mdbook-trpl-listing/Cargo.lock @@ -0,0 +1,2142 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "ammonia" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e6d1c7838db705c9b756557ee27c384ce695a1c51a6fe528784cb1c6840170" +dependencies = [ + "html5ever", + "maplit", + "once_cell", + "tendril", + "url", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.52.5", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", + "terminal_size", +] + +[[package]] +name = "clap_complete" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "elasticlunr-rs" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41e83863a500656dfa214fee6682de9c5b9f03de6860fec531235ed2ae9f6571" +dependencies = [ + "regex", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "globset" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "headers" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" +dependencies = [ + "base64", + "bytes", + "headers-core", + "http 0.2.12", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +dependencies = [ + "http 0.2.12", +] + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http 0.2.12", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "markup5ever" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" +dependencies = [ + "log", + "phf", + "phf_codegen", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "mdbook" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c33564061c3c640bed5ace7d6a2a1b65f2c64257d1ac930c15e94ed0fb561d3" +dependencies = [ + "ammonia", + "anyhow", + "chrono", + "clap", + "clap_complete", + "elasticlunr-rs", + "env_logger", + "futures-util", + "handlebars", + "ignore", + "log", + "memchr", + "notify", + "notify-debouncer-mini", + "once_cell", + "opener", + "pathdiff", + "pulldown-cmark", + "regex", + "serde", + "serde_json", + "shlex", + "tempfile", + "tokio", + "toml 0.5.11", + "topological-sort", + "warp", +] + +[[package]] +name = "mdbook-trpl-listing" +version = "0.1.0" +dependencies = [ + "mdbook", + "pulldown-cmark", + "pulldown-cmark-to-cmark", + "thiserror", + "toml 0.8.12", + "xmlparser", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.5.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "walkdir", + "windows-sys 0.48.0", +] + +[[package]] +name = "notify-debouncer-mini" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d40b221972a1fc5ef4d858a2f671fb34c75983eb385463dff3780eeff6a9d43" +dependencies = [ + "crossbeam-channel", + "log", + "notify", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opener" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c62dcb6174f9cb326eac248f07e955d5d559c272730b6c03e396b443b562788" +dependencies = [ + "bstr", + "normpath", + "winapi", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.1", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pest" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "pest_meta" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags 2.5.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + +[[package]] +name = "pulldown-cmark-to-cmark" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.5.0", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.201" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.201" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix", + "windows-sys 0.48.0", +] + +[[package]] +name = "thiserror" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http 1.1.0", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "warp" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4378d202ff965b011c64817db11d5829506d3404edeadb61f190d111da3f231c" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "headers", + "http 0.2.12", + "hyper", + "log", + "mime", + "mime_guess", + "percent-encoding", + "pin-project", + "scoped-tls", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-tungstenite", + "tokio-util", + "tower-service", + "tracing", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.63", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "winnow" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" +dependencies = [ + "memchr", +] + +[[package]] +name = "xmlparser" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" diff --git a/packages/mdbook-trpl-listing/Cargo.toml b/packages/mdbook-trpl-listing/Cargo.toml new file mode 100644 index 0000000000..3ea7d246ac --- /dev/null +++ b/packages/mdbook-trpl-listing/Cargo.toml @@ -0,0 +1,23 @@ +<<<<<<< +%%%%%%% + [package] + name = "mdbook-trpl-listing" + version = "0.1.0" + edition = "2021" + + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + + [dependencies] + clap = { version = "4.5.4", features = ["derive"] } + mdbook = { version = "0.4.37" } + pulldown-cmark = { version = "0.10.3", features = ["simd"] } + pulldown-cmark-to-cmark = "13.0.0" + serde_json = "1.0.117" + thiserror = "1.0.60" + toml = "0.8.12" + xmlparser = "0.13.6" ++ ++[dev-dependencies] ++assert_cmd = "2.0.14" ++++++++ +>>>>>>> diff --git a/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs similarity index 100% rename from src/lib.rs rename to packages/mdbook-trpl-listing/src/lib.rs diff --git a/src/main.rs b/packages/mdbook-trpl-listing/src/main.rs similarity index 100% rename from src/main.rs rename to packages/mdbook-trpl-listing/src/main.rs From 3254856510e2ccbba7433fd6ba1f317f2631167e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 07:39:44 -0600 Subject: [PATCH 184/720] infra: Hoist mdBook preprocessor workspace dependencies --- Cargo.toml | 5 +++++ packages/mdbook-trpl-listing/Cargo.toml | 12 ++++++------ packages/mdbook-trpl-note/Cargo.toml | 10 +++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a24b0da02..80cdfdcd65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,10 +8,15 @@ exclude = [ ] [workspace.dependencies] +assert_cmd = "2.0.14" walkdir = "2.3.1" +clap = { version = "4.5.4", features = ["derive"] } docopt = "1.1.0" mdbook = "0.4.37" +pulldown-cmark = { version = "0.10.3", features = ["simd"] } +pulldown-cmark-to-cmark = "13.0.0" serde = "1.0" +serde_json = "1.0" regex = "1.3.3" lazy_static = "1.4.0" flate2 = "1.0.13" diff --git a/packages/mdbook-trpl-listing/Cargo.toml b/packages/mdbook-trpl-listing/Cargo.toml index 414b2a7a71..fd829ef180 100644 --- a/packages/mdbook-trpl-listing/Cargo.toml +++ b/packages/mdbook-trpl-listing/Cargo.toml @@ -6,14 +6,14 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4.5.4", features = ["derive"] } -mdbook = { version = "0.4.37" } -pulldown-cmark = { version = "0.10.3", features = ["simd"] } -pulldown-cmark-to-cmark = "13.0.0" -serde_json = "1.0.117" +clap = { workspace = true } +mdbook = { workspace = true } +pulldown-cmark = { workspace = true } +pulldown-cmark-to-cmark = { workspace = true } +serde_json = { workspace = true } thiserror = "1.0.60" toml = "0.8.12" xmlparser = "0.13.6" [dev-dependencies] -assert_cmd = "2.0.14" +assert_cmd = { workspace = true } diff --git a/packages/mdbook-trpl-note/Cargo.toml b/packages/mdbook-trpl-note/Cargo.toml index 5834b96675..d2f80f9b7b 100644 --- a/packages/mdbook-trpl-note/Cargo.toml +++ b/packages/mdbook-trpl-note/Cargo.toml @@ -6,11 +6,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4.5.4", features = ["derive"] } +clap = { workspace = true } mdbook = { workspace = true } -pulldown-cmark = { version = "0.10.3", features = ["simd"] } -pulldown-cmark-to-cmark = "13.0.0" -serde_json = "1.0.116" +pulldown-cmark = { workspace = true } +pulldown-cmark-to-cmark = { workspace = true } +serde_json = { workspace = true } [dev-dependencies] -assert_cmd = "2.0.14" +assert_cmd = { workspace = true } From 04841f73baf38b4a124e4c215b70387ade156388 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 07:44:17 -0600 Subject: [PATCH 185/720] infra: configure trpl-listing preprocessor --- .github/workflows/main.yml | 2 ++ book.toml | 3 +++ nostarch/book.toml | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 04b855e8c8..da2dd5ba7e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,6 +60,8 @@ jobs: echo "$(pwd)/bin" >> ${GITHUB_PATH} - name: Install mdbook-trpl-note run: cargo install --path packages/mdbook-trpl-note + - name: Install mdbook-trpl-listing + run: cargo install --path packages/mdbook-trpl-listing - name: Install aspell run: sudo apt-get install aspell - name: Install shellcheck diff --git a/book.toml b/book.toml index 416f2190fb..518ff6a590 100644 --- a/book.toml +++ b/book.toml @@ -12,3 +12,6 @@ git-repository-url = "https://github.com/rust-lang/book" # Do not sync this preprocessor; it is for the HTML renderer only. [preprocessor.trpl-note] + +[preprocessor.trpl-listing] +output-mode = "default" diff --git a/nostarch/book.toml b/nostarch/book.toml index 4c31179335..55528625d8 100644 --- a/nostarch/book.toml +++ b/nostarch/book.toml @@ -9,4 +9,7 @@ additional-js = ["../ferris.js"] git-repository-url = "https://github.com/rust-lang/book" [build] -build-dir = "../tmp" \ No newline at end of file +build-dir = "../tmp" + +[preprocessor.trpl-listing] +output-mode = "simple" From e65efe3a99db1d6de42ea0e3d4082873f92b41bf Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 07:50:00 -0600 Subject: [PATCH 186/720] infra: handle trailing newlines correctly in mdbook-trpl-listing --- packages/mdbook-trpl-listing/src/lib.rs | 118 +++++++++++++++++++----- 1 file changed, 94 insertions(+), 24 deletions(-) diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index 72d9b86dcb..eeb3db008f 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -156,14 +156,23 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { if tag.starts_with(" match local.as_str() { - "number" => builder.with_number(value.as_str()), - "caption" => builder.with_caption(value.as_str()), - "file-name" => builder.with_file_name(value.as_str()), - _ => builder, // TODO: error on extra attrs? - }, - _ => builder, + .fold(ListingBuilder::new(), |builder, token| { + match token { + Token::Attribute { + local, value, .. + } => { + match local.as_str() { + "number" => builder + .with_number(value.as_str()), + "caption" => builder + .with_caption(value.as_str()), + "file-name" => builder + .with_file_name(value.as_str()), + _ => builder, // TODO: error on extra attrs? + } + } + _ => builder, + } }) .build(); @@ -171,11 +180,13 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { Ok(listing) => { let opening_event = match mode { Mode::Default => { - let opening_html = listing.opening_html(); + let opening_html = + listing.opening_html(); Event::Html(opening_html.into()) } Mode::Simple => { - let opening_text = listing.opening_text(); + let opening_text = + listing.opening_text(); Event::Text(opening_text.into()) } }; @@ -185,16 +196,24 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { } Err(reason) => state.events.push(Err(reason)), } - } else if tag.as_ref() == "
" { + } else if tag.starts_with("") { + let trailing = if !tag.ends_with('>') { + tag.replace("", "") + } else { + String::from("") + }; + match state.current_listing { Some(listing) => { let closing_event = match mode { Mode::Default => { - let closing_html = listing.closing_html(); + let closing_html = + listing.closing_html(&trailing); Event::Html(closing_html.into()) } Mode::Simple => { - let closing_text = listing.closing_text(); + let closing_text = + listing.closing_text(&trailing); Event::Text(closing_text.into()) } }; @@ -232,7 +251,8 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { } let mut buf = String::with_capacity(src.len() * 2); - cmark(events.into_iter().map(|ok| ok.unwrap()), &mut buf).map_err(|e| format!("{e}"))?; + cmark(events.into_iter().map(|ok| ok.unwrap()), &mut buf) + .map_err(|e| format!("{e}"))?; Ok(buf) } @@ -253,10 +273,10 @@ impl Listing { ) } - fn closing_html(&self) -> String { + fn closing_html(&self, trailing: &str) -> String { format!( r#"
Listing {number}: {caption}
-"#, +{trailing}"#, number = self.number, caption = self.caption ) @@ -266,11 +286,11 @@ impl Listing { format!("\nFilename: {file_name}\n", file_name = self.file_name) } - fn closing_text(&self) -> String { + fn closing_text(&self, trailing: &str) -> String { format!( - "Listing {number}: {caption}", + "Listing {number}: {caption}{trailing}", number = self.number, - caption = self.caption + caption = self.caption, ) } } @@ -399,6 +419,46 @@ Listing 1-2: A write-up which might include inline Markdown like ); } + #[test] + fn actual_listing() { + let result = rewrite_listing( + r#"Now open the *main.rs* file you just created and enter the code in Listing 1-1. + ++ +```rust +fn main() { + println!("Hello, world!"); +} +``` + + + +Save the file and go back to your terminal window"#, + Mode::Default, + ); + + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + r#"Now open the *main.rs* file you just created and enter the code in Listing 1-1. + +
+Filename: main.rs + +````rust +fn main() { + println!("Hello, world!"); +} +```` + +
Listing 1-1: A program that prints Hello, world!
+
+ +Save the file and go back to your terminal window"# + ); + } + /// Check that the config options are correctly handled. /// /// Note: none of these tests particularly exercise the *wiring*. They just @@ -448,7 +508,9 @@ Listing 1-2: A write-up which might include inline Markdown like } ]"##; let input_json = input_json.as_bytes(); - let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json) + .unwrap(); let result = TrplListing.run(&ctx, book); assert!(result.is_err()); let err = result.unwrap_err(); @@ -493,7 +555,9 @@ Listing 1-2: A write-up which might include inline Markdown like } ]"##; let input_json = input_json.as_bytes(); - let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json) + .unwrap(); let result = TrplListing.run(&ctx, book); assert!(result.is_ok()); } @@ -538,7 +602,9 @@ Listing 1-2: A write-up which might include inline Markdown like } ]"##; let input_json = input_json.as_bytes(); - let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json) + .unwrap(); let result = TrplListing.run(&ctx, book); assert!(result.is_ok()); } @@ -583,7 +649,9 @@ Listing 1-2: A write-up which might include inline Markdown like } ]"##; let input_json = input_json.as_bytes(); - let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json) + .unwrap(); let result = TrplListing.run(&ctx, book); assert!(result.is_ok()); } @@ -628,7 +696,9 @@ Listing 1-2: A write-up which might include inline Markdown like } ]"##; let input_json = input_json.as_bytes(); - let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json) + .unwrap(); let result = TrplListing.run(&ctx, book); assert!(result.is_err()); let err = result.unwrap_err(); From 17c244ac13933ef70dc888b179acd4f242532b80 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 07:50:00 -0600 Subject: [PATCH 187/720] infra: Convert one listing to use `` - Add CSS for `figure.listing`; this now renders identically to how the existing listings render. - Convert the first listing in the book to use `` instead of a bunch of ``s. --- book.toml | 2 +- src/ch01-02-hello-world.md | 4 ++-- theme/listing.css | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 theme/listing.css diff --git a/book.toml b/book.toml index 518ff6a590..b73ff03b7a 100644 --- a/book.toml +++ b/book.toml @@ -6,7 +6,7 @@ title = "The Rust Programming Language" authors = ["Steve Klabnik", "Carol Nichols", "Contributions from the Rust Community"] [output.html] -additional-css = ["ferris.css", "theme/2018-edition.css", "theme/semantic-notes.css"] +additional-css = ["ferris.css", "theme/2018-edition.css", "theme/semantic-notes.css", "theme/listing.css"] additional-js = ["ferris.js"] git-repository-url = "https://github.com/rust-lang/book" diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index f291463799..f0b97e4949 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -49,7 +49,7 @@ convention is to use an underscore to separate them. For example, use Now open the *main.rs* file you just created and enter the code in Listing 1-1. -Filename: main.rs + ```rust fn main() { @@ -57,7 +57,7 @@ fn main() { } ``` -Listing 1-1: A program that prints `Hello, world!` + Save the file and go back to your terminal window in the *~/projects/hello_world* directory. On Linux or macOS, enter the following diff --git a/theme/listing.css b/theme/listing.css new file mode 100644 index 0000000000..9b5929c6e7 --- /dev/null +++ b/theme/listing.css @@ -0,0 +1,3 @@ +figure.listing { + margin: 0; +} From ad673cfb001f4e1ff87d3110a583aaed21d93198 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 12:32:50 -0600 Subject: [PATCH 188/720] infra: support `Listing`s without `file-name` I did not realize we had some of these, but: we do! --- packages/mdbook-trpl-listing/src/lib.rs | 63 +++++++++++++++++++------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index eeb3db008f..99b62cc0a6 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -260,17 +260,19 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { struct Listing { number: String, caption: String, - file_name: String, + file_name: Option, } impl Listing { fn opening_html(&self) -> String { - format!( - r#"
-Filename: {file_name} -"#, - file_name = self.file_name - ) + let figure = String::from("
\n"); + + match self.file_name.as_ref() { + Some(file_name) => format!( + "{figure}Filename: {file_name}\n", + ), + None => figure, + } } fn closing_html(&self, trailing: &str) -> String { @@ -283,7 +285,10 @@ impl Listing { } fn opening_text(&self) -> String { - format!("\nFilename: {file_name}\n", file_name = self.file_name) + self.file_name + .as_ref() + .map(|file_name| format!("\nFilename: {file_name}\n")) + .unwrap_or_default() } fn closing_text(&self, trailing: &str) -> String { @@ -346,15 +351,10 @@ impl<'a> ListingBuilder<'a> { .ok_or_else(|| String::from("Missing caption"))? .to_owned(); - let file_name = self - .file_name - .ok_or_else(|| String::from("Missing file-name"))? - .to_owned(); - Ok(Listing { number, caption, - file_name, + file_name: self.file_name.map(String::from), }) } } @@ -459,6 +459,41 @@ Save the file and go back to your terminal window"# ); } + #[test] + fn no_filename() { + let result = rewrite_listing( + r#"This is the opening. + ++ +```rust +fn main() {} +``` + + + +This is the closing."#, + Mode::Default, + ); + + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + r#"This is the opening. + +
+ +````rust +fn main() {} +```` + +
Listing 1-1: This is the caption
+
+ +This is the closing."# + ); + } + /// Check that the config options are correctly handled. /// /// Note: none of these tests particularly exercise the *wiring*. They just From 53b7c6faedb6cf92df6cbe8061ec602fd1f4b098 Mon Sep 17 00:00:00 2001 From: David Kurilla <130074511+davidkurilla@users.noreply.github.com> Date: Wed, 15 May 2024 18:09:30 -0700 Subject: [PATCH 189/720] infra: convert listing 1-2 using --- src/ch01-03-hello-cargo.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch01-03-hello-cargo.md b/src/ch01-03-hello-cargo.md index 42cd0889c8..83f4b17a34 100644 --- a/src/ch01-03-hello-cargo.md +++ b/src/ch01-03-hello-cargo.md @@ -58,7 +58,8 @@ repository; you can override this behavior by using `cargo new --vcs=git`. Open *Cargo.toml* in your text editor of choice. It should look similar to the code in Listing 1-2. -Filename: Cargo.toml + ```toml [package] @@ -71,8 +72,7 @@ edition = "2021" [dependencies] ``` -Listing 1-2: Contents of *Cargo.toml* generated by `cargo -new` + This file is in the [*TOML*][toml] (*Tom’s Obvious, Minimal Language*) format, which is Cargo’s configuration format. From dd30faab70745f0e3c527eb7ff4c209cb5419dd4 Mon Sep 17 00:00:00 2001 From: David Kurilla <130074511+davidkurilla@users.noreply.github.com> Date: Wed, 15 May 2024 18:37:00 -0700 Subject: [PATCH 190/720] Update ch01-03-hello-cargo.md --- src/ch01-03-hello-cargo.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ch01-03-hello-cargo.md b/src/ch01-03-hello-cargo.md index 83f4b17a34..9ba2f83912 100644 --- a/src/ch01-03-hello-cargo.md +++ b/src/ch01-03-hello-cargo.md @@ -58,8 +58,7 @@ repository; you can override this behavior by using `cargo new --vcs=git`. Open *Cargo.toml* in your text editor of choice. It should look similar to the code in Listing 1-2. -+ ```toml [package] From e28a6b01f47e2eebee2d5121507dc59b9f7e85e4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 16 May 2024 08:09:40 -0600 Subject: [PATCH 191/720] infra: fix rendering bug in mdbook-trpl-note Previously, this was only pushing in the opening paragraph tag before getting to text, so it was accidentally dropping cases where the text started after some other opening tag, e.g. strong emphasis. --- packages/mdbook-trpl-note/src/lib.rs | 41 ++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/packages/mdbook-trpl-note/src/lib.rs b/packages/mdbook-trpl-note/src/lib.rs index 7a671be1ce..774dc82b55 100644 --- a/packages/mdbook-trpl-note/src/lib.rs +++ b/packages/mdbook-trpl-note/src/lib.rs @@ -34,7 +34,11 @@ impl Preprocessor for TrplNote { "simple-note-preprocessor" } - fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result { + fn run( + &self, + _ctx: &PreprocessorContext, + mut book: Book, + ) -> Result { book.for_each_mut(|item| { if let BookItem::Chapter(ref mut chapter) = item { chapter.content = rewrite(&chapter.content); @@ -75,7 +79,9 @@ pub fn rewrite(text: &str) -> String { events.extend([ SoftBreak, SoftBreak, - Html(r#"
"#.into()), + Html( + r#"
"#.into(), + ), SoftBreak, SoftBreak, Start(Tag::Paragraph), @@ -89,7 +95,10 @@ pub fn rewrite(text: &str) -> String { } } - (StartingBlockquote(_blockquote_events), heading @ Start(Tag::Heading { .. })) => { + ( + StartingBlockquote(_blockquote_events), + heading @ Start(Tag::Heading { .. }), + ) => { events.extend([ SoftBreak, SoftBreak, @@ -101,14 +110,18 @@ pub fn rewrite(text: &str) -> String { state = InNote; } - (StartingBlockquote(ref mut events), Start(Tag::Paragraph)) => { - events.push(Start(Tag::Paragraph)); + (StartingBlockquote(ref mut events), Start(tag)) => { + events.push(Start(tag)); } (InNote, End(TagEnd::BlockQuote)) => { // As with the start of the block HTML, the closing HTML must be // separated from the Markdown text by two newlines. - events.extend([SoftBreak, SoftBreak, Html("
".into())]); + events.extend([ + SoftBreak, + SoftBreak, + Html("
".into()), + ]); state = Default; } @@ -258,7 +271,8 @@ mod tests { #[test] fn h1_then_blockquote() { - let text = "> # Header\n > And then some note content.\n\n> This is quoted."; + let text = + "> # Header\n > And then some note content.\n\n> This is quoted."; let processed = rewrite(text); assert_eq!( render_markdown(&processed), @@ -268,7 +282,8 @@ mod tests { #[test] fn blockquote_then_h1_note() { - let text = "> This is quoted.\n\n> # Header\n > And then some note content."; + let text = + "> This is quoted.\n\n> # Header\n > And then some note content."; let processed = rewrite(text); assert_eq!( render_markdown(&processed), @@ -276,6 +291,16 @@ mod tests { ); } + #[test] + fn blockquote_with_strong() { + let text = "> **Bold text in a paragraph.**"; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Bold text in a paragraph.

\n
\n" + ); + } + fn render_markdown(text: &str) -> String { let parser = Parser::new(text); let mut buf = String::new(); From b539e27d71045846693cf49958d348f6cffc79cb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 16 May 2024 08:54:47 -0600 Subject: [PATCH 192/720] Drop extra text from `Listing[caption]` --- src/ch01-03-hello-cargo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch01-03-hello-cargo.md b/src/ch01-03-hello-cargo.md index 9ba2f83912..5750e4f015 100644 --- a/src/ch01-03-hello-cargo.md +++ b/src/ch01-03-hello-cargo.md @@ -58,7 +58,7 @@ repository; you can override this behavior by using `cargo new --vcs=git`. Open *Cargo.toml* in your text editor of choice. It should look similar to the code in Listing 1-2. -+ ```toml [package] From 3cf8a1e44d99ecf7c324dd74ff8643cab6a66a71 Mon Sep 17 00:00:00 2001 From: David Kurilla <130074511+davidkurilla@users.noreply.github.com> Date: Thu, 16 May 2024 09:35:36 -0700 Subject: [PATCH 193/720] convert ch02-00-guessing-game-tutorial.md --- src/ch02-00-guessing-game-tutorial.md | 29 ++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index f80ad52082..a6b2e6e1c2 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -73,14 +73,13 @@ that input, and check that the input is in the expected form. To start, we’ll allow the player to input a guess. Enter the code in Listing 2-1 into *src/main.rs*. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs:all}} ``` -Listing 2-1: Code that gets a guess from the user and -prints it + This code contains a lot of information, so let’s go over it line by line. To obtain user input and then print the result as output, we need to bring the @@ -376,6 +375,8 @@ rm Cargo.lock cargo clean cargo build --> ++ ```console $ cargo build Updating crates.io index @@ -397,8 +398,7 @@ $ cargo build Finished dev [unoptimized + debuginfo] target(s) in 2.53s ``` -Listing 2-2: The output from running `cargo build` after -adding the rand crate as a dependency + You may see different version numbers (but they will all be compatible with the code, thanks to SemVer!) and different lines (depending on the operating @@ -508,14 +508,13 @@ from a number of packages. Let’s start using `rand` to generate a number to guess. The next step is to update *src/main.rs*, as shown in Listing 2-3. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs:all}} ``` -Listing 2-3: Adding code to generate a random -number + First we add the line `use rand::Rng;`. The `Rng` trait defines methods that random number generators implement, and this trait must be in scope for us to @@ -585,14 +584,13 @@ Now that we have user input and a random number, we can compare them. That step is shown in Listing 2-4. Note that this code won’t compile just yet, as we will explain. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-04/src/main.rs:here}} ``` -Listing 2-4: Handling the possible return values of -comparing two numbers + First we add another `use` statement, bringing a type called `std::cmp::Ordering` into scope from the standard library. The `Ordering` type @@ -827,14 +825,13 @@ the user inputs a non-number, let’s make the game ignore a non-number so the user can continue guessing. We can do that by altering the line where `guess` is converted from a `String` to a `u32`, as shown in Listing 2-5. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-05/src/main.rs:here}} ``` -Listing 2-5: Ignoring a non-number guess and asking for -another guess instead of crashing the program + We switch from an `expect` call to a `match` expression to move from crashing on an error to handling the error. Remember that `parse` returns a `Result` @@ -897,13 +894,13 @@ that the program is still printing the secret number. That worked well for testing, but it ruins the game. Let’s delete the `println!` that outputs the secret number. Listing 2-6 shows the final code. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-06/src/main.rs}} ``` -Listing 2-6: Complete guessing game code + At this point, you’ve successfully built the guessing game. Congratulations! From 9a8cf63f7ec9ef917449e5d0f07c1cd9763354a0 Mon Sep 17 00:00:00 2001 From: David Kurilla <130074511+davidkurilla@users.noreply.github.com> Date: Thu, 16 May 2024 09:45:07 -0700 Subject: [PATCH 194/720] convert ch03-03-how-functions-work.md --- src/ch03-03-how-functions-work.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch03-03-how-functions-work.md b/src/ch03-03-how-functions-work.md index 2b59f0cd45..b282cbb2ab 100644 --- a/src/ch03-03-how-functions-work.md +++ b/src/ch03-03-how-functions-work.md @@ -116,13 +116,13 @@ We’ve actually already used statements and expressions. Creating a variable an assigning a value to it with the `let` keyword is a statement. In Listing 3-1, `let y = 6;` is a statement. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch03-common-programming-concepts/listing-03-01/src/main.rs}} ``` -Listing 3-1: A `main` function declaration containing one statement + Function definitions are also statements; the entire preceding example is a statement in itself. From 9a48839d788c58f7c081dce93b0da94b59af538c Mon Sep 17 00:00:00 2001 From: David Kurilla <130074511+davidkurilla@users.noreply.github.com> Date: Thu, 16 May 2024 10:36:24 -0700 Subject: [PATCH 195/720] convert ch03-05-control-flow.md --- src/ch03-05-control-flow.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/ch03-05-control-flow.md b/src/ch03-05-control-flow.md index ac416660d9..6b1fdd4a0a 100644 --- a/src/ch03-05-control-flow.md +++ b/src/ch03-05-control-flow.md @@ -120,14 +120,13 @@ Rust branching construct called `match` for these cases. Because `if` is an expression, we can use it on the right side of a `let` statement to assign the outcome to a variable, as in Listing 3-2. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch03-common-programming-concepts/listing-03-02/src/main.rs}} ``` -Listing 3-2: Assigning the result of an `if` expression -to a variable + The `number` variable will be bound to a value based on the outcome of the `if` expression. Run this code to see what happens: @@ -285,14 +284,13 @@ that Rust has a built-in language construct for it, called a `while` loop. In Listing 3-3, we use `while` to loop the program three times, counting down each time, and then, after the loop, print a message and exit. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch03-common-programming-concepts/listing-03-03/src/main.rs}} ``` -Listing 3-3: Using a `while` loop to run code while a -condition holds true + This construct eliminates a lot of nesting that would be necessary if you used `loop`, `if`, `else`, and `break`, and it’s clearer. While a condition @@ -304,14 +302,13 @@ You can also use the `while` construct to loop over the elements of a collection, such as an array. For example, the loop in Listing 3-4 prints each element in the array `a`. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch03-common-programming-concepts/listing-03-04/src/main.rs}} ``` -Listing 3-4: Looping through each element of a collection -using a `while` loop + Here, the code counts up through the elements in the array. It starts at index `0`, and then loops until it reaches the final index in the array (that is, @@ -336,14 +333,13 @@ index is within the bounds of the array on every iteration through the loop. As a more concise alternative, you can use a `for` loop and execute some code for each item in a collection. A `for` loop looks like the code in Listing 3-5. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch03-common-programming-concepts/listing-03-05/src/main.rs}} ``` -Listing 3-5: Looping through each element of a collection -using a `for` loop + When we run this code, we’ll see the same output as in Listing 3-4. More importantly, we’ve now increased the safety of the code and eliminated the From efd315a34836a0a002bbd25fb18fc8208bb0a76e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 20 May 2024 12:53:18 -0600 Subject: [PATCH 196/720] infra: remove mdBook preprocessors from workspace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove these from the workspace, because they will need to be used as path dependencies in `rust-lang/rust`, as part of the build, because the Rust build pipeline invokes mdBook programmatically rather than via tools built directly, and we really don’t want to muck with publishing these to crates.io at present. As a result, they cannot be part of this workspace, because path dependencies do not get built as a crate within the hosting workspace. Make sure they do not rely on any features other than the core `mdbook` library. --- .github/workflows/main.yml | 10 +- Cargo.lock | 2225 ++--------------------- Cargo.toml | 13 +- packages/mdbook-trpl-listing/Cargo.toml | 12 +- packages/mdbook-trpl-note/Cargo.toml | 12 +- 5 files changed, 180 insertions(+), 2092 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index da2dd5ba7e..8271cfef38 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,7 +38,15 @@ jobs: rustup set profile minimal rustup toolchain install 1.76 -c rust-docs rustup default 1.76 - - name: Run package tests + - name: Run `tools` package tests + run: | + cargo test + - name: Run `mdbook-trpl-note` package tests + working-directory: packages/mdbook-trpl-note + run: | + cargo test + - name: Run `mdbook-trpl-listing` package tests + working-directory: packages/mdbook-trpl-listing run: | cargo test lint: diff --git a/Cargo.lock b/Cargo.lock index 7641aa9653..d54e8284e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,2113 +3,278 @@ version = 3 [[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "ammonia" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e6d1c7838db705c9b756557ee27c384ce695a1c51a6fe528784cb1c6840170" -dependencies = [ - "html5ever", - "maplit", - "once_cell", - "tendril", - "url", -] - -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anstream" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" - -[[package]] -name = "anstyle-parse" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - -[[package]] -name = "anyhow" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" - -[[package]] -name = "assert_cmd" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" -dependencies = [ - "anstyle", - "bstr", - "doc-comment", - "predicates", - "predicates-core", - "predicates-tree", - "wait-timeout", -] - -[[package]] -name = "autocfg" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bstr" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" -dependencies = [ - "memchr", - "regex-automata", - "serde", -] - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.95" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "num-traits", - "windows-targets 0.52.5", -] - -[[package]] -name = "clap" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim 0.11.1", - "terminal_size", -] - -[[package]] -name = "clap_complete" -version = "4.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" -dependencies = [ - "clap", -] - -[[package]] -name = "clap_derive" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "clap_lex" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" - -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - -[[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - -[[package]] -name = "cpufeatures" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" -dependencies = [ - "libc", -] - -[[package]] -name = "crc32fast" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "data-encoding" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" - -[[package]] -name = "difflib" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "doc-comment" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" - -[[package]] -name = "docopt" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" -dependencies = [ - "lazy_static", - "regex", - "serde", - "strsim 0.10.0", -] - -[[package]] -name = "elasticlunr-rs" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41e83863a500656dfa214fee6682de9c5b9f03de6860fec531235ed2ae9f6571" -dependencies = [ - "regex", - "serde", - "serde_derive", - "serde_json", -] - -[[package]] -name = "env_filter" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" - -[[package]] -name = "filetime" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.4.1", - "windows-sys 0.52.0", -] - -[[package]] -name = "flate2" -version = "1.0.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - -[[package]] -name = "futf" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" -dependencies = [ - "mac", - "new_debug_unreachable", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-core", - "futures-macro", - "futures-sink", - "futures-task", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getopts" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "globset" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" -dependencies = [ - "aho-corasick", - "bstr", - "log", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "h2" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.12", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "handlebars" -version = "5.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" -dependencies = [ - "log", - "pest", - "pest_derive", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - -[[package]] -name = "headers" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" -dependencies = [ - "base64", - "bytes", - "headers-core", - "http 0.2.12", - "httpdate", - "mime", - "sha1", -] - -[[package]] -name = "headers-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" -dependencies = [ - "http 0.2.12", -] - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "html5ever" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" -dependencies = [ - "log", - "mac", - "markup5ever", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "http" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "hyper" -version = "0.14.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http 0.2.12", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "ignore" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" -dependencies = [ - "crossbeam-deque", - "globset", - "log", - "memchr", - "regex-automata", - "same-file", - "walkdir", - "winapi-util", -] - -[[package]] -name = "indexmap" -version = "2.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "inotify" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" -dependencies = [ - "bitflags 1.3.2", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kqueue" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" -dependencies = [ - "kqueue-sys", - "libc", -] - -[[package]] -name = "kqueue-sys" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" -dependencies = [ - "bitflags 1.3.2", - "libc", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "mac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" - -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - -[[package]] -name = "markup5ever" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" -dependencies = [ - "log", - "phf", - "phf_codegen", - "string_cache", - "string_cache_codegen", - "tendril", -] - -[[package]] -name = "mdbook" -version = "0.4.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c33564061c3c640bed5ace7d6a2a1b65f2c64257d1ac930c15e94ed0fb561d3" -dependencies = [ - "ammonia", - "anyhow", - "chrono", - "clap", - "clap_complete", - "elasticlunr-rs", - "env_logger", - "futures-util", - "handlebars", - "ignore", - "log", - "memchr", - "notify", - "notify-debouncer-mini", - "once_cell", - "opener", - "pathdiff", - "pulldown-cmark", - "regex", - "serde", - "serde_json", - "shlex", - "tempfile", - "tokio", - "toml 0.5.11", - "topological-sort", - "warp", -] - -[[package]] -name = "mdbook-trpl-listing" -version = "0.1.0" -dependencies = [ - "assert_cmd", - "clap", - "mdbook", - "pulldown-cmark", - "pulldown-cmark-to-cmark", - "serde_json", - "thiserror", - "toml 0.8.12", - "xmlparser", -] - -[[package]] -name = "mdbook-trpl-note" -version = "1.0.0" -dependencies = [ - "assert_cmd", - "clap", - "mdbook", - "pulldown-cmark", - "pulldown-cmark-to-cmark", - "serde_json", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "mime_guess" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" -dependencies = [ - "mime", - "unicase", -] - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "new_debug_unreachable" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" - -[[package]] -name = "normpath" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "notify" -version = "6.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" -dependencies = [ - "bitflags 2.5.0", - "crossbeam-channel", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "log", - "mio", - "walkdir", - "windows-sys 0.48.0", -] - -[[package]] -name = "notify-debouncer-mini" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d40b221972a1fc5ef4d858a2f671fb34c75983eb385463dff3780eeff6a9d43" -dependencies = [ - "crossbeam-channel", - "log", - "notify", -] - -[[package]] -name = "num-traits" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "opener" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c62dcb6174f9cb326eac248f07e955d5d559c272730b6c03e396b443b562788" -dependencies = [ - "bstr", - "normpath", - "winapi", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.5.1", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pathdiff" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pest" -version = "2.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95" -dependencies = [ - "memchr", - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73541b156d32197eecda1a4014d7f868fd2bcb3c550d5386087cfba442bf69c" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c35eeed0a3fab112f75165fdc026b3913f4183133f19b49be773ac9ea966e8bd" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "pest_meta" -version = "2.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2adbf29bb9776f28caece835398781ab24435585fe0d4dc1374a61db5accedca" -dependencies = [ - "once_cell", - "pest", - "sha2", -] - -[[package]] -name = "phf" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_codegen" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" -dependencies = [ - "phf_generator", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" -dependencies = [ - "phf_shared", - "rand", -] - -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - -[[package]] -name = "predicates" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" -dependencies = [ - "anstyle", - "difflib", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" - -[[package]] -name = "predicates-tree" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" -dependencies = [ - "predicates-core", - "termtree", -] - -[[package]] -name = "proc-macro2" -version = "1.0.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "pulldown-cmark" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" -dependencies = [ - "bitflags 2.5.0", - "getopts", - "memchr", - "pulldown-cmark-escape", - "unicase", -] - -[[package]] -name = "pulldown-cmark-escape" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" - -[[package]] -name = "pulldown-cmark-to-cmark" -version = "13.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" -dependencies = [ - "pulldown-cmark", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags 2.5.0", -] - -[[package]] -name = "regex" -version = "1.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" - -[[package]] -name = "rust-book-tools" -version = "0.0.1" -dependencies = [ - "docopt", - "flate2", - "lazy_static", - "regex", - "serde", - "tar", - "walkdir", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - -[[package]] -name = "ryu" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "serde" -version = "1.0.197" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.197" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", -] - -[[package]] -name = "serde_json" -version = "1.0.117" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_spanned" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "siphasher" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "string_cache" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" -dependencies = [ - "new_debug_unreachable", - "once_cell", - "parking_lot", - "phf_shared", - "precomputed-hash", - "serde", -] - -[[package]] -name = "string_cache_codegen" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" -dependencies = [ - "phf_generator", - "phf_shared", - "proc-macro2", - "quote", -] - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.59" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tar" -version = "0.4.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" -dependencies = [ - "filetime", - "libc", - "xattr", -] - -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - -[[package]] -name = "tendril" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" -dependencies = [ - "futf", - "mac", - "utf-8", -] - -[[package]] -name = "terminal_size" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" -dependencies = [ - "rustix", - "windows-sys 0.48.0", -] - -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - -[[package]] -name = "thiserror" -version = "1.0.60" +name = "adler" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" -dependencies = [ - "thiserror-impl", -] +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] -name = "thiserror-impl" -version = "1.0.60" +name = "aho-corasick" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", + "memchr", ] [[package]] -name = "tinyvec" -version = "1.6.0" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "tinyvec_macros" -version = "0.1.1" +name = "bitflags" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] -name = "tokio" -version = "1.37.0" +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "pin-project-lite", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "tokio-macros" -version = "2.2.0" +name = "crc32fast" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", + "cfg-if", ] [[package]] -name = "tokio-tungstenite" -version = "0.21.0" +name = "docopt" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite", + "lazy_static", + "regex", + "serde", + "strsim", ] [[package]] -name = "tokio-util" -version = "0.7.10" +name = "errno" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", + "libc", + "windows-sys", ] [[package]] -name = "toml" -version = "0.5.11" +name = "filetime" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ - "serde", + "cfg-if", + "libc", + "redox_syscall", + "windows-sys", ] [[package]] -name = "toml" -version = "0.8.12" +name = "flate2" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", + "crc32fast", + "miniz_oxide", ] [[package]] -name = "toml_datetime" -version = "0.6.5" +name = "lazy_static" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" -dependencies = [ - "serde", -] +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] -name = "toml_edit" -version = "0.22.12" +name = "libc" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", -] +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] -name = "topological-sort" -version = "0.2.2" +name = "linux-raw-sys" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] -name = "tower-service" -version = "0.3.2" +name = "memchr" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] -name = "tracing" -version = "0.1.40" +name = "miniz_oxide" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ - "log", - "pin-project-lite", - "tracing-core", + "adler", ] [[package]] -name = "tracing-core" -version = "0.1.32" +name = "proc-macro2" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "once_cell", + "unicode-ident", ] [[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - -[[package]] -name = "tungstenite" -version = "0.21.0" +name = "quote" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http 1.1.0", - "httparse", - "log", - "rand", - "sha1", - "thiserror", - "url", - "utf-8", + "proc-macro2", ] [[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "ucd-trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" - -[[package]] -name = "unicase" -version = "2.7.0" +name = "redox_syscall" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "version_check", + "bitflags 1.3.2", ] [[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - -[[package]] -name = "unicode-ident" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" - -[[package]] -name = "unicode-normalization" -version = "0.1.23" +name = "regex" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ - "tinyvec", + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", ] [[package]] -name = "unicode-width" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" - -[[package]] -name = "url" -version = "2.5.0" +name = "regex-automata" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", + "aho-corasick", + "memchr", + "regex-syntax", ] [[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - -[[package]] -name = "utf8parse" -version = "0.2.1" +name = "regex-syntax" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +name = "rust-book-tools" +version = "0.0.1" +dependencies = [ + "docopt", + "flate2", + "lazy_static", + "regex", + "serde", + "tar", + "walkdir", +] [[package]] -name = "wait-timeout" -version = "0.2.0" +name = "rustix" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ + "bitflags 2.5.0", + "errno", "libc", + "linux-raw-sys", + "windows-sys", ] [[package]] -name = "walkdir" -version = "2.5.0" +name = "same-file" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ - "same-file", "winapi-util", ] [[package]] -name = "want" -version = "0.3.1" +name = "serde" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ - "try-lock", + "serde_derive", ] [[package]] -name = "warp" -version = "0.3.7" +name = "serde_derive" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4378d202ff965b011c64817db11d5829506d3404edeadb61f190d111da3f231c" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "headers", - "http 0.2.12", - "hyper", - "log", - "mime", - "mime_guess", - "percent-encoding", - "pin-project", - "scoped-tls", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-tungstenite", - "tokio-util", - "tower-service", - "tracing", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.92" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" +name = "syn" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "bumpalo", - "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.59", - "wasm-bindgen-shared", + "unicode-ident", ] [[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" +name = "tar" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" dependencies = [ - "quote", - "wasm-bindgen-macro-support", + "filetime", + "libc", + "xattr", ] [[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" +name = "unicode-ident" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.59", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" [[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" +name = "walkdir" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] [[package]] name = "winapi" @@ -2142,46 +307,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -2190,46 +322,28 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -2242,63 +356,30 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" -[[package]] -name = "winnow" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" -dependencies = [ - "memchr", -] - [[package]] name = "xattr" version = "1.3.1" @@ -2309,9 +390,3 @@ dependencies = [ "linux-raw-sys", "rustix", ] - -[[package]] -name = "xmlparser" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" diff --git a/Cargo.toml b/Cargo.toml index 80cdfdcd65..0f04c09dda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,21 @@ [workspace] -members = ["packages/*"] -default-members = ["packages/*"] +members = ["packages/tools"] +# default-members = ["packages/tools"] resolver = "2" exclude = [ "linkchecker", # linkchecker is part of the CI workflow "listings", # these are intentionally distinct from the workspace + + # These are used as path dependencies in `rust-lang/rust` (since we are not + # publishing them to crates.io), so they cannot be part of this workspace, + # because path dependencies do not get built as a crate within the hosting + # workspace. + "packages/mdbook-trpl-listing", + "packages/mdbook-trpl-note", ] [workspace.dependencies] -assert_cmd = "2.0.14" walkdir = "2.3.1" -clap = { version = "4.5.4", features = ["derive"] } docopt = "1.1.0" mdbook = "0.4.37" pulldown-cmark = { version = "0.10.3", features = ["simd"] } diff --git a/packages/mdbook-trpl-listing/Cargo.toml b/packages/mdbook-trpl-listing/Cargo.toml index fd829ef180..2c4aaf0452 100644 --- a/packages/mdbook-trpl-listing/Cargo.toml +++ b/packages/mdbook-trpl-listing/Cargo.toml @@ -6,14 +6,14 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { workspace = true } -mdbook = { workspace = true } -pulldown-cmark = { workspace = true } -pulldown-cmark-to-cmark = { workspace = true } -serde_json = { workspace = true } +clap = { version = "4", features = ["derive"] } +mdbook = { version = "0.4", features = [] } # only need the library +pulldown-cmark = { version = "0.10", features = ["simd"] } +pulldown-cmark-to-cmark = "13" +serde_json = "1" thiserror = "1.0.60" toml = "0.8.12" xmlparser = "0.13.6" [dev-dependencies] -assert_cmd = { workspace = true } +assert_cmd = "2" diff --git a/packages/mdbook-trpl-note/Cargo.toml b/packages/mdbook-trpl-note/Cargo.toml index d2f80f9b7b..385f3b353f 100644 --- a/packages/mdbook-trpl-note/Cargo.toml +++ b/packages/mdbook-trpl-note/Cargo.toml @@ -6,11 +6,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { workspace = true } -mdbook = { workspace = true } -pulldown-cmark = { workspace = true } -pulldown-cmark-to-cmark = { workspace = true } -serde_json = { workspace = true } +clap = { version = "4", features = ["derive"] } +mdbook = { version = "0.4", features = [] } # only need the library +pulldown-cmark = { version = "0.10", features = ["simd"] } +pulldown-cmark-to-cmark = "13" +serde_json = "1" [dev-dependencies] -assert_cmd = { workspace = true } +assert_cmd = "2" From 3367ff4fa6fb41c91dc108e558042bd6257238da Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 22 May 2024 16:19:02 +0200 Subject: [PATCH 197/720] Update listings to account for `cargo new` template update Requires https://github.com/rust-lang/cargo/pull/13939. --- listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs | 2 +- listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs | 2 +- .../no-listing-01-changing-test-name/src/lib.rs | 2 +- .../output-only-02-add-one/add/add_one/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs index 7d12d9af81..b93cf3ffd9 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add(left: usize, right: usize) -> usize { +pub fn add(left: u64, right: u64) -> u64 { left + right } diff --git a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs index 67b6552c71..f83db0ed6d 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs @@ -1,5 +1,5 @@ // ANCHOR: here -pub fn add(left: usize, right: usize) -> usize { +pub fn add(left: u64, right: u64) -> u64 { left + right } diff --git a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs index 5be58b93fc..5014a76f2b 100644 --- a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add(left: usize, right: usize) -> usize { +pub fn add(left: u64, right: u64) -> u64 { left + right } diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs index 7d12d9af81..b93cf3ffd9 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add(left: usize, right: usize) -> usize { +pub fn add(left: u64, right: u64) -> u64 { left + right } From e1c1701837258ab245f2803f4a290f66f1c63a55 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 22 May 2024 16:24:17 +0200 Subject: [PATCH 198/720] Fix some whitespace at end-of-line and end-of-file --- .../ch11-writing-automated-tests/listing-11-03/src/lib.rs | 2 +- redirects/compiler-plugins.md | 2 +- redirects/documentation.md | 4 ++-- redirects/functions.md | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs index f83db0ed6d..a53a1634bc 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs @@ -12,7 +12,7 @@ mod tests { let result = add(2, 2); assert_eq!(result, 4); } - + #[test] fn another() { panic!("Make this test fail"); diff --git a/redirects/compiler-plugins.md b/redirects/compiler-plugins.md index 67187f5f6b..16e6387e4a 100644 --- a/redirects/compiler-plugins.md +++ b/redirects/compiler-plugins.md @@ -2,5 +2,5 @@ There is a new edition of the book and this is an old link. -> Compiler plugins were user-provided libraries that extended the compiler's behavior in certain ways. +> Compiler plugins were user-provided libraries that extended the compiler's behavior in certain ways. > Support for them has been removed. diff --git a/redirects/documentation.md b/redirects/documentation.md index ac7c881de1..d83ba5fbbe 100644 --- a/redirects/documentation.md +++ b/redirects/documentation.md @@ -3,7 +3,7 @@ There is a new edition of the book and this is an old link. > Documentation comments use `///` instead of `//` and support Markdown notation for formatting the text if you’d like. -> You place documentation comments just before the item they are documenting. +> You place documentation comments just before the item they are documenting. ```rust,no_run /// Adds one to the number given. @@ -23,4 +23,4 @@ pub fn add_one(x: i32) -> i32 { --- You can find the latest version of this information -[here](ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments). \ No newline at end of file +[here](ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments). diff --git a/redirects/functions.md b/redirects/functions.md index eecbfd49cd..1a8478ffe4 100644 --- a/redirects/functions.md +++ b/redirects/functions.md @@ -4,7 +4,7 @@ > Function definitions in Rust start with `fn` and have a set of parentheses after the function name. > The curly brackets tell the compiler where the function body begins and ends. -> We can call any function we’ve defined by entering its name followed by a set of parentheses. +> We can call any function we’ve defined by entering its name followed by a set of parentheses. ```rust fn main() { From e737707eb9bf04f5e2bf394a009075105abbfc9d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 07:28:17 -0600 Subject: [PATCH 199/720] infra: disable mdBook default-features for mdBook preprocessors This prevents us from pulling in `notify` accidentally, which is causing a `tidy check` issue in `rust-lang/rust` because of the CC0 license on `notify`. I had intended to address this in efd315a3, but forgot that `features = []` does not imply `default-features = false`. --- packages/mdbook-trpl-listing/Cargo.toml | 2 +- packages/mdbook-trpl-note/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mdbook-trpl-listing/Cargo.toml b/packages/mdbook-trpl-listing/Cargo.toml index 2c4aaf0452..4cf009b3f2 100644 --- a/packages/mdbook-trpl-listing/Cargo.toml +++ b/packages/mdbook-trpl-listing/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] clap = { version = "4", features = ["derive"] } -mdbook = { version = "0.4", features = [] } # only need the library +mdbook = { version = "0.4", default-features = false } # only need the library pulldown-cmark = { version = "0.10", features = ["simd"] } pulldown-cmark-to-cmark = "13" serde_json = "1" diff --git a/packages/mdbook-trpl-note/Cargo.toml b/packages/mdbook-trpl-note/Cargo.toml index 385f3b353f..e8dc53cc4c 100644 --- a/packages/mdbook-trpl-note/Cargo.toml +++ b/packages/mdbook-trpl-note/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] clap = { version = "4", features = ["derive"] } -mdbook = { version = "0.4", features = [] } # only need the library +mdbook = { version = "0.4", default-features = false } # only need the library pulldown-cmark = { version = "0.10", features = ["simd"] } pulldown-cmark-to-cmark = "13" serde_json = "1" From de1c417fafdd65c387ae2181b6a9f7e3d9e5a654 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <193874+carols10cents@users.noreply.github.com> Date: Wed, 22 May 2024 14:31:25 -0400 Subject: [PATCH 200/720] Revert "Update listings to account for `cargo new` template update" --- .../ch11-writing-automated-tests/listing-11-01/src/lib.rs | 2 +- .../ch11-writing-automated-tests/listing-11-03/src/lib.rs | 4 ++-- .../no-listing-01-changing-test-name/src/lib.rs | 2 +- .../output-only-02-add-one/add/add_one/src/lib.rs | 2 +- redirects/compiler-plugins.md | 2 +- redirects/documentation.md | 4 ++-- redirects/functions.md | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs index b93cf3ffd9..7d12d9af81 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add(left: u64, right: u64) -> u64 { +pub fn add(left: usize, right: usize) -> usize { left + right } diff --git a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs index a53a1634bc..67b6552c71 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs @@ -1,5 +1,5 @@ // ANCHOR: here -pub fn add(left: u64, right: u64) -> u64 { +pub fn add(left: usize, right: usize) -> usize { left + right } @@ -12,7 +12,7 @@ mod tests { let result = add(2, 2); assert_eq!(result, 4); } - + #[test] fn another() { panic!("Make this test fail"); diff --git a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs index 5014a76f2b..5be58b93fc 100644 --- a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add(left: u64, right: u64) -> u64 { +pub fn add(left: usize, right: usize) -> usize { left + right } diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs index b93cf3ffd9..7d12d9af81 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add(left: u64, right: u64) -> u64 { +pub fn add(left: usize, right: usize) -> usize { left + right } diff --git a/redirects/compiler-plugins.md b/redirects/compiler-plugins.md index 16e6387e4a..67187f5f6b 100644 --- a/redirects/compiler-plugins.md +++ b/redirects/compiler-plugins.md @@ -2,5 +2,5 @@ There is a new edition of the book and this is an old link. -> Compiler plugins were user-provided libraries that extended the compiler's behavior in certain ways. +> Compiler plugins were user-provided libraries that extended the compiler's behavior in certain ways. > Support for them has been removed. diff --git a/redirects/documentation.md b/redirects/documentation.md index d83ba5fbbe..ac7c881de1 100644 --- a/redirects/documentation.md +++ b/redirects/documentation.md @@ -3,7 +3,7 @@ There is a new edition of the book and this is an old link. > Documentation comments use `///` instead of `//` and support Markdown notation for formatting the text if you’d like. -> You place documentation comments just before the item they are documenting. +> You place documentation comments just before the item they are documenting. ```rust,no_run /// Adds one to the number given. @@ -23,4 +23,4 @@ pub fn add_one(x: i32) -> i32 { --- You can find the latest version of this information -[here](ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments). +[here](ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments). \ No newline at end of file diff --git a/redirects/functions.md b/redirects/functions.md index 1a8478ffe4..eecbfd49cd 100644 --- a/redirects/functions.md +++ b/redirects/functions.md @@ -4,7 +4,7 @@ > Function definitions in Rust start with `fn` and have a set of parentheses after the function name. > The curly brackets tell the compiler where the function body begins and ends. -> We can call any function we’ve defined by entering its name followed by a set of parentheses. +> We can call any function we’ve defined by entering its name followed by a set of parentheses. ```rust fn main() { From a22a6b42b1b38a24b3ef9a76627de098aef01af0 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 22 May 2024 13:31:56 -0400 Subject: [PATCH 201/720] Exclude tmp dir from the workspace This is where the tools/update-rustc.sh script builds listings for the purposes of updating commands' output. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 0f04c09dda..5c675ad926 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ resolver = "2" exclude = [ "linkchecker", # linkchecker is part of the CI workflow "listings", # these are intentionally distinct from the workspace + "tmp", # listings are built here when updating output via tools/update-rustc.sh # These are used as path dependencies in `rust-lang/rust` (since we are not # publishing them to crates.io), so they cannot be part of this workspace, From 1e09221e313a9d267291380995fc7dffc70805a3 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 22 May 2024 13:33:10 -0400 Subject: [PATCH 202/720] Update to Rust 1.77.2 --- .github/workflows/main.yml | 4 ++-- .../listing-02-04/output.txt | 2 +- .../no-listing-04-cant-use-after-move/output.txt | 6 +++--- .../no-listing-19-slice-error/output.txt | 4 ++-- .../no-listing-10-non-exhaustive-match/output.txt | 4 ++-- .../listing-10-16/output.txt | 4 ++-- .../listing-10-23/output.txt | 2 +- .../listing-11-03/output.txt | 2 +- .../no-listing-09-guess-with-panic-msg-bug/output.txt | 2 +- .../output-only-01-comparing-to-reference/output.txt | 10 ---------- .../ch16-fearless-concurrency/listing-16-09/output.txt | 4 ++-- .../ch16-fearless-concurrency/listing-16-14/output.txt | 4 ++-- .../ch19-advanced-features/listing-19-20/output.txt | 2 +- .../output-only-01-missing-unsafe/output.txt | 2 +- listings/ch20-web-server/listing-20-22/output.txt | 2 +- .../no-listing-04-update-worker-definition/output.txt | 2 +- rust-toolchain | 2 +- src/title-page.md | 2 +- 18 files changed, 25 insertions(+), 35 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8271cfef38..fc99b5cc03 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.76 -c rust-docs - rustup default 1.76 + rustup toolchain install 1.77 -c rust-docs + rustup default 1.77 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 9ae3a32d0c..7066a958d4 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,7 +18,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/cmp.rs:814:8 + --> /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/cmp.rs:815: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/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt index 8f9e017980..73e6115d68 100644 --- a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt @@ -1,15 +1,15 @@ $ cargo run Compiling ownership v0.1.0 (file:///projects/ownership) error[E0382]: borrow of moved value: `s1` - --> src/main.rs:5:28 + --> src/main.rs:5:15 | 2 | let s1 = String::from("hello"); | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait 3 | let s2 = s1; | -- value moved here 4 | -5 | println!("{}, world!", s1); - | ^^ value borrowed here after move +5 | println!("{s1}, world!"); + | ^^^^ value borrowed here after move | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider cloning the value if the performance cost is acceptable diff --git a/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt b/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt index be05d65283..c29ddf5bf0 100644 --- a/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt @@ -9,8 +9,8 @@ error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immuta 18 | s.clear(); // error! | ^^^^^^^^^ mutable borrow occurs here 19 | -20 | println!("the first word is: {}", word); - | ---- immutable borrow later used here +20 | println!("the first word is: {word}"); + | ------ immutable borrow later used here For more information about this error, try `rustc --explain E0502`. error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 4ec05abf05..28dc77e9e6 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/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/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:570:1 - ::: /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:574:5 + --> /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:570:1 + ::: /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:574:5 | = note: not covered = note: the matched value is of type `Option` diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt index 6afb5b0c2a..5c44142262 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt @@ -10,8 +10,8 @@ error[E0597]: `x` does not live long enough 7 | } | - `x` dropped here while still borrowed 8 | -9 | println!("r: {}", r); - | - borrow later used here +9 | println!("r: {r}"); + | --- borrow later used here For more information about this error, try `rustc --explain E0597`. error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt index 63d1668cae..cb209ab8af 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt @@ -10,7 +10,7 @@ error[E0597]: `string2` does not live long enough 7 | } | - `string2` dropped here while still borrowed 8 | println!("The longest string is {result}"); - | ------ borrow later used here + | -------- borrow later used here For more information about this error, try `rustc --explain E0597`. error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch11-writing-automated-tests/listing-11-03/output.txt b/listings/ch11-writing-automated-tests/listing-11-03/output.txt index 1947556912..4bc87b7d88 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-03/output.txt @@ -10,7 +10,7 @@ test tests::exploration ... ok failures: ---- tests::another stdout ---- -thread 'tests::another' panicked at src/lib.rs:10:9: +thread 'tests::another' panicked at src/lib.rs:17:9: Make this test fail note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt index 6e80336e5e..96ed0041e7 100644 --- a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt @@ -9,7 +9,7 @@ test tests::greater_than_100 - should panic ... FAILED failures: ---- tests::greater_than_100 stdout ---- -thread 'tests::greater_than_100' panicked at src/lib.rs:13:13: +thread 'tests::greater_than_100' panicked at src/lib.rs:12:13: Guess value must be greater than or equal to 1, got 200. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace note: panic did not contain expected string diff --git a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt index c7ed502b27..d1eccd2b22 100644 --- a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt +++ b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt @@ -7,16 +7,6 @@ error[E0277]: can't compare `{integer}` with `&{integer}` | ^^^^^^^^^^^^^^^^ no implementation for `{integer} == &{integer}` | = help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}` - = help: the following other types implement trait `PartialEq`: - isize - i8 - i16 - i32 - i64 - i128 - usize - u8 - and 6 others = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. diff --git a/listings/ch16-fearless-concurrency/listing-16-09/output.txt b/listings/ch16-fearless-concurrency/listing-16-09/output.txt index d521ebbb4b..ed4797f165 100644 --- a/listings/ch16-fearless-concurrency/listing-16-09/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-09/output.txt @@ -1,14 +1,14 @@ $ cargo run Compiling message-passing v0.1.0 (file:///projects/message-passing) error[E0382]: borrow of moved value: `val` - --> src/main.rs:10:31 + --> src/main.rs:10:26 | 8 | let val = String::from("hi"); | --- move occurs because `val` has type `String`, which does not implement the `Copy` trait 9 | tx.send(val).unwrap(); | --- value moved here 10 | println!("val is {val}"); - | ^^^ value borrowed here after move + | ^^^^^ value borrowed here after move | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider cloning the value if the performance cost is acceptable diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index 504826c1b8..d6f39b640c 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -15,14 +15,14 @@ error[E0277]: `Rc>` cannot be sent between threads safely 15 | | }); | |_________^ `Rc>` cannot be sent between threads safely | - = help: within `{closure@src/main.rs:11:36: 11:43}`, the trait `Send` is not implemented for `Rc>` + = help: within `{closure@src/main.rs:11:36: 11:43}`, the trait `Send` is not implemented for `Rc>`, which is required by `{closure@src/main.rs:11:36: 11:43}: Send` note: required because it's used within this closure --> src/main.rs:11:36 | 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` - --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:678:1 + --> /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/thread/mod.rs:678: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/listings/ch19-advanced-features/listing-19-20/output.txt b/listings/ch19-advanced-features/listing-19-20/output.txt index 3cb5961a1a..0e78ae2d9f 100644 --- a/listings/ch19-advanced-features/listing-19-20/output.txt +++ b/listings/ch19-advanced-features/listing-19-20/output.txt @@ -7,7 +7,7 @@ error[E0790]: cannot call associated function on trait without specifying the co | ------------------------- `Animal::baby_name` defined here ... 20 | println!("A baby dog is called a {}", Animal::baby_name()); - | ^^^^^^^^^^^^^^^^^ cannot call associated function of trait + | ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait | help: use the fully-qualified path to the only available implementation | diff --git a/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt b/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt index b2ed043a10..b14994cdd1 100644 --- a/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt +++ b/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling unsafe-example v0.1.0 (file:///projects/unsafe-example) -error[E0133]: call to unsafe function is unsafe and requires unsafe function or block +error[E0133]: call to unsafe function `dangerous` is unsafe and requires unsafe function or block --> src/main.rs:4:5 | 4 | dangerous(); diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 35588617dd..6928e31017 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/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/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:1649:17 + --> /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/thread/mod.rs:1649: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/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 4a622de7f9..d72e7b497b 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/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/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:1649:5 + --> /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/thread/mod.rs:1649: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/rust-toolchain b/rust-toolchain index 9242d8e7ab..3245dca3d0 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.76 +1.77 diff --git a/src/title-page.md b/src/title-page.md index 19f2fc8de3..de810b97c2 100644 --- a/src/title-page.md +++ b/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.76.0 (released 2024-02-08) +This version of the text assumes you’re using Rust 1.77.2 (released 2024-04-09) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 3d8402b65033443c364fc52b7173f9dc4cb47c99 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 22 May 2024 13:37:24 -0400 Subject: [PATCH 203/720] Rename deprecated .cargo/config to .cargo/config.toml --- .cargo/{config => config.toml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .cargo/{config => config.toml} (100%) diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml From 5fd055e6fb9bc20a647a85009122618b7ee5da86 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 22 May 2024 14:12:57 -0400 Subject: [PATCH 204/720] Update to Rust 1.78.0 --- .github/workflows/main.yml | 4 ++-- .../listing-02-04/output.txt | 2 +- .../no-listing-01-cargo-new/output.txt | 2 +- .../no-listing-02-without-expect/output.txt | 2 +- .../listing-03-02/output.txt | 2 +- .../listing-03-04/output.txt | 2 +- .../no-listing-02-adding-mut/output.txt | 2 +- .../no-listing-03-shadowing/output.txt | 2 +- .../output.txt | 6 ------ .../no-listing-16-functions/output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../no-listing-26-if-true/output.txt | 2 +- .../no-listing-27-if-false/output.txt | 2 +- .../no-listing-30-else-if/output.txt | 2 +- .../no-listing-32-5-loop-labels/output.txt | 2 +- .../output.txt | 11 ++++++++-- .../listing-05-08/output.txt | 2 +- .../listing-05-12/output.txt | 2 +- .../no-listing-05-dbg-macro/output.txt | 2 +- .../output-only-02-pretty-debug/output.txt | 2 +- .../output.txt | 4 ++-- .../quick-reference-example/output.txt | 2 +- .../listing-08-19/output.txt | 18 ++++++++--------- .../output.txt | 2 +- .../listing-09-01/output.txt | 2 +- .../listing-09-04/output.txt | 2 +- .../no-listing-01-panic/output.txt | 2 +- .../listing-10-20/output.txt | 20 ++++++++++++++++++- .../listing-11-01/output.txt | 2 +- .../listing-11-03/output.txt | 2 +- .../listing-11-06/output.txt | 2 +- .../listing-11-07/output.txt | 2 +- .../listing-11-08/output.txt | 2 +- .../listing-11-10/output.txt | 2 +- .../listing-11-11/output.txt | 2 +- .../listing-11-13/output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../output.txt | 2 +- .../no-listing-04-bug-in-add-two/output.txt | 2 +- .../no-listing-06-greeter-with-bug/output.txt | 2 +- .../output.txt | 2 +- .../no-listing-08-guess-with-bug/output.txt | 2 +- .../output.txt | 2 +- .../no-listing-11-ignore-a-test/output.txt | 2 +- .../output.txt | 2 +- .../output-only-01-show-output/output.txt | 2 +- .../output-only-02-single-test/output.txt | 2 +- .../output-only-03-multiple-tests/output.txt | 2 +- .../output-only-04-running-ignored/output.txt | 2 +- .../output.txt | 2 +- .../listing-12-01/output.txt | 2 +- .../listing-12-02/output.txt | 2 +- .../listing-12-04/output.txt | 2 +- .../listing-12-07/output.txt | 2 +- .../listing-12-08/output.txt | 2 +- .../listing-12-10/output.txt | 2 +- .../listing-12-12/output.txt | 2 +- .../listing-12-16/output.txt | 2 +- .../listing-12-19/output.txt | 2 +- .../listing-12-21/output.txt | 2 +- .../listing-12-23/output.txt | 2 +- .../output.txt | 2 +- .../output-only-01-with-args/output.txt | 2 +- .../output.txt | 2 +- .../output-only-04-no-matches/output.txt | 2 +- .../listing-13-01/output.txt | 2 +- .../listing-13-04/output.txt | 2 +- .../listing-13-05/output.txt | 2 +- .../listing-13-07/output.txt | 2 +- .../listing-13-14/output.txt | 2 +- .../listing-15-03/output.txt | 15 ++++++++++++-- .../listing-15-14/output.txt | 2 +- .../listing-15-16/output.txt | 2 +- .../listing-15-19/output.txt | 2 +- .../listing-15-23/output.txt | 2 +- .../listing-15-24/output.txt | 2 +- .../listing-15-26/output.txt | 2 +- .../listing-16-14/output.txt | 2 +- .../listing-18-03/output.txt | 2 +- .../listing-18-10/output.txt | 2 +- .../listing-19-18/output.txt | 2 +- .../listing-19-19/output.txt | 2 +- .../listing-19-21/output.txt | 2 +- .../output.txt | 18 ++++++++++++++++- .../ch20-web-server/listing-20-22/output.txt | 2 +- .../no-listing-03-define-execute/output.txt | 2 +- .../output.txt | 2 +- rust-toolchain | 2 +- src/title-page.md | 2 +- 92 files changed, 154 insertions(+), 110 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc99b5cc03..69ec7ef21c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.77 -c rust-docs - rustup default 1.77 + rustup toolchain install 1.78 -c rust-docs + rustup default 1.78 - name: Install mdbook run: | mkdir bin diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 7066a958d4..4a36350c20 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,7 +18,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/cmp.rs:815:8 + --> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/cmp.rs:836: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/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt index 2724c145d3..33409e38cf 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 1.50s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.50s Running `target/debug/guessing_game` Hello, world! diff --git a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt index c7ce1c5256..417d4e3cb9 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt @@ -14,4 +14,4 @@ help: use `let _ = ...` to ignore the resulting value | +++++++ warning: `guessing_game` (bin "guessing_game") generated 1 warning - Finished dev [unoptimized + debuginfo] target(s) in 0.59s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.59s diff --git a/listings/ch03-common-programming-concepts/listing-03-02/output.txt b/listings/ch03-common-programming-concepts/listing-03-02/output.txt index 3eb8d102a5..3b0deaec6c 100644 --- a/listings/ch03-common-programming-concepts/listing-03-02/output.txt +++ b/listings/ch03-common-programming-concepts/listing-03-02/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling branches v0.1.0 (file:///projects/branches) - Finished dev [unoptimized + debuginfo] target(s) in 0.30s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.30s Running `target/debug/branches` The value of number is: 5 diff --git a/listings/ch03-common-programming-concepts/listing-03-04/output.txt b/listings/ch03-common-programming-concepts/listing-03-04/output.txt index 35c0f804a7..82408ac823 100644 --- a/listings/ch03-common-programming-concepts/listing-03-04/output.txt +++ b/listings/ch03-common-programming-concepts/listing-03-04/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling loops v0.1.0 (file:///projects/loops) - Finished dev [unoptimized + debuginfo] target(s) in 0.32s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.32s Running `target/debug/loops` the value is: 10 the value is: 20 diff --git a/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/output.txt b/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/output.txt index 8ed6598ff1..ed0c0c3429 100644 --- a/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling variables v0.1.0 (file:///projects/variables) - Finished dev [unoptimized + debuginfo] target(s) in 0.30s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.30s Running `target/debug/variables` The value of x is: 5 The value of x is: 6 diff --git a/listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt b/listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt index f310e9ffa2..6ff531b559 100644 --- a/listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling variables v0.1.0 (file:///projects/variables) - Finished dev [unoptimized + debuginfo] target(s) in 0.31s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.31s Running `target/debug/variables` The value of x in the inner scope is: 12 The value of x is: 6 diff --git a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt index 2ddd39ff6e..578a1f4aa5 100644 --- a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt @@ -7,12 +7,6 @@ error[E0308]: mismatched types | ----- expected due to this value 3 | spaces = spaces.len(); | ^^^^^^^^^^^^ expected `&str`, found `usize` - | -help: try removing the method call - | -3 - spaces = spaces.len(); -3 + spaces = spaces; - | For more information about this error, try `rustc --explain E0308`. error: could not compile `variables` (bin "variables") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-16-functions/output.txt b/listings/ch03-common-programming-concepts/no-listing-16-functions/output.txt index 723fad32ad..898cf5fb63 100644 --- a/listings/ch03-common-programming-concepts/no-listing-16-functions/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-16-functions/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling functions v0.1.0 (file:///projects/functions) - Finished dev [unoptimized + debuginfo] target(s) in 0.28s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.28s Running `target/debug/functions` Hello, world! Another function. diff --git a/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/output.txt b/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/output.txt index 546bbc0473..377f72886c 100644 --- a/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling functions v0.1.0 (file:///projects/functions) - Finished dev [unoptimized + debuginfo] target(s) in 1.21s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.21s Running `target/debug/functions` The value of x is: 5 diff --git a/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/output.txt b/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/output.txt index 6210234c9e..91e71c174d 100644 --- a/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling functions v0.1.0 (file:///projects/functions) - Finished dev [unoptimized + debuginfo] target(s) in 0.31s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.31s Running `target/debug/functions` The measurement is: 5h diff --git a/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/output.txt b/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/output.txt index a457e33996..e66e4b980a 100644 --- a/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling functions v0.1.0 (file:///projects/functions) - Finished dev [unoptimized + debuginfo] target(s) in 0.30s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.30s Running `target/debug/functions` The value of x is: 5 diff --git a/listings/ch03-common-programming-concepts/no-listing-26-if-true/output.txt b/listings/ch03-common-programming-concepts/no-listing-26-if-true/output.txt index 3d8c7dc333..d39b3b5fcb 100644 --- a/listings/ch03-common-programming-concepts/no-listing-26-if-true/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-26-if-true/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling branches v0.1.0 (file:///projects/branches) - Finished dev [unoptimized + debuginfo] target(s) in 0.31s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.31s Running `target/debug/branches` condition was true diff --git a/listings/ch03-common-programming-concepts/no-listing-27-if-false/output.txt b/listings/ch03-common-programming-concepts/no-listing-27-if-false/output.txt index e40da961c9..3aa1e1c054 100644 --- a/listings/ch03-common-programming-concepts/no-listing-27-if-false/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-27-if-false/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling branches v0.1.0 (file:///projects/branches) - Finished dev [unoptimized + debuginfo] target(s) in 0.31s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.31s Running `target/debug/branches` condition was false diff --git a/listings/ch03-common-programming-concepts/no-listing-30-else-if/output.txt b/listings/ch03-common-programming-concepts/no-listing-30-else-if/output.txt index b218941ad0..d5195248a9 100644 --- a/listings/ch03-common-programming-concepts/no-listing-30-else-if/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-30-else-if/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling branches v0.1.0 (file:///projects/branches) - Finished dev [unoptimized + debuginfo] target(s) in 0.31s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.31s Running `target/debug/branches` number is divisible by 3 diff --git a/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt index d4d322fb49..4977b2b34d 100644 --- a/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling loops v0.1.0 (file:///projects/loops) - Finished dev [unoptimized + debuginfo] target(s) in 0.58s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.58s Running `target/debug/loops` count = 0 remaining = 10 diff --git a/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt b/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt index 70e58af8b5..0339433f26 100644 --- a/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt @@ -17,5 +17,12 @@ help: instead, you are more likely to want to return an owned value 5 + fn dangle() -> String { | -For more information about this error, try `rustc --explain E0106`. -error: could not compile `ownership` (bin "ownership") due to 1 previous error +error[E0515]: cannot return reference to local variable `s` + --> src/main.rs:8:5 + | +8 | &s + | ^^ returns a reference to data owned by the current function + +Some errors have detailed explanations: E0106, E0515. +For more information about an error, try `rustc --explain E0106`. +error: could not compile `ownership` (bin "ownership") due to 2 previous errors diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-08/output.txt b/listings/ch05-using-structs-to-structure-related-data/listing-05-08/output.txt index c44b58238d..79b8307772 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-08/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-08/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling rectangles v0.1.0 (file:///projects/rectangles) - Finished dev [unoptimized + debuginfo] target(s) in 0.42s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.42s Running `target/debug/rectangles` The area of the rectangle is 1500 square pixels. diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-12/output.txt b/listings/ch05-using-structs-to-structure-related-data/listing-05-12/output.txt index c37be6b5bf..0c810b1f44 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-12/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-12/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling rectangles v0.1.0 (file:///projects/rectangles) - Finished dev [unoptimized + debuginfo] target(s) in 0.48s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s Running `target/debug/rectangles` rect1 is Rectangle { width: 30, height: 50 } diff --git a/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt b/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt index bfb88ebee6..1c1f07dfbc 100644 --- a/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling rectangles v0.1.0 (file:///projects/rectangles) - Finished dev [unoptimized + debuginfo] target(s) in 0.61s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.61s Running `target/debug/rectangles` [src/main.rs:10:16] 30 * scale = 60 [src/main.rs:14:5] &rect1 = Rectangle { diff --git a/listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/output.txt b/listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/output.txt index db6deed9b7..4a6c5a9a14 100644 --- a/listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling rectangles v0.1.0 (file:///projects/rectangles) - Finished dev [unoptimized + debuginfo] target(s) in 0.48s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s Running `target/debug/rectangles` rect1 is Rectangle { width: 30, diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 28dc77e9e6..7d9a661963 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/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/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:570:1 - ::: /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:574:5 + --> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:572:1 + ::: /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:576:5 | = note: not covered = note: the matched value is of type `Option` diff --git a/listings/ch07-managing-growing-projects/quick-reference-example/output.txt b/listings/ch07-managing-growing-projects/quick-reference-example/output.txt index e36a45eb0d..04ac6f6c03 100644 --- a/listings/ch07-managing-growing-projects/quick-reference-example/output.txt +++ b/listings/ch07-managing-growing-projects/quick-reference-example/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling backyard v0.1.0 (file:///projects/backyard) - Finished dev [unoptimized + debuginfo] target(s) in 0.36s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.36s Running `target/debug/backyard` I'm growing Asparagus! diff --git a/listings/ch08-common-collections/listing-08-19/output.txt b/listings/ch08-common-collections/listing-08-19/output.txt index de20b73edf..75d9a56f54 100644 --- a/listings/ch08-common-collections/listing-08-19/output.txt +++ b/listings/ch08-common-collections/listing-08-19/output.txt @@ -1,19 +1,17 @@ $ cargo run Compiling collections v0.1.0 (file:///projects/collections) -error[E0277]: the type `String` cannot be indexed by `{integer}` +error[E0277]: the type `str` cannot be indexed by `{integer}` --> src/main.rs:3:16 | 3 | let h = s1[0]; - | ^ `String` cannot be indexed by `{integer}` + | ^ string indices are ranges of `usize` | - = help: the trait `Index<{integer}>` is not implemented for `String` - = help: the following other types implement trait `Index`: - > - >> - >> - >> - >> - >> + = help: the trait `SliceIndex` is not implemented for `{integer}`, which is required by `String: Index<_>` + = note: you can use `.chars().nth()` or `.bytes().nth()` + for more information, see chapter 8 in The Book: + = help: the trait `SliceIndex<[_]>` is implemented for `usize` + = help: for that trait implementation, expected `[_]`, found `str` + = note: required for `String` to implement `Index<{integer}>` For more information about this error, try `rustc --explain E0277`. error: could not compile `collections` (bin "collections") due to 1 previous error diff --git a/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt b/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt index 855d6d2f6a..de65b05c07 100644 --- a/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt +++ b/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling collections v0.1.0 (file:///projects/collections) - Finished dev [unoptimized + debuginfo] target(s) in 0.43s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s Running `target/debug/collections` thread 'main' panicked at src/main.rs:4:19: byte index 1 is not a char boundary; it is inside 'З' (bytes 0..2) of `Здравствуйте` diff --git a/listings/ch09-error-handling/listing-09-01/output.txt b/listings/ch09-error-handling/listing-09-01/output.txt index 225958320c..5f4def0091 100644 --- a/listings/ch09-error-handling/listing-09-01/output.txt +++ b/listings/ch09-error-handling/listing-09-01/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling panic v0.1.0 (file:///projects/panic) - Finished dev [unoptimized + debuginfo] target(s) in 0.27s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s Running `target/debug/panic` thread 'main' panicked at src/main.rs:4:6: index out of bounds: the len is 3 but the index is 99 diff --git a/listings/ch09-error-handling/listing-09-04/output.txt b/listings/ch09-error-handling/listing-09-04/output.txt index cc135c9fa6..b36bdc05fd 100644 --- a/listings/ch09-error-handling/listing-09-04/output.txt +++ b/listings/ch09-error-handling/listing-09-04/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling error-handling v0.1.0 (file:///projects/error-handling) - Finished dev [unoptimized + debuginfo] target(s) in 0.73s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.73s Running `target/debug/error-handling` thread 'main' panicked at src/main.rs:8:23: Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" } diff --git a/listings/ch09-error-handling/no-listing-01-panic/output.txt b/listings/ch09-error-handling/no-listing-01-panic/output.txt index d90e37e30e..ced4ee7198 100644 --- a/listings/ch09-error-handling/no-listing-01-panic/output.txt +++ b/listings/ch09-error-handling/no-listing-01-panic/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling panic v0.1.0 (file:///projects/panic) - Finished dev [unoptimized + debuginfo] target(s) in 0.25s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.25s Running `target/debug/panic` thread 'main' panicked at src/main.rs:2:5: crash and burn diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt index a6783b2ccd..1af8bd5f1b 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt @@ -12,5 +12,23 @@ help: consider introducing a named lifetime parameter 9 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { | ++++ ++ ++ ++ +error: lifetime may not live long enough + --> src/main.rs:11:9 + | +9 | fn longest(x: &str, y: &str) -> &str { + | - let's call the lifetime of this reference `'1` +10 | if x.len() > y.len() { +11 | x + | ^ returning this value requires that `'1` must outlive `'static` + +error: lifetime may not live long enough + --> src/main.rs:13:9 + | +9 | fn longest(x: &str, y: &str) -> &str { + | - let's call the lifetime of this reference `'2` +... +13 | y + | ^ returning this value requires that `'2` must outlive `'static` + For more information about this error, try `rustc --explain E0106`. -error: could not compile `chapter10` (bin "chapter10") due to 1 previous error +error: could not compile `chapter10` (bin "chapter10") due to 3 previous errors diff --git a/listings/ch11-writing-automated-tests/listing-11-01/output.txt b/listings/ch11-writing-automated-tests/listing-11-01/output.txt index c3e812ed80..128309c129 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-01/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.57s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.57s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test diff --git a/listings/ch11-writing-automated-tests/listing-11-03/output.txt b/listings/ch11-writing-automated-tests/listing-11-03/output.txt index 4bc87b7d88..cf2c206aac 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-03/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.72s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.72s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 2 tests diff --git a/listings/ch11-writing-automated-tests/listing-11-06/output.txt b/listings/ch11-writing-automated-tests/listing-11-06/output.txt index dad02b460f..e03add2290 100644 --- a/listings/ch11-writing-automated-tests/listing-11-06/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-06/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling rectangle v0.1.0 (file:///projects/rectangle) - Finished test [unoptimized + debuginfo] target(s) in 0.66s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s Running unittests src/lib.rs (target/debug/deps/rectangle-6584c4561e48942e) running 1 test diff --git a/listings/ch11-writing-automated-tests/listing-11-07/output.txt b/listings/ch11-writing-automated-tests/listing-11-07/output.txt index fa02835bdc..908ed572c6 100644 --- a/listings/ch11-writing-automated-tests/listing-11-07/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-07/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.58s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.58s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test diff --git a/listings/ch11-writing-automated-tests/listing-11-08/output.txt b/listings/ch11-writing-automated-tests/listing-11-08/output.txt index caca1542f8..a5a764377d 100644 --- a/listings/ch11-writing-automated-tests/listing-11-08/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-08/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished test [unoptimized + debuginfo] target(s) in 0.58s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.58s Running unittests src/lib.rs (target/debug/deps/guessing_game-57d70c3acb738f4d) running 1 test diff --git a/listings/ch11-writing-automated-tests/listing-11-10/output.txt b/listings/ch11-writing-automated-tests/listing-11-10/output.txt index 7a2b200ac2..36fae57883 100644 --- a/listings/ch11-writing-automated-tests/listing-11-10/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-10/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling silly-function v0.1.0 (file:///projects/silly-function) - Finished test [unoptimized + debuginfo] target(s) in 0.58s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.58s Running unittests src/lib.rs (target/debug/deps/silly_function-160869f38cff9166) running 2 tests diff --git a/listings/ch11-writing-automated-tests/listing-11-11/output.txt b/listings/ch11-writing-automated-tests/listing-11-11/output.txt index fe19c83c4b..a0fe55df11 100644 --- a/listings/ch11-writing-automated-tests/listing-11-11/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-11/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.62s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.62s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 3 tests diff --git a/listings/ch11-writing-automated-tests/listing-11-13/output.txt b/listings/ch11-writing-automated-tests/listing-11-13/output.txt index 22970e9e16..84344add72 100644 --- a/listings/ch11-writing-automated-tests/listing-11-13/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-13/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 1.31s + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.31s Running unittests src/lib.rs (target/debug/deps/adder-1082c4b063a8fbe6) running 1 test diff --git a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/output.txt b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/output.txt index 8a3330844b..79d3ae25ce 100644 --- a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.59s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.59s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test diff --git a/listings/ch11-writing-automated-tests/no-listing-02-adding-another-rectangle-test/output.txt b/listings/ch11-writing-automated-tests/no-listing-02-adding-another-rectangle-test/output.txt index 30e45e5259..63044036d1 100644 --- a/listings/ch11-writing-automated-tests/no-listing-02-adding-another-rectangle-test/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-02-adding-another-rectangle-test/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling rectangle v0.1.0 (file:///projects/rectangle) - Finished test [unoptimized + debuginfo] target(s) in 0.66s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s Running unittests src/lib.rs (target/debug/deps/rectangle-6584c4561e48942e) running 2 tests diff --git a/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt index 6e3061b9c3..6d616db377 100644 --- a/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling rectangle v0.1.0 (file:///projects/rectangle) - Finished test [unoptimized + debuginfo] target(s) in 0.66s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s Running unittests src/lib.rs (target/debug/deps/rectangle-6584c4561e48942e) running 2 tests diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt index 102479df6e..5e91c58b4d 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.61s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.61s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test diff --git a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt index bbd42d04dc..0a7d44dce8 100644 --- a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling greeter v0.1.0 (file:///projects/greeter) - Finished test [unoptimized + debuginfo] target(s) in 0.91s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.91s Running unittests src/lib.rs (target/debug/deps/greeter-170b942eb5bf5e3a) running 1 test diff --git a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt index e6cc739c41..d2015d56b2 100644 --- a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling greeter v0.1.0 (file:///projects/greeter) - Finished test [unoptimized + debuginfo] target(s) in 0.93s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.93s Running unittests src/lib.rs (target/debug/deps/greeter-170b942eb5bf5e3a) running 1 test diff --git a/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/output.txt index 9318d4ce0d..9b7ec43f79 100644 --- a/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-08-guess-with-bug/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished test [unoptimized + debuginfo] target(s) in 0.62s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.62s Running unittests src/lib.rs (target/debug/deps/guessing_game-57d70c3acb738f4d) running 1 test diff --git a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt index 96ed0041e7..f30b55ab18 100644 --- a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished test [unoptimized + debuginfo] target(s) in 0.66s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s Running unittests src/lib.rs (target/debug/deps/guessing_game-57d70c3acb738f4d) running 1 test diff --git a/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt b/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt index c559de8d00..8d700c7cd9 100644 --- a/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.60s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.60s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 2 tests diff --git a/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/output.txt b/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/output.txt index 324d566abd..e258394593 100644 --- a/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.89s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.89s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test diff --git a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt index b8aae1fae1..58f1ff4a51 100644 --- a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt @@ -1,6 +1,6 @@ $ cargo test -- --show-output Compiling silly-function v0.1.0 (file:///projects/silly-function) - Finished test [unoptimized + debuginfo] target(s) in 0.60s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.60s Running unittests src/lib.rs (target/debug/deps/silly_function-160869f38cff9166) running 2 tests diff --git a/listings/ch11-writing-automated-tests/output-only-02-single-test/output.txt b/listings/ch11-writing-automated-tests/output-only-02-single-test/output.txt index f2da984427..47e2a478e6 100644 --- a/listings/ch11-writing-automated-tests/output-only-02-single-test/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-02-single-test/output.txt @@ -1,6 +1,6 @@ $ cargo test one_hundred Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.69s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.69s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test diff --git a/listings/ch11-writing-automated-tests/output-only-03-multiple-tests/output.txt b/listings/ch11-writing-automated-tests/output-only-03-multiple-tests/output.txt index 255a051b51..d08940aeed 100644 --- a/listings/ch11-writing-automated-tests/output-only-03-multiple-tests/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-03-multiple-tests/output.txt @@ -1,6 +1,6 @@ $ cargo test add Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.61s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.61s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 2 tests diff --git a/listings/ch11-writing-automated-tests/output-only-04-running-ignored/output.txt b/listings/ch11-writing-automated-tests/output-only-04-running-ignored/output.txt index b37868d3db..4c7782d074 100644 --- a/listings/ch11-writing-automated-tests/output-only-04-running-ignored/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-04-running-ignored/output.txt @@ -1,6 +1,6 @@ $ cargo test -- --ignored Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.61s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.61s Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test diff --git a/listings/ch11-writing-automated-tests/output-only-05-single-integration/output.txt b/listings/ch11-writing-automated-tests/output-only-05-single-integration/output.txt index 260beaa2d6..2745d0f81a 100644 --- a/listings/ch11-writing-automated-tests/output-only-05-single-integration/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-05-single-integration/output.txt @@ -1,6 +1,6 @@ $ cargo test --test integration_test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.64s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.64s Running tests/integration_test.rs (target/debug/deps/integration_test-82e7799c1bc62298) running 1 test diff --git a/listings/ch12-an-io-project/listing-12-01/output.txt b/listings/ch12-an-io-project/listing-12-01/output.txt index 7017af1ab9..d2abb056be 100644 --- a/listings/ch12-an-io-project/listing-12-01/output.txt +++ b/listings/ch12-an-io-project/listing-12-01/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.61s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.61s Running `target/debug/minigrep` [src/main.rs:5:5] args = [ "target/debug/minigrep", diff --git a/listings/ch12-an-io-project/listing-12-02/output.txt b/listings/ch12-an-io-project/listing-12-02/output.txt index 6ef87f7ce0..ad87dcf06d 100644 --- a/listings/ch12-an-io-project/listing-12-02/output.txt +++ b/listings/ch12-an-io-project/listing-12-02/output.txt @@ -1,6 +1,6 @@ $ cargo run -- test sample.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep test sample.txt` Searching for test In file sample.txt diff --git a/listings/ch12-an-io-project/listing-12-04/output.txt b/listings/ch12-an-io-project/listing-12-04/output.txt index 6582ca1693..d8cfe392df 100644 --- a/listings/ch12-an-io-project/listing-12-04/output.txt +++ b/listings/ch12-an-io-project/listing-12-04/output.txt @@ -1,6 +1,6 @@ $ cargo run -- the poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep the poem.txt` Searching for the In file poem.txt diff --git a/listings/ch12-an-io-project/listing-12-07/output.txt b/listings/ch12-an-io-project/listing-12-07/output.txt index 94666c8700..e14b954de6 100644 --- a/listings/ch12-an-io-project/listing-12-07/output.txt +++ b/listings/ch12-an-io-project/listing-12-07/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep` thread 'main' panicked at src/main.rs:27:21: index out of bounds: the len is 1 but the index is 1 diff --git a/listings/ch12-an-io-project/listing-12-08/output.txt b/listings/ch12-an-io-project/listing-12-08/output.txt index 6d1103e4d4..c1aa1a93f9 100644 --- a/listings/ch12-an-io-project/listing-12-08/output.txt +++ b/listings/ch12-an-io-project/listing-12-08/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep` thread 'main' panicked at src/main.rs:26:13: not enough arguments diff --git a/listings/ch12-an-io-project/listing-12-10/output.txt b/listings/ch12-an-io-project/listing-12-10/output.txt index 7aad57f52d..c5e085b45e 100644 --- a/listings/ch12-an-io-project/listing-12-10/output.txt +++ b/listings/ch12-an-io-project/listing-12-10/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.48s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s Running `target/debug/minigrep` Problem parsing arguments: not enough arguments diff --git a/listings/ch12-an-io-project/listing-12-12/output.txt b/listings/ch12-an-io-project/listing-12-12/output.txt index 7cd09e8276..6c5e67ba45 100644 --- a/listings/ch12-an-io-project/listing-12-12/output.txt +++ b/listings/ch12-an-io-project/listing-12-12/output.txt @@ -14,7 +14,7 @@ help: use `let _ = ...` to ignore the resulting value | +++++++ warning: `minigrep` (bin "minigrep") generated 1 warning - Finished dev [unoptimized + debuginfo] target(s) in 0.71s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.71s Running `target/debug/minigrep the poem.txt` Searching for the In file poem.txt diff --git a/listings/ch12-an-io-project/listing-12-16/output.txt b/listings/ch12-an-io-project/listing-12-16/output.txt index 893171bc40..9f4c64d29d 100644 --- a/listings/ch12-an-io-project/listing-12-16/output.txt +++ b/listings/ch12-an-io-project/listing-12-16/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished test [unoptimized + debuginfo] target(s) in 0.97s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.97s Running unittests src/lib.rs (target/debug/deps/minigrep-9cd200e5fac0fc94) running 1 test diff --git a/listings/ch12-an-io-project/listing-12-19/output.txt b/listings/ch12-an-io-project/listing-12-19/output.txt index 9b2078cb82..ed87e4f582 100644 --- a/listings/ch12-an-io-project/listing-12-19/output.txt +++ b/listings/ch12-an-io-project/listing-12-19/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished test [unoptimized + debuginfo] target(s) in 1.22s + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.22s Running unittests src/lib.rs (target/debug/deps/minigrep-9cd200e5fac0fc94) running 1 test diff --git a/listings/ch12-an-io-project/listing-12-21/output.txt b/listings/ch12-an-io-project/listing-12-21/output.txt index dafeb7862c..945df3fd52 100644 --- a/listings/ch12-an-io-project/listing-12-21/output.txt +++ b/listings/ch12-an-io-project/listing-12-21/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished test [unoptimized + debuginfo] target(s) in 1.33s + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.33s Running unittests src/lib.rs (target/debug/deps/minigrep-9cd200e5fac0fc94) running 2 tests diff --git a/listings/ch12-an-io-project/listing-12-23/output.txt b/listings/ch12-an-io-project/listing-12-23/output.txt index eaffc2f24d..5c6fc0c53b 100644 --- a/listings/ch12-an-io-project/listing-12-23/output.txt +++ b/listings/ch12-an-io-project/listing-12-23/output.txt @@ -1,6 +1,6 @@ $ cargo run -- to poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep to poem.txt` Are you nobody, too? How dreary to be somebody! diff --git a/listings/ch12-an-io-project/no-listing-02-using-search-in-run/output.txt b/listings/ch12-an-io-project/no-listing-02-using-search-in-run/output.txt index a5a4ef8c2b..44b203620b 100644 --- a/listings/ch12-an-io-project/no-listing-02-using-search-in-run/output.txt +++ b/listings/ch12-an-io-project/no-listing-02-using-search-in-run/output.txt @@ -1,5 +1,5 @@ $ cargo run -- frog poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.38s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.38s Running `target/debug/minigrep frog poem.txt` How public, like a frog diff --git a/listings/ch12-an-io-project/output-only-01-with-args/output.txt b/listings/ch12-an-io-project/output-only-01-with-args/output.txt index ef5743967e..5f733a7dd6 100644 --- a/listings/ch12-an-io-project/output-only-01-with-args/output.txt +++ b/listings/ch12-an-io-project/output-only-01-with-args/output.txt @@ -1,6 +1,6 @@ $ cargo run -- needle haystack Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 1.57s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.57s Running `target/debug/minigrep needle haystack` [src/main.rs:5:5] args = [ "target/debug/minigrep", diff --git a/listings/ch12-an-io-project/output-only-03-multiple-matches/output.txt b/listings/ch12-an-io-project/output-only-03-multiple-matches/output.txt index b468357665..704df25909 100644 --- a/listings/ch12-an-io-project/output-only-03-multiple-matches/output.txt +++ b/listings/ch12-an-io-project/output-only-03-multiple-matches/output.txt @@ -1,6 +1,6 @@ $ cargo run -- body poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep body poem.txt` I'm nobody! Who are you? Are you nobody, too? diff --git a/listings/ch12-an-io-project/output-only-04-no-matches/output.txt b/listings/ch12-an-io-project/output-only-04-no-matches/output.txt index a53624f836..57f3a617c4 100644 --- a/listings/ch12-an-io-project/output-only-04-no-matches/output.txt +++ b/listings/ch12-an-io-project/output-only-04-no-matches/output.txt @@ -1,4 +1,4 @@ $ cargo run -- monomorphization poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep monomorphization poem.txt` diff --git a/listings/ch13-functional-features/listing-13-01/output.txt b/listings/ch13-functional-features/listing-13-01/output.txt index b64a4d8dc4..28c829f4e9 100644 --- a/listings/ch13-functional-features/listing-13-01/output.txt +++ b/listings/ch13-functional-features/listing-13-01/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling shirt-company v0.1.0 (file:///projects/shirt-company) - Finished dev [unoptimized + debuginfo] target(s) in 0.27s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s Running `target/debug/shirt-company` The user with preference Some(Red) gets Red The user with preference None gets Blue diff --git a/listings/ch13-functional-features/listing-13-04/output.txt b/listings/ch13-functional-features/listing-13-04/output.txt index 64d763b511..fd33cb71fe 100644 --- a/listings/ch13-functional-features/listing-13-04/output.txt +++ b/listings/ch13-functional-features/listing-13-04/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling closure-example v0.1.0 (file:///projects/closure-example) - Finished dev [unoptimized + debuginfo] target(s) in 0.43s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s Running `target/debug/closure-example` Before defining closure: [1, 2, 3] Before calling closure: [1, 2, 3] diff --git a/listings/ch13-functional-features/listing-13-05/output.txt b/listings/ch13-functional-features/listing-13-05/output.txt index ce0ad5e37f..af22182a18 100644 --- a/listings/ch13-functional-features/listing-13-05/output.txt +++ b/listings/ch13-functional-features/listing-13-05/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling closure-example v0.1.0 (file:///projects/closure-example) - Finished dev [unoptimized + debuginfo] target(s) in 0.43s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s Running `target/debug/closure-example` Before defining closure: [1, 2, 3] After calling closure: [1, 2, 3, 7] diff --git a/listings/ch13-functional-features/listing-13-07/output.txt b/listings/ch13-functional-features/listing-13-07/output.txt index f18fce46ed..8c11d84dc6 100644 --- a/listings/ch13-functional-features/listing-13-07/output.txt +++ b/listings/ch13-functional-features/listing-13-07/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling rectangles v0.1.0 (file:///projects/rectangles) - Finished dev [unoptimized + debuginfo] target(s) in 0.41s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.41s Running `target/debug/rectangles` [ Rectangle { diff --git a/listings/ch13-functional-features/listing-13-14/output.txt b/listings/ch13-functional-features/listing-13-14/output.txt index 53715015ed..d46dd5c421 100644 --- a/listings/ch13-functional-features/listing-13-14/output.txt +++ b/listings/ch13-functional-features/listing-13-14/output.txt @@ -14,5 +14,5 @@ help: use `let _ = ...` to ignore the resulting value | +++++++ warning: `iterators` (bin "iterators") generated 1 warning - Finished dev [unoptimized + debuginfo] target(s) in 0.47s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.47s Running `target/debug/iterators` diff --git a/listings/ch15-smart-pointers/listing-15-03/output.txt b/listings/ch15-smart-pointers/listing-15-03/output.txt index 9e54b51938..2563fb6472 100644 --- a/listings/ch15-smart-pointers/listing-15-03/output.txt +++ b/listings/ch15-smart-pointers/listing-15-03/output.txt @@ -13,5 +13,16 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle 2 | Cons(i32, Box), | ++++ + -For more information about this error, try `rustc --explain E0072`. -error: could not compile `cons-list` (bin "cons-list") due to 1 previous error +error[E0391]: cycle detected when computing when `List` needs drop + --> src/main.rs:1:1 + | +1 | enum List { + | ^^^^^^^^^ + | + = note: ...which immediately requires computing when `List` needs drop again + = note: cycle used when computing whether `List` needs drop + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +Some errors have detailed explanations: E0072, E0391. +For more information about an error, try `rustc --explain E0072`. +error: could not compile `cons-list` (bin "cons-list") due to 2 previous errors diff --git a/listings/ch15-smart-pointers/listing-15-14/output.txt b/listings/ch15-smart-pointers/listing-15-14/output.txt index 4e795949a0..1393d44b33 100644 --- a/listings/ch15-smart-pointers/listing-15-14/output.txt +++ b/listings/ch15-smart-pointers/listing-15-14/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling drop-example v0.1.0 (file:///projects/drop-example) - Finished dev [unoptimized + debuginfo] target(s) in 0.60s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.60s Running `target/debug/drop-example` CustomSmartPointers created. Dropping CustomSmartPointer with data `other stuff`! diff --git a/listings/ch15-smart-pointers/listing-15-16/output.txt b/listings/ch15-smart-pointers/listing-15-16/output.txt index e960cd89a2..f032d84b6b 100644 --- a/listings/ch15-smart-pointers/listing-15-16/output.txt +++ b/listings/ch15-smart-pointers/listing-15-16/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling drop-example v0.1.0 (file:///projects/drop-example) - Finished dev [unoptimized + debuginfo] target(s) in 0.73s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.73s Running `target/debug/drop-example` CustomSmartPointer created. Dropping CustomSmartPointer with data `some data`! diff --git a/listings/ch15-smart-pointers/listing-15-19/output.txt b/listings/ch15-smart-pointers/listing-15-19/output.txt index 6a8cc8efe1..252ccae893 100644 --- a/listings/ch15-smart-pointers/listing-15-19/output.txt +++ b/listings/ch15-smart-pointers/listing-15-19/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling cons-list v0.1.0 (file:///projects/cons-list) - Finished dev [unoptimized + debuginfo] target(s) in 0.45s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.45s Running `target/debug/cons-list` count after creating a = 1 count after creating b = 2 diff --git a/listings/ch15-smart-pointers/listing-15-23/output.txt b/listings/ch15-smart-pointers/listing-15-23/output.txt index 5ad2087ed8..d3e560297c 100644 --- a/listings/ch15-smart-pointers/listing-15-23/output.txt +++ b/listings/ch15-smart-pointers/listing-15-23/output.txt @@ -1,6 +1,6 @@ $ cargo test Compiling limit-tracker v0.1.0 (file:///projects/limit-tracker) - Finished test [unoptimized + debuginfo] target(s) in 0.91s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.91s Running unittests src/lib.rs (target/debug/deps/limit_tracker-e599811fa246dbde) running 1 test diff --git a/listings/ch15-smart-pointers/listing-15-24/output.txt b/listings/ch15-smart-pointers/listing-15-24/output.txt index 21b3530d95..bbdc588c6e 100644 --- a/listings/ch15-smart-pointers/listing-15-24/output.txt +++ b/listings/ch15-smart-pointers/listing-15-24/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling cons-list v0.1.0 (file:///projects/cons-list) - Finished dev [unoptimized + debuginfo] target(s) in 0.63s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s Running `target/debug/cons-list` a after = Cons(RefCell { value: 15 }, Nil) b after = Cons(RefCell { value: 3 }, Cons(RefCell { value: 15 }, Nil)) diff --git a/listings/ch15-smart-pointers/listing-15-26/output.txt b/listings/ch15-smart-pointers/listing-15-26/output.txt index 8b8eb40b60..b8e70e47dc 100644 --- a/listings/ch15-smart-pointers/listing-15-26/output.txt +++ b/listings/ch15-smart-pointers/listing-15-26/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling cons-list v0.1.0 (file:///projects/cons-list) - Finished dev [unoptimized + debuginfo] target(s) in 0.53s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.53s Running `target/debug/cons-list` a initial rc count = 1 a next item = Some(RefCell { value: Nil }) diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index d6f39b640c..011e662c01 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/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/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/thread/mod.rs:678:1 + --> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/thread/mod.rs:677: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/listings/ch18-patterns-and-matching/listing-18-03/output.txt b/listings/ch18-patterns-and-matching/listing-18-03/output.txt index 02fdecbf5c..9add287fa4 100644 --- a/listings/ch18-patterns-and-matching/listing-18-03/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-03/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling patterns v0.1.0 (file:///projects/patterns) - Finished dev [unoptimized + debuginfo] target(s) in 0.52s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.52s Running `target/debug/patterns` a is at index 0 b is at index 1 diff --git a/listings/ch18-patterns-and-matching/listing-18-10/output.txt b/listings/ch18-patterns-and-matching/listing-18-10/output.txt index 6488fb29ca..97bc014ec1 100644 --- a/listings/ch18-patterns-and-matching/listing-18-10/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-10/output.txt @@ -11,6 +11,6 @@ warning: irrefutable `if let` pattern = note: `#[warn(irrefutable_let_patterns)]` on by default warning: `patterns` (bin "patterns") generated 1 warning - Finished dev [unoptimized + debuginfo] target(s) in 0.39s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.39s Running `target/debug/patterns` 5 diff --git a/listings/ch19-advanced-features/listing-19-18/output.txt b/listings/ch19-advanced-features/listing-19-18/output.txt index 2e9da17d65..d7e315bfab 100644 --- a/listings/ch19-advanced-features/listing-19-18/output.txt +++ b/listings/ch19-advanced-features/listing-19-18/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) - Finished dev [unoptimized + debuginfo] target(s) in 0.46s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.46s Running `target/debug/traits-example` This is your captain speaking. Up! diff --git a/listings/ch19-advanced-features/listing-19-19/output.txt b/listings/ch19-advanced-features/listing-19-19/output.txt index 087e802b1a..b6e283f202 100644 --- a/listings/ch19-advanced-features/listing-19-19/output.txt +++ b/listings/ch19-advanced-features/listing-19-19/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) - Finished dev [unoptimized + debuginfo] target(s) in 0.54s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s Running `target/debug/traits-example` A baby dog is called a Spot diff --git a/listings/ch19-advanced-features/listing-19-21/output.txt b/listings/ch19-advanced-features/listing-19-21/output.txt index 4d1ee5ab48..f59d0bc27d 100644 --- a/listings/ch19-advanced-features/listing-19-21/output.txt +++ b/listings/ch19-advanced-features/listing-19-21/output.txt @@ -1,5 +1,5 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) - Finished dev [unoptimized + debuginfo] target(s) in 0.48s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s Running `target/debug/traits-example` A baby dog is called a puppy diff --git a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt index d5f2155f83..41af68689f 100644 --- a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt +++ b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt @@ -14,5 +14,21 @@ note: required by a bound in `OutlinePrint` 3 | trait OutlinePrint: fmt::Display { | ^^^^^^^^^^^^ required by this bound in `OutlinePrint` +error[E0277]: `Point` doesn't implement `std::fmt::Display` + --> src/main.rs:24:7 + | +24 | p.outline_print(); + | ^^^^^^^^^^^^^ `Point` cannot be formatted with the default formatter + | + = help: the trait `std::fmt::Display` is not implemented for `Point` + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead +note: required by a bound in `OutlinePrint::outline_print` + --> src/main.rs:3:21 + | +3 | trait OutlinePrint: fmt::Display { + | ^^^^^^^^^^^^ required by this bound in `OutlinePrint::outline_print` +4 | fn outline_print(&self) { + | ------------- required by a bound in this associated function + For more information about this error, try `rustc --explain E0277`. -error: could not compile `traits-example` (bin "traits-example") due to 1 previous error +error: could not compile `traits-example` (bin "traits-example") due to 2 previous errors diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 6928e31017..08a28cc323 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/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/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/thread/mod.rs:1649:17 + --> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/thread/mod.rs:1657: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/listings/ch20-web-server/no-listing-03-define-execute/output.txt b/listings/ch20-web-server/no-listing-03-define-execute/output.txt index dc76c43d6f..10d212672a 100644 --- a/listings/ch20-web-server/no-listing-03-define-execute/output.txt +++ b/listings/ch20-web-server/no-listing-03-define-execute/output.txt @@ -1,3 +1,3 @@ $ cargo check Checking hello v0.1.0 (file:///projects/hello) - Finished dev [unoptimized + debuginfo] target(s) in 0.24s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.24s diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index d72e7b497b..ed97073266 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/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/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/thread/mod.rs:1649:5 + --> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/thread/mod.rs:1657: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/rust-toolchain b/rust-toolchain index 3245dca3d0..8e95c75dac 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.77 +1.78 diff --git a/src/title-page.md b/src/title-page.md index de810b97c2..44741589bc 100644 --- a/src/title-page.md +++ b/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.77.2 (released 2024-04-09) +This version of the text assumes you’re using Rust 1.78.0 (released 2024-05-02) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 82e1e05aef26a5b5def43e8842a23f0e7f29a7de Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 22 May 2024 14:17:06 -0400 Subject: [PATCH 205/720] Suppress new cargo clean output when regenerating output --- tools/update-rustc.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/update-rustc.sh b/tools/update-rustc.sh index 45a0ce4f67..f5349164a6 100755 --- a/tools/update-rustc.sh +++ b/tools/update-rustc.sh @@ -46,7 +46,7 @@ find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do test_binary_hash=$(sed -E -ne 's@.*Running [^[:space:]]+( [^[:space:]\(\)]+)? \(target/debug/deps/[^-]*-([^\s]*)\)@\2@p' "${full_output_path}" | head -n 1) # Act like this is the first time this listing has been built - cargo clean + cargo clean > /dev/null 2>&1 # Run the command in the existing output file cargo_command=$(sed -ne 's/$ \(.*\)/\1/p' "${full_output_path}") @@ -77,7 +77,7 @@ find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do fi # Clean again - cargo clean + cargo clean > /dev/null 2>&1 cd - > /dev/null done From 1755cce5cf2ad8b069b9998ac83568fcc2736455 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 22 May 2024 14:20:38 -0400 Subject: [PATCH 206/720] Update regex to account for new cargo output format --- tools/update-rustc.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/update-rustc.sh b/tools/update-rustc.sh index f5349164a6..92d83ed29a 100755 --- a/tools/update-rustc.sh +++ b/tools/update-rustc.sh @@ -39,7 +39,7 @@ find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do # Save the previous compile time; we're going to keep it to minimize diff # churn - compile_time=$(sed -E -ne 's/.*Finished (dev|test) \[unoptimized \+ debuginfo] target\(s\) in ([0-9.]*).*/\2/p' "${full_output_path}") + compile_time=$(sed -E -ne 's/.*Finished \`(dev|test)\` profile \[unoptimized \+ debuginfo] target\(s\) in ([0-9.]*).*/\2/p' "${full_output_path}") # Save the hash from the first test binary; we're going to keep it to # minimize diff churn @@ -65,7 +65,7 @@ find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do # Restore the previous compile time, if there is one if [ -n "${compile_time}" ]; then - sed -i '' -E -e "s/Finished (dev|test) \[unoptimized \+ debuginfo] target\(s\) in [0-9.]*/Finished \1 [unoptimized + debuginfo] target(s) in ${compile_time}/" "${full_output_path}" + sed -i '' -E -e "s/Finished \`(dev|test)\` profile \[unoptimized \+ debuginfo] target\(s\) in [0-9.]*/Finished \`\1\` profile [unoptimized + debuginfo] target(s) in ${compile_time}/" "${full_output_path}" fi # Restore the previous test binary hash, if there is one From ea8cd41a842c1aa9acba1c175eff843f39cfef55 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 22 May 2024 14:45:52 -0400 Subject: [PATCH 207/720] Switch to double quotes as shellcheck suggests --- tools/update-rustc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/update-rustc.sh b/tools/update-rustc.sh index 92d83ed29a..de04b3a074 100755 --- a/tools/update-rustc.sh +++ b/tools/update-rustc.sh @@ -39,7 +39,7 @@ find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do # Save the previous compile time; we're going to keep it to minimize diff # churn - compile_time=$(sed -E -ne 's/.*Finished \`(dev|test)\` profile \[unoptimized \+ debuginfo] target\(s\) in ([0-9.]*).*/\2/p' "${full_output_path}") + compile_time=$(sed -E -ne "s/.*Finished \`(dev|test)\` profile \[unoptimized \+ debuginfo] target\(s\) in ([0-9.]*).*/\2/p" "${full_output_path}") # Save the hash from the first test binary; we're going to keep it to # minimize diff churn From 48909a19ac878d8447755b32e9c25a6fad046065 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 13:22:13 -0600 Subject: [PATCH 208/720] infra: more workspace cleanup - Turn back on `default-members`. - Remove deps from root only used by mdbook preprocessors, since they are managed by themselves now. --- Cargo.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5c675ad926..2bddb66f9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = ["packages/tools"] -# default-members = ["packages/tools"] +default-members = ["packages/tools"] resolver = "2" exclude = [ "linkchecker", # linkchecker is part of the CI workflow @@ -18,11 +18,7 @@ exclude = [ [workspace.dependencies] walkdir = "2.3.1" docopt = "1.1.0" -mdbook = "0.4.37" -pulldown-cmark = { version = "0.10.3", features = ["simd"] } -pulldown-cmark-to-cmark = "13.0.0" serde = "1.0" -serde_json = "1.0" regex = "1.3.3" lazy_static = "1.4.0" flate2 = "1.0.13" From 40993e8ec7476365d4782a6cc6d4379ecaa45844 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 15:27:00 -0600 Subject: [PATCH 209/720] infra: modernize and improve rigor/safety of ferris.js - Use `let` instead of `var` throughout. All modern browsers support it and have for many years, even the now-EOL IE11.[^ie] - Add a `@ts-check` annotation so that anyone working on a TS-enabled editor will get feedback inline about cases they may otherwise miss. - Add JSDoc-based type definitions for the script, and fix some errors that may occur at runtime. (These will be rare if they happen, but getting rid of them is still a win!) [^ie]: IE11 did not correctly support the semantics of `let` for `for` loops, but the uses in the existing code here already used `var` in a way which would trigger the same behavior as using `let` does. --- ferris.js | 61 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/ferris.js b/ferris.js index bb601a4e28..51e5b12a99 100644 --- a/ferris.js +++ b/ferris.js @@ -1,4 +1,11 @@ -var ferrisTypes = [ +// @ts-check + +/** + * @typedef {{ attr: string, title: string }} FerrisType + */ + +/** @type {Array} */ +const FERRIS_TYPES = [ { attr: 'does_not_compile', title: 'This code does not compile!' @@ -14,46 +21,74 @@ var ferrisTypes = [ ] document.addEventListener('DOMContentLoaded', () => { - for (var ferrisType of ferrisTypes) { + for (let ferrisType of FERRIS_TYPES) { attachFerrises(ferrisType) } }) +/** + * @param {FerrisType} type + */ function attachFerrises(type) { - var elements = document.getElementsByClassName(type.attr) + let elements = document.getElementsByClassName(type.attr) + + for (let codeBlock of elements) { + // Skip SVG etc.: in principle, these should never be attached to those, but + // this means if someone happens to have a browser extension which *is* + // attaching them, it will not break the code. + if (!(codeBlock instanceof HTMLElement)) { + continue + } - for (var codeBlock of elements) { - var lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length - var size = 'large' - if (lines < 4) { - size = 'small' + let lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length + + /** @type {'small' | 'large'} */ + let size = lines < 4 ? 'small' : 'large' + + let container = prepareFerrisContainer(codeBlock, size == 'small') + if (!container) { + continue } - var container = prepareFerrisContainer(codeBlock, size == 'small') container.appendChild(createFerris(type, size)) } } +/** + * @param {HTMLElement} element - Code block element to attach a Ferris to. + * @param {boolean} useButtons - Whether to attach to existing buttons. + * @returns {Element | null} - The container element to use. + */ function prepareFerrisContainer(element, useButtons) { - var foundButtons = element.parentElement.querySelector('.buttons') + let foundButtons = element.parentElement?.querySelector('.buttons') if (useButtons && foundButtons) { return foundButtons } - var div = document.createElement('div') + let div = document.createElement('div') div.classList.add('ferris-container') + if (!element.parentElement) { + console.error(`Could not install Ferris on ${element}, which is missing a parent`); + return null; + } + element.parentElement.insertBefore(div, element) return div } +/** + * @param {FerrisType} type + * @param {'small' | 'large'} size + * @returns {HTMLAnchorElement} - The generated anchor element. + */ function createFerris(type, size) { - var a = document.createElement('a') + let a = document.createElement('a') a.setAttribute('href', 'ch00-00-introduction.html#ferris') a.setAttribute('target', '_blank') - var img = document.createElement('img') + let img = document.createElement('img') img.setAttribute('src', 'img/ferris/' + type.attr + '.svg') img.setAttribute('title', type.title) img.classList.add('ferris') From f82c5caa87c62db0b01c262a945a30a29276bda2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 16:57:34 -0600 Subject: [PATCH 210/720] infra: CSS for `figcaption` to match `span.caption` --- theme/listing.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/theme/listing.css b/theme/listing.css index 9b5929c6e7..5998d39f3b 100644 --- a/theme/listing.css +++ b/theme/listing.css @@ -1,3 +1,8 @@ figure.listing { margin: 0; } + +.listing figcaption { + font-size: .8em; + font-weight: 600; +} From d9e9af10d92e32ea02c19cb3cf607aec05aca65b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 17:02:01 -0600 Subject: [PATCH 211/720] infra: use `mdbook::utils::new_cmark_parser` in preprocessors This guarantees we use the exact same config mdBook does, preventing a class of bugs where we renderer something different than the baseline output would simply because we are preprocessing. --- packages/mdbook-trpl-listing/Cargo.lock | 1170 +++++++++++++++++++++++ packages/mdbook-trpl-listing/src/lib.rs | 7 +- packages/mdbook-trpl-note/Cargo.lock | 1087 +++++++++++++++++++++ packages/mdbook-trpl-note/src/lib.rs | 42 +- 4 files changed, 2300 insertions(+), 6 deletions(-) create mode 100644 packages/mdbook-trpl-listing/Cargo.lock create mode 100644 packages/mdbook-trpl-note/Cargo.lock diff --git a/packages/mdbook-trpl-listing/Cargo.lock b/packages/mdbook-trpl-listing/Cargo.lock new file mode 100644 index 0000000000..dba6f20985 --- /dev/null +++ b/packages/mdbook-trpl-listing/Cargo.lock @@ -0,0 +1,1170 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "assert_cmd" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "cc" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.52.5", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", + "terminal_size", +] + +[[package]] +name = "clap_complete" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "dbus" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" +dependencies = [ + "libc", + "libdbus-sys", + "winapi", +] + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libdbus-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" +dependencies = [ + "cc", + "pkg-config", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "mdbook" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45a38e19bd200220ef07c892b0157ad3d2365e5b5a267ca01ad12182491eea5" +dependencies = [ + "anyhow", + "chrono", + "clap", + "clap_complete", + "env_logger", + "handlebars", + "log", + "memchr", + "once_cell", + "opener", + "pulldown-cmark", + "regex", + "serde", + "serde_json", + "shlex", + "tempfile", + "toml 0.5.11", + "topological-sort", +] + +[[package]] +name = "mdbook-trpl-listing" +version = "0.1.0" +dependencies = [ + "assert_cmd", + "clap", + "mdbook", + "pulldown-cmark", + "pulldown-cmark-to-cmark", + "serde_json", + "thiserror", + "toml 0.8.13", + "xmlparser", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opener" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8df34be653210fbe9ffaff41d3b92721c56ce82dfee58ee684f9afb5e3a90c0" +dependencies = [ + "bstr", + "dbus", + "normpath", + "windows-sys 0.52.0", +] + +[[package]] +name = "pest" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "predicates" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +dependencies = [ + "anstyle", + "difflib", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro2" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + +[[package]] +name = "pulldown-cmark-to-cmark" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.202" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.202" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +dependencies = [ + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix", + "windows-sys 0.48.0", +] + +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + +[[package]] +name = "thiserror" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-width" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "winnow" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" +dependencies = [ + "memchr", +] + +[[package]] +name = "xmlparser" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index 99b62cc0a6..af817ff212 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -2,9 +2,10 @@ use mdbook::{ book::Book, errors::Result, preprocess::{Preprocessor, PreprocessorContext}, + utils::new_cmark_parser, BookItem, }; -use pulldown_cmark::{html, Event, Parser}; +use pulldown_cmark::{html, Event}; use pulldown_cmark_to_cmark::cmark; use xmlparser::{Token, Tokenizer}; @@ -138,7 +139,7 @@ impl TryFrom<&str> for Mode { } fn rewrite_listing(src: &str, mode: Mode) -> Result { - let parser = Parser::new(src); + let parser = new_cmark_parser(src, true); struct State<'e> { current_listing: Option, @@ -339,7 +340,7 @@ impl<'a> ListingBuilder<'a> { let caption = self .caption .map(|caption_source| { - let events = Parser::new(caption_source); + let events = new_cmark_parser(caption_source, true); let mut buf = String::with_capacity(caption_source.len() * 2); html::push_html(&mut buf, events); diff --git a/packages/mdbook-trpl-note/Cargo.lock b/packages/mdbook-trpl-note/Cargo.lock new file mode 100644 index 0000000000..25a63dab12 --- /dev/null +++ b/packages/mdbook-trpl-note/Cargo.lock @@ -0,0 +1,1087 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "assert_cmd" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "cc" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.52.5", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", + "terminal_size", +] + +[[package]] +name = "clap_complete" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "dbus" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" +dependencies = [ + "libc", + "libdbus-sys", + "winapi", +] + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libdbus-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" +dependencies = [ + "cc", + "pkg-config", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "mdbook" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45a38e19bd200220ef07c892b0157ad3d2365e5b5a267ca01ad12182491eea5" +dependencies = [ + "anyhow", + "chrono", + "clap", + "clap_complete", + "env_logger", + "handlebars", + "log", + "memchr", + "once_cell", + "opener", + "pulldown-cmark", + "regex", + "serde", + "serde_json", + "shlex", + "tempfile", + "toml", + "topological-sort", +] + +[[package]] +name = "mdbook-trpl-note" +version = "1.0.0" +dependencies = [ + "assert_cmd", + "clap", + "mdbook", + "pulldown-cmark", + "pulldown-cmark-to-cmark", + "serde_json", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opener" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8df34be653210fbe9ffaff41d3b92721c56ce82dfee58ee684f9afb5e3a90c0" +dependencies = [ + "bstr", + "dbus", + "normpath", + "windows-sys 0.52.0", +] + +[[package]] +name = "pest" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "predicates" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +dependencies = [ + "anstyle", + "difflib", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro2" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + +[[package]] +name = "pulldown-cmark-to-cmark" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.202" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.202" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix", + "windows-sys 0.48.0", +] + +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + +[[package]] +name = "thiserror" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-width" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/packages/mdbook-trpl-note/src/lib.rs b/packages/mdbook-trpl-note/src/lib.rs index 774dc82b55..4b8e2fa427 100644 --- a/packages/mdbook-trpl-note/src/lib.rs +++ b/packages/mdbook-trpl-note/src/lib.rs @@ -2,11 +2,12 @@ use mdbook::{ book::Book, errors::Result, preprocess::{Preprocessor, PreprocessorContext}, + utils::new_cmark_parser, BookItem, }; use pulldown_cmark::{ Event::{self, *}, - Parser, Tag, TagEnd, + Tag, TagEnd, }; use pulldown_cmark_to_cmark::cmark; @@ -53,7 +54,7 @@ impl Preprocessor for TrplNote { } pub fn rewrite(text: &str) -> String { - let parser = Parser::new(text); + let parser = new_cmark_parser(text, true); let mut events = Vec::new(); let mut state = Default; @@ -301,8 +302,43 @@ mod tests { ); } + #[test] + fn normal_table() { + let text = "| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; + let processed = rewrite(text); + + assert_eq!( + processed, + "|Header 1|Header 2|\n|--------|--------|\n|Text 123|More 456|", + "It strips some whitespace but otherwise leaves the table intact." + ); + } + + #[test] + fn table_in_note() { + let text = "> Note: table stuff.\n\n| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; + let processed = rewrite(text); + + assert_eq!( + processed, + "\n\n
\n\nNote: table stuff.\n\n
\n\n|Header 1|Header 2|\n|--------|--------|\n|Text 123|More 456|", + "It adds the note markup but leaves the table untouched, to be rendered as Markdown." + ); + } + + #[test] + fn table_in_quote() { + let text = "> A table.\n\n| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

A table.

\n
\n\n\n
Header 1Header 2
Text 123More 456
\n", + "It renders blockquotes with nested tables as expected." + ); + } + fn render_markdown(text: &str) -> String { - let parser = Parser::new(text); + let parser = new_cmark_parser(text, true); let mut buf = String::new(); pulldown_cmark::html::push_html(&mut buf, parser); buf From e551b7fb75cf3785ca01bc994a6fdd161bd899eb Mon Sep 17 00:00:00 2001 From: Florian TREHAUT Date: Sat, 25 May 2024 00:28:25 +0700 Subject: [PATCH 212/720] fix: ch10-03 - misleading use of expect on .split --- .../listing-10-24/src/main.rs | 2 +- .../no-listing-10-lifetimes-on-methods/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-24/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-24/src/main.rs index 2937b194ca..ca3cf86d21 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-24/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-24/src/main.rs @@ -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, }; diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-10-lifetimes-on-methods/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-10-lifetimes-on-methods/src/main.rs index b8222308d1..c04ec38236 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-10-lifetimes-on-methods/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-10-lifetimes-on-methods/src/main.rs @@ -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, }; From af8e97d00ee14fa693f81b3352794a3a380fd790 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 14 Feb 2023 19:30:40 +0100 Subject: [PATCH 213/720] Fix typo in ch10-03 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "if" is misplaced. Rust definitely deterministically applies the rules 😃 --- src/ch10-03-lifetime-syntax.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index 5229ab74b3..6c93260898 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -432,11 +432,11 @@ The patterns programmed into Rust’s analysis of references are called the a set of particular cases that the compiler will consider, and if your code fits these cases, you don’t need to write the lifetimes explicitly. -The elision rules don’t provide full inference. If Rust deterministically -applies the rules but there is still ambiguity as to what lifetimes the -references have, the compiler won’t guess what the lifetime of the remaining -references should be. Instead of guessing, the compiler will give you an error -that you can resolve by adding the lifetime annotations. +The elision rules don’t provide full inference. If there is still ambiguity as +to what lifetimes the references have after Rust applies the rules, the +compiler won’t guess what the lifetime of the remaining references should be. +Instead of guessing, the compiler will give you an error that you can resolve +by adding the lifetime annotations. Lifetimes on function or method parameters are called *input lifetimes*, and lifetimes on return values are called *output lifetimes*. From 3398f72a6af6b327bb86e8c59a341cda4efad081 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 27 May 2024 15:27:12 -0600 Subject: [PATCH 214/720] infra: Fix clippy warning in remove_markup --- packages/tools/src/bin/remove_markup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tools/src/bin/remove_markup.rs b/packages/tools/src/bin/remove_markup.rs index cda6ebaa3b..6ec0fdfb90 100644 --- a/packages/tools/src/bin/remove_markup.rs +++ b/packages/tools/src/bin/remove_markup.rs @@ -26,7 +26,7 @@ fn remove_markup(input: String) -> String { let caption_start_regex = Regex::new(r#"\A(.*)\z"#).unwrap(); let caption_end_regex = Regex::new(r#"(.*)\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() From 60993ce66ff33b57d3ff84b24201db3fa06b59a9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 27 May 2024 15:16:24 -0600 Subject: [PATCH 215/720] infra: correctly support preprocessors for nostarch - Update the `tools/nostarch` script to `cargo install` each of the preprocessors so they are always available to run and do not require any manual intervention. - Add support for `"markdown"` renderer in the preprocessors. --- packages/mdbook-trpl-listing/src/lib.rs | 2 +- packages/mdbook-trpl-note/src/lib.rs | 2 +- tools/nostarch.sh | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index af817ff212..59d338fe56 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -98,7 +98,7 @@ impl Preprocessor for TrplListing { } fn supports_renderer(&self, renderer: &str) -> bool { - renderer == "html" + renderer == "html" || renderer == "markdown" } } diff --git a/packages/mdbook-trpl-note/src/lib.rs b/packages/mdbook-trpl-note/src/lib.rs index 4b8e2fa427..1508a566ed 100644 --- a/packages/mdbook-trpl-note/src/lib.rs +++ b/packages/mdbook-trpl-note/src/lib.rs @@ -49,7 +49,7 @@ impl Preprocessor for TrplNote { } fn supports_renderer(&self, renderer: &str) -> bool { - renderer == "html" + renderer == "html" || renderer == "markdown" } } diff --git a/tools/nostarch.sh b/tools/nostarch.sh index 430b0809a3..a9dd12d4d3 100755 --- a/tools/nostarch.sh +++ b/tools/nostarch.sh @@ -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 From b4725f95a8678a77b452400c2606e8a8c7554ce4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 27 May 2024 15:16:24 -0600 Subject: [PATCH 216/720] Use `` instead of `` This has some reasonably nice built-in presentation in modern browsers, and may also yield a small accessibility improvement. Fixes #3929 --- src/ch02-00-guessing-game-tutorial.md | 23 ++++++++++---------- src/ch03-05-control-flow.md | 13 +++++------ src/ch20-01-single-threaded.md | 8 +++---- src/ch20-03-graceful-shutdown-and-cleanup.md | 8 +++---- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index f80ad52082..5aebefdd98 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -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 -enter to satisfy `read_line` and input their -guess, which adds a newline character to the string. For example, if the user -types 5 and presses enter, `guess` looks like this: `5\n`. The `\n` -represents “newline.” (On Windows, pressing enter results in a carriage return and a newline, -`\r\n`.) The `trim` method eliminates `\n` or `\r\n`, resulting in just `5`. +enter to satisfy `read_line` and input their guess, which adds a +newline character to the string. For example, if the user types 5 and +presses enter, `guess` looks like this: `5\n`. The `\n` represents +“newline.” (On Windows, pressing enter 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] converts a string to another type. Here, we use it to convert from a string to a number. We need to @@ -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 -ctrl-c. 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): 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: +ctrl-c. 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): 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: + -Let’s look at another example to see what it’s like when a `panic!` call comes -from a library because of a bug in our code instead of from our code calling -the macro directly. Listing 9-1 has some code that attempts to access an -index in a vector beyond the range of valid indexes. +We can use the backtrace of the functions the `panic!` call came from to figure +out the part of our code that is causing the problem. To understand how to use +a `panic!` backtrace, let’s look at another example and see what it’s like when +a `panic!` call comes from a library because of a bug in our code instead of +from our code calling the macro directly. Listing 9-1 has some code that +attempts to access an index in a vector beyond the range of valid indexes. Filename: src/main.rs @@ -74,10 +74,10 @@ index in a vector beyond the range of valid indexes. end of a vector, which will cause a call to `panic!` Here, we’re attempting to access the 100th element of our vector (which is at -index 99 because indexing starts at zero), but the vector has only 3 elements. -In this situation, Rust will panic. Using `[]` is supposed to return an -element, but if you pass an invalid index, there’s no element that Rust could -return here that would be correct. +index 99 because indexing starts at zero), but the vector has only three +elements. In this situation, Rust will panic. Using `[]` is supposed to return +an element, but if you pass an invalid index, there’s no element that Rust +could return here that would be correct. In C, attempting to read beyond the end of a data structure is undefined behavior. You might get whatever is at the location in memory that would @@ -95,18 +95,20 @@ continue. Let’s try it and see: {{#include ../listings/ch09-error-handling/listing-09-01/output.txt}} ``` -This error points at line 4 of our `main.rs` where we attempt to access index -99. The next note line tells us that we can set the `RUST_BACKTRACE` -environment variable to get a backtrace of exactly what happened to cause the -error. A *backtrace* is a list of all the functions that have been called to -get to this point. Backtraces in Rust work as they do in other languages: the -key to reading the backtrace is to start from the top and read until you see -files you wrote. That’s the spot where the problem originated. The lines above -that spot are code that your code has called; the lines below are code that -called your code. These before-and-after lines might include core Rust code, -standard library code, or crates that you’re using. Let’s try getting a -backtrace by setting the `RUST_BACKTRACE` environment variable to any value -except 0. Listing 9-2 shows output similar to what you’ll see. +This error points at line 4 of our *main.rs* where we attempt to access index +`99` of the vector in `v`. + +The `note:` line tells us that we can set the `RUST_BACKTRACE` environment +variable to get a backtrace of exactly what happened to cause the error. A +*backtrace* is a list of all the functions that have been called to get to this +point. Backtraces in Rust work as they do in other languages: the key to +reading the backtrace is to start from the top and read until you see files you +wrote. That’s the spot where the problem originated. The lines above that spot +are code that your code has called; the lines below are code that called your +code. These before-and-after lines might include core Rust code, standard +library code, or crates that you’re using. Let’s try getting a backtrace by +setting the `RUST_BACKTRACE` environment variable to any value except `0`. +Listing 9-2 shows output similar to what you’ll see. in Chapter 2 that the `Result` enum is defined as having two @@ -23,7 +23,7 @@ the type of the value that will be returned in a success case within the `Ok` variant, and `E` represents the type of the error that will be returned in a failure case within the `Err` variant. Because `Result` has these generic type parameters, we can use the `Result` type and the functions defined on it in -many different situations where the successful value and error value we want to +many different situations where the success value and error value we want to return may differ. Let’s call a function that returns a `Result` value because the function could @@ -52,7 +52,7 @@ In the case where `File::open` succeeds, the value in the variable `greeting_file_result` will be an instance of `Ok` that contains a file handle. In the case where it fails, the value in `greeting_file_result` will be an instance of `Err` that contains more information about the kind of error that -happened. +occurred. We need to add to the code in Listing 9-3 to take different actions depending on the value `File::open` returns. Listing 9-4 shows one way to handle the @@ -91,11 +91,11 @@ As usual, this output tells us exactly what has gone wrong. ### Matching on Different Errors The code in Listing 9-4 will `panic!` no matter why `File::open` failed. -However, we want to take different actions for different failure reasons: if +However, we want to take different actions for different failure reasons. If `File::open` failed because the file doesn’t exist, we want to create the file and return the handle to the new file. If `File::open` failed for any other reason—for example, because we didn’t have permission to open the file—we still -want the code to `panic!` in the same way as it did in Listing 9-4. For this we +want the code to `panic!` in the same way it did in Listing 9-4. For this, we add an inner `match` expression, shown in Listing 9-5. Filename: src/main.rs @@ -127,7 +127,7 @@ file can’t be created, a different error message is printed. The second arm of the outer `match` stays the same, so the program panics on any error besides the missing file error. -> ### Alternatives to Using `match` with `Result` +> #### Alternatives to Using `match` with `Result` > > That’s a lot of `match`! The `match` expression is very useful but also very > much a primitive. In Chapter 13, you’ll learn about closures, which are used @@ -162,7 +162,7 @@ the missing file error. > standard library documentation. Many more of these methods can clean up huge > nested `match` expressions when you’re dealing with errors. -### Shortcuts for Panic on Error: `unwrap` and `expect` +#### Shortcuts for Panic on Error: `unwrap` and `expect` Using `match` works well enough, but it can be a bit verbose and doesn’t always communicate intent well. The `Result` type has many helper methods @@ -227,7 +227,7 @@ information to use in debugging. ### Propagating Errors When a function’s implementation calls something that might fail, instead of -handling the error within the function itself, you can return the error to the +handling the error within the function itself you can return the error to the calling code so that it can decide what to do. This is known as *propagating* the error and gives more control to the calling code, where there might be more information or logic that dictates how the error should be handled than what @@ -254,12 +254,12 @@ This function can be written in a much shorter way, but we’re going to start b doing a lot of it manually in order to explore error handling; at the end, we’ll show the shorter way. Let’s look at the return type of the function first: `Result`. This means the function is returning a -value of the type `Result` where the generic parameter `T` has been -filled in with the concrete type `String`, and the generic type `E` has been +value of the type `Result`, where the generic parameter `T` has been +filled in with the concrete type `String` and the generic type `E` has been filled in with the concrete type `io::Error`. If this function succeeds without any problems, the code that calls this -function will receive an `Ok` value that holds a `String`—the username that +function will receive an `Ok` value that holds a `String`—the `username` that this function read from the file. If this function encounters any problems, the calling code will receive an `Err` value that holds an instance of `io::Error` that contains more information about what the problems were. We chose @@ -277,8 +277,8 @@ keyword to return early out of the function entirely and pass the error value from `File::open`, now in the pattern variable `e`, back to the calling code as this function’s error value. -So if we have a file handle in `username_file`, the function then creates a new -`String` in variable `username` and calls the `read_to_string` method on +So, if we have a file handle in `username_file`, the function then creates a +new `String` in variable `username` and calls the `read_to_string` method on the file handle in `username_file` to read the contents of the file into `username`. The `read_to_string` method also returns a `Result` because it might fail, even though `File::open` succeeded. So we need another `match` to @@ -304,8 +304,8 @@ question mark operator `?` to make this easier. #### A Shortcut for Propagating Errors: the `?` Operator Listing 9-7 shows an implementation of `read_username_from_file` that has the -same functionality as in Listing 9-6, but this implementation uses the -`?` operator. +same functionality as in Listing 9-6, but this implementation uses the `?` +operator. Filename: src/main.rs @@ -410,8 +410,8 @@ as the `match` expression we defined in Listing 9-6. In Listing 9-6, the it’s compatible with this `return`. In Listing 9-10, let’s look at the error we’ll get if we use the `?` operator -in a `main` function with a return type incompatible with the type of the value -we use `?` on: +in a `main` function with a return type that is incompatible with the type of +the value we use `?` on. Filename: src/main.rs @@ -420,7 +420,7 @@ we use `?` on: ``` Listing 9-10: Attempting to use the `?` in the `main` -function that returns `()` won’t compile +function that returns `()` won’t compile. This code opens a file, which might fail. The `?` operator follows the `Result` value returned by `File::open`, but this `main` function has the return type of @@ -437,9 +437,9 @@ function that returns `Result`, `Option`, or another type that implements To fix the error, you have two choices. One choice is to change the return type of your function to be compatible with the value you’re using the `?` operator -on as long as you have no restrictions preventing that. The other technique is -to use a `match` or one of the `Result` methods to handle the `Result` in whatever way is appropriate. +on as long as you have no restrictions preventing that. The other choice is to +use a `match` or one of the `Result` methods to handle the `Result` +in whatever way is appropriate. The error message also mentioned that `?` can be used with `Option` values as well. As with using `?` on `Result`, you can only use `?` on `Option` in a @@ -447,9 +447,9 @@ function that returns an `Option`. The behavior of the `?` operator when called on an `Option` is similar to its behavior when called on a `Result`: if the value is `None`, the `None` will be returned early from the function at that point. If the value is `Some`, the value inside the `Some` is the -resulting value of the expression and the function continues. Listing 9-11 has +resultant value of the expression, and the function continues. Listing 9-11 has an example of a function that finds the last character of the first line in the -given text: +given text. ```rust {{#rustdoc_include ../listings/ch09-error-handling/listing-09-11/src/main.rs:here}} @@ -472,7 +472,7 @@ The `?` extracts the string slice, and we can call `chars` on that string slice to get an iterator of its characters. We’re interested in the last character in this first line, so we call `last` to return the last item in the iterator. This is an `Option` because it’s possible that the first line is the empty -string, for example if `text` starts with a blank line but has characters on +string; for example, if `text` starts with a blank line but has characters on other lines, as in `"\nhi"`. However, if there is a last character on the first line, it will be returned in the `Some` variant. The `?` operator in the middle gives us a concise way to express this logic, allowing us to implement the @@ -487,38 +487,40 @@ you can use methods like the `ok` method on `Result` or the `ok_or` method on `Option` to do the conversion explicitly. So far, all the `main` functions we’ve used return `()`. The `main` function is -special because it’s the entry and exit point of executable programs, and there -are restrictions on what its return type can be for the programs to behave as -expected. +special because it’s the entry point and exit point of an executable program, +and there are restrictions on what its return type can be for the program to +behave as expected. -Luckily, `main` can also return a `Result<(), E>`. Listing 9-12 has the -code from Listing 9-10 but we’ve changed the return type of `main` to be +Luckily, `main` can also return a `Result<(), E>`. Listing 9-12 has the code +from Listing 9-10, but we’ve changed the return type of `main` to be `Result<(), Box>` and added a return value `Ok(())` to the end. This -code will now compile: +code will now compile. + +Filename: src/main.rs ```rust,ignore {{#rustdoc_include ../listings/ch09-error-handling/listing-09-12/src/main.rs}} ``` Listing 9-12: Changing `main` to return `Result<(), E>` -allows the use of the `?` operator on `Result` values +allows the use of the `?` operator on `Result` values. The `Box` type is a *trait object*, which we’ll talk about in the [“Using Trait Objects that Allow for Values of Different Types”][trait-objects] section in Chapter 17. For now, you can read `Box` to mean “any kind of error.” Using `?` on a `Result` -value in a `main` function with the error type `Box` is allowed, +value in a `main` function with the error type `Box` is allowed because it allows any `Err` value to be returned early. Even though the body of this `main` function will only ever return errors of type `std::io::Error`, by specifying `Box`, this signature will continue to be correct even if more code that returns other errors is added to the body of `main`. -When a `main` function returns a `Result<(), E>`, the executable will -exit with a value of `0` if `main` returns `Ok(())` and will exit with a -nonzero value if `main` returns an `Err` value. Executables written in C return -integers when they exit: programs that exit successfully return the integer -`0`, and programs that error return some integer other than `0`. Rust also -returns integers from executables to be compatible with this convention. +When a `main` function returns a `Result<(), E>`, the executable will exit with +a value of `0` if `main` returns `Ok(())` and will exit with a nonzero value if +`main` returns an `Err` value. Executables written in C return integers when +they exit: programs that exit successfully return the integer `0`, and programs +that error return some integer other than `0`. Rust also returns integers from +executables to be compatible with this convention. The `main` function may return any types that implement [the `std::process::Termination` trait][termination], which contains diff --git a/src/ch09-03-to-panic-or-not-to-panic.md b/src/ch09-03-to-panic-or-not-to-panic.md index 7c77cf9331..f875f906f2 100644 --- a/src/ch09-03-to-panic-or-not-to-panic.md +++ b/src/ch09-03-to-panic-or-not-to-panic.md @@ -19,11 +19,11 @@ some general guidelines on how to decide whether to panic in library code. ### Examples, Prototype Code, and Tests -When you’re writing an example to illustrate some concept, also including robust -error-handling code can make the example less clear. In -examples, it’s understood that a call to a method like `unwrap` that could -panic is meant as a placeholder for the way you’d want your application to -handle errors, which can differ based on what the rest of your code is doing. +When you’re writing an example to illustrate some concept, also including +robust error-handling code can make the example less clear. In examples, it’s +understood that a call to a method like `unwrap` that could panic is meant as a +placeholder for the way you’d want your application to handle errors, which can +differ based on what the rest of your code is doing. Similarly, the `unwrap` and `expect` methods are very handy when prototyping, before you’re ready to decide how to handle errors. They leave clear markers in @@ -60,16 +60,16 @@ valid IP address. If the IP address string came from a user rather than being hardcoded into the program and therefore *did* have a possibility of failure, we’d definitely want to handle the `Result` in a more robust way instead. Mentioning the assumption that this IP address is hardcoded will prompt us to -change `expect` to better error handling code if in the future, we need to get +change `expect` to better error-handling code if, in the future, we need to get the IP address from some other source instead. ### Guidelines for Error Handling -It’s advisable to have your code panic when it’s possible that your code -could end up in a bad state. In this context, a *bad state* is when some -assumption, guarantee, contract, or invariant has been broken, such as when -invalid values, contradictory values, or missing values are passed to your -code—plus one or more of the following: +It’s advisable to have your code panic when it’s possible that your code could +end up in a bad state. In this context, a *bad state* is when some assumption, +guarantee, contract, or invariant has been broken, such as when invalid values, +contradictory values, or missing values are passed to your code—plus one or +more of the following: * The bad state is something that is unexpected, as opposed to something that will likely happen occasionally, like a user entering data in the wrong @@ -104,7 +104,7 @@ an out-of-bounds memory access: trying to access memory that doesn’t belong to the current data structure is a common security problem. Functions often have *contracts*: their behavior is only guaranteed if the inputs meet particular requirements. Panicking when the contract is violated makes sense because a -contract violation always indicates a caller-side bug and it’s not a kind of +contract violation always indicates a caller-side bug, and it’s not a kind of error you want the calling code to have to explicitly handle. In fact, there’s no reasonable way for calling code to recover; the calling *programmers* need to fix the code. Contracts for a function, especially when a violation will @@ -133,13 +133,15 @@ numbers before checking it against our secret number; we only validated that the guess was positive. In this case, the consequences were not very dire: our output of “Too high” or “Too low” would still be correct. But it would be a useful enhancement to guide the user toward valid guesses and have different -behavior when a user guesses a number that’s out of range versus when a user -types, for example, letters instead. +behavior when the user guesses a number that’s out of range versus when the +user types, for example, letters instead. One way to do this would be to parse the guess as an `i32` instead of only a `u32` to allow potentially negative numbers, and then add a check for the number being in range, like so: +Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch09-error-handling/no-listing-09-guess-out-of-range/src/main.rs:here}} ``` @@ -150,7 +152,7 @@ and ask for another guess. After the `if` expression, we can proceed with the comparisons between `guess` and the secret number knowing that `guess` is between 1 and 100. -However, this is not an ideal solution: if it was absolutely critical that the +However, this is not an ideal solution: if it were absolutely critical that the program only operated on values between 1 and 100, and it had many functions with this requirement, having a check like this in every function would be tedious (and might impact performance). @@ -174,7 +176,7 @@ purposes. --> Listing 9-13: A `Guess` type that will only continue with values between 1 and 100 -First, we define a struct named `Guess` that has a field named `value` that +First we define a struct named `Guess` that has a field named `value` that holds an `i32`. This is where the number will be stored. Then we implement an associated function named `new` on `Guess` that creates @@ -193,7 +195,7 @@ to the `value` parameter and return the `Guess`. Next, we implement a method named `value` that borrows `self`, doesn’t have any other parameters, and returns an `i32`. This kind of method is sometimes called -a *getter*, because its purpose is to get some data from its fields and return +a *getter* because its purpose is to get some data from its fields and return it. This public method is necessary because the `value` field of the `Guess` struct is private. It’s important that the `value` field be private so code using the `Guess` struct is not allowed to set `value` directly: code outside @@ -207,7 +209,7 @@ then declare in its signature that it takes or returns a `Guess` rather than an ## Summary -Rust’s error handling features are designed to help you write more robust code. +Rust’s error-handling features are designed to help you write more robust code. The `panic!` macro signals that your program is in a state it can’t handle and lets you tell the process to stop instead of trying to proceed with invalid or incorrect values. The `Result` enum uses Rust’s type system to indicate that From dd8f47a74b67178cea8c832e3b4eaf3bb515bd72 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 22 May 2024 17:17:55 -0400 Subject: [PATCH 218/720] Extract Guess type definition to a src/lib.rs, which makes more sense It's how we labeled this file in print. This also lets us use rustdoc_include for this example. --- .../listing-09-13/src/lib.rs | 17 +++++++++++++++ .../listing-09-13/src/main.rs | 21 +------------------ src/ch09-03-to-panic-or-not-to-panic.md | 7 ++----- 3 files changed, 20 insertions(+), 25 deletions(-) create mode 100644 listings/ch09-error-handling/listing-09-13/src/lib.rs diff --git a/listings/ch09-error-handling/listing-09-13/src/lib.rs b/listings/ch09-error-handling/listing-09-13/src/lib.rs new file mode 100644 index 0000000000..d093831100 --- /dev/null +++ b/listings/ch09-error-handling/listing-09-13/src/lib.rs @@ -0,0 +1,17 @@ +pub struct Guess { + value: i32, +} + +impl Guess { + pub fn new(value: i32) -> Guess { + if value < 1 || value > 100 { + panic!("Guess value must be between 1 and 100, got {value}."); + } + + Guess { value } + } + + pub fn value(&self) -> i32 { + self.value + } +} diff --git a/listings/ch09-error-handling/listing-09-13/src/main.rs b/listings/ch09-error-handling/listing-09-13/src/main.rs index 42b7d32ef6..cda389303b 100644 --- a/listings/ch09-error-handling/listing-09-13/src/main.rs +++ b/listings/ch09-error-handling/listing-09-13/src/main.rs @@ -1,27 +1,8 @@ +use guessing_game::Guess; use rand::Rng; use std::cmp::Ordering; use std::io; -// ANCHOR: here -pub struct Guess { - value: i32, -} - -impl Guess { - pub fn new(value: i32) -> Guess { - if value < 1 || value > 100 { - panic!("Guess value must be between 1 and 100, got {value}."); - } - - Guess { value } - } - - pub fn value(&self) -> i32 { - self.value - } -} -// ANCHOR_END: here - fn main() { println!("Guess the number!"); diff --git a/src/ch09-03-to-panic-or-not-to-panic.md b/src/ch09-03-to-panic-or-not-to-panic.md index f875f906f2..40f93d67ce 100644 --- a/src/ch09-03-to-panic-or-not-to-panic.md +++ b/src/ch09-03-to-panic-or-not-to-panic.md @@ -164,13 +164,10 @@ confidently use the values they receive. Listing 9-13 shows one way to define a `Guess` type that will only create an instance of `Guess` if the `new` function receives a value between 1 and 100. - +Filename: src/lib.rs ```rust -{{#include ../listings/ch09-error-handling/listing-09-13/src/main.rs:here}} +{{#rustdoc_include ../listings/ch09-error-handling/listing-09-13/src/lib.rs}} ``` Listing 9-13: A `Guess` type that will only continue with From c8dc2f54317566d0484a40242a51d564f995b8cb Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 28 May 2024 13:59:56 -0400 Subject: [PATCH 219/720] Snapshot changes to generated ch9 that SHOULDN'T be sent to nostarch --- nostarch/chapter09.md | 388 +++++++++++++++++++++++------------------- 1 file changed, 216 insertions(+), 172 deletions(-) diff --git a/nostarch/chapter09.md b/nostarch/chapter09.md index 4aa81123fb..ed0e6f63db 100644 --- a/nostarch/chapter09.md +++ b/nostarch/chapter09.md @@ -31,7 +31,7 @@ about returning `Result` values. Additionally, we’ll explore considerations when deciding whether to try to recover from an error or to stop execution. -## Unrecoverable Errors with panic! +## Unrecoverable Errors with `panic!` Sometimes bad things happen in your code, and there’s nothing you can do about it. In these cases, Rust has the `panic!` macro. There are two ways to cause a @@ -45,20 +45,20 @@ panic occurs to make it easier to track down the source of the panic. > ### Unwinding the Stack or Aborting in Response to a Panic > > By default, when a panic occurs the program starts *unwinding*, which means -Rust walks back up the stack and cleans up the data from each function it -encounters. However, walking back and cleaning up is a lot of work. Rust, -therefore, allows you to choose the alternative of immediately *aborting*, -which ends the program without cleaning up. +> Rust walks back up the stack and cleans up the data from each function it +> encounters. However, walking back and cleaning up is a lot of work. Rust, +> therefore, allows you to choose the alternative of immediately *aborting*, +> which ends the program without cleaning up. > > Memory that the program was using will then need to be cleaned up by the -operating system. If in your project you need to make the resultant binary as -small as possible, you can switch from unwinding to aborting upon a panic by -adding `panic = 'abort'` to the appropriate `[profile]` sections in your -*Cargo.toml* file. For example, if you want to abort on panic in release mode, -add this: +> operating system. If in your project you need to make the resultant binary as +> small as possible, you can switch from unwinding to aborting upon a panic by +> adding `panic = 'abort'` to the appropriate `[profile]` sections in your +> *Cargo.toml* file. For example, if you want to abort on panic in release mode, +> add this: > -> ``` -> [profile.release] +> ```toml +> profile.release > panic = 'abort' > ``` @@ -75,9 +75,13 @@ fn main() { When you run the program, you’ll see something like this: ``` -thread 'main' panicked at 'crash and burn', src/main.rs:2:5 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +$ cargo run + Compiling panic v0.1.0 (file:///projects/panic) + Finished dev [unoptimized + debuginfo] target(s) in 0.25s + Running `target/debug/panic` +thread 'main' panicked at src/main.rs:2:5: +crash and burn +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` The call to `panic!` causes the error message contained in the last two lines. @@ -91,6 +95,9 @@ be in code that our code calls, and the filename and line number reported by the error message will be someone else’s code where the `panic!` macro is called, not the line of our code that eventually led to the `panic!` call. + + + We can use the backtrace of the functions the `panic!` call came from to figure out the part of our code that is causing the problem. To understand how to use a `panic!` backtrace, let’s look at another example and see what it’s like when @@ -108,8 +115,8 @@ fn main() { } ``` -Listing 9-1: Attempting to access an element beyond the end of a vector, which -will cause a call to `panic!` +Listing 9-1: Attempting to access an element beyond the +end of a vector, which will cause a call to `panic!` Here, we’re attempting to access the 100th element of our vector (which is at index 99 because indexing starts at zero), but the vector has only three @@ -130,8 +137,12 @@ element at an index that doesn’t exist, Rust will stop execution and refuse to continue. Let’s try it and see: ``` -thread 'main' panicked at 'index out of bounds: the len is 3 but the index is -99', src/main.rs:4:5 +$ cargo run + Compiling panic v0.1.0 (file:///projects/panic) + Finished dev [unoptimized + debuginfo] target(s) in 0.27s + Running `target/debug/panic` +thread 'main' panicked at src/main.rs:4:6: +index out of bounds: the len is 3 but the index is 99 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` @@ -149,40 +160,39 @@ library code, or crates that you’re using. Let’s try getting a backtrace by setting the `RUST_BACKTRACE` environment variable to any value except `0`. Listing 9-2 shows output similar to what you’ll see. + + ``` $ RUST_BACKTRACE=1 cargo run -thread 'main' panicked at 'index out of bounds: the len is 3 but the index is -99', src/main.rs:4:5 +thread 'main' panicked at src/main.rs:4:6: +index out of bounds: the len is 3 but the index is 99 stack backtrace: 0: rust_begin_unwind - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std -/src/panicking.rs:584:5 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5 1: core::panicking::panic_fmt - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core -/src/panicking.rs:142:14 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14 2: core::panicking::panic_bounds_check - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core -/src/panicking.rs:84:5 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:208:5 3: >::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core -/src/slice/index.rs:242:10 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/index.rs:255:10 4: core::slice::index:: for [T]>::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core -/src/slice/index.rs:18:9 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/index.rs:18:9 5: as core::ops::index::Index>::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/alloc -/src/vec/mod.rs:2591:9 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/vec/mod.rs:2770:9 6: panic::main - at ./src/main.rs:4:5 + at ./src/main.rs:4:6 7: core::ops::function::FnOnce::call_once - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core -/src/ops/function.rs:248:5 -note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose -backtrace. + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5 +note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ``` -Listing 9-2: The backtrace generated by a call to `panic!` displayed when the -environment variable `RUST_BACKTRACE` is set +Listing 9-2: The backtrace generated by a call to +`panic!` displayed when the environment variable `RUST_BACKTRACE` is set That’s a lot of output! The exact output you see might be different depending on your operating system and Rust version. In order to get backtraces with this @@ -200,10 +210,11 @@ panics in the future, you’ll need to figure out what action the code is taking with what values to cause the panic and what the code should do instead. We’ll come back to `panic!` and when we should and should not use `panic!` to -handle error conditions in “To panic! or Not to panic!” on page XX. Next, we’ll -look at how to recover from an error using `Result`. +handle error conditions in the “To `panic!` or Not to +`panic!`” section later in this +chapter. Next, we’ll look at how to recover from an error using `Result`. -## Recoverable Errors with Result +## Recoverable Errors with `Result` Most errors aren’t serious enough to require the program to stop entirely. Sometimes when a function fails it’s for a reason that you can easily interpret @@ -211,8 +222,8 @@ and respond to. For example, if you try to open a file and that operation fails because the file doesn’t exist, you might want to create the file instead of terminating the process. -Recall from “Handling Potential Failure with Result” on page XX that the -`Result` enum is defined as having two variants, `Ok` and `Err`, as follows: +Recall from “Handling Potential Failure with `Result`” in Chapter 2 that the `Result` enum is defined as having two +variants, `Ok` and `Err`, as follows: ``` enum Result { @@ -284,8 +295,8 @@ fn main() { } ``` -Listing 9-4: Using a `match` expression to handle the `Result` variants that -might be returned +Listing 9-4: Using a `match` expression to handle the +`Result` variants that might be returned Note that, like the `Option` enum, the `Result` enum and its variants have been brought into scope by the prelude, so we don’t need to specify `Result::` @@ -302,9 +313,13 @@ there’s no file named *hello.txt* in our current directory and we run this code, we’ll see the following output from the `panic!` macro: ``` -thread 'main' panicked at 'Problem opening the file: Os { code: - 2, kind: NotFound, message: "No such file or directory" }', -src/main.rs:8:23 +$ cargo run + Compiling error-handling v0.1.0 (file:///projects/error-handling) + Finished dev [unoptimized + debuginfo] target(s) in 0.73s + Running `target/debug/error-handling` +thread 'main' panicked at src/main.rs:8:23: +Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" } +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` As usual, this output tells us exactly what has gone wrong. @@ -321,6 +336,9 @@ add an inner `match` expression, shown in Listing 9-5. Filename: src/main.rs + + ``` use std::fs::File; use std::io::ErrorKind; @@ -351,7 +369,8 @@ fn main() { } ``` -Listing 9-5: Handling different kinds of errors in different ways +Listing 9-5: Handling different kinds of errors in +different ways The type of the value that `File::open` returns inside the `Err` variant is `io::Error`, which is a struct provided by the standard library. This struct @@ -398,13 +417,7 @@ fn main() { } ``` -Although this code has the same behavior as Listing 9-5, it doesn’t contain any -`match` expressions and is cleaner to read. Come back to this example after -you’ve read Chapter 13, and look up the `unwrap_or_else` method in the standard -library documentation. Many more of these methods can clean up huge nested -`match` expressions when you’re dealing with errors. - -#### Shortcuts for Panic on Error: unwrap and expect +#### Shortcuts for Panic on Error: `unwrap` and `expect` Using `match` works well enough, but it can be a bit verbose and doesn’t always communicate intent well. The `Result` type has many helper methods @@ -427,10 +440,15 @@ fn main() { If we run this code without a *hello.txt* file, we’ll see an error message from the `panic!` call that the `unwrap` method makes: + + ``` -thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { -code: 2, kind: NotFound, message: "No such file or directory" }', -src/main.rs:4:49 +thread 'main' panicked at src/main.rs:4:49: +called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" } ``` Similarly, the `expect` method lets us also choose the `panic!` error message. @@ -454,10 +472,15 @@ the `panic!` macro. The error message used by `expect` in its call to `panic!` will be the parameter that we pass to `expect`, rather than the default `panic!` message that `unwrap` uses. Here’s what it looks like: + + ``` -thread 'main' panicked at 'hello.txt should be included in this project: Os { -code: 2, kind: NotFound, message: "No such file or directory" }', -src/main.rs:5:10 +thread 'main' panicked at src/main.rs:5:10: +hello.txt should be included in this project: Os { code: 2, kind: NotFound, message: "No such file or directory" } ``` In production-quality code, most Rustaceans choose `expect` rather than @@ -480,67 +503,72 @@ to the code that called the function. Filename: src/main.rs + + ``` use std::fs::File; use std::io::{self, Read}; -1 fn read_username_from_file() -> Result { - 2 let username_file_result = File::open("hello.txt"); +fn read_username_from_file() -> Result { + let username_file_result = File::open("hello.txt"); - 3 let mut username_file = match username_file_result { - 4 Ok(file) => file, - 5 Err(e) => return Err(e), + let mut username_file = match username_file_result { + Ok(file) => file, + Err(e) => return Err(e), }; - 6 let mut username = String::new(); + let mut username = String::new(); - 7 match username_file.read_to_string(&mut username) { - 8 Ok(_) => Ok(username), - 9 Err(e) => Err(e), + match username_file.read_to_string(&mut username) { + Ok(_) => Ok(username), + Err(e) => Err(e), } } ``` -Listing 9-6: A function that returns errors to the calling code using `match` +Listing 9-6: A function that returns errors to the +calling code using `match` This function can be written in a much shorter way, but we’re going to start by doing a lot of it manually in order to explore error handling; at the end, we’ll show the shorter way. Let’s look at the return type of the function -first: `Result` [1]. This means the function is returning a +first: `Result`. This means the function is returning a value of the type `Result`, where the generic parameter `T` has been filled in with the concrete type `String` and the generic type `E` has been filled in with the concrete type `io::Error`. If this function succeeds without any problems, the code that calls this function will receive an `Ok` value that holds a `String`—the `username` that -this function read from the file [8]. If this function encounters any problems, -the calling code will receive an `Err` value that holds an instance of -`io::Error` that contains more information about what the problems were. We -chose `io::Error` as the return type of this function because that happens to -be the type of the error value returned from both of the operations we’re -calling in this function’s body that might fail: the `File::open` function [2] -and the `read_to_string` method [7]. - -The body of the function starts by calling the `File::open` function [2]. Then -we handle the `Result` value with a `match` similar to the `match` in Listing -9-4. If `File::open` succeeds, the file handle in the pattern variable `file` -[4] becomes the value in the mutable variable `username_file` [3] and the -function continues. In the `Err` case, instead of calling `panic!`, we use the -`return` keyword to return early out of the function entirely and pass the -error value from `File::open`, now in the pattern variable `e`, back to the -calling code as this function’s error value [5]. +this function read from the file. If this function encounters any problems, the +calling code will receive an `Err` value that holds an instance of `io::Error` +that contains more information about what the problems were. We chose +`io::Error` as the return type of this function because that happens to be the +type of the error value returned from both of the operations we’re calling in +this function’s body that might fail: the `File::open` function and the +`read_to_string` method. + +The body of the function starts by calling the `File::open` function. Then we +handle the `Result` value with a `match` similar to the `match` in Listing 9-4. +If `File::open` succeeds, the file handle in the pattern variable `file` +becomes the value in the mutable variable `username_file` and the function +continues. In the `Err` case, instead of calling `panic!`, we use the `return` +keyword to return early out of the function entirely and pass the error value +from `File::open`, now in the pattern variable `e`, back to the calling code as +this function’s error value. So, if we have a file handle in `username_file`, the function then creates a -new `String` in variable `username` [6] and calls the `read_to_string` method -on the file handle in `username_file` to read the contents of the file into -`username` [7]. The `read_to_string` method also returns a `Result` because it +new `String` in variable `username` and calls the `read_to_string` method on +the file handle in `username_file` to read the contents of the file into +`username`. The `read_to_string` method also returns a `Result` because it might fail, even though `File::open` succeeded. So we need another `match` to handle that `Result`: if `read_to_string` succeeds, then our function has succeeded, and we return the username from the file that’s now in `username` wrapped in an `Ok`. If `read_to_string` fails, we return the error value in the same way that we returned the error value in the `match` that handled the return value of `File::open`. However, we don’t need to explicitly say -`return`, because this is the last expression in the function [9]. +`return`, because this is the last expression in the function. The code that calls this code will then handle getting either an `Ok` value that contains a username or an `Err` value that contains an `io::Error`. It’s @@ -554,7 +582,7 @@ it to handle appropriately. This pattern of propagating errors is so common in Rust that Rust provides the question mark operator `?` to make this easier. -#### A Shortcut for Propagating Errors: The ? Operator +#### A Shortcut for Propagating Errors: the `?` Operator Listing 9-7 shows an implementation of `read_username_from_file` that has the same functionality as in Listing 9-6, but this implementation uses the `?` @@ -562,6 +590,10 @@ operator. Filename: src/main.rs + + ``` use std::fs::File; use std::io::{self, Read}; @@ -574,8 +606,8 @@ fn read_username_from_file() -> Result { } ``` -Listing 9-7: A function that returns errors to the calling code using the `?` -operator +Listing 9-7: A function that returns errors to the +calling code using the `?` operator The `?` placed after a `Result` value is defined to work in almost the same way as the `match` expressions we defined to handle the `Result` values in Listing @@ -614,6 +646,10 @@ method calls immediately after the `?`, as shown in Listing 9-8. Filename: src/main.rs + + ``` use std::fs::File; use std::io::{self, Read}; @@ -627,7 +663,8 @@ fn read_username_from_file() -> Result { } ``` -Listing 9-8: Chaining method calls after the `?` operator +Listing 9-8: Chaining method calls after the `?` +operator We’ve moved the creation of the new `String` in `username` to the beginning of the function; that part hasn’t changed. Instead of creating a variable @@ -642,6 +679,10 @@ Listing 9-9 shows a way to make this even shorter using `fs::read_to_string`. Filename: src/main.rs + + ``` use std::fs; use std::io; @@ -651,8 +692,8 @@ fn read_username_from_file() -> Result { } ``` -Listing 9-9: Using `fs::read_to_string` instead of opening and then reading the -file +Listing 9-9: Using `fs::read_to_string` instead of +opening and then reading the file Reading a file into a string is a fairly common operation, so the standard library provides the convenient `fs::read_to_string` function that opens the @@ -661,7 +702,7 @@ into that `String`, and returns it. Of course, using `fs::read_to_string` doesn’t give us the opportunity to explain all the error handling, so we did it the longer way first. -#### Where the ? Operator Can Be Used +#### Where The `?` Operator Can Be Used The `?` operator can only be used in functions whose return type is compatible with the value the `?` is used on. This is because the `?` operator is defined @@ -685,8 +726,8 @@ fn main() { } ``` -Listing 9-10: Attempting to use the `?` in the `main` function that returns -`()` won’t compile. +Listing 9-10: Attempting to use the `?` in the `main` +function that returns `()` won’t compile. This code opens a file, which might fail. The `?` operator follows the `Result` value returned by `File::open`, but this `main` function has the return type of @@ -694,19 +735,20 @@ value returned by `File::open`, but this `main` function has the return type of message: ``` -error[E0277]: the `?` operator can only be used in a function that returns -`Result` or `Option` (or another type that implements `FromResidual`) +$ cargo run + Compiling error-handling v0.1.0 (file:///projects/error-handling) +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) --> src/main.rs:4:48 | -3 | / fn main() { -4 | | let greeting_file = File::open("hello.txt")?; - | | ^ cannot use the `?` -operator in a function that returns `()` -5 | | } - | |_- this function should return `Result` or `Option` to accept `?` +3 | fn main() { + | --------- this function should return `Result` or `Option` to accept `?` +4 | let greeting_file = File::open("hello.txt")?; + | ^ cannot use the `?` operator in a function that returns `()` | - = help: the trait `FromResidual>` is not -implemented for `()` + = help: the trait `FromResidual>` is not implemented for `()` + +For more information about this error, try `rustc --explain E0277`. +error: could not compile `error-handling` (bin "error-handling") due to 1 previous error ``` This error points out that we’re only allowed to use the `?` operator in a @@ -735,7 +777,8 @@ fn last_char_of_first_line(text: &str) -> Option { } ``` -Listing 9-11: Using the `?` operator on an `Option` value +Listing 9-11: Using the `?` operator on an `Option` +value This function returns `Option` because it’s possible that there is a character there, but it’s also possible that there isn’t. This code takes the @@ -788,18 +831,18 @@ fn main() -> Result<(), Box> { } ``` -Listing 9-12: Changing `main` to return `Result<(), E>` allows the use of the -`?` operator on `Result` values. +Listing 9-12: Changing `main` to return `Result<(), E>` +allows the use of the `?` operator on `Result` values. -The `Box` type is a *trait object*, which we’ll talk about in “Using -Trait Objects That Allow for Values of Different Types” on page XX. For now, -you can read `Box` to mean “any kind of error.” Using `?` on a -`Result` value in a `main` function with the error type `Box` is -allowed because it allows any `Err` value to be returned early. Even though the -body of this `main` function will only ever return errors of type -`std::io::Error`, by specifying `Box`, this signature will continue -to be correct even if more code that returns other errors is added to the body -of `main`. +The `Box` type is a *trait object*, which we’ll talk about in the +“Using Trait Objects that Allow for Values of Different +Types” section in Chapter 17. For now, you can +read `Box` to mean “any kind of error.” Using `?` on a `Result` +value in a `main` function with the error type `Box` is allowed +because it allows any `Err` value to be returned early. Even though the body of +this `main` function will only ever return errors of type `std::io::Error`, by +specifying `Box`, this signature will continue to be correct even if +more code that returns other errors is added to the body of `main`. When a `main` function returns a `Result<(), E>`, the executable will exit with a value of `0` if `main` returns `Ok(())` and will exit with a nonzero value if @@ -809,15 +852,16 @@ that error return some integer other than `0`. Rust also returns integers from executables to be compatible with this convention. The `main` function may return any types that implement the -`std::process::Termination` trait, which contains a function `report` that -returns an `ExitCode`. Consult the standard library documentation for more -information on implementing the `Termination` trait for your own types. +`std::process::Termination` trait, which contains +a function `report` that returns an `ExitCode`. Consult the standard library +documentation for more information on implementing the `Termination` trait for +your own types. Now that we’ve discussed the details of calling `panic!` or returning `Result`, let’s return to the topic of how to decide which is appropriate to use in which cases. -## To panic! or Not to panic! +## To `panic!` or Not to `panic!` So how do you decide when you should call `panic!` and when you should return `Result`? When code panics, there’s no way to recover. You could call `panic!` @@ -866,11 +910,11 @@ that you’ll never have an `Err` variant, it’s perfectly acceptable to call `Err` variant in the `expect` text. Here’s an example: ``` -use std::net::IpAddr; + use std::net::IpAddr; -let home: IpAddr = "127.0.0.1" - .parse() - .expect("Hardcoded IP address should be valid"); + let home: IpAddr = "127.0.0.1" + .parse() + .expect("Hardcoded IP address should be valid"); ``` We’re creating an `IpAddr` instance by parsing a hardcoded string. We can see @@ -895,12 +939,13 @@ contradictory values, or missing values are passed to your code—plus one or more of the following: * The bad state is something that is unexpected, as opposed to something that -will likely happen occasionally, like a user entering data in the wrong format. + will likely happen occasionally, like a user entering data in the wrong + format. * Your code after this point needs to rely on not being in this bad state, -rather than checking for the problem at every step. + rather than checking for the problem at every step. * There’s not a good way to encode this information in the types you use. We’ll -work through an example of what we mean in “Encoding States and Behavior as -Types” on page XX. + work through an example of what we mean in the “Encoding States and Behavior + as Types” section of Chapter 17. If someone calls your code and passes in values that don’t make sense, it’s best to return an error if you can so the user of the library can decide what @@ -965,22 +1010,22 @@ number being in range, like so: Filename: src/main.rs ``` -loop { - --snip-- + loop { + // --snip-- - let guess: i32 = match guess.trim().parse() { - Ok(num) => num, - Err(_) => continue, - }; + let guess: i32 = match guess.trim().parse() { + Ok(num) => num, + Err(_) => continue, + }; - if guess < 1 || guess > 100 { - println!("The secret number will be between 1 and 100."); - continue; - } + if guess < 1 || guess > 100 { + println!("The secret number will be between 1 and 100."); + continue; + } - match guess.cmp(&secret_number) { - --snip-- -} + match guess.cmp(&secret_number) { + // --snip-- + } ``` The `if` expression checks whether our value is out of range, tells the user @@ -1004,7 +1049,7 @@ receives a value between 1 and 100. Filename: src/lib.rs ``` -1 pub struct Guess { +pub struct Guess { value: i32, } @@ -1017,44 +1062,44 @@ impl Guess { ); } - 5 Guess { value } + Guess { value } } - 6 pub fn value(&self) -> i32 { + pub fn value(&self) -> i32 { self.value } } ``` -Listing 9-13: A `Guess` type that will only continue with values between 1 and -100 +Listing 9-13: A `Guess` type that will only continue with +values between 1 and 100 First we define a struct named `Guess` that has a field named `value` that -holds an `i32` [1]. This is where the number will be stored. +holds an `i32`. This is where the number will be stored. Then we implement an associated function named `new` on `Guess` that creates -instances of `Guess` values [2]. The `new` function is defined to have one +instances of `Guess` values. The `new` function is defined to have one parameter named `value` of type `i32` and to return a `Guess`. The code in the -body of the `new` function tests `value` to make sure it’s between 1 and 100 -[3]. If `value` doesn’t pass this test, we make a `panic!` call [4], which will -alert the programmer who is writing the calling code that they have a bug they -need to fix, because creating a `Guess` with a `value` outside this range would +body of the `new` function tests `value` to make sure it’s between 1 and 100. +If `value` doesn’t pass this test, we make a `panic!` call, which will alert +the programmer who is writing the calling code that they have a bug they need +to fix, because creating a `Guess` with a `value` outside this range would violate the contract that `Guess::new` is relying on. The conditions in which `Guess::new` might panic should be discussed in its public-facing API documentation; we’ll cover documentation conventions indicating the possibility of a `panic!` in the API documentation that you create in Chapter 14. If `value` does pass the test, we create a new `Guess` with its `value` field set -to the `value` parameter and return the `Guess` [5]. +to the `value` parameter and return the `Guess`. Next, we implement a method named `value` that borrows `self`, doesn’t have any -other parameters, and returns an `i32` [6]. This kind of method is sometimes -called a *getter* because its purpose is to get some data from its fields and -return it. This public method is necessary because the `value` field of the -`Guess` struct is private. It’s important that the `value` field be private so -code using the `Guess` struct is not allowed to set `value` directly: code -outside the module *must* use the `Guess::new` function to create an instance -of `Guess`, thereby ensuring there’s no way for a `Guess` to have a `value` -that hasn’t been checked by the conditions in the `Guess::new` function. +other parameters, and returns an `i32`. This kind of method is sometimes called +a *getter* because its purpose is to get some data from its fields and return +it. This public method is necessary because the `value` field of the `Guess` +struct is private. It’s important that the `value` field be private so code +using the `Guess` struct is not allowed to set `value` directly: code outside +the module *must* use the `Guess::new` function to create an instance of +`Guess`, thereby ensuring there’s no way for a `Guess` to have a `value` that +hasn’t been checked by the conditions in the `Guess::new` function. A function that has a parameter or returns only numbers between 1 and 100 could then declare in its signature that it takes or returns a `Guess` rather than an @@ -1074,4 +1119,3 @@ situations will make your code more reliable in the face of inevitable problems. Now that you’ve seen useful ways that the standard library uses generics with the `Option` and `Result` enums, we’ll talk about how generics work and how you can use them in your code. - From 4338a6d160bdac69ceb5c50f7ecb393a1fa570ca Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 28 May 2024 14:09:00 -0400 Subject: [PATCH 220/720] Snapshot changes to ch 9 to consider sending to nostarch Inline format and one reference to a nonexisting variable --- nostarch/chapter09.md | 95 ++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/nostarch/chapter09.md b/nostarch/chapter09.md index ed0e6f63db..a7188076c7 100644 --- a/nostarch/chapter09.md +++ b/nostarch/chapter09.md @@ -146,7 +146,8 @@ index out of bounds: the len is 3 but the index is 99 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` -This error points at line 4 of our *main.rs* where we attempt to access `index`. +This error points at line 4 of our *main.rs* where we attempt to access index +`99` of the vector in `v`. The `note:` line tells us that we can set the `RUST_BACKTRACE` environment variable to get a backtrace of exactly what happened to cause the error. A @@ -288,9 +289,7 @@ fn main() { let greeting_file = match greeting_file_result { Ok(file) => file, - Err(error) => { - panic!("Problem opening the file: {:?}", error); - } + Err(error) => panic!("Problem opening the file: {error:?}"), }; } ``` @@ -349,20 +348,12 @@ fn main() { let greeting_file = match greeting_file_result { Ok(file) => file, Err(error) => match error.kind() { - ErrorKind::NotFound => { - match File::create("hello.txt") { - Ok(fc) => fc, - Err(e) => panic!( - "Problem creating the file: {:?}", - e - ), - } - } + ErrorKind::NotFound => match File::create("hello.txt") { + Ok(fc) => fc, + Err(e) => panic!("Problem creating the file: {e:?}"), + }, other_error => { - panic!( - "Problem opening the file: {:?}", - other_error - ); + panic!("Problem opening the file: {other_error:?}"); } }, }; @@ -389,33 +380,40 @@ file can’t be created, a different error message is printed. The second arm of the outer `match` stays the same, so the program panics on any error besides the missing file error. -#### Alternatives to Using match with Result - -That’s a lot of `match`! The `match` expression is very useful but also very -much a primitive. In Chapter 13, you’ll learn about closures, which are used -with many of the methods defined on `Result`. These methods can be more -concise than using `match` when handling `Result` values in your code. - -For example, here’s another way to write the same logic as shown in Listing -9-5, this time using closures and the `unwrap_or_else` method: - -``` -// src/main.rs -use std::fs::File; -use std::io::ErrorKind; - -fn main() { - let greeting_file = File::open("hello.txt").unwrap_or_else(|error| { - if error.kind() == ErrorKind::NotFound { - File::create("hello.txt").unwrap_or_else(|error| { - panic!("Problem creating the file: {:?}", error); - }) - } else { - panic!("Problem opening the file: {:?}", error); - } - }); -} -``` +> #### Alternatives to Using `match` with `Result` +> +> That’s a lot of `match`! The `match` expression is very useful but also very +> much a primitive. In Chapter 13, you’ll learn about closures, which are used +> with many of the methods defined on `Result`. These methods can be more +> concise than using `match` when handling `Result` values in your code. +> +> For example, here’s another way to write the same logic as shown in Listing +> 9-5, this time using closures and the `unwrap_or_else` method: +> +> +> +> ```rust,ignore +> use std::fs::File; +> use std::io::ErrorKind; +> +> fn main() { +> let greeting_file = File::open("hello.txt").unwrap_or_else(|error| { +> if error.kind() == ErrorKind::NotFound { +> File::create("hello.txt").unwrap_or_else(|error| { +> panic!("Problem creating the file: {error:?}"); +> }) +> } else { +> panic!("Problem opening the file: {error:?}"); +> } +> }); +> } +> ``` +> +> Although this code has the same behavior as Listing 9-5, it doesn’t contain +> any `match` expressions and is cleaner to read. Come back to this example +> after you’ve read Chapter 13, and look up the `unwrap_or_else` method in the +> standard library documentation. Many more of these methods can clean up huge +> nested `match` expressions when you’re dealing with errors. #### Shortcuts for Panic on Error: `unwrap` and `expect` @@ -1054,12 +1052,9 @@ pub struct Guess { } impl Guess { - 2 pub fn new(value: i32) -> Guess { - 3 if value < 1 || value > 100 { - 4 panic!( - "Guess value must be between 1 and 100, got {}.", - value - ); + pub fn new(value: i32) -> Guess { + if value < 1 || value > 100 { + panic!("Guess value must be between 1 and 100, got {value}."); } Guess { value } From 665e0766e59959b17a114fa1aee984aa74d6adc5 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 14 May 2024 14:10:38 -0400 Subject: [PATCH 221/720] Backport changes to chapter 10 --- src/ch10-00-generics.md | 28 ++++++------- src/ch10-01-syntax.md | 45 ++++++++++---------- src/ch10-02-traits.md | 69 ++++++++++++++++--------------- src/ch10-03-lifetime-syntax.md | 75 +++++++++++++++++----------------- 4 files changed, 109 insertions(+), 108 deletions(-) diff --git a/src/ch10-00-generics.md b/src/ch10-00-generics.md index bfe7ad3eec..bd18a5e525 100644 --- a/src/ch10-00-generics.md +++ b/src/ch10-00-generics.md @@ -7,13 +7,13 @@ how they relate to other generics without knowing what will be in their place when compiling and running the code. Functions can take parameters of some generic type, instead of a concrete type -like `i32` or `String`, in the same way a function takes parameters with -unknown values to run the same code on multiple concrete values. In fact, we’ve -already used generics in Chapter 6 with `Option`, Chapter 8 with `Vec` -and `HashMap`, and Chapter 9 with `Result`. In this chapter, you’ll +like `i32` or `String`, in the same way they take parameters with unknown +values to run the same code on multiple concrete values. In fact, we’ve already +used generics in Chapter 6 with `Option`, in Chapter 8 with `Vec` and +`HashMap`, and in Chapter 9 with `Result`. In this chapter, you’ll explore how to define your own types, functions, and methods with generics! -First, we’ll review how to extract a function to reduce code duplication. We’ll +First we’ll review how to extract a function to reduce code duplication. We’ll then use the same technique to make a generic function from two functions that differ only in the types of their parameters. We’ll also explain how to use generic types in struct and enum definitions. @@ -32,15 +32,15 @@ help. Generics allow us to replace specific types with a placeholder that represents multiple types to remove code duplication. Before diving into generics syntax, -then, let’s first look at how to remove duplication in a way that doesn’t -involve generic types by extracting a function that replaces specific values -with a placeholder that represents multiple values. Then we’ll apply the same +let’s first look at how to remove duplication in a way that doesn’t involve +generic types by extracting a function that replaces specific values with a +placeholder that represents multiple values. Then we’ll apply the same technique to extract a generic function! By looking at how to recognize duplicated code you can extract into a function, you’ll start to recognize duplicated code that can use generics. -We begin with the short program in Listing 10-1 that finds the largest number -in a list. +We’ll begin with the short program in Listing 10-1 that finds the largest +number in a list. Filename: src/main.rs @@ -54,13 +54,13 @@ numbers We store a list of integers in the variable `number_list` and place a reference to the first number in the list in a variable named `largest`. We then iterate through all the numbers in the list, and if the current number is greater than -the number stored in `largest`, replace the reference in that variable. +the number stored in `largest`, we replace the reference in that variable. However, if the current number is less than or equal to the largest number seen so far, the variable doesn’t change, and the code moves on to the next number in the list. After considering all the numbers in the list, `largest` should refer to the largest number, which in this case is 100. -We've now been tasked with finding the largest number in two different lists of +We’ve now been tasked with finding the largest number in two different lists of numbers. To do so, we can choose to duplicate the code in Listing 10-1 and use the same logic at two different places in the program, as shown in Listing 10-2. @@ -105,9 +105,9 @@ In summary, here are the steps we took to change the code from Listing 10-2 to Listing 10-3: 1. Identify duplicate code. -2. Extract the duplicate code into the body of the function and specify the +1. Extract the duplicate code into the body of the function, and specify the inputs and return values of that code in the function signature. -3. Update the two instances of duplicated code to call the function instead. +1. Update the two instances of duplicated code to call the function instead. Next, we’ll use these same steps with generics to reduce code duplication. In the same way that the function body can operate on an abstract `list` instead diff --git a/src/ch10-01-syntax.md b/src/ch10-01-syntax.md index 431dba9667..0b71c04c5b 100644 --- a/src/ch10-01-syntax.md +++ b/src/ch10-01-syntax.md @@ -13,7 +13,7 @@ parameters and return value. Doing so makes our code more flexible and provides more functionality to callers of our function while preventing code duplication. Continuing with our `largest` function, Listing 10-4 shows two functions that -both find the largest value in a slice. We'll then combine these into a single +both find the largest value in a slice. We’ll then combine these into a single function that uses generics. Filename: src/main.rs @@ -23,7 +23,7 @@ function that uses generics. ``` Listing 10-4: Two functions that differ only in their -names and the types in their signatures +names and in the types in their signatures The `largest_i32` function is the one we extracted in Listing 10-3 that finds the largest `i32` in a slice. The `largest_char` function finds the largest @@ -33,16 +33,16 @@ the duplication by introducing a generic type parameter in a single function. To parameterize the types in a new single function, we need to name the type parameter, just as we do for the value parameters to a function. You can use any identifier as a type parameter name. But we’ll use `T` because, by -convention, type parameter names in Rust are short, often just a letter, and -Rust’s type-naming convention is UpperCamelCase. Short for “type,” `T` is the +convention, type parameter names in Rust are short, often just one letter, and +Rust’s type-naming convention is UpperCamelCase. Short for *type*, `T` is the default choice of most Rust programmers. When we use a parameter in the body of the function, we have to declare the parameter name in the signature so the compiler knows what that name means. Similarly, when we use a type parameter name in a function signature, we have to declare the type parameter name before we use it. To define the generic -`largest` function, place type name declarations inside angle brackets, `<>`, -between the name of the function and the parameter list, like this: +`largest` function, we place type name declarations inside angle brackets, +`<>`, between the name of the function and the parameter list, like this: ```rust,ignore fn largest(list: &[T]) -> &T { @@ -65,7 +65,7 @@ compile yet, but we’ll fix it later in this chapter. ``` Listing 10-5: The `largest` function using generic type -parameters; this doesn’t yet compile +parameters; this doesn’t compile yet If we compile this code right now, we’ll get this error: @@ -79,7 +79,7 @@ states that the body of `largest` won’t work for all possible types that `T` could be. Because we want to compare values of type `T` in the body, we can only use types whose values can be ordered. To enable comparisons, the standard library has the `std::cmp::PartialOrd` trait that you can implement on types -(see Appendix C for more on this trait). By following the help text's +(see Appendix C for more on this trait). By following the help text’s suggestion, we restrict the types valid for `T` to only those that implement `PartialOrd` and this example will compile, because the standard library implements `PartialOrd` on both `i32` and `char`. @@ -100,9 +100,10 @@ fields using the `<>` syntax. Listing 10-6 defines a `Point` struct to hold values of type `T` The syntax for using generics in struct definitions is similar to that used in -function definitions. First, we declare the name of the type parameter inside -angle brackets just after the name of the struct. Then we use the generic type -in the struct definition where we would otherwise specify concrete data types. +function definitions. First we declare the name of the type parameter inside +angle brackets just after the name of the struct. Then we use the generic +type in the struct definition where we would otherwise specify concrete data +types. Note that because we’ve used only one generic type to define `Point`, this definition says that the `Point` struct is generic over some type `T`, and @@ -119,9 +120,9 @@ Listing 10-7, our code won’t compile. Listing 10-7: The fields `x` and `y` must be the same type because both have the same generic data type `T`. -In this example, when we assign the integer value 5 to `x`, we let the compiler -know that the generic type `T` will be an integer for this instance of -`Point`. Then when we specify 4.0 for `y`, which we’ve defined to have the +In this example, when we assign the integer value `5` to `x`, we let the +compiler know that the generic type `T` will be an integer for this instance of +`Point`. Then when we specify `4.0` for `y`, which we’ve defined to have the same type as `x`, we’ll get a type mismatch error like this: ```console @@ -144,7 +145,7 @@ that `x` and `y` can be values of different types Now all the instances of `Point` shown are allowed! You can use as many generic type parameters in a definition as you want, but using more than a few makes -your code hard to read. If you're finding you need lots of generic types in +your code hard to read. If you’re finding you need lots of generic types in your code, it could indicate that your code needs restructuring into smaller pieces. @@ -194,7 +195,7 @@ avoid duplication by using generic types instead. ### In Method Definitions We can implement methods on structs and enums (as we did in Chapter 5) and use -generic types in their definitions, too. Listing 10-9 shows the `Point` +generic types in their definitions too. Listing 10-9 shows the `Point` struct we defined in Listing 10-6 with a method named `x` implemented on it. Filename: src/main.rs @@ -238,7 +239,7 @@ This code means the type `Point` will have a `distance_from_origin` method; other instances of `Point` where `T` is not of type `f32` will not have this method defined. The method measures how far our point is from the point at coordinates (0.0, 0.0) and uses mathematical operations that are -available only for floating point types. +available only for floating-point types. Generic type parameters in a struct definition aren’t always the same as those you use in that same struct’s method signatures. Listing 10-11 uses the generic @@ -260,22 +261,22 @@ In `main`, we’ve defined a `Point` that has an `i32` for `x` (with value `5`) and an `f64` for `y` (with value `10.4`). The `p2` variable is a `Point` struct that has a string slice for `x` (with value `"Hello"`) and a `char` for `y` (with value `c`). Calling `mixup` on `p1` with the argument `p2` gives us `p3`, -which will have an `i32` for `x`, because `x` came from `p1`. The `p3` variable -will have a `char` for `y`, because `y` came from `p2`. The `println!` macro +which will have an `i32` for `x` because `x` came from `p1`. The `p3` variable +will have a `char` for `y` because `y` came from `p2`. The `println!` macro call will print `p3.x = 5, p3.y = c`. The purpose of this example is to demonstrate a situation in which some generic parameters are declared with `impl` and some are declared with the method definition. Here, the generic parameters `X1` and `Y1` are declared after `impl` because they go with the struct definition. The generic parameters `X2` -and `Y2` are declared after `fn mixup`, because they’re only relevant to the +and `Y2` are declared after `fn mixup` because they’re only relevant to the method. ### Performance of Code Using Generics You might be wondering whether there is a runtime cost when using generic type -parameters. The good news is that using generic types won't make your program run -any slower than it would with concrete types. +parameters. The good news is that using generic types won’t make your program +run any slower than it would with concrete types. Rust accomplishes this by performing monomorphization of the code using generics at compile time. *Monomorphization* is the process of turning generic diff --git a/src/ch10-02-traits.md b/src/ch10-02-traits.md index 3c4fb8cad1..53e9b8115c 100644 --- a/src/ch10-02-traits.md +++ b/src/ch10-02-traits.md @@ -1,8 +1,8 @@ ## Traits: Defining Shared Behavior -A *trait* defines functionality a particular type has and can share with other -types. We can use traits to define shared behavior in an abstract way. We can -use *trait bounds* to specify that a generic type can be any type that has +A *trait* defines the functionality a particular type has and can share with +other types. We can use traits to define shared behavior in an abstract way. We +can use *trait bounds* to specify that a generic type can be any type that has certain behavior. > Note: Traits are similar to a feature often called *interfaces* in other @@ -17,15 +17,15 @@ define a set of behaviors necessary to accomplish some purpose. For example, let’s say we have multiple structs that hold various kinds and amounts of text: a `NewsArticle` struct that holds a news story filed in a -particular location and a `Tweet` that can have at most 280 characters along +particular location and a `Tweet` that can have, at most, 280 characters along with metadata that indicates whether it was a new tweet, a retweet, or a reply to another tweet. We want to make a media aggregator library crate named `aggregator` that can display summaries of data that might be stored in a `NewsArticle` or `Tweet` -instance. To do this, we need a summary from each type, and we’ll request -that summary by calling a `summarize` method on an instance. Listing 10-12 -shows the definition of a public `Summary` trait that expresses this behavior. +instance. To do this, we need a summary from each type, and we’ll request that +summary by calling a `summarize` method on an instance. Listing 10-12 shows the +definition of a public `Summary` trait that expresses this behavior. Filename: src/lib.rs @@ -37,7 +37,7 @@ shows the definition of a public `Summary` trait that expresses this behavior. behavior provided by a `summarize` method Here, we declare a trait using the `trait` keyword and then the trait’s name, -which is `Summary` in this case. We’ve also declared the trait as `pub` so that +which is `Summary` in this case. We also declare the trait as `pub` so that crates depending on this crate can make use of this trait too, as we’ll see in a few examples. Inside the curly brackets, we declare the method signatures that describe the behaviors of the types that implement this trait, which in @@ -50,7 +50,7 @@ that any type that has the `Summary` trait will have the method `summarize` defined with this signature exactly. A trait can have multiple methods in its body: the method signatures are listed -one per line and each line ends in a semicolon. +one per line, and each line ends in a semicolon. ### Implementing a Trait on a Type @@ -59,7 +59,7 @@ we can implement it on the types in our media aggregator. Listing 10-13 shows an implementation of the `Summary` trait on the `NewsArticle` struct that uses the headline, the author, and the location to create the return value of `summarize`. For the `Tweet` struct, we define `summarize` as the username -followed by the entire text of the tweet, assuming that tweet content is +followed by the entire text of the tweet, assuming that the tweet content is already limited to 280 characters. Filename: src/lib.rs @@ -95,23 +95,23 @@ know, people`. Other crates that depend on the `aggregator` crate can also bring the `Summary` trait into scope to implement `Summary` on their own types. One restriction to -note is that we can implement a trait on a type only if at least one of the -trait or the type is local to our crate. For example, we can implement standard +note is that we can implement a trait on a type only if either the trait or the +type, or both, are local to our crate. For example, we can implement standard library traits like `Display` on a custom type like `Tweet` as part of our -`aggregator` crate functionality, because the type `Tweet` is local to our +`aggregator` crate functionality because the type `Tweet` is local to our `aggregator` crate. We can also implement `Summary` on `Vec` in our -`aggregator` crate, because the trait `Summary` is local to our `aggregator` +`aggregator` crate because the trait `Summary` is local to our `aggregator` crate. But we can’t implement external traits on external types. For example, we can’t -implement the `Display` trait on `Vec` within our `aggregator` crate, -because `Display` and `Vec` are both defined in the standard library and -aren’t local to our `aggregator` crate. This restriction is part of a property -called *coherence*, and more specifically the *orphan rule*, so named because -the parent type is not present. This rule ensures that other people’s code -can’t break your code and vice versa. Without the rule, two crates could -implement the same trait for the same type, and Rust wouldn’t know which -implementation to use. +implement the `Display` trait on `Vec` within our `aggregator` crate because +`Display` and `Vec` are both defined in the standard library and aren’t +local to our `aggregator` crate. This restriction is part of a property called +*coherence*, and more specifically the *orphan rule*, so named because the +parent type is not present. This rule ensures that other people’s code can’t +break your code and vice versa. Without the rule, two crates could implement +the same trait for the same type, and Rust wouldn’t know which implementation +to use. ### Default Implementations @@ -120,7 +120,7 @@ in a trait instead of requiring implementations for all methods on every type. Then, as we implement the trait on a particular type, we can keep or override each method’s default behavior. -In Listing 10-14 we specify a default string for the `summarize` method of the +In Listing 10-14, we specify a default string for the `summarize` method of the `Summary` trait instead of only defining the method signature, as we did in Listing 10-12. @@ -175,7 +175,8 @@ After we define `summarize_author`, we can call `summarize` on instances of the `Tweet` struct, and the default implementation of `summarize` will call the definition of `summarize_author` that we’ve provided. Because we’ve implemented `summarize_author`, the `Summary` trait has given us the behavior of the -`summarize` method without requiring us to write any more code. +`summarize` method without requiring us to write any more code. Here’s what +that looks like: ```rust,ignore {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/main.rs:here}} @@ -189,7 +190,7 @@ overriding implementation of that same method. ### Traits as Parameters Now that you know how to define and implement traits, we can explore how to use -traits to define functions that accept many different types. We'll use the +traits to define functions that accept many different types. We’ll use the `Summary` trait we implemented on the `NewsArticle` and `Tweet` types in Listing 10-13 to define a `notify` function that calls the `summarize` method on its `item` parameter, which is of some type that implements the `Summary` @@ -274,7 +275,7 @@ bounds, so functions with multiple generic type parameters can contain lots of trait bound information between the function’s name and its parameter list, making the function signature hard to read. For this reason, Rust has alternate syntax for specifying trait bounds inside a `where` clause after the function -signature. So instead of writing this: +signature. So, instead of writing this: ```rust,ignore fn some_function(t: &T, u: &U) -> i32 { @@ -290,7 +291,7 @@ This function’s signature is less cluttered: the function name, parameter list and return type are close together, similar to a function without lots of trait bounds. -### Returning Types that Implement Traits +### Returning Types That Implement Traits We can also use the `impl Trait` syntax in the return position to return a value of some type that implements a trait, as shown here: @@ -349,7 +350,7 @@ generic type depending on trait bounds We can also conditionally implement a trait for any type that implements another trait. Implementations of a trait on any type that satisfies the trait -bounds are called *blanket implementations* and are extensively used in the +bounds are called *blanket implementations* and are used extensively in the Rust standard library. For example, the standard library implements the `ToString` trait on any type that implements the `Display` trait. The `impl` block in the standard library looks similar to this code: @@ -377,12 +378,12 @@ reduce duplication but also specify to the compiler that we want the generic type to have particular behavior. The compiler can then use the trait bound information to check that all the concrete types used with our code provide the correct behavior. In dynamically typed languages, we would get an error at -runtime if we called a method on a type which didn’t define the method. But Rust -moves these errors to compile time so we’re forced to fix the problems before -our code is even able to run. Additionally, we don’t have to write code that -checks for behavior at runtime because we’ve already checked at compile time. -Doing so improves performance without having to give up the flexibility of -generics. +runtime if we called a method on a type which didn’t define the method. But +Rust moves these errors to compile time so we’re forced to fix the problems +before our code is even able to run. Additionally, we don’t have to write code +that checks for behavior at runtime because we’ve already checked at compile +time. Doing so improves performance without having to give up the flexibility +of generics. [using-trait-objects-that-allow-for-values-of-different-types]: ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types [methods]: ch05-03-method-syntax.html#defining-methods diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index 197e2c6f59..de12b6c1e5 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -8,15 +8,15 @@ One detail we didn’t discuss in the [“References and Borrowing”][references-and-borrowing] section in Chapter 4 is that every reference in Rust has a *lifetime*, which is the scope for which that reference is valid. Most of the time, lifetimes are implicit and inferred, -just like most of the time, types are inferred. We only have to annotate types +just like most of the time, types are inferred. We must annotate types only when multiple types are possible. In a similar way, we must annotate lifetimes when the lifetimes of references could be related in a few different ways. Rust requires us to annotate the relationships using generic lifetime parameters to ensure the actual references used at runtime will definitely be valid. -Annotating lifetimes is not a concept most other programming languages -have, so this is going to feel unfamiliar. Although we won’t cover lifetimes in -their entirety in this chapter, we’ll discuss common ways you might encounter +Annotating lifetimes is not a concept most other programming languages have, so +this is going to feel unfamiliar. Although we won’t cover lifetimes in their +entirety in this chapter, we’ll discuss common ways you might encounter lifetime syntax so you can get comfortable with the concept. ### Preventing Dangling References with Lifetimes @@ -33,31 +33,31 @@ scope. Listing 10-16: An attempt to use a reference whose value has gone out of scope -> Note: The examples in Listings 10-16, 10-17, and 10-23 declare variables -> without giving them an initial value, so the variable name exists in the -> outer scope. At first glance, this might appear to be in conflict with Rust’s -> having no null values. However, if we try to use a variable before giving it -> a value, we’ll get a compile-time error, which shows that Rust indeed does -> not allow null values. +> Note: The examples in Listing 10-16, 10-17, and 10-23 declare variables +> without giving them an initial value, so the variable name exists in the outer +> scope. At first glance, this might appear to be in conflict with Rust’s having +> no null values. However, if we try to use a variable before giving it a value, +> we’ll get a compile-time error, which shows that Rust indeed does not allow +> null values. The outer scope declares a variable named `r` with no initial value, and the -inner scope declares a variable named `x` with the initial value of 5. Inside +inner scope declares a variable named `x` with the initial value of `5`. Inside the inner scope, we attempt to set the value of `r` as a reference to `x`. Then the inner scope ends, and we attempt to print the value in `r`. This code won’t -compile because what the value `r` is referring to has gone out of scope before we -try to use it. Here is the error message: +compile because the value that `r` is referring to has gone out of scope before +we try to use it. Here is the error message: ```console {{#include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt}} ``` -The variable `x` doesn’t “live long enough.” The reason is that `x` will be out -of scope when the inner scope ends on line 7. But `r` is still valid for the -outer scope; because its scope is larger, we say that it “lives longer.” If -Rust allowed this code to work, `r` would be referencing memory that was -deallocated when `x` went out of scope, and anything we tried to do with `r` -wouldn’t work correctly. So how does Rust determine that this code is invalid? -It uses a borrow checker. +The error message says that the variable `x` “does not live long enough.” The +reason is that `x` will be out of scope when the inner scope ends on line 7. +But `r` is still valid for the outer scope; because its scope is larger, we say +that it “lives longer.” If Rust allowed this code to work, `r` would be +referencing memory that was deallocated when `x` went out of scope, and +anything we tried to do with `r` wouldn’t work correctly. So how does Rust +determine that this code is invalid? It uses a borrow checker. ### The Borrow Checker @@ -79,7 +79,7 @@ lifetimes and sees that `r` has a lifetime of `'a` but that it refers to memory with a lifetime of `'b`. The program is rejected because `'b` is shorter than `'a`: the subject of the reference doesn’t live as long as the reference. -Listing 10-18 fixes the code so it doesn’t have a dangling reference and +Listing 10-18 fixes the code so it doesn’t have a dangling reference and it compiles without any errors. ```rust @@ -180,7 +180,7 @@ reference to an `i32` that also has the lifetime `'a`. &'a mut i32 // a mutable reference with an explicit lifetime ``` -One lifetime annotation by itself doesn’t have much meaning, because the +One lifetime annotation by itself doesn’t have much meaning because the annotations are meant to tell Rust how generic lifetime parameters of multiple references relate to each other. Let’s examine how the lifetime annotations relate to each other in the context of the `longest` function. @@ -260,7 +260,7 @@ references to `String` values that have different concrete lifetimes In this example, `string1` is valid until the end of the outer scope, `string2` is valid until the end of the inner scope, and `result` references something -that is valid until the end of the inner scope. Run this code, and you’ll see +that is valid until the end of the inner scope. Run this code and you’ll see that the borrow checker approves; it will compile and print `The longest string is long string is long`. @@ -293,7 +293,7 @@ this because we annotated the lifetimes of the function parameters and return values using the same lifetime parameter `'a`. As humans, we can look at this code and see that `string1` is longer than -`string2` and therefore `result` will contain a reference to `string1`. +`string2`, and therefore, `result` will contain a reference to `string1`. Because `string1` has not gone out of scope yet, a reference to `string1` will still be valid for the `println!` statement. However, the compiler can’t see that the reference is valid in this case. We’ve told Rust that the lifetime of @@ -362,9 +362,9 @@ would create dangling pointers or otherwise violate memory safety. ### Lifetime Annotations in Struct Definitions -So far, the structs we’ve defined all hold owned types. We can define structs to -hold references, but in that case we would need to add a lifetime annotation on -every reference in the struct’s definition. Listing 10-24 has a struct named +So far, the structs we’ve defined all hold owned types. We can define structs +to hold references, but in that case we would need to add a lifetime annotation +on every reference in the struct’s definition. Listing 10-24 has a struct named `ImportantExcerpt` that holds a string slice. Filename: src/main.rs @@ -393,9 +393,9 @@ the `ImportantExcerpt` goes out of scope, so the reference in the ### Lifetime Elision You’ve learned that every reference has a lifetime and that you need to specify -lifetime parameters for functions or structs that use references. However, in -Chapter 4 we had a function in Listing 4-9, shown again in Listing 10-25, that -compiled without lifetime annotations. +lifetime parameters for functions or structs that use references. However, we +had a function in Listing 4-9, shown again in Listing 10-25, that compiled +without lifetime annotations. Filename: src/lib.rs @@ -449,8 +449,8 @@ which it can’t figure out lifetimes, the compiler will stop with an error. These rules apply to `fn` definitions as well as `impl` blocks. The first rule is that the compiler assigns a lifetime parameter to each -parameter that’s a reference. In other words, a function with one parameter gets -one lifetime parameter: `fn foo<'a>(x: &'a i32)`; a function with two +parameter that’s a reference. In other words, a function with one parameter +gets one lifetime parameter: `fn foo<'a>(x: &'a i32)`; a function with two parameters gets two separate lifetime parameters: `fn foo<'a, 'b>(x: &'a i32, y: &'b i32)`; and so on. @@ -526,7 +526,7 @@ use the lifetime parameters depends on whether they’re related to the struct fields or the method parameters and return values. Lifetime names for struct fields always need to be declared after the `impl` -keyword and then used after the struct’s name, because those lifetimes are part +keyword and then used after the struct’s name because those lifetimes are part of the struct’s type. In method signatures inside the `impl` block, references might be tied to the @@ -535,7 +535,7 @@ addition, the lifetime elision rules often make it so that lifetime annotations aren’t necessary in method signatures. Let’s look at some examples using the struct named `ImportantExcerpt` that we defined in Listing 10-24. -First, we’ll use a method named `level` whose only parameter is a reference to +First we’ll use a method named `level` whose only parameter is a reference to `self` and whose return value is an `i32`, which is not a reference to anything: ```rust @@ -567,9 +567,8 @@ string literals have the `'static` lifetime, which we can annotate as follows: let s: &'static str = "I have a static lifetime."; ``` -The text of this string is stored directly in the program’s binary, which -is always available. Therefore, the lifetime of all string literals is -`'static`. +The text of this string is stored directly in the program’s binary, which is +always available. Therefore, the lifetime of all string literals is `'static`. You might see suggestions to use the `'static` lifetime in error messages. But before specifying `'static` as the lifetime for a reference, think about @@ -577,7 +576,7 @@ whether the reference you have actually lives the entire lifetime of your program or not, and whether you want it to. Most of the time, an error message suggesting the `'static` lifetime results from attempting to create a dangling reference or a mismatch of the available lifetimes. In such cases, the solution -is fixing those problems, not specifying the `'static` lifetime. +is to fix those problems, not to specify the `'static` lifetime. ## Generic Type Parameters, Trait Bounds, and Lifetimes Together From 553bb202ace16cbf07babe8c9e90f9cc62c77de9 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 17 May 2024 10:36:16 -0400 Subject: [PATCH 222/720] Snapshot changes to generated ch10 that SHOULDN'T be sent to nostarch --- nostarch/chapter10.md | 397 +++++++++++++++++++++++------------------- 1 file changed, 214 insertions(+), 183 deletions(-) diff --git a/nostarch/chapter10.md b/nostarch/chapter10.md index bb8919d790..dc1590ac67 100644 --- a/nostarch/chapter10.md +++ b/nostarch/chapter10.md @@ -54,13 +54,13 @@ Filename: src/main.rs ``` fn main() { - 1 let number_list = vec![34, 50, 25, 100, 65]; + let number_list = vec![34, 50, 25, 100, 65]; - 2 let mut largest = &number_list[0]; + let mut largest = &number_list[0]; - 3 for number in &number_list { - 4 if number > largest { - 5 largest = number; + for number in &number_list { + if number > largest { + largest = number; } } @@ -68,16 +68,17 @@ fn main() { } ``` -Listing 10-1: Finding the largest number in a list of numbers +Listing 10-1: Finding the largest number in a list of +numbers -We store a list of integers in the variable `number_list` [1] and place a -reference to the first number in the list in a variable named `largest` [2]. We -then iterate through all the numbers in the list [3], and if the current number -is greater than the number stored in `largest` [4], we replace the reference in -that variable [5]. However, if the current number is less than or equal to the -largest number seen so far, the variable doesn’t change, and the code moves on -to the next number in the list. After considering all the numbers in the list, -`largest` should refer to the largest number, which in this case is 100. +We store a list of integers in the variable `number_list` and place a reference +to the first number in the list in a variable named `largest`. We then iterate +through all the numbers in the list, and if the current number is greater than +the number stored in `largest`, we replace the reference in that variable. +However, if the current number is less than or equal to the largest number seen +so far, the variable doesn’t change, and the code moves on to the next number +in the list. After considering all the numbers in the list, `largest` should +refer to the largest number, which in this case is 100. We’ve now been tasked with finding the largest number in two different lists of numbers. To do so, we can choose to duplicate the code in Listing 10-1 and use @@ -113,7 +114,8 @@ fn main() { } ``` -Listing 10-2: Code to find the largest number in *two* lists of numbers +Listing 10-2: Code to find the largest number in *two* +lists of numbers Although this code works, duplicating code is tedious and error prone. We also have to remember to update the code in multiple places when we want to change @@ -157,18 +159,20 @@ fn main() { } ``` -Listing 10-3: Abstracted code to find the largest number in two lists +Listing 10-3: Abstracted code to find the largest number +in two lists The `largest` function has a parameter called `list`, which represents any concrete slice of `i32` values we might pass into the function. As a result, -when we call the function, the code runs on the specific values that we pass in. +when we call the function, the code runs on the specific values that we pass +in. In summary, here are the steps we took to change the code from Listing 10-2 to Listing 10-3: 1. Identify duplicate code. 1. Extract the duplicate code into the body of the function, and specify the -inputs and return values of that code in the function signature. + inputs and return values of that code in the function signature. 1. Update the two instances of duplicated code to call the function instead. Next, we’ll use these same steps with generics to reduce code duplication. In @@ -237,8 +241,8 @@ fn main() { } ``` -Listing 10-4: Two functions that differ only in their names and in the types in -their signatures +Listing 10-4: Two functions that differ only in their +names and in the types in their signatures The `largest_i32` function is the one we extracted in Listing 10-3 that finds the largest `i32` in a slice. The `largest_char` function finds the largest @@ -249,7 +253,7 @@ To parameterize the types in a new single function, we need to name the type parameter, just as we do for the value parameters to a function. You can use any identifier as a type parameter name. But we’ll use `T` because, by convention, type parameter names in Rust are short, often just one letter, and -Rust’s type-naming convention is CamelCase. Short for *type*, `T` is the +Rust’s type-naming convention is UpperCamelCase. Short for *type*, `T` is the default choice of most Rust programmers. When we use a parameter in the body of the function, we have to declare the @@ -301,12 +305,14 @@ fn main() { } ``` -Listing 10-5: The `largest` function using generic type parameters; this -doesn’t compile yet +Listing 10-5: The `largest` function using generic type +parameters; this doesn’t compile yet If we compile this code right now, we’ll get this error: ``` +$ cargo run + Compiling chapter10 v0.1.0 (file:///projects/chapter10) error[E0369]: binary operation `>` cannot be applied to type `&T` --> src/main.rs:5:17 | @@ -319,6 +325,9 @@ help: consider restricting type parameter `T` | 1 | fn largest(list: &[T]) -> &T { | ++++++++++++++++++++++ + +For more information about this error, try `rustc --explain E0369`. +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error ``` The help text mentions `std::cmp::PartialOrd`, which is a *trait*, and we’re @@ -341,9 +350,9 @@ fields using the `<>` syntax. Listing 10-6 defines a `Point` struct to hold Filename: src/main.rs ``` -1 struct Point { - 2 x: T, - 3 y: T, +struct Point { + x: T, + y: T, } fn main() { @@ -352,13 +361,14 @@ fn main() { } ``` -Listing 10-6: A `Point` struct that holds `x` and `y` values of type `T` +Listing 10-6: A `Point` struct that holds `x` and `y` +values of type `T` The syntax for using generics in struct definitions is similar to that used in function definitions. First we declare the name of the type parameter inside -angle brackets just after the name of the struct [1]. Then we use the generic +angle brackets just after the name of the struct. Then we use the generic type in the struct definition where we would otherwise specify concrete data -types [23]. +types. Note that because we’ve used only one generic type to define `Point`, this definition says that the `Point` struct is generic over some type `T`, and @@ -379,8 +389,8 @@ fn main() { } ``` -Listing 10-7: The fields `x` and `y` must be the same type because both have -the same generic data type `T`. +Listing 10-7: The fields `x` and `y` must be the same +type because both have the same generic data type `T`. In this example, when we assign the integer value `5` to `x`, we let the compiler know that the generic type `T` will be an integer for this instance of @@ -388,12 +398,16 @@ compiler know that the generic type `T` will be an integer for this instance of same type as `x`, we’ll get a type mismatch error like this: ``` +$ cargo run + Compiling chapter10 v0.1.0 (file:///projects/chapter10) error[E0308]: mismatched types --> src/main.rs:7:38 | 7 | let wont_work = Point { x: 5, y: 4.0 }; - | ^^^ expected integer, found floating- -point number + | ^^^ expected integer, found floating-point number + +For more information about this error, try `rustc --explain E0308`. +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error ``` To define a `Point` struct where `x` and `y` are both generics but could have @@ -416,8 +430,8 @@ fn main() { } ``` -Listing 10-8: A `Point` generic over two types so that `x` and `y` can be -values of different types +Listing 10-8: A `Point` generic over two types so +that `x` and `y` can be values of different types Now all the instances of `Point` shown are allowed! You can use as many generic type parameters in a definition as you want, but using more than a few makes @@ -495,8 +509,9 @@ fn main() { } ``` -Listing 10-9: Implementing a method named `x` on the `Point` struct that -will return a reference to the `x` field of type `T` +Listing 10-9: Implementing a method named `x` on the +`Point` struct that will return a reference to the `x` field of type +`T` Here, we’ve defined a method named `x` on `Point` that returns a reference to the data in the field `x`. @@ -526,8 +541,8 @@ impl Point { } ``` -Listing 10-10: An `impl` block that only applies to a struct with a particular -concrete type for the generic type parameter `T` +Listing 10-10: An `impl` block that only applies to a +struct with a particular concrete type for the generic type parameter `T` This code means the type `Point` will have a `distance_from_origin` method; other instances of `Point` where `T` is not of type `f32` will not @@ -550,11 +565,8 @@ struct Point { y: Y1, } -1 impl Point { - 2 fn mixup( - self, - other: Point, - ) -> Point { +impl Point { + fn mixup(self, other: Point) -> Point { Point { x: self.x, y: other.y, @@ -563,32 +575,32 @@ struct Point { } fn main() { - 3 let p1 = Point { x: 5, y: 10.4 }; - 4 let p2 = Point { x: "Hello", y: 'c' }; + let p1 = Point { x: 5, y: 10.4 }; + let p2 = Point { x: "Hello", y: 'c' }; - 5 let p3 = p1.mixup(p2); + let p3 = p1.mixup(p2); - 6 println!("p3.x = {}, p3.y = {}", p3.x, p3.y); + println!("p3.x = {}, p3.y = {}", p3.x, p3.y); } ``` -Listing 10-11: A method that uses generic types different from its struct’s -definition +Listing 10-11: A method that uses generic types different +from its struct’s definition In `main`, we’ve defined a `Point` that has an `i32` for `x` (with value `5`) -and an `f64` for `y` (with value `10.4` [3]). The `p2` variable is a `Point` -struct that has a string slice for `x` (with value `"Hello"`) and a `char` for -`y` (with value `c` [4]). Calling `mixup` on `p1` with the argument `p2` gives -us `p3` [5], which will have an `i32` for `x` because `x` came from `p1`. The -`p3` variable will have a `char` for `y` because `y` came from `p2`. The -`println!` macro call [6] will print `p3.x = 5, p3.y = c`. +and an `f64` for `y` (with value `10.4`). The `p2` variable is a `Point` struct +that has a string slice for `x` (with value `"Hello"`) and a `char` for `y` +(with value `c`). Calling `mixup` on `p1` with the argument `p2` gives us `p3`, +which will have an `i32` for `x` because `x` came from `p1`. The `p3` variable +will have a `char` for `y` because `y` came from `p2`. The `println!` macro +call will print `p3.x = 5, p3.y = c`. The purpose of this example is to demonstrate a situation in which some generic parameters are declared with `impl` and some are declared with the method definition. Here, the generic parameters `X1` and `Y1` are declared after -`impl` [1] because they go with the struct definition. The generic parameters -`X2` and `Y2` are declared after `fn mixup` [2] because they’re only relevant -to the method. +`impl` because they go with the struct definition. The generic parameters `X2` +and `Y2` are declared after `fn mixup` because they’re only relevant to the +method. ### Performance of Code Using Generics @@ -656,7 +668,7 @@ can use *trait bounds* to specify that a generic type can be any type that has certain behavior. > Note: Traits are similar to a feature often called *interfaces* in other -languages, although with some differences. +> languages, although with some differences. ### Defining a Trait @@ -685,8 +697,8 @@ pub trait Summary { } ``` -Listing 10-12: A `Summary` trait that consists of the behavior provided by a -`summarize` method +Listing 10-12: A `Summary` trait that consists of the +behavior provided by a `summarize` method Here, we declare a trait using the `trait` keyword and then the trait’s name, which is `Summary` in this case. We also declare the trait as `pub` so that @@ -726,12 +738,7 @@ pub struct NewsArticle { impl Summary for NewsArticle { fn summarize(&self) -> String { - format!( - "{}, by {} ({})", - self.headline, - self.author, - self.location - ) + format!("{}, by {} ({})", self.headline, self.author, self.location) } } @@ -749,8 +756,8 @@ impl Summary for Tweet { } ``` -Listing 10-13: Implementing the `Summary` trait on the `NewsArticle` and -`Tweet` types +Listing 10-13: Implementing the `Summary` trait on the +`NewsArticle` and `Tweet` types Implementing a trait on a type is similar to implementing regular methods. The difference is that after `impl`, we put the trait name we want to implement, @@ -828,8 +835,8 @@ pub trait Summary { } ``` -Listing 10-14: Defining a `Summary` trait with a default implementation of the -`summarize` method +Listing 10-14: Defining a `Summary` trait with a default +implementation of the `summarize` method To use a default implementation to summarize instances of `NewsArticle`, we specify an empty `impl` block with `impl Summary for NewsArticle {}`. @@ -840,19 +847,17 @@ directly, we’ve provided a default implementation and specified that the `summarize` method on an instance of `NewsArticle`, like this: ``` -let article = NewsArticle { - headline: String::from( - "Penguins win the Stanley Cup Championship!" - ), - location: String::from("Pittsburgh, PA, USA"), - author: String::from("Iceburgh"), - content: String::from( - "The Pittsburgh Penguins once again are the best \ - hockey team in the NHL.", - ), -}; + let article = NewsArticle { + headline: String::from("Penguins win the Stanley Cup Championship!"), + location: String::from("Pittsburgh, PA, USA"), + author: String::from("Iceburgh"), + content: String::from( + "The Pittsburgh Penguins once again are the best \ + hockey team in the NHL.", + ), + }; -println!("New article available! {}", article.summarize()); + println!("New article available! {}", article.summarize()); ``` This code prints `New article available! (Read more...)`. @@ -875,10 +880,7 @@ pub trait Summary { fn summarize_author(&self) -> String; fn summarize(&self) -> String { - format!( - "(Read more from {}...)", - self.summarize_author() - ) + format!("(Read more from {}...)", self.summarize_author()) } } ``` @@ -902,16 +904,16 @@ definition of `summarize_author` that we’ve provided. Because we’ve implemen that looks like: ``` -let tweet = Tweet { - username: String::from("horse_ebooks"), - content: String::from( - "of course, as you probably already know, people", - ), - reply: false, - retweet: false, -}; + let tweet = Tweet { + username: String::from("horse_ebooks"), + content: String::from( + "of course, as you probably already know, people", + ), + reply: false, + retweet: false, + }; -println!("1 new tweet: {}", tweet.summarize()); + println!("1 new tweet: {}", tweet.summarize()); ``` This code prints `1 new tweet: (Read more from @horse_ebooks...)`. @@ -942,6 +944,9 @@ and pass in any instance of `NewsArticle` or `Tweet`. Code that calls the function with any other type, such as a `String` or an `i32`, won’t compile because those types don’t implement `Summary`. + + + #### Trait Bound Syntax The `impl Trait` syntax works for straightforward cases but is actually syntax @@ -979,7 +984,7 @@ The generic type `T` specified as the type of the `item1` and `item2` parameters constrains the function such that the concrete type of the value passed as an argument for `item1` and `item2` must be the same. -#### Specifying Multiple Trait Bounds with the + Syntax +#### Specifying Multiple Trait Bounds with the `+` Syntax We can also specify more than one trait bound. Say we wanted `notify` to use display formatting as well as `summarize` on `item`: we specify in the `notify` @@ -999,7 +1004,7 @@ pub fn notify(item: &T) { With the two trait bounds specified, the body of `notify` can call `summarize` and use `{}` to format `item`. -#### Clearer Trait Bounds with where Clauses +#### Clearer Trait Bounds with `where` Clauses Using too many trait bounds has its downsides. Each generic has its own trait bounds, so functions with multiple generic type parameters can contain lots of @@ -1089,20 +1094,21 @@ fn returns_summarizable(switch: bool) -> impl Summary { Returning either a `NewsArticle` or a `Tweet` isn’t allowed due to restrictions around how the `impl Trait` syntax is implemented in the compiler. We’ll cover -how to write a function with this behavior in “Using Trait Objects That Allow -for Values of Different Types” on page XX. +how to write a function with this behavior in the “Using Trait Objects That +Allow for Values of Different +Types” section of Chapter 17. ### Using Trait Bounds to Conditionally Implement Methods By using a trait bound with an `impl` block that uses generic type parameters, we can implement methods conditionally for types that implement the specified traits. For example, the type `Pair` in Listing 10-15 always implements the -`new` function to return a new instance of `Pair` (recall from “Defining -Methods” on page XX that `Self` is a type alias for the type of the `impl` -block, which in this case is `Pair`). But in the next `impl` block, -`Pair` only implements the `cmp_display` method if its inner type `T` -implements the `PartialOrd` trait that enables comparison *and* the `Display` -trait that enables printing. +`new` function to return a new instance of `Pair` (recall from the +“Defining Methods” section of Chapter 5 that `Self` +is a type alias for the type of the `impl` block, which in this case is +`Pair`). But in the next `impl` block, `Pair` only implements the +`cmp_display` method if its inner type `T` implements the `PartialOrd` trait +that enables comparison *and* the `Display` trait that enables printing. Filename: src/lib.rs @@ -1131,8 +1137,8 @@ impl Pair { } ``` -Listing 10-15: Conditionally implementing methods on a generic type depending -on trait bounds +Listing 10-15: Conditionally implementing methods on a +generic type depending on trait bounds We can also conditionally implement a trait for any type that implements another trait. Implementations of a trait on any type that satisfies the trait @@ -1143,7 +1149,7 @@ block in the standard library looks similar to this code: ``` impl ToString for T { - --snip-- + // --snip-- } ``` @@ -1177,12 +1183,13 @@ Lifetimes are another kind of generic that we’ve already been using. Rather than ensuring that a type has the behavior we want, lifetimes ensure that references are valid as long as we need them to be. -One detail we didn’t discuss in “References and Borrowing” on page XX is that -every reference in Rust has a *lifetime*, which is the scope for which that -reference is valid. Most of the time, lifetimes are implicit and inferred, just -like most of the time, types are inferred. We must annotate types only when -multiple types are possible. In a similar way, we must annotate lifetimes when -the lifetimes of references could be related in a few different ways. Rust +One detail we didn’t discuss in the “References and +Borrowing” section in Chapter 4 is +that every reference in Rust has a *lifetime*, which is the scope for which +that reference is valid. Most of the time, lifetimes are implicit and inferred, +just like most of the time, types are inferred. We must annotate types only +when multiple types are possible. In a similar way, we must annotate lifetimes +when the lifetimes of references could be related in a few different ways. Rust requires us to annotate the relationships using generic lifetime parameters to ensure the actual references used at runtime will definitely be valid. @@ -1200,44 +1207,52 @@ scope. ``` fn main() { - 1 let r; + let r; { - 2 let x = 5; - 3 r = &x; - 4 } + let x = 5; + r = &x; + } - 5 println!("r: {r}"); + println!("r: {r}"); } ``` -Listing 10-16: An attempt to use a reference whose value has gone out of scope +Listing 10-16: An attempt to use a reference whose value +has gone out of scope > Note: The examples in Listing 10-16, 10-17, and 10-23 declare variables -without giving them an initial value, so the variable name exists in the outer -scope. At first glance, this might appear to be in conflict with Rust’s having -no null values. However, if we try to use a variable before giving it a value, -we’ll get a compile-time error, which shows that Rust indeed does not allow -null values. - -The outer scope declares a variable named `r` with no initial value [1], and -the inner scope declares a variable named `x` with the initial value of `5` -[2]. Inside the inner scope, we attempt to set the value of `r` as a reference -to `x` [3]. Then the inner scope ends [4], and we attempt to print the value in -`r` [5]. This code won’t compile because the value that `r` is referring to has -gone out of scope before we try to use it. Here is the error message: - -``` +> without giving them an initial value, so the variable name exists in the outer +> scope. At first glance, this might appear to be in conflict with Rust’s having +> no null values. However, if we try to use a variable before giving it a value, +> we’ll get a compile-time error, which shows that Rust indeed does not allow +> null values. + +The outer scope declares a variable named `r` with no initial value, and the +inner scope declares a variable named `x` with the initial value of `5`. Inside +the inner scope, we attempt to set the value of `r` as a reference to `x`. Then +the inner scope ends, and we attempt to print the value in `r`. This code won’t +compile because the value that `r` is referring to has gone out of scope before +we try to use it. Here is the error message: + +``` +$ cargo run + Compiling chapter10 v0.1.0 (file:///projects/chapter10) error[E0597]: `x` does not live long enough --> src/main.rs:6:13 | +5 | let x = 5; + | - binding `x` declared here 6 | r = &x; | ^^ borrowed value does not live long enough 7 | } | - `x` dropped here while still borrowed 8 | -9 | println!("r: {r}"); - | - borrow later used here +9 | println!("r: {}", r); + | - borrow later used here + +For more information about this error, try `rustc --explain E0597`. +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error ``` The error message says that the variable `x` “does not live long enough.” The @@ -1267,8 +1282,8 @@ fn main() { } // ---------+ ``` -Listing 10-17: Annotations of the lifetimes of `r` and `x`, named `'a` and -`'b`, respectively +Listing 10-17: Annotations of the lifetimes of `r` and +`x`, named `'a` and `'b`, respectively Here, we’ve annotated the lifetime of `r` with `'a` and the lifetime of `x` with `'b`. As you can see, the inner `'b` block is much smaller than the outer @@ -1291,8 +1306,8 @@ fn main() { } // ----------+ ``` -Listing 10-18: A valid reference because the data has a longer lifetime than -the reference +Listing 10-18: A valid reference because the data has a +longer lifetime than the reference Here, `x` has the lifetime `'b`, which in this case is larger than `'a`. This means `r` can reference `x` because Rust knows that the reference in `r` will @@ -1321,12 +1336,13 @@ fn main() { } ``` -Listing 10-19: A `main` function that calls the `longest` function to find the -longer of two string slices +Listing 10-19: A `main` function that calls the `longest` +function to find the longer of two string slices Note that we want the function to take string slices, which are references, rather than strings, because we don’t want the `longest` function to take -ownership of its parameters. Refer to “String Slices as Parameters” on page XX +ownership of its parameters. Refer to the “String Slices as +Parameters” section in Chapter 4 for more discussion about why the parameters we use in Listing 10-19 are the ones we want. @@ -1345,24 +1361,29 @@ fn longest(x: &str, y: &str) -> &str { } ``` -Listing 10-20: An implementation of the `longest` function that returns the -longer of two string slices but does not yet compile +Listing 10-20: An implementation of the `longest` +function that returns the longer of two string slices but does not yet +compile Instead, we get the following error that talks about lifetimes: ``` +$ cargo run + Compiling chapter10 v0.1.0 (file:///projects/chapter10) error[E0106]: missing lifetime specifier --> src/main.rs:9:33 | 9 | fn longest(x: &str, y: &str) -> &str { | ---- ---- ^ expected named lifetime parameter | - = help: this function's return type contains a borrowed value, -but the signature does not say whether it is borrowed from `x` or `y` + = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y` help: consider introducing a named lifetime parameter | 9 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { | ++++ ++ ++ ++ + +For more information about this error, try `rustc --explain E0106`. +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error ``` The help text reveals that the return type needs a generic lifetime parameter @@ -1435,8 +1456,9 @@ fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { } ``` -Listing 10-21: The `longest` function definition specifying that all the -references in the signature must have the same lifetime `'a` +Listing 10-21: The `longest` function definition +specifying that all the references in the signature must have the same lifetime +`'a` This code should compile and produce the result we want when we use it with the `main` function in Listing 10-19. @@ -1494,8 +1516,8 @@ fn main() { } ``` -Listing 10-22: Using the `longest` function with references to `String` values -that have different concrete lifetimes +Listing 10-22: Using the `longest` function with +references to `String` values that have different concrete lifetimes In this example, `string1` is valid until the end of the outer scope, `string2` is valid until the end of the inner scope, and `result` references something @@ -1525,21 +1547,28 @@ fn main() { } ``` -Listing 10-23: Attempting to use `result` after `string2` has gone out of scope +Listing 10-23: Attempting to use `result` after `string2` +has gone out of scope When we try to compile this code, we get this error: ``` +$ cargo run + Compiling chapter10 v0.1.0 (file:///projects/chapter10) error[E0597]: `string2` does not live long enough --> src/main.rs:6:44 | +5 | let string2 = String::from("xyz"); + | ------- binding `string2` declared here 6 | result = longest(string1.as_str(), string2.as_str()); - | ^^^^^^^^^^^^^^^^ borrowed value -does not live long enough + | ^^^^^^^ borrowed value does not live long enough 7 | } | - `string2` dropped here while still borrowed 8 | println!("The longest string is {result}"); | ------ borrow later used here + +For more information about this error, try `rustc --explain E0597`. +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error ``` The error shows that for `result` to be valid for the `println!` statement, @@ -1604,12 +1633,19 @@ lifetime is not related to the lifetime of the parameters at all. Here is the error message we get: ``` -error[E0515]: cannot return reference to local variable `result` +$ cargo run + Compiling chapter10 v0.1.0 (file:///projects/chapter10) +error[E0515]: cannot return value referencing local variable `result` --> src/main.rs:11:5 | 11 | result.as_str() - | ^^^^^^^^^^^^^^^ returns a reference to data owned by the -current function + | ------^^^^^^^^^ + | | + | returns a value referencing data owned by the current function + | `result` is borrowed here + +For more information about this error, try `rustc --explain E0515`. +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error ``` The problem is that `result` goes out of scope and gets cleaned up at the end @@ -1635,39 +1671,35 @@ on every reference in the struct’s definition. Listing 10-24 has a struct name Filename: src/main.rs ``` -1 struct ImportantExcerpt<'a> { - 2 part: &'a str, +struct ImportantExcerpt<'a> { + part: &'a str, } fn main() { - 3 let novel = String::from( - "Call me Ishmael. Some years ago..." - ); - 4 let first_sentence = novel - .split('.') - .next() - .expect("Could not find a '.'"); - 5 let i = ImportantExcerpt { + let novel = String::from("Call me Ishmael. Some years ago..."); + let first_sentence = novel.split('.').next().expect("Could not find a '.'"); + let i = ImportantExcerpt { part: first_sentence, }; } ``` -Listing 10-24: A struct that holds a reference, requiring a lifetime annotation +Listing 10-24: A struct that holds a reference, requiring +a lifetime annotation This struct has the single field `part` that holds a string slice, which is a -reference [2]. As with generic data types, we declare the name of the generic +reference. As with generic data types, we declare the name of the generic lifetime parameter inside angle brackets after the name of the struct so we can -use the lifetime parameter in the body of the struct definition [1]. This +use the lifetime parameter in the body of the struct definition. This annotation means an instance of `ImportantExcerpt` can’t outlive the reference it holds in its `part` field. The `main` function here creates an instance of the `ImportantExcerpt` struct -[5] that holds a reference to the first sentence of the `String` [4] owned by -the variable `novel` [3]. The data in `novel` exists before the -`ImportantExcerpt` instance is created. In addition, `novel` doesn’t go out of -scope until after the `ImportantExcerpt` goes out of scope, so the reference in -the `ImportantExcerpt` instance is valid. +that holds a reference to the first sentence of the `String` owned by the +variable `novel`. The data in `novel` exists before the `ImportantExcerpt` +instance is created. In addition, `novel` doesn’t go out of scope until after +the `ImportantExcerpt` goes out of scope, so the reference in the +`ImportantExcerpt` instance is valid. ### Lifetime Elision @@ -1692,8 +1724,9 @@ fn first_word(s: &str) -> &str { } ``` -Listing 10-25: A function we defined in Listing 4-9 that compiled without -lifetime annotations, even though the parameter and return type are references +Listing 10-25: A function we defined in Listing 4-9 that +compiled without lifetime annotations, even though the parameter and return +type are references The reason this function compiles without lifetime annotations is historical: in early versions (pre-1.0) of Rust, this code wouldn’t have compiled because @@ -1924,7 +1957,5 @@ Believe it or not, there is much more to learn on the topics we discussed in this chapter: Chapter 17 discusses trait objects, which are another way to use traits. There are also more complex scenarios involving lifetime annotations that you will only need in very advanced scenarios; for those, you should read -the Rust Reference at *https://doc.rust-lang.org/reference/trait-bounds.html*. -But next, you’ll learn how to write tests in Rust so you can make sure your -code is working the way it should. - +the Rust Reference at *../reference/index.html*. But next, you’ll learn how to write tests in +Rust so you can make sure your code is working the way it should. From 81e74f93aa938a8536de391f8b93ff40aa49d4ee Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 17 May 2024 12:23:56 -0400 Subject: [PATCH 223/720] Snapshot changes to ch 10 to consider sending to nostarch --- nostarch/chapter10.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nostarch/chapter10.md b/nostarch/chapter10.md index dc1590ac67..bc315d12ce 100644 --- a/nostarch/chapter10.md +++ b/nostarch/chapter10.md @@ -1193,9 +1193,9 @@ when the lifetimes of references could be related in a few different ways. Rust requires us to annotate the relationships using generic lifetime parameters to ensure the actual references used at runtime will definitely be valid. -Annotating lifetimes is not even a concept most other programming languages -have, so this is going to feel unfamiliar. Although we won’t cover lifetimes in -their entirety in this chapter, we’ll discuss common ways you might encounter +Annotating lifetimes is not a concept most other programming languages have, so +this is going to feel unfamiliar. Although we won’t cover lifetimes in their +entirety in this chapter, we’ll discuss common ways you might encounter lifetime syntax so you can get comfortable with the concept. ### Preventing Dangling References with Lifetimes @@ -1313,7 +1313,7 @@ Here, `x` has the lifetime `'b`, which in this case is larger than `'a`. This means `r` can reference `x` because Rust knows that the reference in `r` will always be valid while `x` is valid. -Now that you know where the lifetimes of references are and how Rust analyzes +Now that you know what the lifetimes of references are and how Rust analyzes lifetimes to ensure references will always be valid, let’s explore generic lifetimes of parameters and return values in the context of functions. From 36bc7f0e0728e15a371836c0b0c3c5078a7afeee Mon Sep 17 00:00:00 2001 From: bryanzierk Date: Wed, 12 Jun 2024 08:43:03 -0600 Subject: [PATCH 224/720] Convert chapter 11 to use Listing component --- src/ch11-01-writing-tests.md | 57 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index f1295931f4..3b83195fa2 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -43,7 +43,7 @@ $ cd adder The contents of the *src/lib.rs* file in your `adder` library should look like Listing 11-1. -Filename: src/lib.rs + , where we called `panic!` when the @@ -265,14 +261,13 @@ function we’re now calling `Config::build` and the body of the function needed to return a `Result`. Note that this won’t compile until we update `main` as well, which we’ll do in the next listing. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-09/src/main.rs:here}} ``` -Listing 12-9: Returning a `Result` from -`Config::build` + Our `build` function returns a `Result` with a `Config` instance in the success case and a `&'static str` in the error case. Our error values will always be @@ -299,14 +294,13 @@ tool with a nonzero error code away from `panic!` and instead implement it by hand. A nonzero exit status is a convention to signal to the process that called our program that the program exited with an error state. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-10/src/main.rs:here}} ``` -Listing 12-10: Exiting with an error code if building a -`Config` fails + In this listing, we’ve used a method we haven’t covered in detail yet: `unwrap_or_else`, which is defined on `Result` by the standard library. @@ -350,14 +344,15 @@ Listing 12-11 shows the extracted `run` function. For now, we’re just making the small, incremental improvement of extracting the function. We’re still defining the function in *src/main.rs*. ++ Filename: src/main.rs ```rust,ignore {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-11/src/main.rs:here}} ``` -Listing 12-11: Extracting a `run` function containing the -rest of the program logic + The `run` function now contains all the remaining logic from `main`, starting from reading the file. The `run` function takes the `Config` instance as an @@ -373,14 +368,13 @@ us further consolidate the logic around handling errors into `main` in a user-friendly way. Listing 12-12 shows the changes we need to make to the signature and body of `run`. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-12/src/main.rs:here}} ``` -Listing 12-12: Changing the `run` function to return -`Result` + We’ve made three significant changes here. First, we changed the return type of the `run` function to `Result<(), Box>`. This function previously @@ -458,14 +452,13 @@ The contents of *src/lib.rs* should have the signatures shown in Listing 12-13 (we’ve omitted the bodies of the functions for brevity). Note that this won’t compile until we modify *src/main.rs* in Listing 12-14. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-13/src/lib.rs:here}} ``` -Listing 12-13: Moving `Config` and `run` into -*src/lib.rs* + We’ve made liberal use of the `pub` keyword: on `Config`, on its fields and its `build` method, and on the `run` function. We now have a library crate that has @@ -474,14 +467,13 @@ a public API we can test! Now we need to bring the code we moved to *src/lib.rs* into the scope of the binary crate in *src/main.rs*, as shown in Listing 12-14. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-14/src/main.rs:here}} ``` -Listing 12-14: Using the `minigrep` library crate in -*src/main.rs* + We add a `use minigrep::Config` line to bring the `Config` type from the library crate into the binary crate’s scope, and we prefix the `run` function diff --git a/src/ch12-04-testing-the-librarys-functionality.md b/src/ch12-04-testing-the-librarys-functionality.md index 129f835aa1..c4a435bc08 100644 --- a/src/ch12-04-testing-the-librarys-functionality.md +++ b/src/ch12-04-testing-the-librarys-functionality.md @@ -35,14 +35,13 @@ behavior we want the `search` function to have: it will take a query and the text to search, and it will return only the lines from the text that contain the query. Listing 12-15 shows this test, which won’t compile yet. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-15/src/lib.rs:here}} ``` -Listing 12-15: Creating a failing test for the `search` -function we wish we had + This test searches for the string `"duct"`. The text we’re searching is three lines, only one of which contains `"duct"` (Note that the backslash after the @@ -58,14 +57,13 @@ vector, as shown in Listing 12-16. Then the test should compile and fail because an empty vector doesn’t match a vector containing the line `"safe, fast, productive."` -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-16/src/lib.rs:here}} ``` -Listing 12-16: Defining just enough of the `search` -function so our test will compile + Notice that we need to define an explicit lifetime `'a` in the signature of `search` and use that lifetime with the `contents` argument and the return @@ -128,14 +126,13 @@ Rust has a helpful method to handle line-by-line iteration of strings, conveniently named `lines`, that works as shown in Listing 12-17. Note this won’t compile yet. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-17/src/lib.rs:here}} ``` -Listing 12-17: Iterating through each line in `contents` - + The `lines` method returns an iterator. We’ll talk about iterators in depth in [Chapter 13][ch13-iterators], but recall that you saw this way @@ -149,14 +146,13 @@ Fortunately, strings have a helpful method named `contains` that does this for us! Add a call to the `contains` method in the `search` function, as shown in Listing 12-18. Note this still won’t compile yet. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-18/src/lib.rs:here}} ``` -Listing 12-18: Adding functionality to see whether the -line contains the string in `query` + At the moment, we’re building up functionality. To get it to compile, we need to return a value from the body as we indicated we would in the function @@ -169,14 +165,13 @@ to return. For that, we can make a mutable vector before the `for` loop and call the `push` method to store a `line` in the vector. After the `for` loop, we return the vector, as shown in Listing 12-19. -Filename: src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-19/src/lib.rs:here}} ``` -Listing 12-19: Storing the lines that match so we can -return them + Now the `search` function should return only the lines that contain `query`, and our test should pass. Let’s run the test: diff --git a/src/ch12-05-working-with-environment-variables.md b/src/ch12-05-working-with-environment-variables.md index 263c80cd06..f050b5b479 100644 --- a/src/ch12-05-working-with-environment-variables.md +++ b/src/ch12-05-working-with-environment-variables.md @@ -16,14 +16,13 @@ the new `search_case_insensitive` function and rename our old test from `one_result` to `case_sensitive` to clarify the differences between the two tests, as shown in Listing 12-20. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-20/src/lib.rs:here}} ``` -Listing 12-20: Adding a new failing test for the -case-insensitive function we’re about to add + Note that we’ve edited the old test’s `contents` too. We’ve added a new line with the text `"Duct tape."` using a capital D that shouldn’t match the query @@ -48,14 +47,13 @@ the same as the `search` function. The only difference is that we’ll lowercase the `query` and each `line` so whatever the case of the input arguments, they’ll be the same case when we check whether the line contains the query. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-21/src/lib.rs:here}} ``` -Listing 12-21: Defining the `search_case_insensitive` -function to lowercase the query and the line before comparing them + First, we lowercase the `query` string and store it in a shadowed variable with the same name. Calling `to_lowercase` on the query is necessary so no @@ -101,14 +99,13 @@ function to check the `ignore_case` field’s value and use that to decide whether to call the `search` function or the `search_case_insensitive` function, as shown in Listing 12-22. This still won’t compile yet. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-22/src/lib.rs:there}} ``` -Listing 12-22: Calling either `search` or -`search_case_insensitive` based on the value in `config.ignore_case` + Finally, we need to check for the environment variable. The functions for working with environment variables are in the `env` module in the standard @@ -117,14 +114,13 @@ we’ll use the `var` function from the `env` module to check if any value has been set for an environment variable named `IGNORE_CASE`, as shown in Listing 12-23. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-23/src/lib.rs:here}} ``` -Listing 12-23: Checking for any value in an environment -variable named `IGNORE_CASE` + Here, we create a new variable `ignore_case`. To set its value, we call the `env::var` function and pass it the name of the `IGNORE_CASE` environment diff --git a/src/ch12-06-writing-to-stderr-instead-of-stdout.md b/src/ch12-06-writing-to-stderr-instead-of-stdout.md index d017fa3245..99e50e6f00 100644 --- a/src/ch12-06-writing-to-stderr-instead-of-stdout.md +++ b/src/ch12-06-writing-to-stderr-instead-of-stdout.md @@ -54,14 +54,13 @@ the `eprintln!` macro that prints to the standard error stream, so let’s chang the two places we were calling `println!` to print errors to use `eprintln!` instead. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-24/src/main.rs:here}} ``` -Listing 12-24: Writing error messages to standard error -instead of standard output using `eprintln!` + Let’s now run the program again in the same way, without any arguments and redirecting standard output with `>`: diff --git a/src/ch13-01-closures.md b/src/ch13-01-closures.md index a1e1cec80e..1983fbdacf 100644 --- a/src/ch13-01-closures.md +++ b/src/ch13-01-closures.md @@ -35,13 +35,13 @@ The method `giveaway` defined on `Inventory` gets the optional shirt color preference of the free shirt winner, and returns the shirt color the person will get. This setup is shown in Listing 13-1: -Filename: src/main.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch13-functional-features/listing-13-01/src/main.rs}} ``` -Listing 13-1: Shirt company giveaway situation + The `store` defined in `main` has two blue shirts and one red shirt remaining to distribute for this limited-edition promotion. We call the `giveaway` method @@ -105,14 +105,13 @@ shown in Listing 13-2. In this example, we’re defining a closure and storing i in a variable rather than defining the closure in the spot we pass it as an argument as we did in Listing 13-1. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-02/src/main.rs:here}} ``` -Listing 13-2: Adding optional type annotations of the -parameter and return value types in the closure + With type annotations added, the syntax of closures looks more similar to the syntax of functions. Here we define a function that adds 1 to its parameter and @@ -147,14 +146,13 @@ Because there are no type annotations, we can call the closure with any type, which we’ve done here with `String` the first time. If we then try to call `example_closure` with an integer, we’ll get an error. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch13-functional-features/listing-13-03/src/main.rs:here}} ``` -Listing 13-3: Attempting to call a closure whose types -are inferred with two different types + The compiler gives us this error: @@ -179,14 +177,13 @@ In Listing 13-4, we define a closure that captures an immutable reference to the vector named `list` because it only needs an immutable reference to print the value: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-04/src/main.rs}} ``` -Listing 13-4: Defining and calling a closure that -captures an immutable reference + This example also illustrates that a variable can bind to a closure definition, and we can later call the closure by using the variable name and parentheses as @@ -204,14 +201,13 @@ is called. This code compiles, runs, and prints: Next, in Listing 13-5, we change the closure body so that it adds an element to the `list` vector. The closure now captures a mutable reference: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-05/src/main.rs}} ``` -Listing 13-5: Defining and calling a closure that -captures a mutable reference + This code compiles, runs, and prints: @@ -238,14 +234,13 @@ concurrency, but for now, let’s briefly explore spawning a new thread using a closure that needs the `move` keyword. Listing 13-6 shows Listing 13-4 modified to print the vector in a new thread rather than in the main thread: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-06/src/main.rs}} ``` -Listing 13-6: Using `move` to force the closure for the -thread to take ownership of `list` + We spawn a new thread, giving the thread a closure to run as an argument. The closure body prints out the list. In Listing 13-4, the closure only captured @@ -348,14 +343,13 @@ when you want to sort a slice by a particular attribute of each item. In Listing 13-7, we have a list of `Rectangle` instances and we use `sort_by_key` to order them by their `width` attribute from low to high: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-07/src/main.rs}} ``` -Listing 13-7: Using `sort_by_key` to order rectangles by -width + This code prints: @@ -372,14 +366,13 @@ In contrast, Listing 13-8 shows an example of a closure that implements just the `FnOnce` trait, because it moves a value out of the environment. The compiler won’t let us use this closure with `sort_by_key`: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch13-functional-features/listing-13-08/src/main.rs}} ``` -Listing 13-8: Attempting to use an `FnOnce` closure with -`sort_by_key` + This is a contrived, convoluted way (that doesn’t work) to try and count the number of times `sort_by_key` calls the closure when sorting `list`. This code @@ -406,14 +399,13 @@ in Listing 13-9 works with `sort_by_key` because it is only capturing a mutable reference to the `num_sort_operations` counter and can therefore be called more than once: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-09/src/main.rs}} ``` -Listing 13-9: Using an `FnMut` closure with `sort_by_key` -is allowed + The `Fn` traits are important when defining or using functions or types that make use of closures. In the next section, we’ll discuss iterators. Many diff --git a/src/ch13-02-iterators.md b/src/ch13-02-iterators.md index 030ebf48eb..c99fcd6998 100644 --- a/src/ch13-02-iterators.md +++ b/src/ch13-02-iterators.md @@ -11,11 +11,13 @@ Listing 13-10 creates an iterator over the items in the vector `v1` by calling the `iter` method defined on `Vec`. This code by itself doesn’t do anything useful. ++ ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-10/src/main.rs:here}} ``` -Listing 13-10: Creating an iterator + The iterator is stored in the `v1_iter` variable. Once we’ve created an iterator, we can use it in a variety of ways. In Listing 3-5 in Chapter 3, we @@ -28,11 +30,13 @@ the use of the iterator in the `for` loop. When the `for` loop is called using the iterator in `v1_iter`, each element in the iterator is used in one iteration of the loop, which prints out each value. ++ ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-11/src/main.rs:here}} ``` -Listing 13-11: Using an iterator in a `for` loop + In languages that don’t have iterators provided by their standard libraries, you would likely write this same functionality by starting a variable at index @@ -76,14 +80,13 @@ We can call the `next` method on iterators directly; Listing 13-12 demonstrates what values are returned from repeated calls to `next` on the iterator created from the vector. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch13-functional-features/listing-13-12/src/lib.rs:here}} ``` -Listing 13-12: Calling the `next` method on an -iterator + Note that we needed to make `v1_iter` mutable: calling the `next` method on an iterator changes internal state that the iterator uses to keep track of where @@ -115,14 +118,13 @@ consuming the iterator. As it iterates through, it adds each item to a running total and returns the total when iteration is complete. Listing 13-13 has a test illustrating a use of the `sum` method: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch13-functional-features/listing-13-13/src/lib.rs:here}} ``` -Listing 13-13: Calling the `sum` method to get the total -of all items in the iterator + We aren’t allowed to use `v1_iter` after the call to `sum` because `sum` takes ownership of the iterator we call it on. @@ -139,14 +141,13 @@ The `map` method returns a new iterator that produces the modified items. The closure here creates a new iterator in which each item from the vector will be incremented by 1: -Filename: src/main.rs + ```rust,not_desired_behavior {{#rustdoc_include ../listings/ch13-functional-features/listing-13-14/src/main.rs:here}} ``` -Listing 13-14: Calling the iterator adaptor `map` to -create a new iterator + However, this code produces a warning: @@ -167,15 +168,13 @@ In Listing 13-15, we collect the results of iterating over the iterator that’s returned from the call to `map` into a vector. This vector will end up containing each item from the original vector incremented by 1. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch13-functional-features/listing-13-15/src/main.rs:here}} ``` -Listing 13-15: Calling the `map` method to create a new -iterator and then calling the `collect` method to consume the new iterator and -create a vector + Because `map` takes a closure, we can specify any operation we want to perform on each item. This is a great example of how closures let you customize some @@ -201,14 +200,13 @@ In Listing 13-16, we use `filter` with a closure that captures the `shoe_size` variable from its environment to iterate over a collection of `Shoe` struct instances. It will return only shoes that are the specified size. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch13-functional-features/listing-13-16/src/lib.rs}} ``` -Listing 13-16: Using the `filter` method with a closure -that captures `shoe_size` + The `shoes_in_size` function takes ownership of a vector of shoes and a shoe size as parameters. It returns a vector containing only shoes of the specified diff --git a/src/ch13-03-improving-our-io-project.md b/src/ch13-03-improving-our-io-project.md index e4deec5627..4c1a508458 100644 --- a/src/ch13-03-improving-our-io-project.md +++ b/src/ch13-03-improving-our-io-project.md @@ -13,14 +13,13 @@ values, allowing the `Config` struct to own those values. In Listing 13-17, we’ve reproduced the implementation of the `Config::build` function as it was in Listing 12-23: -Filename: src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch13-functional-features/listing-12-23-reproduced/src/lib.rs:ch13}} ``` -Listing 13-17: Reproduction of the `Config::build` -function from Listing 12-23 + At the time, we said not to worry about the inefficient `clone` calls because we would remove them in the future. Well, that time is now! @@ -54,14 +53,13 @@ We’ll first change the start of the `main` function that we had in Listing 12-24 to the code in Listing 13-18, which this time uses an iterator. This won’t compile until we update `Config::build` as well. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch13-functional-features/listing-13-18/src/main.rs:here}} ``` -Listing 13-18: Passing the return value of `env::args` to -`Config::build` + The `env::args` function returns an iterator! Rather than collecting the iterator values into a vector and then passing a slice to `Config::build`, now @@ -73,14 +71,13 @@ project’s *src/lib.rs* file, let’s change the signature of `Config::build` t look like Listing 13-19. This still won’t compile because we need to update the function body. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch13-functional-features/listing-13-19/src/lib.rs:here}} ``` -Listing 13-19: Updating the signature of `Config::build` -to expect an iterator + The standard library documentation for the `env::args` function shows that the type of the iterator it returns is `std::env::Args`, and that type implements @@ -103,14 +100,13 @@ Next, we’ll fix the body of `Config::build`. Because `args` implements the `Iterator` trait, we know we can call the `next` method on it! Listing 13-20 updates the code from Listing 12-23 to use the `next` method: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch13-functional-features/listing-13-20/src/lib.rs:here}} ``` -Listing 13-20: Changing the body of `Config::build` to use -iterator methods + Remember that the first value in the return value of `env::args` is the name of the program. We want to ignore that and get to the next value, so first we call @@ -125,14 +121,13 @@ the same thing for the `file_path` value. We can also take advantage of iterators in the `search` function in our I/O project, which is reproduced here in Listing 13-21 as it was in Listing 12-19: -Filename: src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-19/src/lib.rs:ch13}} ``` -Listing 13-21: The implementation of the `search` -function from Listing 12-19 + We can write this code in a more concise way using iterator adaptor methods. Doing so also lets us avoid having a mutable intermediate `results` vector. The @@ -141,14 +136,13 @@ make code clearer. Removing the mutable state might enable a future enhancement to make searching happen in parallel, because we wouldn’t have to manage concurrent access to the `results` vector. Listing 13-22 shows this change: -Filename: src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch13-functional-features/listing-13-22/src/lib.rs:here}} ``` -Listing 13-22: Using iterator adaptor methods in the -implementation of the `search` function + Recall that the purpose of the `search` function is to return all lines in `contents` that contain the `query`. Similar to the `filter` example in Listing diff --git a/src/ch14-02-publishing-to-crates-io.md b/src/ch14-02-publishing-to-crates-io.md index d4d33babc4..b4cfb22d6c 100644 --- a/src/ch14-02-publishing-to-crates-io.md +++ b/src/ch14-02-publishing-to-crates-io.md @@ -26,14 +26,13 @@ Markdown notation for formatting the text. Place documentation comments just before the item they’re documenting. Listing 14-1 shows documentation comments for an `add_one` function in a crate named `my_crate`. -Filename: src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-01/src/lib.rs}} ``` -Listing 14-1: A documentation comment for a -function + Here, we give a description of what the `add_one` function does, start a section with the heading `Examples`, and then provide code that demonstrates @@ -115,14 +114,13 @@ crate that contains the `add_one` function, we add documentation comments that start with `//!` to the beginning of the *src/lib.rs* file, as shown in Listing 14-2: -Filename: src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-02/src/lib.rs:here}} ``` -Listing 14-2: Documentation for the `my_crate` crate as a -whole + Notice there isn’t any code after the last line that begins with `//!`. Because we started the comments with `//!` instead of `///`, we’re documenting the item @@ -172,14 +170,13 @@ Within this library are two modules: a `kinds` module containing two enums named `PrimaryColor` and `SecondaryColor` and a `utils` module containing a function named `mix`, as shown in Listing 14-3: -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-03/src/lib.rs:here}} ``` -Listing 14-3: An `art` library with items organized into -`kinds` and `utils` modules + Figure 14-3 shows what the front page of the documentation for this crate generated by `cargo doc` would look like: @@ -198,14 +195,13 @@ bring the items from `art` into scope, specifying the module structure that’s currently defined. Listing 14-4 shows an example of a crate that uses the `PrimaryColor` and `mix` items from the `art` crate: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-04/src/main.rs}} ``` -Listing 14-4: A crate using the `art` crate’s items with -its internal structure exported + The author of the code in Listing 14-4, which uses the `art` crate, had to figure out that `PrimaryColor` is in the `kinds` module and `mix` is in the @@ -220,14 +216,13 @@ To remove the internal organization from the public API, we can modify the `art` crate code in Listing 14-3 to add `pub use` statements to re-export the items at the top level, as shown in Listing 14-5: -Filename: src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-05/src/lib.rs:here}} ``` -Listing 14-5: Adding `pub use` statements to re-export -items + The API documentation that `cargo doc` generates for this crate will now list and link re-exports on the front page, as shown in Figure 14-4, making the @@ -242,14 +237,13 @@ The `art` crate users can still see and use the internal structure from Listing 14-3 as demonstrated in Listing 14-4, or they can use the more convenient structure in Listing 14-5, as shown in Listing 14-6: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-06/src/main.rs:here}} ``` -Listing 14-6: A program using the re-exported items from -the `art` crate + In cases where there are many nested modules, re-exporting the types at the top level with `pub use` can make a significant difference in the experience of diff --git a/src/ch14-03-cargo-workspaces.md b/src/ch14-03-cargo-workspaces.md index cbece82335..afc9c65a7c 100644 --- a/src/ch14-03-cargo-workspaces.md +++ b/src/ch14-03-cargo-workspaces.md @@ -142,14 +142,13 @@ Next, let’s use the `add_one` function (from the `add_one` crate) in the top to bring the new `add_one` library crate into scope. Then change the `main` function to call the `add_one` function, as in Listing 14-7. -Filename: adder/src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-07/add/adder/src/main.rs}} ``` -Listing 14-7: Using the `add_one` library crate from the - `adder` crate + Let’s build the workspace by running `cargo build` in the top-level *add* directory! diff --git a/src/ch15-01-box.md b/src/ch15-01-box.md index 53e829a4c3..ae31195682 100644 --- a/src/ch15-01-box.md +++ b/src/ch15-01-box.md @@ -35,14 +35,13 @@ syntax and how to interact with values stored within a `Box`. Listing 15-1 shows how to use a box to store an `i32` value on the heap: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-01/src/main.rs}} ``` -Listing 15-1: Storing an `i32` value on the heap using a -box + We define the variable `b` to have the value of a `Box` that points to the value `5`, which is allocated on the heap. This program will print `b = 5`; in @@ -106,14 +105,13 @@ Listing 15-2 contains an enum definition for a cons list. Note that this code won’t compile yet because the `List` type doesn’t have a known size, which we’ll demonstrate. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-02/src/main.rs:here}} ``` -Listing 15-2: The first attempt at defining an enum to -represent a cons list data structure of `i32` values + > Note: We’re implementing a cons list that holds only `i32` values for the > purposes of this example. We could have implemented it using generics, as we @@ -123,14 +121,13 @@ represent a cons list data structure of `i32` values Using the `List` type to store the list `1, 2, 3` would look like the code in Listing 15-3: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-03/src/main.rs:here}} ``` -Listing 15-3: Using the `List` enum to store the list `1, -2, 3` + The first `Cons` value holds `1` and another `List` value. This `List` value is another `Cons` value that holds `2` and another `List` value. This `List` value @@ -140,12 +137,13 @@ is one more `Cons` value that holds `3` and a `List` value, which is finally If we try to compile the code in Listing 15-3, we get the error shown in Listing 15-4: ++ ```console {{#include ../listings/ch15-smart-pointers/listing-15-03/output.txt}} ``` -Listing 15-4: The error we get when attempting to define -a recursive enum + The error shows this type “has infinite size.” The reason is that we’ve defined `List` with a variant that is recursive: it holds another value of itself @@ -215,14 +213,13 @@ rather than inside one another. We can change the definition of the `List` enum in Listing 15-2 and the usage of the `List` in Listing 15-3 to the code in Listing 15-5, which will compile: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-05/src/main.rs}} ``` -Listing 15-5: Definition of `List` that uses `Box` in -order to have a known size + The `Cons` variant needs the size of an `i32` plus the space to store the box’s pointer data. The `Nil` variant stores no values, so it needs less space diff --git a/src/ch15-02-deref.md b/src/ch15-02-deref.md index 56db7c0a02..d8b60f187b 100644 --- a/src/ch15-02-deref.md +++ b/src/ch15-02-deref.md @@ -29,14 +29,13 @@ as an arrow to a value stored somewhere else. In Listing 15-6, we create a reference to an `i32` value and then use the dereference operator to follow the reference to the value: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-06/src/main.rs}} ``` -Listing 15-6: Using the dereference operator to follow a -reference to an `i32` value + The variable `x` holds an `i32` value `5`. We set `y` equal to a reference to `x`. We can assert that `x` is equal to `5`. However, if we want to make an @@ -63,14 +62,13 @@ reference; the dereference operator used on the `Box` in Listing 15-7 functions in the same way as the dereference operator used on the reference in Listing 15-6: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-07/src/main.rs}} ``` -Listing 15-7: Using the dereference operator on a -`Box` + The main difference between Listing 15-7 and Listing 15-6 is that here we set `y` to be an instance of a `Box` pointing to a copied value of `x` rather @@ -91,13 +89,13 @@ The `Box` type is ultimately defined as a tuple struct with one element, so Listing 15-8 defines a `MyBox` type in the same way. We’ll also define a `new` function to match the `new` function defined on `Box`. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-08/src/main.rs:here}} ``` -Listing 15-8: Defining a `MyBox` type + We define a struct named `MyBox` and declare a generic parameter `T`, because we want our type to hold values of any type. The `MyBox` type is a tuple struct @@ -109,14 +107,13 @@ changing it to use the `MyBox` type we’ve defined instead of `Box`. The code in Listing 15-9 won’t compile because Rust doesn’t know how to dereference `MyBox`. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-09/src/main.rs:here}} ``` -Listing 15-9: Attempting to use `MyBox` in the same -way we used references and `Box` + Here’s the resulting compilation error: @@ -137,13 +134,13 @@ by the standard library, requires us to implement one method named `deref` that borrows `self` and returns a reference to the inner data. Listing 15-10 contains an implementation of `Deref` to add to the definition of `MyBox`: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-10/src/main.rs:here}} ``` -Listing 15-10: Implementing `Deref` on `MyBox` + The `type Target = T;` syntax defines an associated type for the `Deref` trait to use. Associated types are a slightly different way of declaring a @@ -210,27 +207,25 @@ Listing 15-8 as well as the implementation of `Deref` that we added in Listing 15-10. Listing 15-11 shows the definition of a function that has a string slice parameter: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-11/src/main.rs:here}} ``` -Listing 15-11: A `hello` function that has the parameter -`name` of type `&str` + We can call the `hello` function with a string slice as an argument, such as `hello("Rust");` for example. Deref coercion makes it possible to call `hello` with a reference to a value of type `MyBox`, as shown in Listing 15-12: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-12/src/main.rs:here}} ``` -Listing 15-12: Calling `hello` with a reference to a -`MyBox` value, which works because of deref coercion + Here we’re calling the `hello` function with the argument `&m`, which is a reference to a `MyBox` value. Because we implemented the `Deref` trait @@ -244,14 +239,13 @@ If Rust didn’t implement deref coercion, we would have to write the code in Listing 15-13 instead of the code in Listing 15-12 to call `hello` with a value of type `&MyBox`. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-13/src/main.rs:here}} ``` -Listing 15-13: The code we would have to write if Rust -didn’t have deref coercion + The `(*m)` dereferences the `MyBox` into a `String`. Then the `&` and `[..]` take a string slice of the `String` that is equal to the whole string to diff --git a/src/ch15-03-drop.md b/src/ch15-03-drop.md index 05ab86873b..8c402f408f 100644 --- a/src/ch15-03-drop.md +++ b/src/ch15-03-drop.md @@ -28,14 +28,13 @@ Listing 15-14 shows a `CustomSmartPointer` struct whose only custom functionality is that it will print `Dropping CustomSmartPointer!` when the instance goes out of scope, to show when Rust runs the `drop` function. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-14/src/main.rs}} ``` -Listing 15-14: A `CustomSmartPointer` struct that -implements the `Drop` trait where we would put our cleanup code + The `Drop` trait is included in the prelude, so we don’t need to bring it into scope. We implement the `Drop` trait on `CustomSmartPointer` and provide an @@ -79,14 +78,13 @@ If we try to call the `Drop` trait’s `drop` method manually by modifying the `main` function from Listing 15-14, as shown in Listing 15-15, we’ll get a compiler error: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-15/src/main.rs:here}} ``` -Listing 15-15: Attempting to call the `drop` method from -the `Drop` trait manually to clean up early + When we try to compile this code, we’ll get this error: @@ -114,14 +112,13 @@ trait. We call it by passing as an argument the value we want to force drop. The function is in the prelude, so we can modify `main` in Listing 15-15 to call the `drop` function, as shown in Listing 15-16: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-16/src/main.rs:here}} ``` -Listing 15-16: Calling `std::mem::drop` to explicitly -drop a value before it goes out of scope + Running this code will print the following: diff --git a/src/ch15-04-rc.md b/src/ch15-04-rc.md index 87a42eb1a5..c5bf9a4897 100644 --- a/src/ch15-04-rc.md +++ b/src/ch15-04-rc.md @@ -48,14 +48,13 @@ words, both lists will share the first list containing 5 and 10. Trying to implement this scenario using our definition of `List` with `Box` won’t work, as shown in Listing 15-17: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-17/src/main.rs}} ``` -Listing 15-17: Demonstrating we’re not allowed to have -two lists using `Box` that try to share ownership of a third list + When we compile this code, we get this error: @@ -84,14 +83,13 @@ we call `Rc::clone`, the reference count to the data within the `Rc` will increase, and the data won’t be cleaned up unless there are zero references to it. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-18/src/main.rs}} ``` -Listing 15-18: A definition of `List` that uses -`Rc` + We need to add a `use` statement to bring `Rc` into scope because it’s not in the prelude. In `main`, we create the list holding 5 and 10 and store it in @@ -118,13 +116,13 @@ counts changing as we create and drop references to the `Rc` in `a`. In Listing 15-19, we’ll change `main` so it has an inner scope around list `c`; then we can see how the reference count changes when `c` goes out of scope. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-19/src/main.rs:here}} ``` -Listing 15-19: Printing the reference count + At each point in the program where the reference count changes, we print the reference count, which we get by calling the `Rc::strong_count` function. This diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index 7b5e825d7e..c51302b31c 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -129,14 +129,13 @@ email, send a text message, or something else. The library doesn’t need to kno that detail. All it needs is something that implements a trait we’ll provide called `Messenger`. Listing 15-20 shows the library code: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-20/src/lib.rs}} ``` -Listing 15-20: A library to keep track of how close a -value is to a maximum value and warn when the value is at certain levels + One important part of this code is that the `Messenger` trait has one method called `send` that takes an immutable reference to `self` and the text of the @@ -156,14 +155,13 @@ mock object, call the `set_value` method on `LimitTracker`, and then check that the mock object has the messages we expect. Listing 15-21 shows an attempt to implement a mock object to do just that, but the borrow checker won’t allow it: -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-21/src/lib.rs:here}} ``` -Listing 15-21: An attempt to implement a `MockMessenger` -that isn’t allowed by the borrow checker + This test code defines a `MockMessenger` struct that has a `sent_messages` field with a `Vec` of `String` values to keep track of the messages it’s told @@ -200,14 +198,13 @@ This is a situation in which interior mutability can help! We’ll store the able to modify `sent_messages` to store the messages we’ve seen. Listing 15-22 shows what that looks like: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-22/src/lib.rs:here}} ``` -Listing 15-22: Using `RefCell` to mutate an inner -value while the outer value is considered immutable + The `sent_messages` field is now of type `RefCell>` instead of `Vec`. In the `new` function, we create a new `RefCell>` @@ -249,14 +246,13 @@ Listing 15-22. We’re deliberately trying to create two mutable borrows active for the same scope to illustrate that `RefCell` prevents us from doing this at runtime. -Filename: src/lib.rs + ```rust,ignore,panics {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-23/src/lib.rs:here}} ``` -Listing 15-23: Creating two mutable references in the -same scope to see that `RefCell` will panic + We create a variable `one_borrow` for the `RefMut` smart pointer returned from `borrow_mut`. Then we create another mutable borrow in the same way in the @@ -298,14 +294,13 @@ change the values in the lists. Listing 15-24 shows that by using a `RefCell` in the `Cons` definition, we can modify the value stored in all the lists: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-24/src/main.rs}} ``` -Listing 15-24: Using `Rc>` to create a -`List` that we can mutate + We create a value that is an instance of `Rc>` and store it in a variable named `value` so we can access it directly later. Then we create a diff --git a/src/ch15-06-reference-cycles.md b/src/ch15-06-reference-cycles.md index beb2bc2169..2ea12edb6f 100644 --- a/src/ch15-06-reference-cycles.md +++ b/src/ch15-06-reference-cycles.md @@ -15,14 +15,13 @@ Let’s look at how a reference cycle might happen and how to prevent it, starting with the definition of the `List` enum and a `tail` method in Listing 15-25: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-25/src/main.rs}} ``` -Listing 15-25: A cons list definition that holds a -`RefCell` so we can modify what a `Cons` variant is referring to + We’re using another variation of the `List` definition from Listing 15-5. The second element in the `Cons` variant is now `RefCell>`, meaning that @@ -37,14 +36,13 @@ the list in `a`. Then it modifies the list in `a` to point to `b`, creating a reference cycle. There are `println!` statements along the way to show what the reference counts are at various points in this process. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-26/src/main.rs:here}} ``` -Listing 15-26: Creating a reference cycle of two `List` -values pointing to each other + We create an `Rc` instance holding a `List` value in the variable `a` with an initial list of `5, Nil`. We then create an `Rc` instance holding @@ -163,14 +161,13 @@ Next, we’ll use our struct definition and create one `Node` instance named `leaf` with the value 3 and no children, and another instance named `branch` with the value 5 and `leaf` as one of its children, as shown in Listing 15-27: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-27/src/main.rs:there}} ``` -Listing 15-27: Creating a `leaf` node with no children -and a `branch` node with `leaf` as one of its children + We clone the `Rc` in `leaf` and store that in `branch`, meaning the `Node` in `leaf` now has two owners: `leaf` and `branch`. We can get from @@ -207,14 +204,13 @@ A node will be able to refer to its parent node but doesn’t own its parent. In Listing 15-28, we update `main` to use this new definition so the `leaf` node will have a way to refer to its parent, `branch`: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-28/src/main.rs:there}} ``` -Listing 15-28: A `leaf` node with a weak reference to its -parent node `branch` + Creating the `leaf` node looks similar to Listing 15-27 with the exception of the `parent` field: `leaf` starts out without a parent, so we create a new, @@ -260,14 +256,13 @@ instances change by creating a new inner scope and moving the creation of created and then dropped when it goes out of scope. The modifications are shown in Listing 15-29: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-29/src/main.rs:here}} ``` -Listing 15-29: Creating `branch` in an inner scope and -examining strong and weak reference counts + After `leaf` is created, its `Rc` has a strong count of 1 and a weak count of 0. In the inner scope, we create `branch` and associate it with From 3216c0f57ba4722835785dd4031ded4298a798ee Mon Sep 17 00:00:00 2001 From: bryanzierk Date: Wed, 12 Jun 2024 13:25:53 -0600 Subject: [PATCH 230/720] Remove extraneous span --- src/ch12-03-improving-error-handling-and-modularity.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ch12-03-improving-error-handling-and-modularity.md b/src/ch12-03-improving-error-handling-and-modularity.md index a082737d9a..0de3ec2c22 100644 --- a/src/ch12-03-improving-error-handling-and-modularity.md +++ b/src/ch12-03-improving-error-handling-and-modularity.md @@ -346,8 +346,6 @@ defining the function in *src/main.rs*. -Filename: src/main.rs - ```rust,ignore {{#rustdoc_include ../listings/ch12-an-io-project/listing-12-11/src/main.rs:here}} ``` From 0c00b174d455c1fe15bed0b69e766901c844c8f4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 10 May 2024 14:06:44 -0600 Subject: [PATCH 231/720] Ch. 17: reorganize 17.01 and get a useable intro to Future --- src/ch17-01-tasks.md | 139 ++++++++++++++++++++++++------------------- src/ch17-02.md | 7 ++- 2 files changed, 82 insertions(+), 64 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 9c379c45fb..b634c052f7 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -91,12 +91,16 @@ That explains why we got the `unused_must_use` warning: writing `async fn` meant we were actually returning an anonymous `Future`. Just like with `Result`, Rust will let us know if we don’t use a `Future`. It is often a mistake to ignore an error in an operation your program performed. With a `Future`, it is even more -significant. To see why, let’s look at the other part of the warning. It told us -that “futures do nothing unless you `.await` or poll them”. That is, futures are -*lazy*: they don’t do anything until you ask them to. The compiler is telling us -that ignoring a `Future` makes it completely useless! We will see why that is -later on. For now, let’s start by awaiting the future returned by `hello_async` -to actually have it run. +significant. The compiler also warned us that “futures do nothing unless you +`.await` or poll them”. That is, futures are *lazy*: they don’t do anything +until you ask them to. + +The compiler is telling us that ignoring a `Future` makes it completely useless! +This is different from the behavior we saw when using `thread::spawn` in the +previous chapter, and it is different from how many other languages approach +async. This allows Rust to avoid running async code unless it is actually +needed. We will see why that is later on. For now, let’s start by awaiting the +future returned by `hello_async` to actually have it run. > Note: Rust’s `await` keyword goes *after* the expression you are awaiting—that > is, it is a *postfix keyword*. This is different from what you might be used @@ -111,7 +115,7 @@ fn main() { } ``` -Oh no! We have gone from a compiler warning ton an actual error: +Oh no! We have gone from a compiler warning to an actual error: ```text error[E0728]: `await` is only allowed inside `async` functions and blocks @@ -123,9 +127,19 @@ error[E0728]: `await` is only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks ``` -This time, the compiler is informing us we cannot actually use `.await` in -`main`, because `main` is not an `async` function. As of today, it cannot be -without some extra help: it needs a *runtime* to execute the asynchronous code. +This time, the compiler is informing us we cannot use `.await` in `main`, +because `main` is not an `async` function. That is because async code needs a +*runtime*: a Rust crate which manages the details of executing the asynchronous +code, including whether or not to use threads for it, scheduling different async +operations, and so on. + +Most languages which support async, including C#, JavaScript, Go, Kotlin, +Erlang, and Swift, bundle a runtime with the language. At least for now, Rust +does not. Instead, there are many different async runtimes available, each of +which makes different tradeoffs suitable to the use case they target. For +example, a high-throughput web server with dozens of CPU cores and terabytes of +RAM has very different different needs than a microcontroller with a single +core, one gigabyte of RAM, and no ability to do heap allocations. To keep this chapter focused on learning async, rather than juggling parts of the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust @@ -143,8 +157,9 @@ For now, go ahead and add the `trpl` crate to your `hello-async` project: $ cargo add trpl ``` -Now we can get our code working by using the `trpl::block_on` function, which -takes in a `Future` and runs it until it completes. +In our `main` function, let’s wrap the call to `hello_async` with the +`trpl::block_on` function, which takes in a `Future` and runs it until it +completes. ```rust fn main() { @@ -156,7 +171,7 @@ async fn hello_async() { } ``` -Now when we run this, we get the behavior we might have expected initially: +When we run this, we get the behavior we might have expected initially: ```console @@ -169,14 +184,31 @@ Hello, async! Phew: we finally have some working async code! Now we can answer that second question: what is a future anyway? That will also help us understand why we need -a runtime to make this work. +that `trpl::block_on` call to make this work. ### Futures -Since `async fn` compiles to a return type with `impl Future`, we -know that `Future` is a trait, with an associated type `Output`. The other part -of the trait is its one method: `poll`. The `poll` method returns a fairly -simple type: +A *future* is a data structure which represents the state of some async +operation. More precisely, a Rust `Future` is a trait; it allows many different +data structures to represent different async operations in different ways, but +with a common interface. Here is the definition of the trait: + +```rust +pub trait Future { + type Output; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; +} +``` + +`Future` has an associated type, `Output`, which says what the result of the +future will be when it resolves. (This is analogous to the `Item` associated +type for the `Iterator` trait, which we saw back in Chapter 13.) Beyond that, +`Future` has only one method: `poll`, which takes a special `Pin` reference for +its `self` parameter and a mutable reference to some `Context` type, and returns +a `Poll`. We will talk a little more about `Pin` and `Context` +later in the chapter. For now, let’s focus on what the method returns, the +`Poll` type: ```rust enum Poll { @@ -198,7 +230,7 @@ work and the `T` value is available. > documentation. Under the hood, when you call `.await`, Rust compiles that to code which calls -`poll` instead, kind of like this: +`poll`, kind of like this: ```rust @@ -231,51 +263,33 @@ loop { } ``` -If we wrote that code, though, we would block the computer from doing anything -else, though—the opposite of what we were going for. It also wouldn’t compile -for three other reasons: - -1. The `poll` method actually requires an argument: a `Context` that carries - along a way to say when to call it again, to avoid exactly the problem of - blocking other operations from making progress. - -2. The `Future` returned by our `async fn` is not actually ready to use here, - because `poll` requires that the future be “pinned”—guaranteed not to get - moved around in memory, so that any references to the future can be checked - for memory safety. - -3. Even if we pinned the future, this code would move `hello_async_fut` in the - first iteration through the `loop`. After the first time through the loop, we - would not be able to call it again. - -When we use the `async fn` form with `.await`, Rust compiles it to something -smarter than the `loop` above, in conjunction with a *runtime* responsible for -executing that loop. - -> Note: Some languages, including Go, Kotlin, Erlang, and Swift, ship runtimes -> with the language. In Rust, there are many different runtimes, because a -> runtime might need to do very different things to support a high-throughput -> web server with dozens of CPU cores and terabytes of RAM than it would for a -> microcontroller with a single core and one gigabyte of RAM should do. - - - -The other thing to notice here is that futures in Rust are *lazy*. They do not -do anything until you explicitly ask them to—whether by calling `poll` or by -using `.await` to do so. This is different from the behavior we saw when using -`thread::spawn` in the previous chapter, and it is different from how many other -languages approach async. This allows Rust to avoid running async code unless it -is actually needed, and supports some of the memory safety features Rust brings -to async. (The details are beyond the scope of this book, but are well worth -digging into. In particular, see [Chapter 4: Pinning][pinning] in the official -[_Asynchronous Programming in Rust_][async-book] book.) +And in fact, when we use `.await`, Rust compiles it to something very similar to +that `loop`. However, if Rust compiled it to *only* that code, every `.await` +would block the computer from doing anything else—the opposite of what we were +going for! -### Running Async Code +> Note: It also wouldn’t compile, because it doesn’t actually satisfy the +> contract for a `Future`. In particular, `hello_async_fut` is not *pinned* with +> the `Pin` type and we did not pass along a `Context` argument. The details are +> beyond the scope of this book, but are well worth digging into. In particular, +> see [Chapter 4: Pinning][pinning] in the official [_Asynchronous Programming +> in Rust_][async-book] book. + + - +What is more, eventually we end up back in some non-async function. At that point, something needs to “translate” between the async +and sync worlds. That “something” is a *runtime*, a crate which handles the +top-level `poll()` call, scheduling and handing off between the different async +operations which may be in flight, and often providing async versions of +functionality like file I/O. -Going back to `main`, this explains why we cannot have an `async fn main`: what -would execute the async code? We need to pick a runtime and executor. +Now we can understand what is happening in Listing 17-XX. The `main` function is +not `async`—and it really cannot be: if it were, something would need to call +`poll()` on whatever `main` returned! Instead, we use the `trpl::block_on` +function, which polls the `Future` returned by `hello_async` until it returns +`Ready`. + +### Running Async Code Now, that’s a lot of work to just print a string, but we have laid some key foundations for working with async in Rust! Now that you know the basics of how @@ -284,3 +298,6 @@ futures work, and the [impl-trait]: ch10-02-traits.html#traits-as-parameters [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html [async-book]: https://rust-lang.github.io/async-book/ +[crate-source]: https://github.com/rust-lang/book/tree/main/packages/trpl + + diff --git a/src/ch17-02.md b/src/ch17-02.md index 9dfa186927..0eeb815d7b 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -6,11 +6,12 @@ runtimes in the Rust ecosystem. > ### The `futures` and `tokio` Crates > > Whenever you see code from the `trpl` crate throughout the rest of the -> chapter, it will be re-exporting code from the `futures` and [`tokio`][tokio] crates. +> chapter, it will be re-exporting code from the `futures` and [`tokio`][tokio] +> crates. > > - The `futures` crate is an official home for Rust experimentation for async > code, and is actually where the `Future` type was originally designed. -> +> > - Tokio is the most widely used async runtime in Rust today, especially (but > not only!) for web applications. There are other great options out there, > too, and they may be more suitable for your purposes. We are using Tokio @@ -38,4 +39,4 @@ async fn main() { [tokio]: https://tokio.rs -[crate-source]: TODO + From 23027cb6ece4fb200c612003f7cc23387b143ddb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 10 May 2024 14:15:44 -0600 Subject: [PATCH 232/720] Ch. 17: wording and formatting in 17.01 --- src/ch17-01-tasks.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index b634c052f7..26237f901e 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -64,10 +64,10 @@ questions: ### Async functions -In Rust, `async fn` is equivalent to writing a function which returns a -future of the return type, using the `impl Trait` syntax we discussed back in -the [“Traits as Parameters”][impl-trait] section in Chapter 10. An `async` -block compiles to an anonymous struct which implements the `Future` trait. +In Rust, `async fn` is equivalent to writing a function which returns a future +of the return type, using the `impl Trait` syntax we discussed back in the +[“Traits as Parameters”][impl-trait] section in Chapter 10. An `async` block +compiles to an anonymous struct which implements the `Future` trait. That means these two are roughly equivalent: @@ -102,12 +102,6 @@ async. This allows Rust to avoid running async code unless it is actually needed. We will see why that is later on. For now, let’s start by awaiting the future returned by `hello_async` to actually have it run. -> Note: Rust’s `await` keyword goes *after* the expression you are awaiting—that -> is, it is a *postfix keyword*. This is different from what you might be used -> to if you have used async in languages like JavaScript or C#. Rust chose this -> because it makes chains of async and non-async methods much nicer to work -> with. As of now, `await` is the only postfix keyword in the language. - ```rust fn main() { @@ -115,6 +109,12 @@ fn main() { } ``` +> Note: Rust’s `await` keyword goes *after* the expression you are awaiting—that +> is, it is a *postfix keyword*. This is different from what you might be used +> to if you have used async in languages like JavaScript or C#. Rust chose this +> because it makes chains of async and non-async methods much nicer to work +> with. As of now, `await` is the only postfix keyword in the language. + Oh no! We have gone from a compiler warning to an actual error: ```text @@ -277,11 +277,11 @@ going for! -What is more, eventually we end up back in some non-async function. At that point, something needs to “translate” between the async -and sync worlds. That “something” is a *runtime*, a crate which handles the -top-level `poll()` call, scheduling and handing off between the different async -operations which may be in flight, and often providing async versions of -functionality like file I/O. +What is more, eventually we end up back in some non-async function. At that +point, something needs to “translate” between the async and sync worlds. That +“something” is a *runtime*, a crate which handles the top-level `poll()` call, +scheduling and handing off between the different async operations which may be +in flight, and often providing async versions of functionality like file I/O. Now we can understand what is happening in Listing 17-XX. The `main` function is not `async`—and it really cannot be: if it were, something would need to call @@ -293,7 +293,7 @@ function, which polls the `Future` returned by `hello_async` until it returns Now, that’s a lot of work to just print a string, but we have laid some key foundations for working with async in Rust! Now that you know the basics of how -futures work, and the +futures and runtimes work, we can see some of the things we can *do* with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html From 3cf4faeeca93731b0b37aa831608922d5290a48c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 10 May 2024 16:27:15 -0600 Subject: [PATCH 233/720] Ch. 17: corrections/discussion on runtimes, mostly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Tie off the discussion about needing a runtime so that it is clear what is needed in `main` and therefore why `main` cannot natively be `async` itself. - Correct the description of what `.await` compiles to. - Extend the note about the “under the hood” bits: mention generators so people know what to go looking for if they are curious. - Rewrite the existing introduction of the `#[async_main]` macro to lean on the material now covered in the previous chapter. --- src/ch17-01-tasks.md | 49 +++++++++++++++++++++++++------------------- src/ch17-02.md | 19 +++++++++-------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 26237f901e..2d747a0448 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -264,38 +264,45 @@ loop { ``` And in fact, when we use `.await`, Rust compiles it to something very similar to -that `loop`. However, if Rust compiled it to *only* that code, every `.await` -would block the computer from doing anything else—the opposite of what we were -going for! - -> Note: It also wouldn’t compile, because it doesn’t actually satisfy the -> contract for a `Future`. In particular, `hello_async_fut` is not *pinned* with -> the `Pin` type and we did not pass along a `Context` argument. The details are -> beyond the scope of this book, but are well worth digging into. In particular, -> see [Chapter 4: Pinning][pinning] in the official [_Asynchronous Programming -> in Rust_][async-book] book. - - - -What is more, eventually we end up back in some non-async function. At that -point, something needs to “translate” between the async and sync worlds. That -“something” is a *runtime*, a crate which handles the top-level `poll()` call, -scheduling and handing off between the different async operations which may be -in flight, and often providing async versions of functionality like file I/O. +that loop. If Rust compiled it to *exactly* that code, every `.await` would +block the computer from doing anything else—the opposite of what we were going +for! Instead, Rust internally makes sure that the loop can hand back control to +the the context of the code where which is awaiting this little bit of code. + +When we follow that chain far enough, eventually we end up back in some +non-async function. At that point, something needs to “translate” between the +async and sync worlds. That “something” is a *runtime*, a crate which handles +the top-level `poll()` call, scheduling and handing off between the different +async operations which may be in flight, and often providing async versions of +functionality like file I/O. Now we can understand what is happening in Listing 17-XX. The `main` function is not `async`—and it really cannot be: if it were, something would need to call `poll()` on whatever `main` returned! Instead, we use the `trpl::block_on` function, which polls the `Future` returned by `hello_async` until it returns -`Ready`. - -### Running Async Code +`Ready`. Every async program in Rust has at least one place where it sets up an +executor and executes code. + +> Note: Under the hood, Rust uses *generators* so that it can hand off control +> between different functions. These are an implementation detail, though, and +> you never have to think about it when writing Rust. +> +> The loop as written also wouldn’t compile, because it doesn’t actually satisfy +> the contract for a `Future`. In particular, `hello_async_fut` is not *pinned* +> with the `Pin` type and we did not pass along a `Context` argument. +> +> More details here are beyond the scope of this book, but are well worth +> digging into if you want to understand how things work “under the hood.” In +> particular, see [Chapter 2: Under the Hood: Executing Futures and +> Tasks][under-the-hood] and [Chapter 4: Pinning][pinning] in the official +> [_Asynchronous Programming in Rust_][async-book] book. Now, that’s a lot of work to just print a string, but we have laid some key foundations for working with async in Rust! Now that you know the basics of how futures and runtimes work, we can see some of the things we can *do* with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters +[under-the-hood]: https://rust-lang.github.io/async-book/02_execution/01_chapter.html [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html [async-book]: https://rust-lang.github.io/async-book/ [crate-source]: https://github.com/rust-lang/book/tree/main/packages/trpl diff --git a/src/ch17-02.md b/src/ch17-02.md index 0eeb815d7b..0cf64d42a3 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -1,7 +1,9 @@ The executor from `futures` we used in the previous section is intentionally -quite limited. It works quite well, but if you are going to build a real-world -application, you will likely want to use the executor from one of the *other* -runtimes in the Rust ecosystem. +quite limited. It works well, but it requires you to set it up yourself, as we +did in the previous chapter, and it it is not tuned for any particular use case. +Accordingly, if you are going to build a real-world application, you will likely +want to use the executor from one of the *other* runtimes in the Rust +ecosystem. Once again, we will use code from the `trpl` crate to set things up. > ### The `futures` and `tokio` Crates > @@ -18,12 +20,10 @@ runtimes in the Rust ecosystem. > because it is the most widely-used runtime—not as a judgment call on whether > it is the *best* runtime! -Okay, now let’s start exploring. Going forward, we will use a new `async_main` -macro so that we can use `async fn` with a `main` function. Under the hood, this -little utility macro from Tokio sets up the Tokio runtime and wires up a call -kind of like we saw with `futures::executor::block_on` in the previous section. -Now we can use `async` blocks directly in `main` and not worry about wiring up -the runtime ourselves: +This time, it uses a macro, `async_main`, which allows us to use `async fn` with +a `main` function. The macro just rewrites the function to do something similar +to what we wrote by hand in the previous chapter, but lets us skip writing it +out by hand. Now we can write that `async` block and `.await` it in `main`: ```rust use trpl::async_main; @@ -36,6 +36,7 @@ async fn main() { } ``` +Okay, now let’s start exploring. [tokio]: https://tokio.rs From c3ebabeea464e03c986e341b25868968f29590d7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 10 May 2024 16:28:39 -0600 Subject: [PATCH 234/720] Ch. 17: pull disconnected material out of 17.01 --- src/ch17-01-tasks.md | 20 -------------------- src/ch17-03-vs-threads.md | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 src/ch17-03-vs-threads.md diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 2d747a0448..48ee45f4a5 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -1,25 +1,5 @@ ## Futures and the Async Syntax -As we saw in the previous chapter, threads provide one approach to concurrency, -and they let us solve some of these issues. However, they also have some -tradeoffs. On many operating systems, they use a fair bit of memory for each -thread, and they come with some overhead for starting up and shutting down. -Threads are also only an option when your operating system and hardware support -them! While mainstream desktop and mobile operating systems have all had -threading for many years, many embedded operating systems, like those used on -some microcontrollers, do not. - -The async model provides a different—and ultimately complementary—set of -tradeoffs. In - - - -In the async model, concurrent operations do not require their own threads. -Instead, they can run on *tasks*. A task is a bit like a thread, but instead of -being managed by the operating system, it is managed by a runtime. - - - Like other languages with async, Rust uses the `async` and `await` keywords—though with some important differences, as we will see. Blocks and functions can be marked `async`, and you can wait on the result of an `async` diff --git a/src/ch17-03-vs-threads.md b/src/ch17-03-vs-threads.md new file mode 100644 index 0000000000..63f270522f --- /dev/null +++ b/src/ch17-03-vs-threads.md @@ -0,0 +1,23 @@ + + +As we saw in the previous chapter, threads provide one approach to concurrency, +and they let us solve some of these issues. However, they also have some +tradeoffs. On many operating systems, they use a fair bit of memory for each +thread, and they come with some overhead for starting up and shutting down. +Threads are also only an option when your operating system and hardware support +them! While mainstream desktop and mobile operating systems have all had +threading for many years, many embedded operating systems, like those used on +some microcontrollers, do not. + +The async model provides a different—and ultimately complementary—set of +tradeoffs. In the async model, concurrent operations do not require their own +threads. Instead, they can run on *tasks*. A task is a bit like a thread, but +instead of being managed by the operating system, it is managed by code that +lives at the level of libraries. + + From 5657a4907186ff85194190dd92c044e0e6436269 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 10 May 2024 16:41:42 -0600 Subject: [PATCH 235/720] Ch. 17: minor wording improvement --- src/ch17-01-tasks.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 48ee45f4a5..75411528dc 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -1,9 +1,10 @@ ## Futures and the Async Syntax Like other languages with async, Rust uses the `async` and `await` -keywords—though with some important differences, as we will see. Blocks and -functions can be marked `async`, and you can wait on the result of an `async` -function or block to resolve using the `await` keyword. +keywords—though with some important differences from how other languages do +things, as we will see. Blocks and functions can be marked `async`, and you can +wait on the result of an `async` function or block to resolve using the `await` +keyword. Let’s write our first async function, and call it: From b4e30305b72b6f48a0111bb43bd6778e28e27845 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 12:25:48 -0600 Subject: [PATCH 236/720] Ch. 17: eliminate duplicate runtime description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep both references, but make the first one a simple definition, and the second one the “ah, now we can make sense of that definition”. --- src/ch17-01-tasks.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index c045d1cd26..7ce057fcd9 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -112,13 +112,10 @@ error[E0728]: `await` is only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks ``` - - This time, the compiler is informing us we cannot use `.await` in `main`, because `main` is not an `async` function. That is because async code needs a -*runtime*: a Rust crate which manages the details of executing the asynchronous -code, including whether or not to use threads for it, scheduling different async -operations, and so on. +*runtime*: a Rust crate which manages the details of executing asynchronous +code. Most languages which support async, including C#, JavaScript, Go, Kotlin, Erlang, and Swift, bundle a runtime with the language. At least for now, Rust @@ -266,10 +263,10 @@ of code. When we follow that chain far enough, eventually we end up back in some non-async function. At that point, something needs to “translate” between the -async and sync worlds. That “something” is a *runtime*, a crate which handles -the top-level `poll()` call, scheduling and handing off between the different -async operations which may be in flight, and often providing async versions of -functionality like file I/O. +async and sync worlds. That “something” is the runtime! Whatever runtime you use +is what handles the top-level `poll()` call, scheduling and handing off between +the different async operations which may be in flight, and often also providing +async versions of functionality like file I/O. Now we can understand why the compiler was blocking us in Listing 17-2 (before we added the `trpl::block_on` function). The `main` function is not `async`—and From 95105d23d7da27abc7deadb541a539ccb83a1b83 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 15:59:10 -0600 Subject: [PATCH 237/720] Ch. 17: Add `futures` to `trpl` crate for re-exports --- Cargo.lock | 36 +++++++++++++++++++++++++ packages/trpl/Cargo.toml | 1 + packages/trpl/src/lib.rs | 1 + packages/trpl/tests/integration/main.rs | 8 +++++- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 5203a716e4..03c7ee8b62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -501,6 +501,21 @@ dependencies = [ "new_debug_unreachable", ] +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -517,6 +532,23 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + [[package]] name = "futures-macro" version = "0.3.30" @@ -546,10 +578,13 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-macro", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", @@ -1908,6 +1943,7 @@ dependencies = [ name = "trpl" version = "0.1.0" dependencies = [ + "futures", "tokio", ] diff --git a/packages/trpl/Cargo.toml b/packages/trpl/Cargo.toml index fe35925a69..046f95da5b 100644 --- a/packages/trpl/Cargo.toml +++ b/packages/trpl/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +futures = "0.3.30" tokio = { version = "1", features = ["full"] } diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index a0fddb1b09..4d8c08fcab 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -12,4 +12,5 @@ //! never be broken by upstream changes, e.g. if Tokio does a breaking 2.0 //! release at some point. +pub use futures::executor::block_on; pub use tokio::main as async_main; diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index fd232ccc7e..8f091d5df4 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -9,7 +9,7 @@ //! //! [post]: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html -use trpl::async_main; +use trpl::{async_main, block_on}; /// This test makes sure the re-exported version of the `tokio::main` macro, /// which is applied like `#[tokio::main] async fn some_fn() { … }`, continues @@ -27,3 +27,9 @@ fn re_exported_macro_works() { assert_eq!(internal(), "Hello", "value returns correctly"); } + +#[test] +fn re_exported_block_on_works() { + let val = block_on(async { "Hello" }); + assert_eq!(val, "Hello"); +} From f418ceba2e3f7d805b297519c356a34effcac7b8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 15:59:10 -0600 Subject: [PATCH 238/720] Ch. 17: abandon attempt to re-export `tokio::main` Re-exporting the macro does not work unless you have `tokio` as a direct dependency, because its expansion is in terms of Tokio doc-hidden items. --- packages/trpl/src/lib.rs | 22 ++++++++++-- packages/trpl/tests/integration/main.rs | 42 +++++++++++++--------- src/ch17-01-tasks.md | 16 +++++++++ src/ch17-02.md | 48 +------------------------ 4 files changed, 62 insertions(+), 66 deletions(-) diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 4d8c08fcab..521aa28cb1 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -12,5 +12,23 @@ //! never be broken by upstream changes, e.g. if Tokio does a breaking 2.0 //! release at some point. -pub use futures::executor::block_on; -pub use tokio::main as async_main; +use std::future::Future; + +pub use futures::future::join; +pub use tokio::{runtime::Runtime, task::spawn as spawn_task, time::sleep}; + +/// Run a single future to completion on a bespoke Tokio `Runtime`. +/// +/// Every time you call this, a new instance of `tokio::runtime::Runtime` will +/// be created (see the implementation for details: it is trivial). This is: +/// +/// - Reasonable for teaching purposes, in that you do not generally need to set +/// up more than one runtime anyway, and especially do not in basic code like +/// we are showing! +/// +/// - Not *that* far off from what Tokio itself does under the hood in its own +/// `tokio::main` macro for supporting `async fn main`. +pub fn block_on(future: F) -> F::Output { + let rt = Runtime::new().unwrap(); + rt.block_on(future) +} diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index 8f091d5df4..e55aea5703 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -9,27 +9,35 @@ //! //! [post]: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html -use trpl::{async_main, block_on}; +use trpl::{block_on, sleep, spawn_task}; -/// This test makes sure the re-exported version of the `tokio::main` macro, -/// which is applied like `#[tokio::main] async fn some_fn() { … }`, continues -/// to work. However, tests cannot use `async fn`, so to test it, we need to -/// have a non-`async` test function, which then applies the macro to an `async` -/// function in its body, and invokes *that*. +/// This test is foundational for all the others, as they depend on `block_on`. +/// +/// If we mess this up, *all* the tests below will fail -- so by the same token, +/// if all the tests below are failing, this one probably is too; fix it and the +/// others will likely start working again. #[test] -fn re_exported_macro_works() { - #[async_main] - async fn internal() -> &'static str { - let val = async { "Hello" }.await; - assert_eq!(val, "Hello", "Async is usable in async_main function"); - val - } +fn re_exported_block_on_works() { + let val = block_on(async { "Hello" }); + assert_eq!(val, "Hello"); +} - assert_eq!(internal(), "Hello", "value returns correctly"); +#[test] +fn re_exported_spawn_works() { + let result = block_on(async { + let handle_a = spawn_task(async { "Hello" }); + let handle_b = spawn_task(async { "Goodbye" }); + vec![handle_a.await.unwrap(), handle_b.await.unwrap()] + }); + + assert_eq!(result, vec!["Hello", "Goodbye"]); } #[test] -fn re_exported_block_on_works() { - let val = block_on(async { "Hello" }); - assert_eq!(val, "Hello"); +fn re_exported_sleep_works() { + let val = block_on(async { + sleep(std::time::Duration::from_micros(1)).await; + "Done!" + }); + assert_eq!(val, "Done!"); } diff --git a/src/ch17-01-tasks.md b/src/ch17-01-tasks.md index 7ce057fcd9..0654274fe3 100644 --- a/src/ch17-01-tasks.md +++ b/src/ch17-01-tasks.md @@ -135,6 +135,21 @@ source code][crate-source]. You will be able to see what crate each re-export comes from, and we have left extensive comments explaining what the handful of helper functions we supply are doing. +> ### The `futures` and `tokio` Crates +> +> Whenever you see code from the `trpl` crate throughout the rest of the +> chapter, it will be re-exporting code from the `futures` and [`tokio`][tokio] +> crates. +> +> - The `futures` crate is an official home for Rust experimentation for async +> code, and is actually where the `Future` type was originally designed. +> +> - Tokio is the most widely used async runtime in Rust today, especially (but +> not only!) for web applications. There are other great options out there, +> too, and they may be more suitable for your purposes. We are using Tokio +> because it is the most widely-used runtime—not as a judgment call on whether +> it is the *best* runtime! + For now, go ahead and add the `trpl` crate to your `hello-async` project: ```console @@ -299,5 +314,6 @@ futures and runtimes work, we can see some of the things we can *do* with async. [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html [async-book]: https://rust-lang.github.io/async-book/ [crate-source]: https://github.com/rust-lang/book/tree/main/packages/trpl +[tokio]: https://tokio.rs diff --git a/src/ch17-02.md b/src/ch17-02.md index 116c5040f6..2ff1a880d6 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -1,47 +1 @@ -The executor from `futures` we used in the previous section is intentionally -quite limited. It works well, but it requires you to set it up yourself, as we -did in the previous chapter, and it it is not tuned for any particular use case. -Accordingly, if you are going to build a real-world application, you will likely -want to use the executor from one of the *other* runtimes in the Rust -ecosystem. Once again, we will use code from the `trpl` crate to set things up. - -> ### The `futures` and `tokio` Crates -> -> Whenever you see code from the `trpl` crate throughout the rest of the -> chapter, it will be re-exporting code from the `futures` and [`tokio`][tokio] -> crates. -> -> - The `futures` crate is an official home for Rust experimentation for async -> code, and is actually where the `Future` type was originally designed. -> -> - Tokio is the most widely used async runtime in Rust today, especially (but -> not only!) for web applications. There are other great options out there, -> too, and they may be more suitable for your purposes. We are using Tokio -> because it is the most widely-used runtime—not as a judgment call on whether -> it is the *best* runtime! - -This time, it uses a macro, `async_main`, which allows us to use `async fn` with -a `main` function. The macro just rewrites the function to do something similar -to what we wrote by hand in the previous chapter, but lets us skip writing it -out by hand. Now we can write that `async` block and `.await` it in `main`: - -- -```rust -use trpl::async_main; - -#[async_main] -async fn main() { - async { - println!("Hello, world!"); - }.await; -} -``` - - - -Okay, now let’s start exploring. - - -[tokio]: https://tokio.rs - +## TODO: Section Title From 8e7420e2a18747d8760398a3caea161ce6bc3cee Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 14 May 2024 15:59:10 -0600 Subject: [PATCH 239/720] =?UTF-8?q?Ch.=2017:=20start=20in=20earnest=20on?= =?UTF-8?q?=20=C2=A72,=20showing=20relation=20to=20threads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add some listings which I can actually run, with `TODO` paths in them since I do not know what the numbers will be, since I have not actually finished with §0 or §1 yet! --- .../listing-TODO-01/Cargo.lock | 540 ++++++++++++++++++ .../listing-TODO-01/Cargo.toml | 9 + .../listing-TODO-01/src/main.rs | 17 + .../listing-TODO-02/Cargo.lock | 540 ++++++++++++++++++ .../listing-TODO-02/Cargo.toml | 9 + .../listing-TODO-02/src/main.rs | 19 + .../listing-TODO-03/Cargo.lock | 540 ++++++++++++++++++ .../listing-TODO-03/Cargo.toml | 9 + .../listing-TODO-03/src/main.rs | 21 + src/ch17-02.md | 110 ++++ 10 files changed, 1814 insertions(+) create mode 100644 listings/ch17-async-await/listing-TODO-01/Cargo.lock create mode 100644 listings/ch17-async-await/listing-TODO-01/Cargo.toml create mode 100644 listings/ch17-async-await/listing-TODO-01/src/main.rs create mode 100644 listings/ch17-async-await/listing-TODO-02/Cargo.lock create mode 100644 listings/ch17-async-await/listing-TODO-02/Cargo.toml create mode 100644 listings/ch17-async-await/listing-TODO-02/src/main.rs create mode 100644 listings/ch17-async-await/listing-TODO-03/Cargo.lock create mode 100644 listings/ch17-async-await/listing-TODO-03/Cargo.toml create mode 100644 listings/ch17-async-await/listing-TODO-03/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-01/Cargo.lock b/listings/ch17-async-await/listing-TODO-01/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-01/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-TODO-01/Cargo.toml b/listings/ch17-async-await/listing-TODO-01/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-01/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-TODO-01/src/main.rs b/listings/ch17-async-await/listing-TODO-01/src/main.rs new file mode 100644 index 0000000000..4af024741e --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-01/src/main.rs @@ -0,0 +1,17 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }); + + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }); +} diff --git a/listings/ch17-async-await/listing-TODO-02/Cargo.lock b/listings/ch17-async-await/listing-TODO-02/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-02/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-TODO-02/Cargo.toml b/listings/ch17-async-await/listing-TODO-02/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-02/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-TODO-02/src/main.rs b/listings/ch17-async-await/listing-TODO-02/src/main.rs new file mode 100644 index 0000000000..71cb24e34c --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-02/src/main.rs @@ -0,0 +1,19 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let handle = trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }); + + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + + handle.await; + }); +} diff --git a/listings/ch17-async-await/listing-TODO-03/Cargo.lock b/listings/ch17-async-await/listing-TODO-03/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-03/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-TODO-03/Cargo.toml b/listings/ch17-async-await/listing-TODO-03/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-03/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-TODO-03/src/main.rs b/listings/ch17-async-await/listing-TODO-03/src/main.rs new file mode 100644 index 0000000000..8797b5d634 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-03/src/main.rs @@ -0,0 +1,21 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let fut1 = async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }; + + let fut2 = async { + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }; + + trpl::join(fut1, fut2).await; + }); +} diff --git a/src/ch17-02.md b/src/ch17-02.md index 2ff1a880d6..eeb335866e 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -1 +1,111 @@ ## TODO: Section Title + +Back in Chapter 16, we saw an example of counting up on multiple threads. Given +that threads allow us to implement a form of concurrency, we might expect that +async APIs can substitute fairly directly for the threading APIs. The `trpl` +crate supplies a `spawn_task` function which looks very similar to the +`thread::spawn` API, and a `sleep` function which is an async version of the +`thread::sleep` API. We can use these together to implement the same counting +example as with threads: + + + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs}} +``` + + + +This does something very similar to what the thread-base implementation did, as +we can see from the output: + +```text +hi number 1 from the second task! +hi number 1 from the first task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +``` + +Just like with the threading example, you may see a different order in your own +terminal output when you run this. And, just like the threading example, if you +want to run all the way to the completion of the first task, you will need to +use a join handle to wait for the first task to complete. With threads, we used +the `join` method to “block” until the thread was done running. Here, we can use +`await` to do the same thing: + + + +```rust +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let handle = trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }); + + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + + handle.join().await + }); +} +``` + +Now the output again matches + +```text +hi number 1 from the second task! +hi number 1 from the first task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +hi number 6 from the first task! +hi number 7 from the first task! +hi number 8 from the first task! +hi number 9 from the first task! +``` + + + + + +```text +hi number 1 from the first task! +hi number 1 from the second task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +hi number 6 from the first task! +hi number 7 from the first task! +hi number 8 from the first task! +hi number 9 from the first task! +``` + +Here, at least with the implementation we are using in `trpl`, you will see +the exact same order every time, which is *very* different from what we saw with +threads. + From 1ee7975b247d0c00dace93257f7cd15355687d48 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 15 May 2024 09:31:53 -0600 Subject: [PATCH 240/720] =?UTF-8?q?Ch.=2017:=20add=20more=20examples=20and?= =?UTF-8?q?=20explanation=20to=20=C2=A702.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-TODO-01/src/main.rs | 8 ++ src/ch17-02.md | 98 ++++++++++++------- 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/listings/ch17-async-await/listing-TODO-01/src/main.rs b/listings/ch17-async-await/listing-TODO-01/src/main.rs index 4af024741e..e766efdf18 100644 --- a/listings/ch17-async-await/listing-TODO-01/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-01/src/main.rs @@ -1,7 +1,11 @@ +// ANCHOR: all use std::time::Duration; +// ANCHOR: block_on fn main() { trpl::block_on(async { + // ANCHOR_END: block_on + // ANCHOR: task trpl::spawn_task(async { for i in 1..10 { println!("hi number {i} from the first task!"); @@ -13,5 +17,9 @@ fn main() { println!("hi number {i} from the second task!"); trpl::sleep(Duration::from_millis(1)).await; } + // ANCHOR_END: task + // ANCHOR: block_on }); } +// ANCHOR_END: block_on +// ANCHOR_END: all diff --git a/src/ch17-02.md b/src/ch17-02.md index eeb335866e..0200abe2ce 100644 --- a/src/ch17-02.md +++ b/src/ch17-02.md @@ -6,23 +6,36 @@ async APIs can substitute fairly directly for the threading APIs. The `trpl` crate supplies a `spawn_task` function which looks very similar to the `thread::spawn` API, and a `sleep` function which is an async version of the `thread::sleep` API. We can use these together to implement the same counting -example as with threads: +example as with threads. - +To start, we will set up our `main` function with `trpl::block_on`: + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:block_on}} +``` + +Then we can write two loops within that block, each with a `trpl::sleep` call in +them. Similar to the threading example, we put one in the body of a +`trpl::spawn_task`, just like we did with `thread::spawn`, and the other in a +top-level `for` loop. Notice that we also need to add a `.await` after the +`sleep` calls. + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:task}} +``` + +Putting that all together, we end up with the code in Listing 17-TODO: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:all}} ``` This does something very similar to what the thread-base implementation did, as -we can see from the output: +we can see from the output when we run it: ```text hi number 1 from the second task! @@ -43,31 +56,15 @@ use a join handle to wait for the first task to complete. With threads, we used the `join` method to “block” until the thread was done running. Here, we can use `await` to do the same thing: - + ```rust -use std::time::Duration; - -fn main() { - trpl::block_on(async { - let handle = trpl::spawn_task(async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }); - - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - - handle.join().await - }); -} +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-02/src/main.rs}} ``` -Now the output again matches + + +Now the output again looks like what we saw in the threading example. ```text hi number 1 from the second task! @@ -85,9 +82,30 @@ hi number 8 from the first task! hi number 9 from the first task! ``` - +So far, it looks like async and threads basically give us the same basic +behavior. However, there are a few important differences already. One was using +`.await` instead of calling `join` on the join handle. Another is that we needed +to await both `sleep` calls. Most importantly, though, we did not need to spawn +another operating system thread to do this. We were able to get concurrency for +just the cost of a task, which has much faster startup time and uses much less +memory than an OS thread. - + + +What is more, we actually do not need the `spawn_task` call at all to get +concurrency here. Remember that each async block compiles to an anonymous +future. That means we can put each of these two loops in an async block and then +ask the runtime to run them both to completion using `trpl::join`: + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-03/src/main.rs}} +``` + + + +When we run this, we see both futures run to completion: ```text hi number 1 from the first task! @@ -105,7 +123,19 @@ hi number 8 from the first task! hi number 9 from the first task! ``` -Here, at least with the implementation we are using in `trpl`, you will see -the exact same order every time, which is *very* different from what we saw with -threads. - +Here, at least with the implementation we are using in `trpl`, you will see the +exact same order every time, which is very different from what we saw with +threads. That is because the `trpl::join` function is *fair*, meaning it checks +both futures at an equal rate. With threads, the operating system decides which +thread to check, and that is ultimately out of our control. With an async +runtime, the runtime itself decides which future to check, so it has the final +say. In practice, the details get complicated because an async runtime might use +operating system threads under the hood as part of how it manages concurrency, +but a well-designed runtime can still guarantee fairness. + +Try combining different places to await the futures and see what they do. See if you can figure out what the output will be *before* running the code! + +* Remove the async block from around either or both of the loops. +* Await each async block immediately after defining it. +* Wrap only the first loop in an async block, and await the resulting future + after the body of second loop. From 9c1f4c8cd6712594924e17a58f3cecd63562bdfa Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 15 May 2024 16:44:01 -0600 Subject: [PATCH 241/720] Ch. 17: Finish 'Counting', start on 'Async Move Blocks' Also rename the files to match their actual titles now that I know them. Or at least: know a good first pass for them. --- src/SUMMARY.md | 4 +- ...tasks.md => ch17-01-futures-and-syntax.md} | 0 src/ch17-02-concurrency-with-async.md | 191 ++++++++++++++++++ src/ch17-02.md | 141 ------------- 4 files changed, 193 insertions(+), 143 deletions(-) rename src/{ch17-01-tasks.md => ch17-01-futures-and-syntax.md} (100%) create mode 100644 src/ch17-02-concurrency-with-async.md delete mode 100644 src/ch17-02.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index daa9a07af7..60680d1983 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -102,8 +102,8 @@ - [Extensible Concurrency with the `Sync` and `Send` Traits](ch16-04-extensible-concurrency-sync-and-send.md) - [Async and Await](ch17-00-async-await.md) - - [Futures and the Async Syntax](ch17-01-tasks.md) - - [something something tokio?!?](ch17-02.md) + - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) + - [Concurrency With Async](ch17-02-concurrency-with-async.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) diff --git a/src/ch17-01-tasks.md b/src/ch17-01-futures-and-syntax.md similarity index 100% rename from src/ch17-01-tasks.md rename to src/ch17-01-futures-and-syntax.md diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md new file mode 100644 index 0000000000..5e86b00fde --- /dev/null +++ b/src/ch17-02-concurrency-with-async.md @@ -0,0 +1,191 @@ +## Concurrency With Async + +In this section, we will apply async to some of the same concurrency challenges +we tackled with threads in chapter 16. Since we already talked about a lot of +the key ideas there, in this section we will focus on what is different between +threads and futures. + +In many cases, the APIs for working with concurrency using async are very similar to those for using threads. In other cases, they end up being shaped fairly differently. Even when the APIs look similar, they often have different behavior and they nearly always have different performance characteristics. + +### Counting + +The first task we tackled in Chapter 16 was counting up on two separate threads. +Let’s do the same using async. The `trpl` crate supplies a `spawn_task` function +which looks very similar to the `thread::spawn` API, and a `sleep` function +which is an async version of the `thread::sleep` API. We can use these together +to implement the same counting example as with threads. + +To start, we will set up our `main` function with `trpl::block_on`: + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:block_on}} +``` + +Then we can write two loops within that block, each with a `trpl::sleep` call in +them. Similar to the threading example, we put one in the body of a +`trpl::spawn_task`, just like we did with `thread::spawn`, and the other in a +top-level `for` loop. Notice that we also need to add a `.await` after the +`sleep` calls. + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:task}} +``` + +Putting that all together, we end up with the code in Listing 17-TODO: + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:all}} +``` + + + +This does something very similar to what the thread-base implementation did, as +we can see from the output when we run it. (As with the threading example, you +may see a different order in your own terminal output when you run this.) + +```text +hi number 1 from the second task! +hi number 1 from the first task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +``` + +This stops as soon as the for loop in the body of the main async block finishes, +because the task spawned by `spawn_task` is shut down when the main function +ends—just like threads are. Thus, if you want to run all the way to the +completion of the task, you will need to use a join handle to wait for the first +task to complete. With threads, we used the `join` method to “block” until the +thread was done running. Here, we can use `await` to do the same thing: + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-02/src/main.rs}} +``` + + + +Now the output again looks like what we saw in the threading example. + +```text +hi number 1 from the second task! +hi number 1 from the first task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +hi number 6 from the first task! +hi number 7 from the first task! +hi number 8 from the first task! +hi number 9 from the first task! +``` + +So far, it looks like async and threads basically give us the same basic +behavior. However, there are a few important differences already. One was using +`.await` instead of calling `join` on the join handle. Another is that we needed +to await both `sleep` calls. Most importantly, though, we did not need to spawn +another operating system thread to do this. We were able to get concurrency for +just the cost of a task, which has much faster startup time and uses much less +memory than an OS thread. + +What is more, we actually do not need the `spawn_task` call at all to get +concurrency here. Remember that each async block compiles to an anonymous +future. That means we can put each of these two loops in an async block and then +ask the runtime to run them both to completion using `trpl::join`: + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-03/src/main.rs}} +``` + + + +When we run this, we see both futures run to completion: + +```text +hi number 1 from the first task! +hi number 1 from the second task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +hi number 6 from the first task! +hi number 7 from the first task! +hi number 8 from the first task! +hi number 9 from the first task! +``` + +Here, you will see the exact same order every time, which is very different from +what we saw with threads. That is because the `trpl::join` function is *fair*, +meaning it checks both futures equally, rather than letting one race ahead. With +threads, the operating system decides which thread to check, and that is +ultimately out of our control. With an async runtime, the runtime itself decides +which future to check, so it has the final say. In practice, the details get +complicated because an async runtime might use operating system threads under +the hood as part of how it manages concurrency, but a runtime can still choose +to guarantee fairness even so. However, runtimes do not have to guarantee +fairness for any given operation, and even within a given runtime, different +APIs sometimes exist to let you choose whether fairness is something you care +about as a caller. + +Try some of these different variations on awaiting the futures and see what they +do. For an extra challenge, see if you can figure out what the output will be +*before* running the code! + +* Remove the async block from around either or both of the loops. +* Await each async block immediately after defining it. +* Wrap only the first loop in an async block, and await the resulting future + after the body of second loop. + +### Tasks vs. Threads + + + +### Async Move Blocks + +In Chapter 13, we learned how to use the `move` keyword with closures, and in +Chapter 16, we saw that we often need to use closures marked with `move` when +working with threads. The `move` keyword also works with async blocks, which +also sometimes need to take ownership of the data they reference. Remember, any +time you write a future, a runtime is ultimately responsible for executing it. +That means that an async block might outlive the function where you write it, the +same way a closure does—even if you do not pass it to a closure explicitly. + +> Note: the `async` keyword does not yet work with closures directly, so you +> cannot write code like these function calls: +> +> ```rust,ignore +> example_1(async || { ... }); +> example_2(async move || { ... }); +> ``` +> +> However, since async blocks themselves can be marked with `move`, this ends up +> not being a problem. Remember that `async` blocks compile to anonymous +> futures. That means you can write calls like this instead: +> +> ```rust,ignore +> example_1(|| async { ... }); +> example_2(|| async move { ... }); +> ``` +> +> These closures now return anonymous futures, meaning they work basically the +> same way that an async function does. + +### Message Passing + +Sharing data between futures will look familiar. We can again use async versions +of Rust’s types for diff --git a/src/ch17-02.md b/src/ch17-02.md deleted file mode 100644 index 0200abe2ce..0000000000 --- a/src/ch17-02.md +++ /dev/null @@ -1,141 +0,0 @@ -## TODO: Section Title - -Back in Chapter 16, we saw an example of counting up on multiple threads. Given -that threads allow us to implement a form of concurrency, we might expect that -async APIs can substitute fairly directly for the threading APIs. The `trpl` -crate supplies a `spawn_task` function which looks very similar to the -`thread::spawn` API, and a `sleep` function which is an async version of the -`thread::sleep` API. We can use these together to implement the same counting -example as with threads. - -To start, we will set up our `main` function with `trpl::block_on`: - -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:block_on}} -``` - -Then we can write two loops within that block, each with a `trpl::sleep` call in -them. Similar to the threading example, we put one in the body of a -`trpl::spawn_task`, just like we did with `thread::spawn`, and the other in a -top-level `for` loop. Notice that we also need to add a `.await` after the -`sleep` calls. - -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:task}} -``` - -Putting that all together, we end up with the code in Listing 17-TODO: - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:all}} -``` - - - -This does something very similar to what the thread-base implementation did, as -we can see from the output when we run it: - -```text -hi number 1 from the second task! -hi number 1 from the first task! -hi number 2 from the first task! -hi number 2 from the second task! -hi number 3 from the first task! -hi number 3 from the second task! -hi number 4 from the first task! -hi number 4 from the second task! -hi number 5 from the first task! -``` - -Just like with the threading example, you may see a different order in your own -terminal output when you run this. And, just like the threading example, if you -want to run all the way to the completion of the first task, you will need to -use a join handle to wait for the first task to complete. With threads, we used -the `join` method to “block” until the thread was done running. Here, we can use -`await` to do the same thing: - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-02/src/main.rs}} -``` - - - -Now the output again looks like what we saw in the threading example. - -```text -hi number 1 from the second task! -hi number 1 from the first task! -hi number 2 from the first task! -hi number 2 from the second task! -hi number 3 from the first task! -hi number 3 from the second task! -hi number 4 from the first task! -hi number 4 from the second task! -hi number 5 from the first task! -hi number 6 from the first task! -hi number 7 from the first task! -hi number 8 from the first task! -hi number 9 from the first task! -``` - -So far, it looks like async and threads basically give us the same basic -behavior. However, there are a few important differences already. One was using -`.await` instead of calling `join` on the join handle. Another is that we needed -to await both `sleep` calls. Most importantly, though, we did not need to spawn -another operating system thread to do this. We were able to get concurrency for -just the cost of a task, which has much faster startup time and uses much less -memory than an OS thread. - - - -What is more, we actually do not need the `spawn_task` call at all to get -concurrency here. Remember that each async block compiles to an anonymous -future. That means we can put each of these two loops in an async block and then -ask the runtime to run them both to completion using `trpl::join`: - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-03/src/main.rs}} -``` - - - -When we run this, we see both futures run to completion: - -```text -hi number 1 from the first task! -hi number 1 from the second task! -hi number 2 from the first task! -hi number 2 from the second task! -hi number 3 from the first task! -hi number 3 from the second task! -hi number 4 from the first task! -hi number 4 from the second task! -hi number 5 from the first task! -hi number 6 from the first task! -hi number 7 from the first task! -hi number 8 from the first task! -hi number 9 from the first task! -``` - -Here, at least with the implementation we are using in `trpl`, you will see the -exact same order every time, which is very different from what we saw with -threads. That is because the `trpl::join` function is *fair*, meaning it checks -both futures at an equal rate. With threads, the operating system decides which -thread to check, and that is ultimately out of our control. With an async -runtime, the runtime itself decides which future to check, so it has the final -say. In practice, the details get complicated because an async runtime might use -operating system threads under the hood as part of how it manages concurrency, -but a well-designed runtime can still guarantee fairness. - -Try combining different places to await the futures and see what they do. See if you can figure out what the output will be *before* running the code! - -* Remove the async block from around either or both of the loops. -* Await each async block immediately after defining it. -* Wrap only the first loop in an async block, and await the resulting future - after the body of second loop. From c1c3c7fac80b38112054659e9da8ca6fc1d77b8b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 16 May 2024 14:06:15 -0600 Subject: [PATCH 242/720] =?UTF-8?q?Ch.=2017:=20start=20on=20message-passin?= =?UTF-8?q?g=20and=20`async=20move`=20in=20=C2=A72?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduce the relevant supporting features in `trpl`. - Add a couple listings to show how things do or do not work. --- .../listing-TODO-04/Cargo.lock | 540 ++++++++++++++++++ .../listing-TODO-04/Cargo.toml | 9 + .../listing-TODO-04/src/main.rs | 29 + .../listing-TODO-05/Cargo.lock | 540 ++++++++++++++++++ .../listing-TODO-05/Cargo.toml | 9 + .../listing-TODO-05/src/main.rs | 31 + packages/trpl/src/lib.rs | 21 +- packages/trpl/tests/integration/main.rs | 22 +- src/ch17-02-concurrency-with-async.md | 38 +- 9 files changed, 1233 insertions(+), 6 deletions(-) create mode 100644 listings/ch17-async-await/listing-TODO-04/Cargo.lock create mode 100644 listings/ch17-async-await/listing-TODO-04/Cargo.toml create mode 100644 listings/ch17-async-await/listing-TODO-04/src/main.rs create mode 100644 listings/ch17-async-await/listing-TODO-05/Cargo.lock create mode 100644 listings/ch17-async-await/listing-TODO-05/Cargo.toml create mode 100644 listings/ch17-async-await/listing-TODO-05/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-04/Cargo.lock b/listings/ch17-async-await/listing-TODO-04/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-TODO-04/Cargo.toml b/listings/ch17-async-await/listing-TODO-04/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-TODO-04/src/main.rs b/listings/ch17-async-await/listing-TODO-04/src/main.rs new file mode 100644 index 0000000000..2bd9e3353f --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04/src/main.rs @@ -0,0 +1,29 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + async { + let (tx, mut rx) = trpl::channel(); + + let tx_fut = async { + println!("Sending 'Hello'"); + tx.send("Hello").unwrap(); + println!("Sleeping!"); + trpl::sleep(Duration::from_millis(1)).await; + println!("Sending 'Goodbye'"); + tx.send("Goodbye").unwrap(); + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; + } + .await; + }); + + println!("Done!"); +} diff --git a/listings/ch17-async-await/listing-TODO-05/Cargo.lock b/listings/ch17-async-await/listing-TODO-05/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-05/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-TODO-05/Cargo.toml b/listings/ch17-async-await/listing-TODO-05/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-05/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-TODO-05/src/main.rs b/listings/ch17-async-await/listing-TODO-05/src/main.rs new file mode 100644 index 0000000000..8780297b10 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-05/src/main.rs @@ -0,0 +1,31 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + async { + let (tx, mut rx) = trpl::channel(); + + // ANCHOR: move + let tx_fut = async move { + // ANCHOR_END: move + println!("Sending 'Hello'"); + tx.send("Hello").unwrap(); + println!("Sleeping!"); + trpl::sleep(Duration::from_millis(1)).await; + println!("Sending 'Goodbye'"); + tx.send("Goodbye").unwrap(); + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; + } + .await; + }); + + println!("Done!"); +} diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 521aa28cb1..d49290f111 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -15,7 +15,26 @@ use std::future::Future; pub use futures::future::join; -pub use tokio::{runtime::Runtime, task::spawn as spawn_task, time::sleep}; +pub use tokio::{ + runtime::Runtime, + // We use the `unbounded` variants because they most closely match the APIs + // from `std::sync::mpsc::channel`. Tokio's API choices are interesting: + // + // | `tokio::sync::mpsc` | `std::sync::mpsc` | + // | ------------------- | ----------------- | + // | `channel` | `sync_channel` | + // | `unbounded_channel` | `channel` | + // + // The book collapses these differences for pedagogical simplicity, so that + // readers are not asking why `unbounded` is now important and can focus on + // the more important differences between sync and async APIs. + sync::mpsc::{ + unbounded_channel as channel, UnboundedReceiver as Receiver, + UnboundedSender as Sender, + }, + task::spawn as spawn_task, + time::sleep, +}; /// Run a single future to completion on a bespoke Tokio `Runtime`. /// diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index e55aea5703..17dc7e2e15 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -9,7 +9,9 @@ //! //! [post]: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html -use trpl::{block_on, sleep, spawn_task}; +use std::time::Duration; + +use trpl::{block_on, channel, sleep, spawn_task, Receiver, Sender}; /// This test is foundational for all the others, as they depend on `block_on`. /// @@ -36,8 +38,24 @@ fn re_exported_spawn_works() { #[test] fn re_exported_sleep_works() { let val = block_on(async { - sleep(std::time::Duration::from_micros(1)).await; + sleep(Duration::from_micros(1)).await; "Done!" }); assert_eq!(val, "Done!"); } + +#[test] +fn re_exported_channel_apis_work() { + block_on(async { + let (tx, mut rx) = channel(); + + tx.send("Hello").unwrap(); + trpl::sleep(Duration::from_millis(1)).await; + tx.send("Goodbye").unwrap(); + drop(tx); + + assert_eq!(rx.recv().await, Some("Hello")); + assert_eq!(rx.recv().await, Some("Goodbye")); + assert_eq!(rx.recv().await, None); + }); +} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 5e86b00fde..a8c29fe834 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -5,7 +5,10 @@ we tackled with threads in chapter 16. Since we already talked about a lot of the key ideas there, in this section we will focus on what is different between threads and futures. -In many cases, the APIs for working with concurrency using async are very similar to those for using threads. In other cases, they end up being shaped fairly differently. Even when the APIs look similar, they often have different behavior and they nearly always have different performance characteristics. +In many cases, the APIs for working with concurrency using async are very +similar to those for using threads. In other cases, they end up being shaped +fairly differently. Even when the APIs look similar, they often have different +behavior and they nearly always have different performance characteristics. ### Counting @@ -165,7 +168,10 @@ time you write a future, a runtime is ultimately responsible for executing it. That means that an async block might outlive the function where you write it, the same way a closure does—even if you do not pass it to a closure explicitly. -> Note: the `async` keyword does not yet work with closures directly, so you + + +> Note: the `async` keyword does not yet work with closures directly—that is, +> there is no direct equivalent to `async fn` for anonymous functions—so you > cannot write code like these function calls: > > ```rust,ignore @@ -187,5 +193,31 @@ same way a closure does—even if you do not pass it to a closure explicitly. ### Message Passing + + Sharing data between futures will look familiar. We can again use async versions -of Rust’s types for +of Rust’s types for message-passing. Instead of `std::sync:mpsc::channel`, we +will use a `tprl::channel`, for example. The `Receiver::recv()` method in the +`std` channel blocks until it receives a message. The `trpl::Receiver::recv()` +method, by contrast, is an `async` function. Instead of blocking, it sleeps +until a message is received or the send side of the channel closes. + + + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04/src/main.rs}} +``` + + + +If we run this, though, it never stops! We can see that `rx` receives and prints all the messages, but + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-05/src/main.rs:move}} +``` + + From 4b7886e09245e9e39677f8796f5458368970d60b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 17 May 2024 15:18:21 -0600 Subject: [PATCH 243/720] Ch. 17: Finish a pass on Message Passing example - Incorporate a good discusion of the need to make sure that the `tx` in this example gets dropped. - Add more listings which show borrowing vs. moving a `tx`, covering the full territory in that example. - Add and test more re-exports in `trpl`. I made a conscious choice here *not* to use `future::join_all()` because that ends up getting into a discussion of `Pin`. I left a TODO item here for now because I think it is probably worth getting into, and that could be a good thing to transition to *after* this section. --- .../listing-TODO-04/src/main.rs | 39 +- .../listing-TODO-04b/Cargo.lock | 540 ++++++++++++++++++ .../listing-TODO-04b/Cargo.toml | 9 + .../listing-TODO-04b/src/main.rs | 38 ++ .../listing-TODO-05/src/main.rs | 37 +- packages/trpl/src/lib.rs | 2 +- packages/trpl/tests/integration/main.rs | 40 +- src/ch17-02-concurrency-with-async.md | 103 +++- 8 files changed, 752 insertions(+), 56 deletions(-) create mode 100644 listings/ch17-async-await/listing-TODO-04b/Cargo.lock create mode 100644 listings/ch17-async-await/listing-TODO-04b/Cargo.toml create mode 100644 listings/ch17-async-await/listing-TODO-04b/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-04/src/main.rs b/listings/ch17-async-await/listing-TODO-04/src/main.rs index 2bd9e3353f..d0e76ecd45 100644 --- a/listings/ch17-async-await/listing-TODO-04/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-04/src/main.rs @@ -1,29 +1,32 @@ +// ANCHOR: all use std::time::Duration; fn main() { trpl::block_on(async { - async { - let (tx, mut rx) = trpl::channel(); + let (tx, mut rx) = trpl::channel(); - let tx_fut = async { - println!("Sending 'Hello'"); - tx.send("Hello").unwrap(); - println!("Sleeping!"); - trpl::sleep(Duration::from_millis(1)).await; - println!("Sending 'Goodbye'"); - tx.send("Goodbye").unwrap(); - }; + let tx_fut = async { + println!("Sending 'Hello'"); + tx.send("Hello").unwrap(); - let rx_fut = async { - while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); - } - }; + println!("Sleeping!"); + trpl::sleep(Duration::from_millis(1)).await; - trpl::join(tx_fut, rx_fut).await; - } - .await; + println!("Sending 'Goodbye'"); + tx.send("Goodbye").unwrap(); + }; + + // ANCHOR: loop + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; + // ANCHOR_END: loop }); println!("Done!"); } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-TODO-04b/Cargo.lock b/listings/ch17-async-await/listing-TODO-04b/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04b/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-TODO-04b/Cargo.toml b/listings/ch17-async-await/listing-TODO-04b/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-TODO-04b/src/main.rs b/listings/ch17-async-await/listing-TODO-04b/src/main.rs new file mode 100644 index 0000000000..7fb7c9ce86 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04b/src/main.rs @@ -0,0 +1,38 @@ +use std::{boxed::Box, future::Future, pin::Pin, time::Duration}; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx_fut = async { + println!("Sending 'Hello'"); + tx.send("Hello").unwrap(); + + println!("Sleeping!"); + trpl::sleep(Duration::from_millis(1)).await; + + println!("Sending 'Goodbye'"); + tx.send("Goodbye").unwrap(); + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + // ANCHOR: updated + let tx_fut2 = async { + println!("Sending 'Extra'"); + tx.send("Extra").unwrap(); + + println!("Sleeping from tx_fut2"); + trpl::sleep(Duration::from_millis(1)).await; + }; + + trpl::join3(tx_fut, tx_fut2, rx_fut).await; + // ANCHOR_END: updated + }); + + println!("Done!"); +} diff --git a/listings/ch17-async-await/listing-TODO-05/src/main.rs b/listings/ch17-async-await/listing-TODO-05/src/main.rs index 8780297b10..6f24a19cff 100644 --- a/listings/ch17-async-await/listing-TODO-05/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-05/src/main.rs @@ -2,29 +2,26 @@ use std::time::Duration; fn main() { trpl::block_on(async { - async { - let (tx, mut rx) = trpl::channel(); + let (tx, mut rx) = trpl::channel(); - // ANCHOR: move - let tx_fut = async move { - // ANCHOR_END: move - println!("Sending 'Hello'"); - tx.send("Hello").unwrap(); - println!("Sleeping!"); - trpl::sleep(Duration::from_millis(1)).await; - println!("Sending 'Goodbye'"); - tx.send("Goodbye").unwrap(); - }; + // ANCHOR: move + let tx_fut = async move { + // ANCHOR_END: move + println!("Sending 'Hello'"); + tx.send("Hello").unwrap(); + println!("Sleeping!"); + trpl::sleep(Duration::from_millis(1)).await; + println!("Sending 'Goodbye'"); + tx.send("Goodbye").unwrap(); + }; - let rx_fut = async { - while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); - } - }; + let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } + }; - trpl::join(tx_fut, rx_fut).await; - } - .await; + trpl::join(tx_fut, rx_fut).await; }); println!("Done!"); diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index d49290f111..43764b97e9 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -14,7 +14,7 @@ use std::future::Future; -pub use futures::future::join; +pub use futures::future::{join, join3}; pub use tokio::{ runtime::Runtime, // We use the `unbounded` variants because they most closely match the APIs diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index 17dc7e2e15..c0fa703562 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -11,7 +11,7 @@ use std::time::Duration; -use trpl::{block_on, channel, sleep, spawn_task, Receiver, Sender}; +use trpl::{Receiver, Sender}; /// This test is foundational for all the others, as they depend on `block_on`. /// @@ -20,15 +20,15 @@ use trpl::{block_on, channel, sleep, spawn_task, Receiver, Sender}; /// others will likely start working again. #[test] fn re_exported_block_on_works() { - let val = block_on(async { "Hello" }); + let val = trpl::block_on(async { "Hello" }); assert_eq!(val, "Hello"); } #[test] fn re_exported_spawn_works() { - let result = block_on(async { - let handle_a = spawn_task(async { "Hello" }); - let handle_b = spawn_task(async { "Goodbye" }); + let result = trpl::block_on(async { + let handle_a = trpl::spawn_task(async { "Hello" }); + let handle_b = trpl::spawn_task(async { "Goodbye" }); vec![handle_a.await.unwrap(), handle_b.await.unwrap()] }); @@ -37,8 +37,8 @@ fn re_exported_spawn_works() { #[test] fn re_exported_sleep_works() { - let val = block_on(async { - sleep(Duration::from_micros(1)).await; + let val = trpl::block_on(async { + trpl::sleep(Duration::from_micros(1)).await; "Done!" }); assert_eq!(val, "Done!"); @@ -46,8 +46,9 @@ fn re_exported_sleep_works() { #[test] fn re_exported_channel_apis_work() { - block_on(async { - let (tx, mut rx) = channel(); + trpl::block_on(async { + // Explicitly naming the type to confirm the re-exports are aligned. + let (tx, mut rx): (Sender<&str>, Receiver<&str>) = trpl::channel(); tx.send("Hello").unwrap(); trpl::sleep(Duration::from_millis(1)).await; @@ -59,3 +60,24 @@ fn re_exported_channel_apis_work() { assert_eq!(rx.recv().await, None); }); } + +#[test] +fn re_exported_join_apis_work() { + let result = trpl::block_on(async { + let a = async { 1 }; + let b = async { 2 }; + trpl::join(a, b).await + }); + + assert_eq!(result, (1, 2)); + + let result = trpl::block_on(async { + let a = async { 1 }; + let b = async { 2 }; + let c = async { 3 }; + + trpl::join3(a, b, c).await + }); + + assert_eq!(result, (1, 2, 3)); +} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index a8c29fe834..132acd9635 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -165,8 +165,8 @@ Chapter 16, we saw that we often need to use closures marked with `move` when working with threads. The `move` keyword also works with async blocks, which also sometimes need to take ownership of the data they reference. Remember, any time you write a future, a runtime is ultimately responsible for executing it. -That means that an async block might outlive the function where you write it, the -same way a closure does—even if you do not pass it to a closure explicitly. +That means that an async block might outlive the function where you write it, +the same way a closure does—even if you do not pass it to a closure explicitly. @@ -197,22 +197,100 @@ same way a closure does—even if you do not pass it to a closure explicitly. Sharing data between futures will look familiar. We can again use async versions of Rust’s types for message-passing. Instead of `std::sync:mpsc::channel`, we -will use a `tprl::channel`, for example. The `Receiver::recv()` method in the -`std` channel blocks until it receives a message. The `trpl::Receiver::recv()` -method, by contrast, is an `async` function. Instead of blocking, it sleeps -until a message is received or the send side of the channel closes. +will use a `tprl::channel`, for example. + +The `Receiver::recv()` method in the `std` channel blocks until it receives a +message. The `trpl::Receiver::recv()` method, by contrast, is an `async` +function. Instead of blocking, it sleeps until a message is received or the send +side of the channel closes. One other difference with this particular `recv()` +implementation is that it returns an `Option` of the type sent over the channel +instead of a `Result`. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04/src/main.rs:all}} +``` + + + +If we run this, though, it never stops! You will need to shut it down using +ctrl-c. We can see that `tx` sends all the +messages,and `rx` receives and prints them, but we never see the “Done!” +message, and the program never stops running. That’s because of the combination +of the `while let` loop and the `trpl::join` call: + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04/src/main.rs:loop}} +``` + +Let’s consider the way this loop works: + +* The `trpl::join` future only completes once *both* futures passed to it + have completed. +* The `tx` future completes after sending the second message. +* The `rx` future will not complete until the `while let` loop ends, though. +* The `while let` loop will not end until `rx.recv().await` produces `None`. +* The `rx.recv().await` will only return `None` once the other end of the + channel is closed. +* The channel will only close if we call `rx.close()` or when the sender side, + `tx`, is dropped. +* We do not call `rx.close()` anywhere, and `tx` will not be dropped until the + function exits. +* The function cannot exit because it is blocked on `trpl::join` completing, + which takes us back to the top of the list! + +To solve this, then, we need to make sure the channel gets closed so that +`trpl::join` will complete. We could manually close `rx` somewhere by calling +`rx.close()`, but that does not make much sense in this case. The idea is that +`rx` should keep listening until `tx` is done sending. Stopping after handling +some arbitrary number of messages would make the program shut down, but it would +mean we could miss messages if the sending side changed. Given that we cannot +use `rx.close()`, we need to make sure that `tx` gets dropped *before* the end +of the function. + +Right now, the async block only borrows `tx`. We can confirm this by adding +another async block which uses `tx`, and using `trpl::join3` to wait for all +three futures to complete: + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04b/src/main.rs:updated}} ``` -If we run this, though, it never stops! We can see that `rx` receives and prints all the messages, but +Now both blocks borrow `tx`, so they are both able to use it to send messages, +which `rx` can then receive. When we run that code, we see the extra output from +the new `async` block, and the message it sends being received by the +`rx.recv()`: + +```text +Sending 'Hello' +Sleeping! +Sending 'Extra' +Sleeping from tx_fut2 +received 'Hello' +received 'Extra' +Sending 'Goodbye' +received 'Goodbye' +``` + +As before, we also see that the program does not shut down on its own and requires a ctrl-c. Now that we have seen how `async` blocks borrow the items they reference from their outer scope, we can go ahead and remove the extra block we just added, and switch back to using `trpl::join` instead of `trpl::join3`. + +We now know enough to solve the original issue here. We need to move `tx` into +the async block. Once that block ends, `tx` will be dropped. We can do that by +making the first async block an `async move` block: + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-05/src/main.rs:move}} +``` + +The result is Listing 17-TODO, and when we run *this* version of the code, it +shuts down gracefully after the last message is sent. @@ -221,3 +299,12 @@ If we run this, though, it never stops! We can see that `rx` receives and prints ``` + + + + From 548329994b2b1c35cf929ea03e1cc880cddcd3c7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 13:44:36 -0600 Subject: [PATCH 244/720] Exclude `trpl` from workspace It should manage its own dependencies. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 2bddb66f9f..b65d859e5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ exclude = [ "linkchecker", # linkchecker is part of the CI workflow "listings", # these are intentionally distinct from the workspace "tmp", # listings are built here when updating output via tools/update-rustc.sh + "trpl", # manages its own dependencies as a standalone crate # These are used as path dependencies in `rust-lang/rust` (since we are not # publishing them to crates.io), so they cannot be part of this workspace, From acde825992ac8a9b5f1a6ff4b5d132fdf983b264 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 13:45:06 -0600 Subject: [PATCH 245/720] Ch. 17: skip `main` and `trpl::block_on` in some listings Wherever it makes sense to elide these for the sake of clarity, do so! --- listings/ch17-async-await/listing-TODO-01/src/main.rs | 4 ++-- listings/ch17-async-await/listing-TODO-02/src/main.rs | 2 ++ listings/ch17-async-await/listing-TODO-03/src/main.rs | 2 ++ src/ch17-01-futures-and-syntax.md | 8 ++------ src/ch17-02-concurrency-with-async.md | 8 ++++++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/listings/ch17-async-await/listing-TODO-01/src/main.rs b/listings/ch17-async-await/listing-TODO-01/src/main.rs index e766efdf18..62b08cf5e9 100644 --- a/listings/ch17-async-await/listing-TODO-01/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-01/src/main.rs @@ -1,8 +1,8 @@ // ANCHOR: all use std::time::Duration; -// ANCHOR: block_on fn main() { + // ANCHOR: block_on trpl::block_on(async { // ANCHOR_END: block_on // ANCHOR: task @@ -20,6 +20,6 @@ fn main() { // ANCHOR_END: task // ANCHOR: block_on }); + // ANCHOR_END: block_on } -// ANCHOR_END: block_on // ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-TODO-02/src/main.rs b/listings/ch17-async-await/listing-TODO-02/src/main.rs index 71cb24e34c..079cbe06a9 100644 --- a/listings/ch17-async-await/listing-TODO-02/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-02/src/main.rs @@ -2,6 +2,7 @@ use std::time::Duration; fn main() { trpl::block_on(async { + // ANCHOR: handle let handle = trpl::spawn_task(async { for i in 1..10 { println!("hi number {i} from the first task!"); @@ -15,5 +16,6 @@ fn main() { } handle.await; + // ANCHOR_END: handle }); } diff --git a/listings/ch17-async-await/listing-TODO-03/src/main.rs b/listings/ch17-async-await/listing-TODO-03/src/main.rs index 8797b5d634..60889f3aed 100644 --- a/listings/ch17-async-await/listing-TODO-03/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-03/src/main.rs @@ -2,6 +2,7 @@ use std::time::Duration; fn main() { trpl::block_on(async { + // ANCHOR: join let fut1 = async { for i in 1..10 { println!("hi number {i} from the first task!"); @@ -17,5 +18,6 @@ fn main() { }; trpl::join(fut1, fut2).await; + // ANCHOR_END: join }); } diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 0654274fe3..e299f1b5d2 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -236,9 +236,7 @@ work and the `T` value is available. Under the hood, when you call `.await`, Rust compiles that to code which calls `poll`, kind of like this: - - -```rust +```rust,ignore match hello_async().poll() { Ready(_) => { // We’re done! @@ -253,9 +251,7 @@ As you can see from this sample, though, there is a question: what happens when the `Future` is still `Pending`? We need some way to try again. We would need to have something like this instead: - - -```rust +```rust,ignore let hello_async_fut = hello_async(); loop { match hello_async_fut.poll() { diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 132acd9635..f08907084d 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -24,6 +24,10 @@ To start, we will set up our `main` function with `trpl::block_on`: {{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:block_on}} ``` +> Note: From this point forward in the chapter, every example will include this +> exact same code, so we will often skip it just like we do with `main`. Don’t +> forget to include it in your own code! + Then we can write two loops within that block, each with a `trpl::sleep` call in them. Similar to the threading example, we put one in the body of a `trpl::spawn_task`, just like we did with `thread::spawn`, and the other in a @@ -70,7 +74,7 @@ thread was done running. Here, we can use `await` to do the same thing: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-02/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-02/src/main.rs:handle}} ``` @@ -109,7 +113,7 @@ ask the runtime to run them both to completion using `trpl::join`: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-03/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-03/src/main.rs:join}} ``` From 7b14d7dbde929b8c037779f3986e6b500b024a5f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 13:45:06 -0600 Subject: [PATCH 246/720] Ch. 17: inline some note content and fix some phrasing --- src/ch17-02-concurrency-with-async.md | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index f08907084d..028d7fc14c 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -48,7 +48,7 @@ Putting that all together, we end up with the code in Listing 17-TODO: -This does something very similar to what the thread-base implementation did, as +This does something very similar to what the thread-based implementation did, as we can see from the output when we run it. (As with the threading example, you may see a different order in your own terminal output when you run this.) @@ -170,30 +170,30 @@ working with threads. The `move` keyword also works with async blocks, which also sometimes need to take ownership of the data they reference. Remember, any time you write a future, a runtime is ultimately responsible for executing it. That means that an async block might outlive the function where you write it, -the same way a closure does—even if you do not pass it to a closure explicitly. +the same way a closure can. -> Note: the `async` keyword does not yet work with closures directly—that is, -> there is no direct equivalent to `async fn` for anonymous functions—so you -> cannot write code like these function calls: -> -> ```rust,ignore -> example_1(async || { ... }); -> example_2(async move || { ... }); -> ``` -> -> However, since async blocks themselves can be marked with `move`, this ends up -> not being a problem. Remember that `async` blocks compile to anonymous -> futures. That means you can write calls like this instead: -> -> ```rust,ignore -> example_1(|| async { ... }); -> example_2(|| async move { ... }); -> ``` -> -> These closures now return anonymous futures, meaning they work basically the -> same way that an async function does. +The `async` keyword does not yet work with closures directly. That is, there is +no direct equivalent to `async fn` for anonymous functions. As a result, you +cannot write code like these function calls: + +```rust,ignore +example_1(async || { ... }); +example_2(async move || { ... }); +``` + +However, since async blocks themselves can be marked with `move`, this ends up +not being a problem. Remember that `async` blocks compile to anonymous futures. +That means you can write calls like this instead: + +```rust,ignore +example_1(|| async { ... }); +example_2(|| async move { ... }); +``` + +These closures now return anonymous futures, meaning they work basically the +same way that an async function does. ### Message Passing From 1d7c987288d6e6313ec4fd1c32d6466ed306da90 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 15:55:59 -0600 Subject: [PATCH 247/720] Ch. 17: Rewrite listings to be more similar to Ch. 16 --- .../listing-TODO-04/src/main.rs | 19 ++++---- .../listing-TODO-04b/src/main.rs | 43 +++++++++++-------- .../listing-TODO-05/src/main.rs | 19 ++++---- src/ch17-02-concurrency-with-async.md | 16 +++---- 4 files changed, 54 insertions(+), 43 deletions(-) diff --git a/listings/ch17-async-await/listing-TODO-04/src/main.rs b/listings/ch17-async-await/listing-TODO-04/src/main.rs index d0e76ecd45..0c364f43dd 100644 --- a/listings/ch17-async-await/listing-TODO-04/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-04/src/main.rs @@ -6,14 +6,17 @@ fn main() { let (tx, mut rx) = trpl::channel(); let tx_fut = async { - println!("Sending 'Hello'"); - tx.send("Hello").unwrap(); + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - println!("Sleeping!"); - trpl::sleep(Duration::from_millis(1)).await; - - println!("Sending 'Goodbye'"); - tx.send("Goodbye").unwrap(); + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } }; // ANCHOR: loop @@ -26,7 +29,5 @@ fn main() { trpl::join(tx_fut, rx_fut).await; // ANCHOR_END: loop }); - - println!("Done!"); } // ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-TODO-04b/src/main.rs b/listings/ch17-async-await/listing-TODO-04b/src/main.rs index 7fb7c9ce86..e5d8f86066 100644 --- a/listings/ch17-async-await/listing-TODO-04b/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-04b/src/main.rs @@ -1,38 +1,45 @@ -use std::{boxed::Box, future::Future, pin::Pin, time::Duration}; +use std::time::Duration; fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); let tx_fut = async { - println!("Sending 'Hello'"); - tx.send("Hello").unwrap(); - - println!("Sleeping!"); - trpl::sleep(Duration::from_millis(1)).await; - - println!("Sending 'Goodbye'"); - tx.send("Goodbye").unwrap(); + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } }; let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); + while let Some(received) = rx.recv().await { + println!("Got: {received}"); } }; // ANCHOR: updated let tx_fut2 = async { - println!("Sending 'Extra'"); - tx.send("Extra").unwrap(); - - println!("Sleeping from tx_fut2"); - trpl::sleep(Duration::from_millis(1)).await; + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } }; trpl::join3(tx_fut, tx_fut2, rx_fut).await; // ANCHOR_END: updated }); - - println!("Done!"); } diff --git a/listings/ch17-async-await/listing-TODO-05/src/main.rs b/listings/ch17-async-await/listing-TODO-05/src/main.rs index 6f24a19cff..b88571997e 100644 --- a/listings/ch17-async-await/listing-TODO-05/src/main.rs +++ b/listings/ch17-async-await/listing-TODO-05/src/main.rs @@ -7,12 +7,17 @@ fn main() { // ANCHOR: move let tx_fut = async move { // ANCHOR_END: move - println!("Sending 'Hello'"); - tx.send("Hello").unwrap(); - println!("Sleeping!"); - trpl::sleep(Duration::from_millis(1)).await; - println!("Sending 'Goodbye'"); - tx.send("Goodbye").unwrap(); + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } }; let rx_fut = async { @@ -23,6 +28,4 @@ fn main() { trpl::join(tx_fut, rx_fut).await; }); - - println!("Done!"); } diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 028d7fc14c..7002919027 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -273,14 +273,14 @@ the new `async` block, and the message it sends being received by the `rx.recv()`: ```text -Sending 'Hello' -Sleeping! -Sending 'Extra' -Sleeping from tx_fut2 -received 'Hello' -received 'Extra' -Sending 'Goodbye' -received 'Goodbye' +Got: hi +Got: more +Got: from +Got: messages +Got: the +Got: for +Got: future +Got: you ``` As before, we also see that the program does not shut down on its own and requires a ctrl-c. Now that we have seen how `async` blocks borrow the items they reference from their outer scope, we can go ahead and remove the extra block we just added, and switch back to using `trpl::join` instead of `trpl::join3`. From 1db4ee255afb14141399056a002b3ac8c941fff7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 15:55:59 -0600 Subject: [PATCH 248/720] Ch. 17: wording and structure tweaks --- src/ch17-01-futures-and-syntax.md | 2 +- src/ch17-02-concurrency-with-async.md | 94 +++++++++++++++------------ 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index e299f1b5d2..8e943e3b4a 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -279,7 +279,7 @@ is what handles the top-level `poll()` call, scheduling and handing off between the different async operations which may be in flight, and often also providing async versions of functionality like file I/O. -Now we can understand why the compiler was blocking us in Listing 17-2 (before +Now we can understand why the compiler was stopping us in Listing 17-2 (before we added the `trpl::block_on` function). The `main` function is not `async`—and it really cannot be: if it were, something would need to call `poll()` on whatever `main` returned! Instead, we use the `trpl::block_on` function, which diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 7002919027..ea865e45d1 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -29,8 +29,8 @@ To start, we will set up our `main` function with `trpl::block_on`: > forget to include it in your own code! Then we can write two loops within that block, each with a `trpl::sleep` call in -them. Similar to the threading example, we put one in the body of a -`trpl::spawn_task`, just like we did with `thread::spawn`, and the other in a +them. Similar to the threading example, we put one loop in the body of a +`trpl::spawn_task`, the same way we did with `thread::spawn`, and the other in a top-level `for` loop. Notice that we also need to add a `.await` after the `sleep` calls. @@ -150,50 +150,19 @@ APIs sometimes exist to let you choose whether fairness is something you care about as a caller. Try some of these different variations on awaiting the futures and see what they -do. For an extra challenge, see if you can figure out what the output will be -*before* running the code! +do: * Remove the async block from around either or both of the loops. * Await each async block immediately after defining it. * Wrap only the first loop in an async block, and await the resulting future after the body of second loop. -### Tasks vs. Threads +For an extra challenge, see if you can figure out what the output will be in +each case *before* running the code! - - -### Async Move Blocks - -In Chapter 13, we learned how to use the `move` keyword with closures, and in -Chapter 16, we saw that we often need to use closures marked with `move` when -working with threads. The `move` keyword also works with async blocks, which -also sometimes need to take ownership of the data they reference. Remember, any -time you write a future, a runtime is ultimately responsible for executing it. -That means that an async block might outlive the function where you write it, -the same way a closure can. - - - -The `async` keyword does not yet work with closures directly. That is, there is -no direct equivalent to `async fn` for anonymous functions. As a result, you -cannot write code like these function calls: +### Futures, Tasks, and Threads -```rust,ignore -example_1(async || { ... }); -example_2(async move || { ... }); -``` - -However, since async blocks themselves can be marked with `move`, this ends up -not being a problem. Remember that `async` blocks compile to anonymous futures. -That means you can write calls like this instead: - -```rust,ignore -example_1(|| async { ... }); -example_2(|| async move { ... }); -``` - -These closures now return anonymous futures, meaning they work basically the -same way that an async function does. + ### Message Passing @@ -283,11 +252,29 @@ Got: future Got: you ``` -As before, we also see that the program does not shut down on its own and requires a ctrl-c. Now that we have seen how `async` blocks borrow the items they reference from their outer scope, we can go ahead and remove the extra block we just added, and switch back to using `trpl::join` instead of `trpl::join3`. +As before, we also see that the program does not shut down on its own and +requires a ctrl-c. Now that we have seen how +`async` blocks borrow the items they reference from their outer scope, we can go +ahead and remove the extra block we just added, and switch back to using +`trpl::join` instead of `trpl::join3`. -We now know enough to solve the original issue here. We need to move `tx` into -the async block. Once that block ends, `tx` will be dropped. We can do that by -making the first async block an `async move` block: +This little exploration makes the original issue much clearer: it is ultimately +about *ownership*. We need to move `tx` into the async block so that once that +block ends, `tx` will be dropped. + +In Chapter 13, we learned how to use the `move` keyword with closures, and in +Chapter 16, we saw that we often need to use closures marked with `move` when +working with threads. As we have discovered, the same dynamics apply to async +blocks—so the `move` keyword also works with async blocks, allowing them to take +ownership of the data they reference. + + +Remember, any time you write a future, a runtime is ultimately responsible for +executing it. That means that an async block might outlive the function where +you write it, the same way a closure can. + + +We can do that by making the first async block an `async move` block. ```rust {{#rustdoc_include ../listings/ch17-async-await/listing-TODO-05/src/main.rs:move}} @@ -312,3 +299,26 @@ shuts down gracefully after the last message is sent. --> + + +The `async` keyword does not yet work with closures directly. That is, there is +no direct equivalent to `async fn` for anonymous functions. As a result, you +cannot write code like these function calls: + +```rust,ignore +example_1(async || { ... }); +example_2(async move || { ... }); +``` + +However, since async blocks themselves can be marked with `move`, this ends up +not being a problem. Remember that `async` blocks compile to anonymous futures. +That means you can write calls like this instead: + +```rust,ignore +example_1(|| async { ... }); +example_2(|| async move { ... }); +``` + +These closures now return anonymous futures, meaning they work basically the +same way that an async function does. + From af18d2b969311846e8648b4b566fe6ee2452f080 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 22 May 2024 15:55:59 -0600 Subject: [PATCH 249/720] Ch. 17: show multiple producers working with `clone` --- .../listing-TODO-04b2/Cargo.lock | 540 ++++++++++++++++++ .../listing-TODO-04b2/Cargo.toml | 9 + .../listing-TODO-04b2/src/main.rs | 46 ++ src/ch17-02-concurrency-with-async.md | 22 + 4 files changed, 617 insertions(+) create mode 100644 listings/ch17-async-await/listing-TODO-04b2/Cargo.lock create mode 100644 listings/ch17-async-await/listing-TODO-04b2/Cargo.toml create mode 100644 listings/ch17-async-await/listing-TODO-04b2/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-04b2/Cargo.lock b/listings/ch17-async-await/listing-TODO-04b2/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04b2/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-TODO-04b2/Cargo.toml b/listings/ch17-async-await/listing-TODO-04b2/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04b2/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-TODO-04b2/src/main.rs b/listings/ch17-async-await/listing-TODO-04b2/src/main.rs new file mode 100644 index 0000000000..4c5e65da9b --- /dev/null +++ b/listings/ch17-async-await/listing-TODO-04b2/src/main.rs @@ -0,0 +1,46 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + // ANCHOR: here + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + trpl::join3(tx1_fut, tx_fut, rx_fut).await; + // ANCHOR_END: here + }); +} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index ea865e45d1..4a9102866a 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -179,6 +179,8 @@ side of the channel closes. One other difference with this particular `recv()` implementation is that it returns an `Option` of the type sent over the channel instead of a `Result`. +We can start by introducing an async version of the `channel` + @@ -291,6 +293,26 @@ shuts down gracefully after the last message is sent. +### Multiple Producers with Async + +This async channel is also a multiple-producer channel, so we can call `clone` +on `tx` if we want to send messages from multiple futures. For example, we can +make the code from Listing 17-TODO work by cloning the `tx` before moving it +into the first async block, moving the original `tx` into the second async +block, and switchign back to `join3`. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04b2/src/main.rs:here}} +``` + + + + +Both of these blocks need to be `async move` blocks, or else we will end up back +in the same infinite loop we started out in. + + +### Parallelism and Concurrency + In the previous chapter we treated parallelism and concurrency as interchangeable. Now we need to distinguish between the two a little more: @@ -54,34 +140,10 @@ can pause one activity and switch to others before eventually cycling back to that first activity again. So all parallel operations are also concurrent, but not all concurrent operations happen in parallel! -> Note: When working with async in Rust, we need to think in terms of -> *concurrency*. Depending on the hardware, the operating system, and the async -> runtime we are using, that concurrency may use some degree of parallelism -> under the hood, or it may not. More about async runtimes in a later section! - -Consider again the examples of exporting a video file and waiting on the video -file to finish uploading. The video export will use as much CPU and GPU power as -it can. If you only had one CPU core, and your operating system never paused -that export until it completed, you could not do anything else on your computer -while it was running. That would be a pretty frustrating experience, though, so -instead your computer can (and does!) invisibly interrupt the export often -enough to let you get other small amounts of work done along the way. - -The file upload is different. It does not take up very much CPU time. Instead, -you are mostly waiting on data to transfer across the network. If you only have -a single CPU core, you might write a bunch of data to a network socket and then -wait for it to finish getting sent by the network controller. You could choose -to wait for all the data to get “flushed” from the socket and actually sent over -the network, but if there is a busy network connection, you might be waiting for -a while… with your CPU doing not much! Thus, even if you make a blocking call to -write to a socket, your computer probably does other things while the network -operation is happening. - -In both of these cases, it might be useful for *your program* to participate in -the same kind of concurrency the computer is providing for the rest of the -system. One way to do this is the approach we saw last chapter: using threads, -which are provided and managed by the operating system. Another way to get -access to concurrency is using language-specific capabilities—like async. +When working with async in Rust, we are always dealing with concurrency. +Depending on the hardware, the operating system, and the async runtime we are +using, that concurrency may use some degree of parallelism under the hood, or it +may not. (More about async runtimes later!) A big difference between the cooking analogy and Rust’s async model for concurrency is that in the cooking example, the cook makes the decision about diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 4a9102866a..f1684622a0 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -166,8 +166,6 @@ each case *before* running the code! ### Message Passing - - Sharing data between futures will look familiar. We can again use async versions of Rust’s types for message-passing. Instead of `std::sync:mpsc::channel`, we will use a `tprl::channel`, for example. From 1010b1fc51e910ea3c939576bb1f99b1750979b1 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 24 May 2024 11:22:22 -0600 Subject: [PATCH 251/720] Ch. 17: further motivation for async w/examples I am not 100% sure we will keep these, but right now they feel useful for helping see how `async` can help solve some of these problems. --- src/ch17-00-async-await.md | 96 +++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 28 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index dd56ec2a9f..2892948f93 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -4,7 +4,7 @@ In Chapter 16, we saw one of Rust’s approaches to concurrency: using threads. Since Rust 1.39, there has been another option for concurrency: asynchronous programming, or *async*. -In the rest of chapter, we will: +In the rest of this chapter, we will: * see how to use Rust’s `async` and `.await` syntax * explore how to use the async model to solve some of the same challenges we @@ -23,15 +23,12 @@ upload that video to some service to share it with your family, that upload process might take a long time. It would be nice if we could do something else while we are waiting for those long-running processes to complete. - - -Consider again the examples of exporting a video file and waiting on the video -file to finish uploading. The video export will use as much CPU and GPU power as -it can. If you only had one CPU core, and your operating system never paused -that export until it completed, you could not do anything else on your computer -while it was running. That would be a pretty frustrating experience, though, so -instead your computer can (and does!) invisibly interrupt the export often -enough to let you get other small amounts of work done along the way. +The video export will use as much CPU and GPU power as it can. If you only had +one CPU core, and your operating system never paused that export until it +completed, you could not do anything else on your computer while it was running. +That would be a pretty frustrating experience, though, so instead your computer +can (and does!) invisibly interrupt the export often enough to let you get other +small amounts of work done along the way. The file upload is different. It does not take up very much CPU time. Instead, you are mostly waiting on data to transfer across the network. If you only have @@ -74,38 +71,81 @@ dedicated thread which handles the write operation, it will *not* block the rest of the program. But in many ways, it would be nicer if the call were not blocking in the first place. + + One way to accomplish that would be to use an API built around callbacks. For each blocking operation, we could pass in a function to call once the operation completes: ```rust,ignore -network_socket.non_blocking_send(data).and_then(|result| { +network_socket.non_blocking_send(data, |result| { + // ... +}); +``` + +Or we could register callbacks to run when events happen: + +```rust,ignore +network_socket.add_listener(Event::DoneSending, || { // ... }); ``` -This is the basic design of most event-based APIs. It is also the basic mechanic -used when working directly with promises in JavaScript. Historically, it was -also the way that Rust implemented async! This can make the control flow for the -program much more complicated, though. In particular, you can end up with many -nested callbacks, and debugging those can be very painful. Even with chains of -function calls, this can get laborious: +Or we could have our functions return a type with an `and_then` method on it, +which in turn accepts a callback which can do more work of the same sort: ```rust,ignore -network_socket - .non_blocking_send(data) - .and_then(|first_result| { /* another non_blocking operation */ }) - .and_then(|next_result| { /* another non_blocking operation */ }) - .and_then(|yet_another_result| { /* finish things up */ }); +network_socket.non_blocking_send(data) + .and_then(|result| { /* another non_blocking operation */ }) + .and_then(|next_result| { /* ... */ }); +``` + +Historically, this last choice was the way that Rust did async! Each of these +can make the control flow for the program more complicated, though. You can end +up with many nested callbacks, or long chains of callbacks, and understanding +the flow of data through the program can become more difficult as a result. + +With other common types in Rust, we often use pattern-matching in scenarios like +this. When we are using callbacks we do not yet have the data at the time we +call `non_blocking_send`—and we will not have it until the callback gets called. +That means that there is no way to match on the data it will return: it is not +here yet! + +There are also no particularly good ways to get data out of those callbacks. We +might try something like this, imagining a `read_to_string_non_blocking` which +has eaxctly the kind of `and_then` method described above. If we were to try to +use that, with code something like this, it would not compile: + +```rust,ignore,does_not_compile +let mut data = None; +read_to_string_non_blocking(some_path).and_then(|result| { + data = Some(result); +}); +println!("{data:?}"); ``` -With other common types in Rust, we often use pattern-matching on operations -like this. However, when we are using callbacks like these to avoid blocking, we -cannot use pattern matching, because we do not yet have the data at the time we -call `non_blocking_send`—and we will not have it until the callback gets -called. +The callback passed to `and_then` needs a mutable reference to `data`, but the +`load` function tries to return `data` to the caller. Rust would helpfully tell +us that we cannot borrow `data` immutably to print it because it is still +borrowed mutably for the `and_then` callback. This is not just Rust being fussy, +either: the result of this would normally always just print the `None` value and +exit, but if the read *happened* to go fast enough, it is possible it could +sometimes print some string data instead. That is *definitely* not what we +want! + +We also cannot cancel `read_to_string_non_blocking`: once it has started, it +will run till it finishes unless the whole program stops. + +What we really want to be able to write is something much simpler, like we would +in blocking code, but in a way that + +```rust,ignore,does_not_compile +let data = read_to_string_non_blocking(&path).await; +printl!("{data}"); +``` - +That is exactly what Rust’s async abstraction gives us. It is designed to help +us solve all of these issues. ### Parallelism and Concurrency From 8ce6c8a5442396e864b6e199a2655a8994264797 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 24 May 2024 17:13:10 -0600 Subject: [PATCH 252/720] =?UTF-8?q?Ch.=2017:=20rework=20=C2=A700=20to=20ta?= =?UTF-8?q?lk=20about=20reads=20instead=20of=20writes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This lets me combine the examples of trying to get data “out” with the existing network socket example, rather than introducing yet another imaginary API, and gives us a final API that looks much closer to what users will actually see with a real world socket. --- src/ch17-00-async-await.md | 82 ++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 2892948f93..296dae8bb0 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -19,9 +19,9 @@ First, though, let’s explore what async gives us. Many operations we ask the computer to do can take a while to finish. For example, if you used a video editor to create a video of a family celebration, exporting it could take anywhere from minutes to hours. Similarly, when you -upload that video to some service to share it with your family, that upload -process might take a long time. It would be nice if we could do something else -while we are waiting for those long-running processes to complete. +download a video shared by someone in your family, that download process might +take a long time. It would be nice if we could do something else while we are +waiting for those long-running processes to complete. The video export will use as much CPU and GPU power as it can. If you only had one CPU core, and your operating system never paused that export until it @@ -30,32 +30,35 @@ That would be a pretty frustrating experience, though, so instead your computer can (and does!) invisibly interrupt the export often enough to let you get other small amounts of work done along the way. -The file upload is different. It does not take up very much CPU time. Instead, -you are mostly waiting on data to transfer across the network. If you only have -a single CPU core, you might write a bunch of data to a network socket and then -wait for it to finish getting sent by the network controller. You could choose -to wait for all the data to get “flushed” from the socket and actually sent over -the network, but if there is a busy network connection, you might be waiting for -a while… with your CPU doing not much! Thus, even if your program cannot do -anything until it finishes writing data to a network socket, your computer -probably still does other things while the network operation is happening. +The file download is different. It does not take up very much CPU time. Instead, +you are mostly waiting on data to transfer across the network. You can start +reading from a network socket, but it might take a while for all the data to +arrive and be fed into the socket by the network controller. Moreover, even once +the data has all arrived, videos can be quite large, so it might take some time +to load all the data from the socket. Even if “some time” here is just a second +or two, that is a very long time for a modern processor, which can do billions +of operations every second. You could choose to wait for all of that to finish, +but you might be waiting for a while… with your CPU doing not much! Thus, even +if your specific program cannot do anything until it finishes reading data from +a network socket, your computer will once again invisibly interrupt your +program so other things can happen at the same time as the network operation. > Note: The video export is the kind of operation which is often described as > “CPU-bound”. It is limited by the speed of the computer’s CPU (and GPU), and -> how much of that power it can use. The video upload is the kind of operation +> how much of that power it can use. The video download is the kind of operation > which is often described as “IO-bound,” because it is limited by the speed of > the computer’s *input and output*. It can only go as fast as the data can be > sent across the network, which means that it can only go as fast as the data -> can be written to the socket. +> can be written to the socket by the network controller. In both of these examples, the concurrency happens at the level of the whole program. The operating system decides to interrupt the program to let other programs get work done. In many cases, since we understand our programs at a much more granular level than the operating system does, we can lots of opportunities for concurrency that the operating system cannot see. For example, -if we are building a tool to manage file uploads, it is important that the user -interface stay responsive while an upload is happening. In fact, we should even -be able to start multiple uploads at the same time. +if we are building a tool to manage file downloads, it is important that the +user interface stay responsive while a download is happening. In fact, we should +even be able to start multiple downloads at the same time. However, many operating system APIs for interacting with network sockets are *blocking*. That is, the function calls block further progress in the program @@ -65,20 +68,18 @@ function calls which interact with files, network sockets, or other resources on the computer, because those are the places where an individual program would benefit from the operation being *non*-blocking. -When doing file uploads, we could work around the fact that the call to write to +When doing file downloads, we could work around the fact that the call to write to a network socket is blocking using threads. If we move the data over to a dedicated thread which handles the write operation, it will *not* block the rest of the program. But in many ways, it would be nicer if the call were not blocking in the first place. - - One way to accomplish that would be to use an API built around callbacks. For each blocking operation, we could pass in a function to call once the operation completes: ```rust,ignore -network_socket.non_blocking_send(data, |result| { +network_socket.read_non_blocking(|result| { // ... }); ``` @@ -86,18 +87,18 @@ network_socket.non_blocking_send(data, |result| { Or we could register callbacks to run when events happen: ```rust,ignore -network_socket.add_listener(Event::DoneSending, || { +network_socket.add_listener(Event::ReadFinished, |data| { // ... }); ``` -Or we could have our functions return a type with an `and_then` method on it, -which in turn accepts a callback which can do more work of the same sort: +Or we could have our functions return a type with `and_then` method, which in +turn accepts a callback which can do more work of the same sort: ```rust,ignore -network_socket.non_blocking_send(data) - .and_then(|result| { /* another non_blocking operation */ }) - .and_then(|next_result| { /* ... */ }); +network_socket.read_non_blocking().and_then(|result| { + /* another non_blocking operation */ +}); ``` Historically, this last choice was the way that Rust did async! Each of these @@ -107,18 +108,18 @@ the flow of data through the program can become more difficult as a result. With other common types in Rust, we often use pattern-matching in scenarios like this. When we are using callbacks we do not yet have the data at the time we -call `non_blocking_send`—and we will not have it until the callback gets called. +call `read_non_blocking`—and we will not have it until the callback gets called. That means that there is no way to match on the data it will return: it is not here yet! There are also no particularly good ways to get data out of those callbacks. We -might try something like this, imagining a `read_to_string_non_blocking` which -has eaxctly the kind of `and_then` method described above. If we were to try to -use that, with code something like this, it would not compile: +might try something like this, imagining a `read_non_blocking` which has exactly +the kind of `and_then` method described above. If we were to try to use that, +with code something like this, it would not compile: ```rust,ignore,does_not_compile let mut data = None; -read_to_string_non_blocking(some_path).and_then(|result| { +network_socket.read_non_blocking().and_then(|result| { data = Some(result); }); println!("{data:?}"); @@ -133,19 +134,20 @@ exit, but if the read *happened* to go fast enough, it is possible it could sometimes print some string data instead. That is *definitely* not what we want! -We also cannot cancel `read_to_string_non_blocking`: once it has started, it -will run till it finishes unless the whole program stops. +We also cannot cancel `read_non_blocking`: once it has started, it will run till +it finishes unless the whole program stops. -What we really want to be able to write is something much simpler, like we would -in blocking code, but in a way that +What we really want to be able to write is something much more direct, like we +would write in blocking code, but with the benefits of getting the data when it +is available and *not* blocking the rest of the program while waiting for the +data to arrive—something like this: ```rust,ignore,does_not_compile -let data = read_to_string_non_blocking(&path).await; -printl!("{data}"); +let data = network_socket.read(&path).await; +println!("{data}"); ``` That is exactly what Rust’s async abstraction gives us. It is designed to help -us solve all of these issues. ### Parallelism and Concurrency @@ -189,3 +191,5 @@ A big difference between the cooking analogy and Rust’s async model for concurrency is that in the cooking example, the cook makes the decision about when to switch tasks. In Rust’s async model, the tasks are in control of that. To see how, let’s look at how Rust actually uses async. +us solve all of these issues. In the next section, we will see how this works in +practice. From 52bf9e49a1652c9d4bb819bf02cba77e2b0ecb66 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 24 May 2024 17:13:10 -0600 Subject: [PATCH 253/720] =?UTF-8?q?Ch.=2017:=20extract=20parallelism=20dis?= =?UTF-8?q?cussion=20from=20=C2=A700=20to=20=C2=A703?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit §03 is the current place I expect to tackle the distinctions between threads, tasks, and futures, and is therefore a reasonable home for a brief discussion on these two big ideas, I think? --- src/ch17-00-async-await.md | 43 ------------------------------------ src/ch17-03-vs-threads.md | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 296dae8bb0..7f97432f95 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -148,48 +148,5 @@ println!("{data}"); ``` That is exactly what Rust’s async abstraction gives us. It is designed to help - -### Parallelism and Concurrency - -In the previous chapter we treated parallelism and concurrency as -interchangeable. Now we need to distinguish between the two a little more: - -* *Parallelism* is when operations can happen simultaneously. - -* *Concurrency* is when operations can make progress without having to wait for - all other operations to complete. - -One common analogy for thinking about the difference between concurrency and -parallelism is cooking in a kitchen. Parallelism is like having two cooks: one -working on cooking eggs, and the other working on preparing fruit bowls. Those -can happen at the same time, without either affecting the other. Concurrency is -like having a single cook who can start cooking some eggs, start dicing up some -vegetables to use in the omelette, adding seasoning and whatever vegetables are -ready to the eggs at certain points, and switching back and forth between those -tasks. - -(This analogy breaks down if you think about it too hard. The eggs keep cooking -while the cook is chopping up the vegetables, after all. That is parallelism, -not just concurrency! The focus of the analogy is the *cook*, not the food, -though, and as long as you keep that in mind, it mostly works.) - -On a machine with multiple CPU cores, we can actually do work in parallel. One -core can be doing one thing while another core does something completely -unrelated, and those actually happen at the same time. On a machine with a -single CPU core, the CPU can only do one operation at a time, but we can still -have concurrency. Using tools like threads, processes, and async, the computer -can pause one activity and switch to others before eventually cycling back to -that first activity again. So all parallel operations are also concurrent, but -not all concurrent operations happen in parallel! - -When working with async in Rust, we are always dealing with concurrency. -Depending on the hardware, the operating system, and the async runtime we are -using, that concurrency may use some degree of parallelism under the hood, or it -may not. (More about async runtimes later!) - -A big difference between the cooking analogy and Rust’s async model for -concurrency is that in the cooking example, the cook makes the decision about -when to switch tasks. In Rust’s async model, the tasks are in control of that. -To see how, let’s look at how Rust actually uses async. us solve all of these issues. In the next section, we will see how this works in practice. diff --git a/src/ch17-03-vs-threads.md b/src/ch17-03-vs-threads.md index 63f270522f..357213a174 100644 --- a/src/ch17-03-vs-threads.md +++ b/src/ch17-03-vs-threads.md @@ -21,3 +21,48 @@ lives at the level of libraries. task primitive to run (and there are runtimes which do *not* use tasks!) so it might make more sense to find another common, appropriate term for it instead. --> + +### Parallelism and Concurrency + +First, though, we need to dig a little deeper into the differences between +parallelism and concurrency. In the previous chapter we treated them as mostly +interchangeable. Now we need to distinguish between the two a little more, +because the differences will show up as we start working: + +* *Parallelism* is when operations can happen simultaneously. + +* *Concurrency* is when operations can make progress without having to wait for + all other operations to complete. + +One common analogy for thinking about the difference between concurrency and +parallelism is cooking in a kitchen. Parallelism is like having two cooks: one +working on cooking eggs, and the other working on preparing fruit bowls. Those +can happen at the same time, without either affecting the other. Concurrency is +like having a single cook who can start cooking some eggs, start dicing up some +vegetables to use in the omelette, adding seasoning and whatever vegetables are +ready to the eggs at certain points, and switching back and forth between those +tasks. + +(This analogy breaks down if you think about it too hard. The eggs keep cooking +while the cook is chopping up the vegetables, after all. That is parallelism, +not just concurrency! The focus of the analogy is the *cook*, not the food, +though, and as long as you keep that in mind, it mostly works.) + +On a machine with multiple CPU cores, we can actually do work in parallel. One +core can be doing one thing while another core does something completely +unrelated, and those actually happen at the same time. On a machine with a +single CPU core, the CPU can only do one operation at a time, but we can still +have concurrency. Using tools like threads, processes, and async, the computer +can pause one activity and switch to others before eventually cycling back to +that first activity again. So all parallel operations are also concurrent, but +not all concurrent operations happen in parallel! + +When working with async in Rust, we are always dealing with concurrency. +Depending on the hardware, the operating system, and the async runtime we are +using, that concurrency may use some degree of parallelism under the hood, or it +may not. (More about async runtimes later!) + +A big difference between the cooking analogy and Rust’s async model for +concurrency is that in the cooking example, the cook makes the decision about +when to switch tasks. In Rust’s async model, the tasks are in control of that. +To see how, let’s look at how Rust actually uses async. From 3224ceba42e2ac9e78667989d771ad0bc5f44c10 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 27 May 2024 09:38:04 -0600 Subject: [PATCH 254/720] =?UTF-8?q?Ch.=2017:=20dedicate=20=C2=A703=20to=20?= =?UTF-8?q?'Futures,=20Tasks,=20and=20Threads'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move the heading out from §03. - Add this to the summary. --- src/SUMMARY.md | 1 + src/ch17-02-concurrency-with-async.md | 4 ---- ...ch17-03-vs-threads.md => ch17-03-futures-tasks-threads.md} | 4 +++- 3 files changed, 4 insertions(+), 5 deletions(-) rename src/{ch17-03-vs-threads.md => ch17-03-futures-tasks-threads.md} (97%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 60680d1983..18c89533a5 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -104,6 +104,7 @@ - [Async and Await](ch17-00-async-await.md) - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) - [Concurrency With Async](ch17-02-concurrency-with-async.md) + - [Futures, Tasks, and Threads](ch17-03-futures-tasks-threads.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index f1684622a0..c829d18336 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -160,10 +160,6 @@ do: For an extra challenge, see if you can figure out what the output will be in each case *before* running the code! -### Futures, Tasks, and Threads - - - ### Message Passing Sharing data between futures will look familiar. We can again use async versions diff --git a/src/ch17-03-vs-threads.md b/src/ch17-03-futures-tasks-threads.md similarity index 97% rename from src/ch17-03-vs-threads.md rename to src/ch17-03-futures-tasks-threads.md index 357213a174..ca27ce27be 100644 --- a/src/ch17-03-vs-threads.md +++ b/src/ch17-03-futures-tasks-threads.md @@ -1,4 +1,6 @@ - +## Futures, Tasks, and Threads + + As we saw in the previous chapter, threads provide one approach to concurrency, and they let us solve some of these issues. However, they also have some From 82f47c3459c80c48f3e7dc29aea1ae8e4af47bbd Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 27 May 2024 11:48:42 -0600 Subject: [PATCH 255/720] Ch. 17: Listings are all `17-*`! --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 2 ++ .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 src/ch17-02-concurrency-with-async.md | 22 +++++++++---------- 22 files changed, 13 insertions(+), 11 deletions(-) rename listings/ch17-async-await/{listing-TODO-01 => listing-17-01}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-TODO-01 => listing-17-01}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-TODO-01 => listing-17-01}/src/main.rs (100%) rename listings/ch17-async-await/{listing-TODO-02 => listing-17-02}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-TODO-02 => listing-17-02}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-TODO-02 => listing-17-02}/src/main.rs (100%) rename listings/ch17-async-await/{listing-TODO-03 => listing-17-03}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-TODO-03 => listing-17-03}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-TODO-03 => listing-17-03}/src/main.rs (100%) rename listings/ch17-async-await/{listing-TODO-04 => listing-17-04}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-TODO-04 => listing-17-04}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-TODO-04 => listing-17-04}/src/main.rs (92%) rename listings/ch17-async-await/{listing-TODO-04b => listing-17-04b}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-TODO-04b => listing-17-04b}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-TODO-04b => listing-17-04b}/src/main.rs (100%) rename listings/ch17-async-await/{listing-TODO-04b2 => listing-17-04b2}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-TODO-04b2 => listing-17-04b2}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-TODO-04b2 => listing-17-04b2}/src/main.rs (100%) rename listings/ch17-async-await/{listing-TODO-05 => listing-17-05}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-TODO-05 => listing-17-05}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-TODO-05 => listing-17-05}/src/main.rs (100%) diff --git a/listings/ch17-async-await/listing-TODO-01/Cargo.lock b/listings/ch17-async-await/listing-17-01/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-TODO-01/Cargo.lock rename to listings/ch17-async-await/listing-17-01/Cargo.lock diff --git a/listings/ch17-async-await/listing-TODO-01/Cargo.toml b/listings/ch17-async-await/listing-17-01/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-TODO-01/Cargo.toml rename to listings/ch17-async-await/listing-17-01/Cargo.toml diff --git a/listings/ch17-async-await/listing-TODO-01/src/main.rs b/listings/ch17-async-await/listing-17-01/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-TODO-01/src/main.rs rename to listings/ch17-async-await/listing-17-01/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-02/Cargo.lock b/listings/ch17-async-await/listing-17-02/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-TODO-02/Cargo.lock rename to listings/ch17-async-await/listing-17-02/Cargo.lock diff --git a/listings/ch17-async-await/listing-TODO-02/Cargo.toml b/listings/ch17-async-await/listing-17-02/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-TODO-02/Cargo.toml rename to listings/ch17-async-await/listing-17-02/Cargo.toml diff --git a/listings/ch17-async-await/listing-TODO-02/src/main.rs b/listings/ch17-async-await/listing-17-02/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-TODO-02/src/main.rs rename to listings/ch17-async-await/listing-17-02/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-03/Cargo.lock b/listings/ch17-async-await/listing-17-03/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-TODO-03/Cargo.lock rename to listings/ch17-async-await/listing-17-03/Cargo.lock diff --git a/listings/ch17-async-await/listing-TODO-03/Cargo.toml b/listings/ch17-async-await/listing-17-03/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-TODO-03/Cargo.toml rename to listings/ch17-async-await/listing-17-03/Cargo.toml diff --git a/listings/ch17-async-await/listing-TODO-03/src/main.rs b/listings/ch17-async-await/listing-17-03/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-TODO-03/src/main.rs rename to listings/ch17-async-await/listing-17-03/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-04/Cargo.lock b/listings/ch17-async-await/listing-17-04/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-TODO-04/Cargo.lock rename to listings/ch17-async-await/listing-17-04/Cargo.lock diff --git a/listings/ch17-async-await/listing-TODO-04/Cargo.toml b/listings/ch17-async-await/listing-17-04/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-TODO-04/Cargo.toml rename to listings/ch17-async-await/listing-17-04/Cargo.toml diff --git a/listings/ch17-async-await/listing-TODO-04/src/main.rs b/listings/ch17-async-await/listing-17-04/src/main.rs similarity index 92% rename from listings/ch17-async-await/listing-TODO-04/src/main.rs rename to listings/ch17-async-await/listing-17-04/src/main.rs index 0c364f43dd..7e0546bbb3 100644 --- a/listings/ch17-async-await/listing-TODO-04/src/main.rs +++ b/listings/ch17-async-await/listing-17-04/src/main.rs @@ -3,7 +3,9 @@ use std::time::Duration; fn main() { trpl::block_on(async { + // ANCHOR: add-channel let (tx, mut rx) = trpl::channel(); + // ANCHOR_END: add-channel let tx_fut = async { let vals = vec![ diff --git a/listings/ch17-async-await/listing-TODO-04b/Cargo.lock b/listings/ch17-async-await/listing-17-04b/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-TODO-04b/Cargo.lock rename to listings/ch17-async-await/listing-17-04b/Cargo.lock diff --git a/listings/ch17-async-await/listing-TODO-04b/Cargo.toml b/listings/ch17-async-await/listing-17-04b/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-TODO-04b/Cargo.toml rename to listings/ch17-async-await/listing-17-04b/Cargo.toml diff --git a/listings/ch17-async-await/listing-TODO-04b/src/main.rs b/listings/ch17-async-await/listing-17-04b/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-TODO-04b/src/main.rs rename to listings/ch17-async-await/listing-17-04b/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-04b2/Cargo.lock b/listings/ch17-async-await/listing-17-04b2/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-TODO-04b2/Cargo.lock rename to listings/ch17-async-await/listing-17-04b2/Cargo.lock diff --git a/listings/ch17-async-await/listing-TODO-04b2/Cargo.toml b/listings/ch17-async-await/listing-17-04b2/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-TODO-04b2/Cargo.toml rename to listings/ch17-async-await/listing-17-04b2/Cargo.toml diff --git a/listings/ch17-async-await/listing-TODO-04b2/src/main.rs b/listings/ch17-async-await/listing-17-04b2/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-TODO-04b2/src/main.rs rename to listings/ch17-async-await/listing-17-04b2/src/main.rs diff --git a/listings/ch17-async-await/listing-TODO-05/Cargo.lock b/listings/ch17-async-await/listing-17-05/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-TODO-05/Cargo.lock rename to listings/ch17-async-await/listing-17-05/Cargo.lock diff --git a/listings/ch17-async-await/listing-TODO-05/Cargo.toml b/listings/ch17-async-await/listing-17-05/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-TODO-05/Cargo.toml rename to listings/ch17-async-await/listing-17-05/Cargo.toml diff --git a/listings/ch17-async-await/listing-TODO-05/src/main.rs b/listings/ch17-async-await/listing-17-05/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-TODO-05/src/main.rs rename to listings/ch17-async-await/listing-17-05/src/main.rs diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index c829d18336..be5561624f 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -21,7 +21,7 @@ to implement the same counting example as with threads. To start, we will set up our `main` function with `trpl::block_on`: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:block_on}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:block_on}} ``` > Note: From this point forward in the chapter, every example will include this @@ -35,7 +35,7 @@ top-level `for` loop. Notice that we also need to add a `.await` after the `sleep` calls. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:task}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:task}} ``` Putting that all together, we end up with the code in Listing 17-TODO: @@ -43,7 +43,7 @@ Putting that all together, we end up with the code in Listing 17-TODO: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-01/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:all}} ``` @@ -74,7 +74,7 @@ thread was done running. Here, we can use `await` to do the same thing: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-02/src/main.rs:handle}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-02/src/main.rs:handle}} ``` @@ -113,7 +113,7 @@ ask the runtime to run them both to completion using `trpl::join`: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-03/src/main.rs:join}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-03/src/main.rs:join}} ``` @@ -180,7 +180,7 @@ We can start by introducing an async version of the `channel` ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:all}} ``` @@ -192,7 +192,7 @@ message, and the program never stops running. That’s because of the combinatio of the `while let` loop and the `trpl::join` call: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04/src/main.rs:loop}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:loop}} ``` Let’s consider the way this loop works: @@ -227,7 +227,7 @@ three futures to complete: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04b/src/main.rs:updated}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04b/src/main.rs:updated}} ``` @@ -273,7 +273,7 @@ you write it, the same way a closure can. We can do that by making the first async block an `async move` block. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-05/src/main.rs:move}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:move}} ``` The result is Listing 17-TODO, and when we run *this* version of the code, it @@ -282,7 +282,7 @@ shuts down gracefully after the last message is sent. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-05/src/main.rs:move}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:move}} ``` @@ -298,7 +298,7 @@ block, and switchign back to `join3`. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-TODO-04b2/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04b2/src/main.rs:here}} ``` From 91ffec833c6426fb3aa5ff16e7369e615a024fee Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 27 May 2024 11:48:42 -0600 Subject: [PATCH 256/720] Ch. 17: Fill out message-passing example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Gradually build up to the full thing, rather than dumping it all at once at the start. - Show several more “false starts” along the way, using them to teach a couple key ideas about async and control flow. - Update the listings to have their actual expected numbers. --- .../listing-17-04/src/main.rs | 30 +- .../listing-17-05/src/main.rs | 42 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-06/src/main.rs | 33 ++ .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../ch17-async-await/listing-17-08/Cargo.lock | 540 ++++++++++++++++++ .../ch17-async-await/listing-17-08/Cargo.toml | 9 + .../listing-17-08/src/main.rs | 34 ++ .../ch17-async-await/listing-17-09/Cargo.lock | 540 ++++++++++++++++++ .../ch17-async-await/listing-17-09/Cargo.toml | 9 + .../src/main.rs | 0 src/ch17-02-concurrency-with-async.md | 175 ++++-- 15 files changed, 1327 insertions(+), 85 deletions(-) rename listings/ch17-async-await/{listing-17-04b => listing-17-06}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-04b => listing-17-06}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-06/src/main.rs rename listings/ch17-async-await/{listing-17-04b2 => listing-17-07}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-04b2 => listing-17-07}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-04b => listing-17-07}/src/main.rs (100%) create mode 100644 listings/ch17-async-await/listing-17-08/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-08/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-08/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-09/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-09/Cargo.toml rename listings/ch17-async-await/{listing-17-04b2 => listing-17-09}/src/main.rs (100%) diff --git a/listings/ch17-async-await/listing-17-04/src/main.rs b/listings/ch17-async-await/listing-17-04/src/main.rs index 7e0546bbb3..a6033e5994 100644 --- a/listings/ch17-async-await/listing-17-04/src/main.rs +++ b/listings/ch17-async-await/listing-17-04/src/main.rs @@ -1,35 +1,17 @@ // ANCHOR: all -use std::time::Duration; - fn main() { trpl::block_on(async { // ANCHOR: add-channel let (tx, mut rx) = trpl::channel(); // ANCHOR_END: add-channel - let tx_fut = async { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - // ANCHOR: loop - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; + // ANCHOR: send-and-receive + let val = String::from("hi"); + tx.send(val).unwrap(); - trpl::join(tx_fut, rx_fut).await; - // ANCHOR_END: loop + let received = rx.recv().await.unwrap(); + println!("Got: {received}"); + // ANCHOR_END: send-and-receive }); } // ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-05/src/main.rs b/listings/ch17-async-await/listing-17-05/src/main.rs index b88571997e..c1b62d8e66 100644 --- a/listings/ch17-async-await/listing-17-05/src/main.rs +++ b/listings/ch17-async-await/listing-17-05/src/main.rs @@ -1,31 +1,31 @@ +// ANCHOR: all +// ANCHOR: many-messages use std::time::Duration; +// ANCHOR_END: many-messages fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); - // ANCHOR: move - let tx_fut = async move { - // ANCHOR_END: move - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; + // ANCHOR: many-messages + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR_END: many-messages - let rx_fut = async { - while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); - } - }; - - trpl::join(tx_fut, rx_fut).await; + // ANCHOR: loop + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR_END: loop }); } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-04b/Cargo.lock b/listings/ch17-async-await/listing-17-06/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-04b/Cargo.lock rename to listings/ch17-async-await/listing-17-06/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-04b/Cargo.toml b/listings/ch17-async-await/listing-17-06/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-04b/Cargo.toml rename to listings/ch17-async-await/listing-17-06/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-06/src/main.rs b/listings/ch17-async-await/listing-17-06/src/main.rs new file mode 100644 index 0000000000..aeeacc5462 --- /dev/null +++ b/listings/ch17-async-await/listing-17-06/src/main.rs @@ -0,0 +1,33 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + // ANCHOR: futures + let tx_fut = async { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + // ANCHOR: loop + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR_END: loop + }; + + trpl::join(tx_fut, rx_fut).await; + // ANCHOR_END: futures + }); +} diff --git a/listings/ch17-async-await/listing-17-04b2/Cargo.lock b/listings/ch17-async-await/listing-17-07/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-04b2/Cargo.lock rename to listings/ch17-async-await/listing-17-07/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-04b2/Cargo.toml b/listings/ch17-async-await/listing-17-07/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-04b2/Cargo.toml rename to listings/ch17-async-await/listing-17-07/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-04b/src/main.rs b/listings/ch17-async-await/listing-17-07/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-04b/src/main.rs rename to listings/ch17-async-await/listing-17-07/src/main.rs diff --git a/listings/ch17-async-await/listing-17-08/Cargo.lock b/listings/ch17-async-await/listing-17-08/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-08/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-08/Cargo.toml b/listings/ch17-async-await/listing-17-08/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-08/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-08/src/main.rs b/listings/ch17-async-await/listing-17-08/src/main.rs new file mode 100644 index 0000000000..fa02e21a87 --- /dev/null +++ b/listings/ch17-async-await/listing-17-08/src/main.rs @@ -0,0 +1,34 @@ +// ANCHOR: all +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + // ANCHOR: move + let tx_fut = async move { + // ANCHOR_END: move + + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; + }); +} +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-09/Cargo.lock b/listings/ch17-async-await/listing-17-09/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-09/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-09/Cargo.toml b/listings/ch17-async-await/listing-17-09/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-09/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-04b2/src/main.rs b/listings/ch17-async-await/listing-17-09/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-04b2/src/main.rs rename to listings/ch17-async-await/listing-17-09/src/main.rs diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index be5561624f..bad5699359 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -173,52 +173,147 @@ side of the channel closes. One other difference with this particular `recv()` implementation is that it returns an `Option` of the type sent over the channel instead of a `Result`. -We can start by introducing an async version of the `channel` +We can start by introducing an async version of the multiple-producer, +single-consumer channel channel API we used with threads back in Chapter 16: - + -+```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:add-channel}} +``` + + + +Now we can send messages from the sender to the receiver. Unlike in Chapter 16, +where we needed to spawn a separate thread to allow the message passing to +happen asynchronously, here we opt into async behavior on the receiver side by +using `.await` on the `rx.recv()` call. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:send-and-receive}} +``` + + + +The `send` call does not block, since the channel we are sending it into is +unbounded. That was true with our threading example back in Chapter 16, too, +though. The difference here is that the `rx.recv()` call here does not block the +rest of the program, whereas the one in Chapter 16 *did* block the main thread. +Instead, once the program hits the `.await` on the `rx.recv()` call, it hands +control back to the runtime, which can go on scheduling other operations until a +message arrives. It might be hard to see that from this code, though, since the +message will arrive right away! + +> Note: Since this is all wrapped in a `trpl::block_on`, this would effectively +> block anything happening outside that. That is the whole point of `block_on`, +> in fact: to allow you to *choose* where to block on some set of async code to +> transition between sync and async code. However, *within* this block, the +> `.await` does not block further operations—as we will see! + +Let’s go ahead and send a whole series of messages, and sleep in between them, +as shown in Listing 17-TODO: + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:many-messages}} ``` -If we run this, though, it never stops! You will need to shut it down using -ctrl-c. We can see that `tx` sends all the -messages,and `rx` receives and prints them, but we never see the “Done!” -message, and the program never stops running. That’s because of the combination -of the `while let` loop and the `trpl::join` call: +Then we can wait on each of those messages in a loop. Here, we need to use a +`while let` loop rather than a `for` loop, because Rust does not yet have an +async version of `Iterator`, which is what the `for` loop does. In TODO: SECTION +TITLE, we will see more about two related traits the community has been working +on, `AsyncIterator` and `Stream`. For now, we can stick with `while let`, as in +Listing 17-TODO, and the loop will end when `rx.recv().await` produces a `None`. + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:loop}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:loop}} ``` -Let’s consider the way this loop works: + + +This code does not do what we want. It does successfully send and receive the +messages, but instead of seeing the messages received at one-second intervals, +we see them arrive all at once, four seconds after we start the program. It +also never stops! You will need to shut it down using +ctrl-c. + +Let’s start by understanding why the messages all come in at once after the full +delay, rather than coming in with delays in between each one. This highlights an +important point about the way that async works in Rust. Within any given async +block, the await points are sequential: each one happens one after another. That +is, after all, one of the big motivations for using this syntax instead of +callbacks, event handlers, or chains of methods: the flow through the program is +much easier to follow, because having the order that `.await` keywords appear in +the *code* is also the order they happen when running the *program*. + +With that in mind, we can see why this code behaves the way it does by looking +at the whole thing all together. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:all}} +``` + + + +There is just one async block here, so everything here will proceed linearly. +Every one of the `.await` points for the `trpl::sleep` calls appears before the +`.await` points on the `rx.recv()`, so all the `tx.send` calls happen, +interspersed with all of the `trpl::sleep` calls. Only then does the `while let` +loop get to go through all of the `.await` points on the `recv` calls. + +To get the behavior we actually want, where the delay happens in between +receiving each message, rather than before receiving any message, we need to +give put the `tx` and `rx` operations in their own async blocks, so the runtime +can execute each of them separately. We also need to tell the runtime to +actually run them using `trpl::join`, just like we did for the counting example +above. Listing 17-TODO shows how that looks. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-06/src/main.rs:futures}} +``` + + + +With these changes made, the messages get printed at one-second intervals, +rather than all in a rush after four seconds. + +The program still never stops running, though. That’s because of the combination +of the `while let` loop and the `trpl::join` call. Let’s consider the way this +loop works: * The `trpl::join` future only completes once *both* futures passed to it have completed. -* The `tx` future completes after sending the second message. -* The `rx` future will not complete until the `while let` loop ends, though. +* The `tx` future completes once it finishes sleeping after sending the last + message in `vals`. +* The `rx` future will not complete until the `while let` loop ends. * The `while let` loop will not end until `rx.recv().await` produces `None`. * The `rx.recv().await` will only return `None` once the other end of the channel is closed. * The channel will only close if we call `rx.close()` or when the sender side, `tx`, is dropped. * We do not call `rx.close()` anywhere, and `tx` will not be dropped until the - function exits. -* The function cannot exit because it is blocked on `trpl::join` completing, - which takes us back to the top of the list! - -To solve this, then, we need to make sure the channel gets closed so that -`trpl::join` will complete. We could manually close `rx` somewhere by calling -`rx.close()`, but that does not make much sense in this case. The idea is that -`rx` should keep listening until `tx` is done sending. Stopping after handling -some arbitrary number of messages would make the program shut down, but it would -mean we could miss messages if the sending side changed. Given that we cannot -use `rx.close()`, we need to make sure that `tx` gets dropped *before* the end -of the function. + async block ends. +* The block cannot end because it is blocked on `trpl::join` completing, + which takes us back to the top of this list! + +We need to make sure the channel gets closed so that `trpl::join` will complete. +We could manually close `rx` somewhere by calling `rx.close()`, but that does +not make much sense in this case. The idea is that `rx` should keep listening +until `tx` is done sending. Stopping after handling some arbitrary number of +messages would make the program shut down, but it would mean we could miss +messages if the sending side changed. Given that we cannot use `rx.close()`, we +need to make sure that `tx` gets dropped *before* the end of the function. Right now, the async block only borrows `tx`. We can confirm this by adding another async block which uses `tx`, and using `trpl::join3` to wait for all @@ -227,7 +322,7 @@ three futures to complete: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04b/src/main.rs:updated}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-07/src/main.rs:updated}} ``` @@ -262,27 +357,22 @@ In Chapter 13, we learned how to use the `move` keyword with closures, and in Chapter 16, we saw that we often need to use closures marked with `move` when working with threads. As we have discovered, the same dynamics apply to async blocks—so the `move` keyword also works with async blocks, allowing them to take -ownership of the data they reference. +ownership of the data they reference. We can do that by change the first async +block from an `async` block to an `async move` block, as in Listing 17-TODO: - -Remember, any time you write a future, a runtime is ultimately responsible for -executing it. That means that an async block might outlive the function where -you write it, the same way a closure can. - - -We can do that by making the first async block an `async move` block. + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:move}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:move}} ``` The result is Listing 17-TODO, and when we run *this* version of the code, it shuts down gracefully after the last message is sent. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:move}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:all}} ``` @@ -293,17 +383,16 @@ This async channel is also a multiple-producer channel, so we can call `clone` on `tx` if we want to send messages from multiple futures. For example, we can make the code from Listing 17-TODO work by cloning the `tx` before moving it into the first async block, moving the original `tx` into the second async -block, and switchign back to `join3`. +block, and switching back to `join3`. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04b2/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-09/src/main.rs:here}} ``` - Both of these blocks need to be `async move` blocks, or else we will end up back in the same infinite loop we started out in. @@ -338,3 +427,9 @@ example_2(|| async move { ... }); These closures now return anonymous futures, meaning they work basically the same way that an async function does. + + +Remember, any time you write a future, a runtime is ultimately responsible for +executing it. That means that an async block might outlive the function where +you write it, the same way a closure can. + From 91348caaeb4ce424474f82293b057ea0ba48a263 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 27 May 2024 16:06:20 -0600 Subject: [PATCH 257/720] Ch. 17: A minor wording improvement --- src/ch17-02-concurrency-with-async.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index bad5699359..88f992adf9 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -416,8 +416,8 @@ example_2(async move || { ... }); ``` However, since async blocks themselves can be marked with `move`, this ends up -not being a problem. Remember that `async` blocks compile to anonymous futures. -That means you can write calls like this instead: +not being a problem. Because `async` blocks compile to anonymous futures, you +can write calls like this instead: ```rust,ignore example_1(|| async { ... }); From 068f30b4061c223f6a3580582e7454f27cdc83a7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 27 May 2024 16:06:20 -0600 Subject: [PATCH 258/720] Ch 17.02: motivating `futures::join!` and `Box::pin` Up to this point, the chapter has stuck to `join` and `join3`, as simple function-based APIs. The `join_all` API is obviously more convenient than those *if you can use it*, but being able to use it requires having something which `impl Iterator` of a given type, and therefore demands a homogeneous type, which motivates introducing `Box::pin`. That in turn is quite annoying to work with and requires `Output = ` for all the futures in the collection, because of how `join_all` is typed (Rust does not have the ability to do do variadic types, which is what would be necessary for `join_all` to work the way we might want). Thus, we get a motivation for `futures::join!`, which unlike `join_all` *can* work with heterogeneous types. This fills out a fair bit of the text here and adds a lot of the listing support, and outlines what remains to do text-wise. --- Cargo.toml | 2 +- .../ch17-async-await/listing-17-10/Cargo.lock | 540 ++++++++++++++++++ .../ch17-async-await/listing-17-10/Cargo.toml | 9 + .../listing-17-10/src/main.rs | 47 ++ .../ch17-async-await/listing-17-11/Cargo.lock | 540 ++++++++++++++++++ .../ch17-async-await/listing-17-11/Cargo.toml | 9 + .../listing-17-11/src/main.rs | 49 ++ .../ch17-async-await/listing-17-12/Cargo.lock | 540 ++++++++++++++++++ .../ch17-async-await/listing-17-12/Cargo.toml | 9 + .../listing-17-12/src/main.rs | 53 ++ .../ch17-async-await/listing-17-13/Cargo.lock | 540 ++++++++++++++++++ .../ch17-async-await/listing-17-13/Cargo.toml | 9 + .../listing-17-13/src/main.rs | 53 ++ packages/trpl/Cargo.lock | 533 +++++++++++++++++ packages/trpl/src/lib.rs | 5 +- packages/trpl/tests/integration/main.rs | 81 ++- src/ch17-02-concurrency-with-async.md | 184 +++++- 17 files changed, 3168 insertions(+), 35 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-10/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-10/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-10/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-11/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-11/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-11/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-12/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-12/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-12/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-13/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-13/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-13/src/main.rs create mode 100644 packages/trpl/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index b65d859e5b..20fc14643d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ exclude = [ "linkchecker", # linkchecker is part of the CI workflow "listings", # these are intentionally distinct from the workspace "tmp", # listings are built here when updating output via tools/update-rustc.sh - "trpl", # manages its own dependencies as a standalone crate + "packages/trpl", # manages its own dependencies as a standalone crate # These are used as path dependencies in `rust-lang/rust` (since we are not # publishing them to crates.io), so they cannot be part of this workspace, diff --git a/listings/ch17-async-await/listing-17-10/Cargo.lock b/listings/ch17-async-await/listing-17-10/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-10/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-10/Cargo.toml b/listings/ch17-async-await/listing-17-10/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-10/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-10/src/main.rs b/listings/ch17-async-await/listing-17-10/src/main.rs new file mode 100644 index 0000000000..78e17a3846 --- /dev/null +++ b/listings/ch17-async-await/listing-17-10/src/main.rs @@ -0,0 +1,47 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + // ANCHOR: here + let futures = vec![tx1_fut, rx_fut, tx_fut]; + trpl::join_all(futures).await; + // ANCHOR_END: here + }); +} diff --git a/listings/ch17-async-await/listing-17-11/Cargo.lock b/listings/ch17-async-await/listing-17-11/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-11/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-11/Cargo.toml b/listings/ch17-async-await/listing-17-11/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-11/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-11/src/main.rs b/listings/ch17-async-await/listing-17-11/src/main.rs new file mode 100644 index 0000000000..f96fecb929 --- /dev/null +++ b/listings/ch17-async-await/listing-17-11/src/main.rs @@ -0,0 +1,49 @@ +use std::{future::Future, time::Duration}; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + // ANCHOR: here + let futures: Vec>> = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + + trpl::join_all(futures).await; + // ANCHOR_END: here + }); +} diff --git a/listings/ch17-async-await/listing-17-12/Cargo.lock b/listings/ch17-async-await/listing-17-12/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-12/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-12/Cargo.toml b/listings/ch17-async-await/listing-17-12/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-12/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-12/src/main.rs b/listings/ch17-async-await/listing-17-12/src/main.rs new file mode 100644 index 0000000000..6320a17a71 --- /dev/null +++ b/listings/ch17-async-await/listing-17-12/src/main.rs @@ -0,0 +1,53 @@ +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = pin!(async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }); + + let rx_fut = pin!(async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }); + + let tx_fut = pin!(async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }); + + // ANCHOR: here + let futures: Vec>>> = + vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; + + trpl::join_all(futures).await; + // ANCHOR_END: here + }); +} diff --git a/listings/ch17-async-await/listing-17-13/Cargo.lock b/listings/ch17-async-await/listing-17-13/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-13/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-13/Cargo.toml b/listings/ch17-async-await/listing-17-13/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-13/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-13/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs new file mode 100644 index 0000000000..20c7627a3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-13/src/main.rs @@ -0,0 +1,53 @@ +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = pin!(async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }); + + let rx_fut = pin!(async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }); + + let tx_fut = pin!(async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }); + + // ANCHOR: here + let futures: Vec>> = + vec![tx1_fut, rx_fut, tx_fut]; + + trpl::join_all(futures).await; + // ANCHOR_END: here + }); +} diff --git a/packages/trpl/Cargo.lock b/packages/trpl/Cargo.lock new file mode 100644 index 0000000000..20893eeaaa --- /dev/null +++ b/packages/trpl/Cargo.lock @@ -0,0 +1,533 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 43764b97e9..9d53d86ddf 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -14,7 +14,10 @@ use std::future::Future; -pub use futures::future::{join, join3}; +pub use futures::{ + future::{join, join3, join_all}, + join, +}; pub use tokio::{ runtime::Runtime, // We use the `unbounded` variants because they most closely match the APIs diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index c0fa703562..106deb152d 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -9,8 +9,9 @@ //! //! [post]: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html -use std::time::Duration; +use std::{pin::Pin, time::Duration}; +use futures::Future; use trpl::{Receiver, Sender}; /// This test is foundational for all the others, as they depend on `block_on`. @@ -61,23 +62,71 @@ fn re_exported_channel_apis_work() { }); } -#[test] -fn re_exported_join_apis_work() { - let result = trpl::block_on(async { - let a = async { 1 }; - let b = async { 2 }; - trpl::join(a, b).await - }); +mod re_exported_join_apis_work { + use super::*; - assert_eq!(result, (1, 2)); + #[test] + fn join_fn() { + let result = trpl::block_on(async { + let a = async { 1 }; + let b = async { 2 }; + trpl::join(a, b).await + }); - let result = trpl::block_on(async { - let a = async { 1 }; - let b = async { 2 }; - let c = async { 3 }; + assert_eq!(result, (1, 2)); + } - trpl::join3(a, b, c).await - }); + #[test] + fn join3_fn() { + let result = trpl::block_on(async { + let a = async { 1 }; + let b = async { 2 }; + let c = async { 3 }; + + trpl::join3(a, b, c).await + }); + + assert_eq!(result, (1, 2, 3)); + } + + #[test] + fn join_all_fn() { + let result = trpl::block_on(async { + let a = async { format!("{}", 1) }; + + let b = async { format!("Hello") }; + + let outer = String::from("World"); + let c = async move { format!("{outer}") }; + + let futures: Vec>>> = + vec![Box::pin(a), Box::pin(b), Box::pin(c)]; + + trpl::join_all(futures).await + }); + + assert_eq!( + result, + vec![ + String::from("1"), + String::from("Hello"), + String::from("World") + ] + ); + } + + #[test] + fn join_macro() { + let result = trpl::block_on(async { + let a = async { 1 }; + let b = async { "Hello" }; + + let outer = vec![String::from("World")]; + let c = async move { outer }; + + trpl::join!(a, b, c) + }); - assert_eq!(result, (1, 2, 3)); + assert_eq!(result, (1, "Hello", vec![String::from("World")])); + } } diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 88f992adf9..622154bdfd 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -38,16 +38,6 @@ top-level `for` loop. Notice that we also need to add a `.await` after the {{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:task}} ``` -Putting that all together, we end up with the code in Listing 17-TODO: - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:all}} -``` - - - This does something very similar to what the thread-based implementation did, as we can see from the output when we run it. (As with the threading example, you may see a different order in your own terminal output when you run this.) @@ -377,8 +367,6 @@ shuts down gracefully after the last message is sent. -### Multiple Producers with Async - This async channel is also a multiple-producer channel, so we can call `clone` on `tx` if we want to send messages from multiple futures. For example, we can make the code from Listing 17-TODO work by cloning the `tx` before moving it @@ -396,14 +384,173 @@ block, and switching back to `join3`. Both of these blocks need to be `async move` blocks, or else we will end up back in the same infinite loop we started out in. +### Working with More Futures + +When we switched from using two futures to three, we also had to switch from +using `join` to using `join3`. It would be annoying to do this every time we +changed our code. + + + +However, both the function nor macro forms of `join` only work for cases where +we know the number of futures ahead of time. If instead we have a dynamic number +of futures, we need a function which works with a collection type which can grow +and shrink dynamically at runtime, such as a vector. In real-world Rust, pushing +futures into a collection and then waiting on some or all the futures in that +collection to complete is a very common pattern. + +The `trpl::join_all` function accepts any type which implements the `Iterator` +trait, which we learned about back in Chapter 13, so it seems like just the +ticket. Let’s try putting our futures in a vector, so we can swap out our +`join3` call and replace it with `join_all`. + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:here}} +``` + + + +Unfortunately, this does not compile. Instead, we get this error: + + + +```text +error[E0308]: mismatched types + --> src/main.rs:43:37 + | +8 | let tx1_fut = async move { + | _______________________- +9 | | let vals = vec![ +10 | | String::from("hi"), +11 | | String::from("from"), +... | +19 | | } +20 | | }; + | |_________- the expected `async` block +21 | +22 | let rx_fut = async { + | ______________________- +23 | | while let Some(value) = rx.recv().await { +24 | | println!("received '{value}'"); +25 | | } +26 | | }; + | |_________- the found `async` block +... +43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; + | ^^^^^^ expected `async` block, found a different `async` block + | + = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` + found `async` block `{async block@src/main.rs:22:22: 26:10}` +``` + +This error message is admittedly not the most helpful! It only tells us that it +expected one async block and found another—but why is it looking for the async +blocks that it names here, and why does it only reference them by where they +appear in the code? + +One clue is the format of this message. Notice that it is exactly the same as if +we had tried to create a `Vec` with a a number and a string in it: + + + +```rust +let a = 1; +let b = "Hello"; +let vals = vec![a, b]; +``` + +The output there would be: + +```text +error[E0308]: mismatched types + --> src/main.rs:4:24 + | +4 | let vals = vec![a, b]; + | ^ expected integer, found `&str` +``` + +Saying “expected *something*, found *something else*” is Rust’s standard format +for telling us about a type mismatch. As we saw with vectors in [Using an Enum +to Store Multiple Types][collections] back in Chapter 8, we need the type of +each item in a collection to be the same—and `tx1_fut`, `rx_fut`, and `tx_fut` +do not have the same type. + +The underlying issue here is what we learned in the previous section: async +blocks compile to anonymous futures. Under the hood, there is a data structure +corresponding to each of these blocks, and it has its own unique type. This +might be surprising. After all, none of them returns anything, so the `Future` +type in each case is `Future`. However, `Future` is a trait, not a +concrete type. The actual types here are invisible from our point of view as the +person writing the code. + +In Chapter 8, we discussed one way to include multiple types in a single vector: +using an enum to represent each of the different types which can appear in the +vector. We cannot do that here, though. For one thing, we do not even have a way +to name the different types, because they are anonymous. For another, the reason +we reached for a vector and `join_all` in the first place was to be able to work +with a dynamic collection of futures where we do not know what they will all be +until runtime. + +To make this work, we need to use *trait objects*, just as we did for returning +different kinds of errors from the same function in [Returning Errors from the +run function][dyn] back in Chapter 12. Again, we will cover trait objects in +detail in Chapter 17. Here, it just lets us use + +Back in Chapter 13, we saw that we can use `Box` to provide enough indirection +to tell Rust what *size* a type will be at runtime and avoid having types which +are infinitely large. We can use `Box` in a similar way here to represent these +different futures as the same type: a pointer to a *trait object*. We will talk +more about trait objects later in the book. For now, it is enough to know that +we can wrap a trait-based type like this in a `Box`, with the keyword `dyn` to +tell the compiler that this is a + + + ++ +{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:here}} + + + + + ++ +{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} + + + +This comes with a small amount of extra overhead from putting these futures on +the heap with `Box`—and we are only doing that to get the types to line up. It +would be nice if we could make this + +This keeps everything on the stack, and that is a nice little performance win, +but it is still a lot of explicit types, which is quite unusual for Rust! There +is another problem, too. We got this far by ignoring the fact that we might have + + + ++ +{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} + + + - + + + +> Note: This is how closures work, too, but we did not have to talk about it +> back in Chapter 13, because the details did not bubble up to the surface the +> way they do here! + The `async` keyword does not yet work with closures directly. That is, there is @@ -433,3 +580,6 @@ Remember, any time you write a future, a runtime is ultimately responsible for executing it. That means that an async block might outlive the function where you write it, the same way a closure can. + +[collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types +[dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html From 7a5bdb298da6c6cf0d07f4030722c64cb7b61df1 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 28 May 2024 13:41:10 -0600 Subject: [PATCH 259/720] Ch. 17: finish motivating `Pin` and `pin!` This does not yet actually *explain* either of them, but it gets us to the point where an explanation is well-motivated and can make some sense, and it (more or less successfully) covers the set of errors that gets us to that point. --- .../listing-17-11/src/main.rs | 4 +- .../listing-17-12/src/main.rs | 24 +- .../listing-17-13/src/main.rs | 4 +- .../ch17-async-await/listing-17-14/Cargo.lock | 540 ++++++++++++++++++ .../ch17-async-await/listing-17-14/Cargo.toml | 9 + .../listing-17-14/src/main.rs | 53 ++ src/ch17-02-concurrency-with-async.md | 97 +++- 7 files changed, 701 insertions(+), 30 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-14/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-14/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-14/src/main.rs diff --git a/listings/ch17-async-await/listing-17-11/src/main.rs b/listings/ch17-async-await/listing-17-11/src/main.rs index f96fecb929..beff676dbe 100644 --- a/listings/ch17-async-await/listing-17-11/src/main.rs +++ b/listings/ch17-async-await/listing-17-11/src/main.rs @@ -1,4 +1,4 @@ -use std::{future::Future, time::Duration}; +use std::time::Duration; fn main() { trpl::block_on(async { @@ -40,7 +40,7 @@ fn main() { }; // ANCHOR: here - let futures: Vec>> = + let futures = vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; trpl::join_all(futures).await; diff --git a/listings/ch17-async-await/listing-17-12/src/main.rs b/listings/ch17-async-await/listing-17-12/src/main.rs index 6320a17a71..b712d344c0 100644 --- a/listings/ch17-async-await/listing-17-12/src/main.rs +++ b/listings/ch17-async-await/listing-17-12/src/main.rs @@ -1,15 +1,11 @@ -use std::{ - future::Future, - pin::{pin, Pin}, - time::Duration, -}; +use std::{future::Future, time::Duration}; fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); - let tx1_fut = pin!(async move { + let tx1_fut = async move { let vals = vec![ String::from("hi"), String::from("from"), @@ -21,15 +17,15 @@ fn main() { tx1.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }); + }; - let rx_fut = pin!(async { + let rx_fut = async { while let Some(value) = rx.recv().await { println!("received '{value}'"); } - }); + }; - let tx_fut = pin!(async move { + let tx_fut = async move { let vals = vec![ String::from("more"), String::from("messages"), @@ -41,13 +37,13 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }); + }; // ANCHOR: here - let futures: Vec>>> = - vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; + let futures: Vec>> = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + // ANCHOR_END: here trpl::join_all(futures).await; - // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-13/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs index 20c7627a3f..6320a17a71 100644 --- a/listings/ch17-async-await/listing-17-13/src/main.rs +++ b/listings/ch17-async-await/listing-17-13/src/main.rs @@ -44,8 +44,8 @@ fn main() { }); // ANCHOR: here - let futures: Vec>> = - vec![tx1_fut, rx_fut, tx_fut]; + let futures: Vec>>> = + vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; trpl::join_all(futures).await; // ANCHOR_END: here diff --git a/listings/ch17-async-await/listing-17-14/Cargo.lock b/listings/ch17-async-await/listing-17-14/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-14/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-14/Cargo.toml b/listings/ch17-async-await/listing-17-14/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-14/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs new file mode 100644 index 0000000000..20c7627a3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-14/src/main.rs @@ -0,0 +1,53 @@ +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = pin!(async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }); + + let rx_fut = pin!(async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }); + + let tx_fut = pin!(async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }); + + // ANCHOR: here + let futures: Vec>> = + vec![tx1_fut, rx_fut, tx_fut]; + + trpl::join_all(futures).await; + // ANCHOR_END: here + }); +} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 622154bdfd..66755292f8 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -496,29 +496,99 @@ until runtime. To make this work, we need to use *trait objects*, just as we did for returning different kinds of errors from the same function in [Returning Errors from the run function][dyn] back in Chapter 12. Again, we will cover trait objects in -detail in Chapter 17. Here, it just lets us use +detail in Chapter 17. Here, it lets us treat each of the anonymous futures +produced by these types as interchangeable, since all of them by definition +implement the `Future` trait. -Back in Chapter 13, we saw that we can use `Box` to provide enough indirection -to tell Rust what *size* a type will be at runtime and avoid having types which -are infinitely large. We can use `Box` in a similar way here to represent these -different futures as the same type: a pointer to a *trait object*. We will talk -more about trait objects later in the book. For now, it is enough to know that -we can wrap a trait-based type like this in a `Box`, with the keyword `dyn` to -tell the compiler that this is a - - +We can start by wrapping each of the futures in the `vec!` in a `Box::new()`. +Unfortunately, the initial way we might try this, as shown in Listing 17-TODO, +still does not compile. +```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:here}} +``` - +In fact, we have the same basic error we did before, but we get one for both the +second and third `Box::new` calls, and we also get new errors referring to the +`Unpin` trait. + +We can start by fixing the type error around the `Box::new` calls, by telling +the compiler explicitly that we want to use these types as trait objects. The +clearest way to do that here is by adding a type annotation to the declaration +of `futures`, as we see in Listing 17-TODO. The type we have to write here is a +little involved, so let’s walk through each part of it. + +- The innermost type is the future itself. We note explicitly that it the output + of the future is the unit type `()` by writing `Future`. +- Then we annotate the trait with `dyn` to mark it as dynamic. +- The entire trait is wrapped in a `Box`. +- Finally, we state explicitly that `futures` is a `Vec` containing these items. +```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} +``` + + + +That already made a big difference. Now when we run the compiler, we only have +the errors mentioning `Unpin`, each of which is a variation on this same output: + + + +```text +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:33 + | +46 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `Future` +note: required by a bound in `futures_util::future::join_all::JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` +``` + +That is a *lot* to digest, so let’s pull it apart. The first part of the message +tell us that the first async block (`src/main.rs:8:23: 20:10`) does not +implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve +it. The rest of the message tells us *why* that is required: the `JoinAll` +struct is generic over a `Future`, and `Future` itself requires the `Unpin` +trait. + +`Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. +Recall that marker traits have no functionality of their own. They exist only to +tell the compiler that it is safe to use the type which implements a given trait +in certain context. Just like `Send` and `Sync`, `Unpin` is automatically +implemented for all types where the compiler can prove it should be. You may +also recall that there is an opposite for each of `Send` and `Sync`: `?Send` and +`?Sync`, which tell the compiler that the types in question *might* be `Send` or +`Sync` but are not guaranteed to. `Unpin`, as its name implies, is similarly the +opposite of `Pin`, which we saw as part of the signature of the `Future::poll` +method when we covered the API of `Future` in the [Futures][futures] section +earlier in this chapter. + +### The Pin Trait and Pinning + + + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:here}} +``` @@ -534,7 +604,9 @@ is another problem, too. We got this far by ignoring the fact that we might have -{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} +``` @@ -583,3 +655,4 @@ you write it, the same way a closure can. [collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html +[futures]: /ch17-01-futures-and-syntax.html#futures From 626aec8b40d7882b22f0217599cdb317b59810a2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 28 May 2024 16:36:24 -0600 Subject: [PATCH 260/720] =?UTF-8?q?Ch.=2017:=20A=20small=20wording=20tweak?= =?UTF-8?q?=20about=20`JoinAll`=20in=20=C2=A703?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-02-concurrency-with-async.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 66755292f8..b1b00ff571 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -561,12 +561,12 @@ note: required by a bound in `futures_util::future::join_all::JoinAll` | ^^^^^^ required by this bound in `JoinAll` ``` -That is a *lot* to digest, so let’s pull it apart. The first part of the message -tell us that the first async block (`src/main.rs:8:23: 20:10`) does not -implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve -it. The rest of the message tells us *why* that is required: the `JoinAll` -struct is generic over a `Future`, and `Future` itself requires the `Unpin` -trait. +That is a *lot* to digest, so let’s pull it apart. The first part of the +message tell us that the first async block (`src/main.rs:8:23: 20:10`) +does not implement the `Unpin` trait, and suggests using `pin!` or +`Box::pin` to resolve it. The rest of the message tells us *why* that is +required: the `JoinAll` struct, which is itself a `Future`, is also +generic over a `Future`, and `Future` itself requires the `Unpin` trait. `Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. Recall that marker traits have no functionality of their own. They exist only to From b3827671518caef5ff8b7914480f8745317ba3f5 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 28 May 2024 16:44:28 -0600 Subject: [PATCH 261/720] Ch. 17: Start building out explanation of `Pin` --- src/ch17-02-concurrency-with-async.md | 70 ++++++++++++++++++++------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index b1b00ff571..b10a639205 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -561,12 +561,51 @@ note: required by a bound in `futures_util::future::join_all::JoinAll` | ^^^^^^ required by this bound in `JoinAll` ``` -That is a *lot* to digest, so let’s pull it apart. The first part of the -message tell us that the first async block (`src/main.rs:8:23: 20:10`) -does not implement the `Unpin` trait, and suggests using `pin!` or -`Box::pin` to resolve it. The rest of the message tells us *why* that is -required: the `JoinAll` struct, which is itself a `Future`, is also -generic over a `Future`, and `Future` itself requires the `Unpin` trait. +That is a *lot* to digest, so let’s pull it apart. The first part of the message +tell us that the first async block (`src/main.rs:8:23: 20:10`) does not +implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve +it. The rest of the message tells us *why* that is required: the `JoinAll` +struct, which is itself a `Future`, is also generic over a `Future`, and +`Future` itself requires the `Unpin` trait. Understanding this error means we +need to dive into a little more of how the `Future` type actually works, in +particular the idea of *pinning*. + +### Pinning and the Pin and Unpin Traits + +When we introduced the `Future` trait in the previous chapter, we saw that the +definition of its `poll` method has an unusual way of specifying the `self` +parameter. To review, here is the full definition of `Future`: + +```rust +pub trait Future { + type Output; + + // Required method + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; +} +``` + +We have not seen a method definition like this before, where `self` has a type +annotation rather than simply being named like `self`, `mut self`, `&self`, or +`&mut self`. This syntax means that the method can only be called when the +instance of the type which implements `Future` is behind a `Pin` pointer type. +This syntax is not specific to `Pin`; it also works with `Box` and other smart +pointer types, and we will see it again in Chapter 18. + +Here, the signature tells us that if we want to poll a future to check whether +it is `Pending` or `Ready(Output)`, the type which implements `Future` has to be +behind a `Pin` smart pointer type. Recalling that `.await` is implemented in +terms of calls to `poll()`, this starts to explain the error message we saw +above—but that was in terms of `Unpin`, not `Pin`. So what exactly are `Pin` and +`Unpin`, how do they relate, and why does `Future` need `self` to be in a `Pin` +type to call `poll`? + + + +Remember that any time you write a future, a runtime is ultimately responsible +for executing it. That means that an async block might outlive the function +where you write it, the same way a closure can. `Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. Recall that marker traits have no functionality of their own. They exist only to @@ -580,10 +619,10 @@ opposite of `Pin`, which we saw as part of the signature of the `Future::poll` method when we covered the API of `Future` in the [Futures][futures] section earlier in this chapter. -### The Pin Trait and Pinning - +Now we know enough to understand the error message from above. The problem + ```rust,ignore,does_not_compile @@ -596,10 +635,6 @@ This comes with a small amount of extra overhead from putting these futures on the heap with `Box`—and we are only doing that to get the types to line up. It would be nice if we could make this -This keeps everything on the stack, and that is a nice little performance win, -but it is still a lot of explicit types, which is quite unusual for Rust! There -is another problem, too. We got this far by ignoring the fact that we might have - @@ -610,6 +645,11 @@ is another problem, too. We got this far by ignoring the fact that we might have +This keeps everything on the stack, and that is a nice little performance win, +but it is still a lot of explicit types, which is quite unusual for Rust! There +is another problem, too. We got this far by ignoring the fact that we might have +different `Output` types from the `Future`. + - -Remember, any time you write a future, a runtime is ultimately responsible for -executing it. That means that an async block might outlive the function where -you write it, the same way a closure can. - - [collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html [futures]: /ch17-01-futures-and-syntax.html#futures From e000ea332f2ab358058ae385a0e53a455c867643 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 29 May 2024 10:17:28 -0600 Subject: [PATCH 262/720] Ch. 17: Iterate on explanation of `Pin` and `Unpin` This is (a) far from perfect and (b) far from done, but it represents a useful increment of work and includes a bunch of notes for where to go next with this quite tricky section. listings/ch17-async-await/listing-17-13/src/main.rs JJ: M listings/ch17-async-await/listing-17-14/src/main.rs JJ: M src/ch17-02-concurrency-with-async.md --- .../listing-17-13/src/main.rs | 2 +- .../listing-17-14/src/main.rs | 17 ++++- src/ch17-02-concurrency-with-async.md | 65 ++++++++++++++++--- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/listings/ch17-async-await/listing-17-13/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs index 6320a17a71..5520a58ca5 100644 --- a/listings/ch17-async-await/listing-17-13/src/main.rs +++ b/listings/ch17-async-await/listing-17-13/src/main.rs @@ -46,8 +46,8 @@ fn main() { // ANCHOR: here let futures: Vec>>> = vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; + // ANCHOR_END: here trpl::join_all(futures).await; - // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs index 20c7627a3f..a22c9570f7 100644 --- a/listings/ch17-async-await/listing-17-14/src/main.rs +++ b/listings/ch17-async-await/listing-17-14/src/main.rs @@ -9,7 +9,10 @@ fn main() { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); + // ANCHOR: here let tx1_fut = pin!(async move { + // snip... + // ANCHOR_END: here let vals = vec![ String::from("hi"), String::from("from"), @@ -21,15 +24,25 @@ fn main() { tx1.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } + // ANCHOR: here }); + // ANCHOR_END: here + // ANCHOR: here let rx_fut = pin!(async { + // snip... + // ANCHOR_END: here while let Some(value) = rx.recv().await { println!("received '{value}'"); } + // ANCHOR: here }); + // ANCHOR_END: here + // ANCHOR: here let tx_fut = pin!(async move { + // snip... + // ANCHOR_END: here let vals = vec![ String::from("more"), String::from("messages"), @@ -41,13 +54,13 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } + // ANCHOR: here }); - // ANCHOR: here let futures: Vec>> = vec![tx1_fut, rx_fut, tx_fut]; + // ANCHOR_END: here trpl::join_all(futures).await; - // ANCHOR_END: here }); } diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index b10a639205..ed5e9342c0 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -621,9 +621,31 @@ earlier in this chapter. -Now we know enough to understand the error message from above. The problem - -+ + +Now we know enough to understand the error message from above. The problem is +that the futures produced by an async block are *not* pinned by default. +Strictly: they implement `!Unpin` to opt out of being copyable by default the +way most types are. We need to pin them explicitly. + +Now that we have an idea what that error message was telling us, we can finally +get our `join_all` call to compile! First, we need to explicitly annotate +`futures` as referring to a pinned `Box` of futures. Second, we actually need to +pin the futures, which we can do using the handy `Box::pin` API, which exists +for exactly this. Putting that together, we end up with the code in Listing +17-TODO. + + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:here}} @@ -631,13 +653,40 @@ Now we know enough to understand the error message from above. The problem -This comes with a small amount of extra overhead from putting these futures on -the heap with `Box`—and we are only doing that to get the types to line up. It -would be nice if we could make this +If we compile and run this, we finally get the output we hoped for: - + -+```text +received 'hi' +received 'more' +received 'from' +received 'messages' +received 'the' +received 'for' +received 'future' +received 'you' +``` + +Phew! + +There is a bit more we can explore here. For one thing, using `Pin>` +comes with a small amount of extra overhead from putting these futures on the +heap with `Box`—and we are only doing that to get the types to line up. We don’t +actually *need* the heap allocation, after all: these futures are local to this +particular function. As noted above, `Pin` is itself a smart pointer, so we can +get the benefit of having a single type in the `Vec`—the original reason we +reached for `Box`—without doing a heap allocation. We can use `Pin` directly +instead. + +The `std::pin::pin` macro exists to do just that for values. However, we must +still be explicit about the type of the pinned reference; otherwise Rust will +still not know to interpret these as dynamic trait objects, which is what we +need them to be in the `Vec`. We therefore `pin!` each future when we define it, +and define `futures` as a `Vec` containing pinned mutable references to the +dynamic `Future` type. + + ```rust {{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} From 0032e07f80289dbe3b80d83cf5b2e35452f1f646 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 29 May 2024 16:46:36 -0600 Subject: [PATCH 263/720] =?UTF-8?q?Ch.=2017:=20iterate=20on=20=C2=A702=20e?= =?UTF-8?q?xamples,=20extract=20=E2=80=9Cextra=E2=80=9D=20material?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ch17-async-await/listing-17-15/Cargo.lock | 540 ++++++++++++++++++ .../ch17-async-await/listing-17-15/Cargo.toml | 9 + .../listing-17-15/src/main.rs | 12 + src/ch17-02-concurrency-with-async.md | 74 ++- src/ch17-03-futures-tasks-threads.md | 32 ++ 5 files changed, 629 insertions(+), 38 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-15/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-15/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-15/src/main.rs diff --git a/listings/ch17-async-await/listing-17-15/Cargo.lock b/listings/ch17-async-await/listing-17-15/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-15/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-15/Cargo.toml b/listings/ch17-async-await/listing-17-15/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-15/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-15/src/main.rs b/listings/ch17-async-await/listing-17-15/src/main.rs new file mode 100644 index 0000000000..24845f0887 --- /dev/null +++ b/listings/ch17-async-await/listing-17-15/src/main.rs @@ -0,0 +1,12 @@ +fn main() { + trpl::block_on(async { + // ANCHOR: here + let a = async { 1u32 }; + let b = async { "Hello!" }; + let c = async { true }; + // ANCHOR_END: here + + let (a_result, b_result, c_result) = trpl::join!(a, b, c); + println!("{a_result}, {b_result}, {c_result}"); + }); +} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index ed5e9342c0..772418ad5e 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -610,14 +610,12 @@ need for pinning. --> `Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. Recall that marker traits have no functionality of their own. They exist only to tell the compiler that it is safe to use the type which implements a given trait -in certain context. Just like `Send` and `Sync`, `Unpin` is automatically -implemented for all types where the compiler can prove it should be. You may -also recall that there is an opposite for each of `Send` and `Sync`: `?Send` and -`?Sync`, which tell the compiler that the types in question *might* be `Send` or -`Sync` but are not guaranteed to. `Unpin`, as its name implies, is similarly the -opposite of `Pin`, which we saw as part of the signature of the `Future::poll` -method when we covered the API of `Future` in the [Futures][futures] section -earlier in this chapter. +in certain context. Just like `Send` and `Sync`, the compiler implements `Unpin` +automatically for most types. + +`Unpin`’s job is to tell the compiler that a given type does *not* need to +uphold any particular guarantees about whether the value in question can be +moved. For example, if a future @@ -697,44 +695,44 @@ dynamic `Future` type. This keeps everything on the stack, and that is a nice little performance win, but it is still a lot of explicit types, which is quite unusual for Rust! There is another problem, too. We got this far by ignoring the fact that we might have -different `Output` types from the `Future`. - - +different `Output` types. For example, in Listing 17-TODO, the anonymous future +type for `a` implements `Future` and the anonymous future type for +`b` implements `Future`. + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} +``` - -> Note: This is how closures work, too, but we did not have to talk about it -> back in Chapter 13, because the details did not bubble up to the surface the -> way they do here! - + - -The `async` keyword does not yet work with closures directly. That is, there is -no direct equivalent to `async fn` for anonymous functions. As a result, you -cannot write code like these function calls: +We can use `trpl::join!` to await them together, since it accepts two different +future types, but we cannot use `trpl::join_all` with these futures, because we +will never be able to make them have the same type. (This is the same as working +with any other type in Rust, though: futures are not special, even though we +have some nice syntax for working with them, and that is a good thing!) We have +a basic tradeoff here: we can either deal with a dynamic number of futures with +`join_all`, as long as they all have the same type, or we can deal with a +static number of futures with `join!`, and so on, -```rust,ignore -example_1(async || { ... }); -example_2(async move || { ... }); -``` + +In practice, you will usually work directly with `async` and `.await`, and only +as a secondary tool reach for the functions like `join` or `join_all`, or their +corresponding macro equivalents. These kinds of tools are really handy for +building frameworks, or especially when you are building a runtime itself. -However, since async blocks themselves can be marked with `move`, this ends up -not being a problem. Because `async` blocks compile to anonymous futures, you -can write calls like this instead: +### Select -```rust,ignore -example_1(|| async { ... }); -example_2(|| async move { ... }); -``` +Thus far, we have only used the `join` family of functions and macros. When we +“join” on some collection of futures, we require *all* of them to finish before +we move on. Sometimes, though, we only need *some* future from a set to finish +before we move on. -These closures now return anonymous futures, meaning they work basically the -same way that an async function does. - + [collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html diff --git a/src/ch17-03-futures-tasks-threads.md b/src/ch17-03-futures-tasks-threads.md index ca27ce27be..230289d086 100644 --- a/src/ch17-03-futures-tasks-threads.md +++ b/src/ch17-03-futures-tasks-threads.md @@ -68,3 +68,35 @@ A big difference between the cooking analogy and Rust’s async model for concurrency is that in the cooking example, the cook makes the decision about when to switch tasks. In Rust’s async model, the tasks are in control of that. To see how, let’s look at how Rust actually uses async. + +## Misc. other stuff + + +The `async` keyword does not yet work with closures directly. That is, there is +no direct equivalent to `async fn` for anonymous functions. As a result, you +cannot write code like these function calls: + +```rust,ignore +example_1(async || { ... }); +example_2(async move || { ... }); +``` + +However, since async blocks themselves can be marked with `move`, this ends up +not being a problem. Because `async` blocks compile to anonymous futures, you +can write calls like this instead: + +```rust,ignore +example_1(|| async { ... }); +example_2(|| async move { ... }); +``` + +These closures now return anonymous futures, meaning they work basically the +same way that an async function does. + + + +> Note: This is how closures work, too, but we did not have to talk about it +> back in Chapter 13, because the details did not bubble up to the surface the +> way they do here! + + From 42363712e801ae23d5fa6ff6baa08cae8ba04ff4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 30 May 2024 11:42:49 -0600 Subject: [PATCH 264/720] =?UTF-8?q?Ch.=2017:=20Explain=20`join!`=20in=20?= =?UTF-8?q?=C2=A702?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-09b/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-09b/Cargo.toml | 9 + .../listing-17-09b/src/main.rs | 46 ++ src/ch17-02-concurrency-with-async.md | 26 +- 4 files changed, 613 insertions(+), 8 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-09b/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-09b/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-09b/src/main.rs diff --git a/listings/ch17-async-await/listing-17-09b/Cargo.lock b/listings/ch17-async-await/listing-17-09b/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-09b/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-09b/Cargo.toml b/listings/ch17-async-await/listing-17-09b/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-09b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-09b/src/main.rs b/listings/ch17-async-await/listing-17-09b/src/main.rs new file mode 100644 index 0000000000..945442dd8a --- /dev/null +++ b/listings/ch17-async-await/listing-17-09b/src/main.rs @@ -0,0 +1,46 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + // ANCHOR: here + trpl::join!(tx1_fut, tx_fut, rx_fut); + // ANCHOR_END: here + }); +} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 772418ad5e..e33b854c97 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -388,16 +388,26 @@ in the same infinite loop we started out in. When we switched from using two futures to three, we also had to switch from using `join` to using `join3`. It would be annoying to do this every time we -changed our code. +changed our code. Happily, we have a macro form of `join` to which we can pass +an arbitrary number of arguments. It also handles awaiting the futures itself. +Thus, we could rewrite the code from Listing 17-TODO to use `join!` instead of `join3`, as in Listing 17-TODO: - + -However, both the function nor macro forms of `join` only work for cases where -we know the number of futures ahead of time. If instead we have a dynamic number -of futures, we need a function which works with a collection type which can grow -and shrink dynamically at runtime, such as a vector. In real-world Rust, pushing -futures into a collection and then waiting on some or all the futures in that -collection to complete is a very common pattern. +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-09b/src/main.rs:here}} +``` + + + +This is definitely a nice improvement over needing to swap between `join` and +`join3` and `join4` and so on! However, both the function nor macro forms of +`join` only work for cases where we know the number of futures ahead of time. If +instead we have a dynamic number of futures, we need a function which works with +a collection type which can grow and shrink dynamically at runtime, such as a +vector. In real-world Rust, pushing futures into a collection and then waiting +on some or all the futures in that collection to complete is a very common +pattern. The `trpl::join_all` function accepts any type which implements the `Iterator` trait, which we learned about back in Chapter 13, so it seems like just the From 97f5bcc4d54fc3f39f718e51b9a216cc58218ace Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 30 May 2024 11:49:00 -0600 Subject: [PATCH 265/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20Clarify=20the=20?= =?UTF-8?q?`move`=20discussion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-02-concurrency-with-async.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index e33b854c97..b95a0cf542 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -320,7 +320,7 @@ three futures to complete: Now both blocks borrow `tx`, so they are both able to use it to send messages, which `rx` can then receive. When we run that code, we see the extra output from the new `async` block, and the message it sends being received by the -`rx.recv()`: +`rx.recv()`. ```text Got: hi @@ -334,21 +334,21 @@ Got: you ``` As before, we also see that the program does not shut down on its own and -requires a ctrl-c. Now that we have seen how -`async` blocks borrow the items they reference from their outer scope, we can go -ahead and remove the extra block we just added, and switch back to using -`trpl::join` instead of `trpl::join3`. - -This little exploration makes the original issue much clearer: it is ultimately -about *ownership*. We need to move `tx` into the async block so that once that -block ends, `tx` will be dropped. +requires a ctrl-c, though. This little +exploration helps us understand why: it is ultimately about *ownership*. We need +to move `tx` into the async block so that once that block ends, `tx` will be +dropped. In Chapter 13, we learned how to use the `move` keyword with closures, and in Chapter 16, we saw that we often need to use closures marked with `move` when working with threads. As we have discovered, the same dynamics apply to async blocks—so the `move` keyword also works with async blocks, allowing them to take -ownership of the data they reference. We can do that by change the first async -block from an `async` block to an `async move` block, as in Listing 17-TODO: +ownership of the data they reference. + +Since we have seen how `async` blocks borrow the items they reference from their +outer scope, we can go ahead and remove the extra block we just added for now, +and switch back from `join3` to `join`. Then we can change the first async block +from an `async` block to an `async move` block, as in Listing 17-TODO: From c6965ca05715256016feb9a17737c1d221e22e4c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 30 May 2024 12:44:38 -0600 Subject: [PATCH 266/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20Start=20showing?= =?UTF-8?q?=20timeouts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also has the setup for showing `select`, but currently jumps ahead to showing a `timeout` example. --- .../listing-17-timeout/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-timeout/Cargo.toml | 9 + .../listing-17-timeout/src/main.rs | 20 + packages/trpl/src/lib.rs | 19 +- packages/trpl/tests/integration/main.rs | 23 + src/ch17-02-concurrency-with-async.md | 16 + 6 files changed, 626 insertions(+), 1 deletion(-) create mode 100644 listings/ch17-async-await/listing-17-timeout/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-timeout/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-timeout/src/main.rs diff --git a/listings/ch17-async-await/listing-17-timeout/Cargo.lock b/listings/ch17-async-await/listing-17-timeout/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-timeout/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-timeout/Cargo.toml b/listings/ch17-async-await/listing-17-timeout/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-timeout/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-timeout/src/main.rs b/listings/ch17-async-await/listing-17-timeout/src/main.rs new file mode 100644 index 0000000000..6e06ef7e42 --- /dev/null +++ b/listings/ch17-async-await/listing-17-timeout/src/main.rs @@ -0,0 +1,20 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + // ANCHOR: here + let limit = Duration::from_secs(2); + let slow = async { + trpl::sleep(Duration::from_secs(5)).await; + "Finally finished" + }; + + match trpl::timeout(limit, slow).await { + Ok(message) => println!("Succeded with '{message}'"), + Err(duration) => { + println!("Failed after {} seconds", duration.as_secs()) + } + } + // ANCHOR_END: here + }); +} diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 9d53d86ddf..4ab3c6d352 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -12,7 +12,8 @@ //! never be broken by upstream changes, e.g. if Tokio does a breaking 2.0 //! release at some point. -use std::future::Future; +use std::{future::Future, time::Duration}; +use tokio::time::{self, Timeout}; pub use futures::{ future::{join, join3, join_all}, @@ -54,3 +55,19 @@ pub fn block_on(future: F) -> F::Output { let rt = Runtime::new().unwrap(); rt.block_on(future) } + +/// Race a future against a specified timeout duration. +/// +/// Under the hood, this uses `tokio::time::timeout`, but instead of returning +/// Tokio's internal error type in the case of a failure, this simply returns +/// the duration which had elapsed. (It actually provides strictly *more* info +/// than Tokio's error does, though it does not `impl Error`.) +pub async fn timeout( + duration: Duration, + future: F, +) -> Result +where + F: Future, +{ + time::timeout(duration, future).await.map_err(|_| duration) +} diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index 106deb152d..477691b30f 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -130,3 +130,26 @@ mod re_exported_join_apis_work { assert_eq!(result, (1, "Hello", vec![String::from("World")])); } } + +#[test] +fn re_exported_timeout_works() { + let val = trpl::block_on(async { + let winner = async { + trpl::sleep(Duration::from_millis(1)).await; + String::from("Hello") + }; + trpl::timeout(Duration::from_millis(2), winner).await + }); + + assert_eq!(val, Ok(String::from("Hello"))); + + let val = trpl::block_on(async { + let loser = async { + trpl::sleep(Duration::from_millis(2)).await; + String::from("Hello") + }; + trpl::timeout(Duration::from_millis(1), loser).await + }); + + assert!(val.is_err()); +} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index b95a0cf542..776710e0bc 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -744,6 +744,22 @@ before we move on. +Many of these patterns are common enough to warrant abstracting over. For +example, the `trpl::timeout` function takes a `Duration` for the maximum time to +run, but also takes a future to run, and produces a new future you can await, +whose `Output` type is a `Result`. Listing 17-TODO shows how we can use it. If +the passed-in future finishes first, the output result will be `Ok`, with the +result of that passed-in future. If the duration elapses before the passed-in +future finishes, the result will be `Err` with the duration that elapsed. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout/src/main.rs:here}} +``` + + + [collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html [futures]: /ch17-01-futures-and-syntax.html#futures From c58f94376c30d3795edf4ede527666776b193779 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 30 May 2024 12:44:38 -0600 Subject: [PATCH 267/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20Start=20on=20exa?= =?UTF-8?q?mple=20of=20select.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-select-a/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-select-a/Cargo.toml | 9 + .../listing-17-select-a/src/main.rs | 5 + packages/trpl/src/lib.rs | 4 +- packages/trpl/tests/integration/main.rs | 33 +- src/ch17-02-concurrency-with-async.md | 10 +- 6 files changed, 597 insertions(+), 4 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-select-a/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-select-a/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-select-a/src/main.rs diff --git a/listings/ch17-async-await/listing-17-select-a/Cargo.lock b/listings/ch17-async-await/listing-17-select-a/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-select-a/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-select-a/Cargo.toml b/listings/ch17-async-await/listing-17-select-a/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-select-a/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-select-a/src/main.rs b/listings/ch17-async-await/listing-17-select-a/src/main.rs new file mode 100644 index 0000000000..3ed5bec9d0 --- /dev/null +++ b/listings/ch17-async-await/listing-17-select-a/src/main.rs @@ -0,0 +1,5 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { trpl::select!(todo!()) }); +} diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 4ab3c6d352..4a9c970756 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -13,10 +13,10 @@ //! release at some point. use std::{future::Future, time::Duration}; -use tokio::time::{self, Timeout}; +use tokio::time; pub use futures::{ - future::{join, join3, join_all}, + future::{join, join3, join_all, select}, join, }; pub use tokio::{ diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index 477691b30f..ff800b2d7c 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -9,7 +9,10 @@ //! //! [post]: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html -use std::{pin::Pin, time::Duration}; +use std::{ + pin::{pin, Pin}, + time::Duration, +}; use futures::Future; use trpl::{Receiver, Sender}; @@ -153,3 +156,31 @@ fn re_exported_timeout_works() { assert!(val.is_err()); } + +#[test] +fn re_exported_select_macro() { + #[derive(Debug, PartialEq)] + enum Output { + Fast, + Slow, + } + + let result: Result = trpl::block_on(async { + // 1 second is 1,000 times slower than 1 millisecond, so this should + // reliably lose to the `fast` version. + let slow = pin!(async { + trpl::sleep(Duration::from_secs(1)).await; + Ok(Output::Slow) + }); + + let fast = pin!(async { + trpl::sleep(Duration::from_millis(1)).await; + Ok(Output::Fast) + }); + + trpl::select(slow, fast).await.factor_first().0 + }); + + let val = result.unwrap(); + assert_eq!(val, Output::Fast); +} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 776710e0bc..2fe5c01716 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -740,7 +740,15 @@ building frameworks, or especially when you are building a runtime itself. Thus far, we have only used the `join` family of functions and macros. When we “join” on some collection of futures, we require *all* of them to finish before we move on. Sometimes, though, we only need *some* future from a set to finish -before we move on. +before we move on—kind of like racing one future against another. This operation +is usually called “select” after the name of a Unix system call used to check +the status of IO operations after a time delay. Just like with `join`, there are +both function and macro versions of `select`. For this example, we will use the +function version. + + From 7da440af2e2a098bccf6a3ddcca4608171dd83d0 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 4 Jun 2024 19:13:41 -0600 Subject: [PATCH 268/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20Implement=20`tim?= =?UTF-8?q?eout`=20example=20and=20building=20blocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create a `trpl::race` function which simplifies the `select` API by ignoring the future which resolves second. Use the `race` function to show how you can implement an even simpler `timeout` function on top of it, i.e. showing how futures can compose nicely. With that in place, there is enough to be able to “work up to it” in the body of the text. --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-timeout-final/src/main.rs | 29 +++++++++++++++ .../listing-17-timeout/src/main.rs | 20 ----------- packages/trpl/src/lib.rs | 32 +++++++++++++++-- packages/trpl/tests/integration/main.rs | 35 +++++++++---------- src/ch17-02-concurrency-with-async.md | 10 +++--- 7 files changed, 80 insertions(+), 46 deletions(-) rename listings/ch17-async-await/{listing-17-timeout => listing-17-timeout-final}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-timeout => listing-17-timeout-final}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-timeout-final/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-timeout/src/main.rs diff --git a/listings/ch17-async-await/listing-17-timeout/Cargo.lock b/listings/ch17-async-await/listing-17-timeout-final/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-timeout/Cargo.lock rename to listings/ch17-async-await/listing-17-timeout-final/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-timeout/Cargo.toml b/listings/ch17-async-await/listing-17-timeout-final/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-timeout/Cargo.toml rename to listings/ch17-async-await/listing-17-timeout-final/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-timeout-final/src/main.rs b/listings/ch17-async-await/listing-17-timeout-final/src/main.rs new file mode 100644 index 0000000000..dc40b89329 --- /dev/null +++ b/listings/ch17-async-await/listing-17-timeout-final/src/main.rs @@ -0,0 +1,29 @@ +use std::{future::Future, time::Duration}; + +use trpl::Either; + +fn main() { + trpl::block_on(async { + let slow = async { + trpl::sleep(Duration::from_secs(5)).await; + "Finally finished" + }; + + match timeout(Duration::from_secs(2), slow).await { + Ok(message) => println!("Succeeded with '{message}'"), + Err(duration) => { + println!("Failed after {} seconds", duration.as_secs()) + } + } + }); +} + +async fn timeout( + max_time: Duration, + future: F, +) -> Result { + match trpl::race(future, trpl::sleep(max_time)).await { + Either::Left(output) => Ok(output), + Either::Right(_) => Err(max_time), + } +} diff --git a/listings/ch17-async-await/listing-17-timeout/src/main.rs b/listings/ch17-async-await/listing-17-timeout/src/main.rs deleted file mode 100644 index 6e06ef7e42..0000000000 --- a/listings/ch17-async-await/listing-17-timeout/src/main.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - // ANCHOR: here - let limit = Duration::from_secs(2); - let slow = async { - trpl::sleep(Duration::from_secs(5)).await; - "Finally finished" - }; - - match trpl::timeout(limit, slow).await { - Ok(message) => println!("Succeded with '{message}'"), - Err(duration) => { - println!("Failed after {} seconds", duration.as_secs()) - } - } - // ANCHOR_END: here - }); -} diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 4a9c970756..fa7efba50c 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -12,11 +12,11 @@ //! never be broken by upstream changes, e.g. if Tokio does a breaking 2.0 //! release at some point. -use std::{future::Future, time::Duration}; +use std::{future::Future, pin::pin, time::Duration}; use tokio::time; pub use futures::{ - future::{join, join3, join_all, select}, + future::{self, join, join3, join_all}, join, }; pub use tokio::{ @@ -71,3 +71,31 @@ where { time::timeout(duration, future).await.map_err(|_| duration) } + +///Run two futures +pub async fn race(f1: F1, f2: F2) -> Either +where + F1: Future, + F2: Future, +{ + let f1 = pin!(f1); + let f2 = pin!(f2); + match future::select(f1, f2).await { + future::Either::Left((a, _f2)) => Either::Left(a), + future::Either::Right((b, _f1)) => Either::Right(b), + } +} + +/// A type which represents a simple choice between two options. +/// +/// You can think of this as being like [`Result`], but where `Result` gives +/// specific meaning to the two types (success with `Ok`, failure with `Err`), +/// `Either` does not. +/// +/// Here, we use it with [`race`] because the point of `select` is to choose +/// whichever type finishes first, but neither is more “correct” than the other. +#[derive(Debug, PartialEq)] +pub enum Either { + Left(A), + Right(B), +} diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index ff800b2d7c..bb8d763d17 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -15,7 +15,7 @@ use std::{ }; use futures::Future; -use trpl::{Receiver, Sender}; +use trpl::{Either, Receiver, Sender}; /// This test is foundational for all the others, as they depend on `block_on`. /// @@ -158,29 +158,26 @@ fn re_exported_timeout_works() { } #[test] -fn re_exported_select_macro() { +fn race() { #[derive(Debug, PartialEq)] - enum Output { - Fast, - Slow, - } + struct Slow; - let result: Result = trpl::block_on(async { - // 1 second is 1,000 times slower than 1 millisecond, so this should - // reliably lose to the `fast` version. - let slow = pin!(async { - trpl::sleep(Duration::from_secs(1)).await; - Ok(Output::Slow) - }); + #[derive(Debug, PartialEq)] + struct Fast; + + let val = trpl::block_on(async { + let slow = async { + trpl::sleep(Duration::from_millis(1_000)).await; + Slow + }; - let fast = pin!(async { + let fast = async { trpl::sleep(Duration::from_millis(1)).await; - Ok(Output::Fast) - }); + Fast + }; - trpl::select(slow, fast).await.factor_first().0 + trpl::race(slow, fast).await }); - let val = result.unwrap(); - assert_eq!(val, Output::Fast); + assert_eq!(val, Either::Right(Fast)); } diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 2fe5c01716..8e85971769 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -625,13 +625,13 @@ automatically for most types. `Unpin`’s job is to tell the compiler that a given type does *not* need to uphold any particular guarantees about whether the value in question can be -moved. For example, if a future +moved. For example, if a future - - +However, we do not actually need to sleep to accomplish this. We just +need to hand back control to the runtime. We can actually *yield* +control back to the runtime, using a function named `yield_now`. It does +just what it says: hands control back to the runtime, so that the +runtime can check whether any other tasks are ready to make progress. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-b/src/main.rs:futures}} +``` + + + +This is both clearer about the actual intent and can be significantly faster +than using `sleep`, because timers like the one used by `sleep` often have +limits to how granular they can be. The version of `sleep` we are using, for +example, will always sleep for at least a millisecond, even if we pass it a +`Duration` of one nanosecond. Again, modern computers are *fast*: they can do a +lot in one millisecond! You can see this for yourself by comparing what happens +if you change Listings 17-TODO and 17-TODO to both do 100 or 1,000 iterations +instead of just 5. You will see that the version with `yield_now` is *way* faster! + + Many of these patterns are common enough to warrant abstracting over. For example, the `trpl::timeout` function takes a `Duration` for the maximum time to @@ -768,6 +831,9 @@ future finishes, the result will be `Err` with the duration that elapsed. +Here we were using the `timeout` supplied by `trpl`, but we do not have to. We +can implement it ourselves using the + [collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html [futures]: /ch17-01-futures-and-syntax.html#futures From 5a0fb4233bf2239b0d579d69f21ca7e13ef532ff Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 6 Jun 2024 11:41:32 -0600 Subject: [PATCH 272/720] =?UTF-8?q?Ch.=2017:=20Split=20the=20over-long=20?= =?UTF-8?q?=C2=A702=20into=20two=20parts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …and fix a bunch of the listing references and make some word choice and sentence structure improvements along the way to boot. --- .../listing-17-select-a/Cargo.lock | 540 ------------------ .../listing-17-select-a/Cargo.toml | 9 - .../listing-17-select-a/src/main.rs | 5 - .../listing-17-timeout-a/src/main.rs | 4 +- .../listing-17-yield-a-sleep/src/main.rs | 2 +- src/SUMMARY.md | 4 +- src/ch17-02-concurrency-with-async.md | 454 +-------------- src/ch17-03-more-futures.md | 351 ++++++++++++ src/ch17-04-TODO.md | 107 ++++ ...ds.md => ch17-05-futures-tasks-threads.md} | 0 10 files changed, 465 insertions(+), 1011 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-select-a/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-select-a/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-select-a/src/main.rs create mode 100644 src/ch17-03-more-futures.md create mode 100644 src/ch17-04-TODO.md rename src/{ch17-03-futures-tasks-threads.md => ch17-05-futures-tasks-threads.md} (100%) diff --git a/listings/ch17-async-await/listing-17-select-a/Cargo.lock b/listings/ch17-async-await/listing-17-select-a/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-select-a/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-select-a/Cargo.toml b/listings/ch17-async-await/listing-17-select-a/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-select-a/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-select-a/src/main.rs b/listings/ch17-async-await/listing-17-select-a/src/main.rs deleted file mode 100644 index 3ed5bec9d0..0000000000 --- a/listings/ch17-async-await/listing-17-select-a/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { trpl::select!(todo!()) }); -} diff --git a/listings/ch17-async-await/listing-17-timeout-a/src/main.rs b/listings/ch17-async-await/listing-17-timeout-a/src/main.rs index 3272806fd8..5e702a2edc 100644 --- a/listings/ch17-async-await/listing-17-timeout-a/src/main.rs +++ b/listings/ch17-async-await/listing-17-timeout-a/src/main.rs @@ -2,12 +2,11 @@ use std::time::Duration; fn main() { trpl::block_on(async { - // ANCHOR: slow + // ANCHOR: here let slow = async { trpl::sleep(Duration::from_secs(5)).await; "I finished!" }; - // ANCHOR_END: slow match trpl::timeout(Duration::from_secs(2), slow).await { Ok(message) => println!("Succeeded with '{message}'"), @@ -15,5 +14,6 @@ fn main() { println!("Failed after {} seconds", duration.as_secs()) } } + // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs b/listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs index 78a3d2c885..97480fbab8 100644 --- a/listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs +++ b/listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs @@ -22,7 +22,7 @@ fn main() { } println!("'b' finished."); }; - // ANCHOR_end: here + // ANCHOR_END: here trpl::race(a, b).await; }); diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 18c89533a5..e34b10da22 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -104,7 +104,9 @@ - [Async and Await](ch17-00-async-await.md) - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) - [Concurrency With Async](ch17-02-concurrency-with-async.md) - - [Futures, Tasks, and Threads](ch17-03-futures-tasks-threads.md) + - [Working With More Futures](ch17-03-more-futures.md) + - [TODO](ch17-04-TODO.md) + - [Futures, Tasks, and Threads](ch17-05-futures-tasks-threads.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index a8938877ea..e80b7605d4 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -384,456 +384,4 @@ block, and switching back to `join3`. Both of these blocks need to be `async move` blocks, or else we will end up back in the same infinite loop we started out in. -### Working with More Futures - -When we switched from using two futures to three, we also had to switch from -using `join` to using `join3`. It would be annoying to do this every time we -changed our code. Happily, we have a macro form of `join` to which we can pass -an arbitrary number of arguments. It also handles awaiting the futures itself. -Thus, we could rewrite the code from Listing 17-TODO to use `join!` instead of `join3`, as in Listing 17-TODO: - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-09b/src/main.rs:here}} -``` - - - -This is definitely a nice improvement over needing to swap between `join` and -`join3` and `join4` and so on! However, both the function nor macro forms of -`join` only work for cases where we know the number of futures ahead of time. If -instead we have a dynamic number of futures, we need a function which works with -a collection type which can grow and shrink dynamically at runtime, such as a -vector. In real-world Rust, pushing futures into a collection and then waiting -on some or all the futures in that collection to complete is a very common -pattern. - -The `trpl::join_all` function accepts any type which implements the `Iterator` -trait, which we learned about back in Chapter 13, so it seems like just the -ticket. Let’s try putting our futures in a vector, so we can swap out our -`join3` call and replace it with `join_all`. - -- -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:here}} -``` - - - -Unfortunately, this does not compile. Instead, we get this error: - - - -```text -error[E0308]: mismatched types - --> src/main.rs:43:37 - | -8 | let tx1_fut = async move { - | _______________________- -9 | | let vals = vec![ -10 | | String::from("hi"), -11 | | String::from("from"), -... | -19 | | } -20 | | }; - | |_________- the expected `async` block -21 | -22 | let rx_fut = async { - | ______________________- -23 | | while let Some(value) = rx.recv().await { -24 | | println!("received '{value}'"); -25 | | } -26 | | }; - | |_________- the found `async` block -... -43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; - | ^^^^^^ expected `async` block, found a different `async` block - | - = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` - found `async` block `{async block@src/main.rs:22:22: 26:10}` -``` - -This error message is admittedly not the most helpful! It only tells us that it -expected one async block and found another—but why is it looking for the async -blocks that it names here, and why does it only reference them by where they -appear in the code? - -One clue is the format of this message. Notice that it is exactly the same as if -we had tried to create a `Vec` with a a number and a string in it: - - - -```rust -let a = 1; -let b = "Hello"; -let vals = vec![a, b]; -``` - -The output there would be: - -```text -error[E0308]: mismatched types - --> src/main.rs:4:24 - | -4 | let vals = vec![a, b]; - | ^ expected integer, found `&str` -``` - -Saying “expected *something*, found *something else*” is Rust’s standard format -for telling us about a type mismatch. As we saw with vectors in [Using an Enum -to Store Multiple Types][collections] back in Chapter 8, we need the type of -each item in a collection to be the same—and `tx1_fut`, `rx_fut`, and `tx_fut` -do not have the same type. - -The underlying issue here is what we learned in the previous section: async -blocks compile to anonymous futures. Under the hood, there is a data structure -corresponding to each of these blocks, and it has its own unique type. This -might be surprising. After all, none of them returns anything, so the `Future` -type in each case is `Future`. However, `Future` is a trait, not a -concrete type. The actual types here are invisible from our point of view as the -person writing the code. - -In Chapter 8, we discussed one way to include multiple types in a single vector: -using an enum to represent each of the different types which can appear in the -vector. We cannot do that here, though. For one thing, we do not even have a way -to name the different types, because they are anonymous. For another, the reason -we reached for a vector and `join_all` in the first place was to be able to work -with a dynamic collection of futures where we do not know what they will all be -until runtime. - -To make this work, we need to use *trait objects*, just as we did for returning -different kinds of errors from the same function in [Returning Errors from the -run function][dyn] back in Chapter 12. Again, we will cover trait objects in -detail in Chapter 17. Here, it lets us treat each of the anonymous futures -produced by these types as interchangeable, since all of them by definition -implement the `Future` trait. - -We can start by wrapping each of the futures in the `vec!` in a `Box::new()`. -Unfortunately, the initial way we might try this, as shown in Listing 17-TODO, -still does not compile. - -- -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:here}} -``` - - - -In fact, we have the same basic error we did before, but we get one for both the -second and third `Box::new` calls, and we also get new errors referring to the -`Unpin` trait. - -We can start by fixing the type error around the `Box::new` calls, by telling -the compiler explicitly that we want to use these types as trait objects. The -clearest way to do that here is by adding a type annotation to the declaration -of `futures`, as we see in Listing 17-TODO. The type we have to write here is a -little involved, so let’s walk through each part of it. - -- The innermost type is the future itself. We note explicitly that it the output - of the future is the unit type `()` by writing `Future`. -- Then we annotate the trait with `dyn` to mark it as dynamic. -- The entire trait is wrapped in a `Box`. -- Finally, we state explicitly that `futures` is a `Vec` containing these items. - -- -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} -``` - - - -That already made a big difference. Now when we run the compiler, we only have -the errors mentioning `Unpin`, each of which is a variation on this same output: - - - -```text -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:33 - | -46 | trpl::join_all(futures).await; - | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: Future` - | - = note: consider using the `pin!` macro - consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `Future` -note: required by a bound in `futures_util::future::join_all::JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 - | -27 | pub struct JoinAll - | ------- required by a bound in this struct -28 | where -29 | F: Future, - | ^^^^^^ required by this bound in `JoinAll` -``` - -That is a *lot* to digest, so let’s pull it apart. The first part of the message -tell us that the first async block (`src/main.rs:8:23: 20:10`) does not -implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve -it. The rest of the message tells us *why* that is required: the `JoinAll` -struct, which is itself a `Future`, is also generic over a `Future`, and -`Future` itself requires the `Unpin` trait. Understanding this error means we -need to dive into a little more of how the `Future` type actually works, in -particular the idea of *pinning*. - -### Pinning and the Pin and Unpin Traits - -When we introduced the `Future` trait in the previous chapter, we saw that the -definition of its `poll` method has an unusual way of specifying the `self` -parameter. To review, here is the full definition of `Future`: - -```rust -pub trait Future { - type Output; - - // Required method - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; -} -``` - -We have not seen a method definition like this before, where `self` has a type -annotation rather than simply being named like `self`, `mut self`, `&self`, or -`&mut self`. This syntax means that the method can only be called when the -instance of the type which implements `Future` is behind a `Pin` pointer type. -This syntax is not specific to `Pin`; it also works with `Box` and other smart -pointer types, and we will see it again in Chapter 18. - -Here, the signature tells us that if we want to poll a future to check whether -it is `Pending` or `Ready(Output)`, the type which implements `Future` has to be -behind a `Pin` smart pointer type. Recalling that `.await` is implemented in -terms of calls to `poll()`, this starts to explain the error message we saw -above—but that was in terms of `Unpin`, not `Pin`. So what exactly are `Pin` and -`Unpin`, how do they relate, and why does `Future` need `self` to be in a `Pin` -type to call `poll`? - - - -Remember that any time you write a future, a runtime is ultimately responsible -for executing it. That means that an async block might outlive the function -where you write it, the same way a closure can. - -`Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. -Recall that marker traits have no functionality of their own. They exist only to -tell the compiler that it is safe to use the type which implements a given trait -in certain context. Just like `Send` and `Sync`, the compiler implements `Unpin` -automatically for most types. - -`Unpin`’s job is to tell the compiler that a given type does *not* need to -uphold any particular guarantees about whether the value in question can be -moved. For example, if a future - - - - - -Now we know enough to understand the error message from above. The problem is -that the futures produced by an async block are *not* pinned by default. -Strictly: they implement `!Unpin` to opt out of being copyable by default the -way most types are. We need to pin them explicitly. - -Now that we have an idea what that error message was telling us, we can finally -get our `join_all` call to compile! First, we need to explicitly annotate -`futures` as referring to a pinned `Box` of futures. Second, we actually need to -pin the futures, which we can do using the handy `Box::pin` API, which exists -for exactly this. Putting that together, we end up with the code in Listing -17-TODO. - -- -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:here}} -``` - - - -If we compile and run this, we finally get the output we hoped for: - - - -```text -received 'hi' -received 'more' -received 'from' -received 'messages' -received 'the' -received 'for' -received 'future' -received 'you' -``` - -Phew! - -There is a bit more we can explore here. For one thing, using `Pin>` -comes with a small amount of extra overhead from putting these futures on the -heap with `Box`—and we are only doing that to get the types to line up. We don’t -actually *need* the heap allocation, after all: these futures are local to this -particular function. As noted above, `Pin` is itself a smart pointer, so we can -get the benefit of having a single type in the `Vec`—the original reason we -reached for `Box`—without doing a heap allocation. We can use `Pin` directly -instead. - -The `std::pin::pin` macro exists to do just that for values. However, we must -still be explicit about the type of the pinned reference; otherwise Rust will -still not know to interpret these as dynamic trait objects, which is what we -need them to be in the `Vec`. We therefore `pin!` each future when we define it, -and define `futures` as a `Vec` containing pinned mutable references to the -dynamic `Future` type. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} -``` - - - -This keeps everything on the stack, and that is a nice little performance win, -but it is still a lot of explicit types, which is quite unusual for Rust! There -is another problem, too. We got this far by ignoring the fact that we might have -different `Output` types. For example, in Listing 17-TODO, the anonymous future -type for `a` implements `Future` and the anonymous future type for -`b` implements `Future`. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} -``` - - - -We can use `trpl::join!` to await them together, since it accepts two different -future types, but we cannot use `trpl::join_all` with these futures, because we -will never be able to make them have the same type. (This is the same as working -with any other type in Rust, though: futures are not special, even though we -have some nice syntax for working with them, and that is a good thing!) We have -a basic tradeoff here: we can either deal with a dynamic number of futures with -`join_all`, as long as they all have the same type, or we can deal with a -static number of futures with `join!`, and so on, - - -In practice, you will usually work directly with `async` and `.await`, and only -as a secondary tool reach for the functions like `join` or `join_all`, or their -corresponding macro equivalents. These kinds of tools are really handy for -building frameworks, or especially when you are building a runtime itself. - -### Race - -Thus far, we have only used the `join` family of functions and macros. When we -“join” on some collection of futures, we require *all* of them to finish before -we move on. Sometimes, though, we only need *some* future from a set to finish -before we move on—kind of like racing one future against another. This operation -is often named `race` for exactly that reason. - -In Listing 17-TODO, we use `race` to run two futures, `slow` and `fast` against -each other. First, we introduce the two futures. Each one prints a message when -it starts running, pauses for some amount of time by calling and awaiting -`sleep`, and then prints another message when it finishes. Then we pass both to -`trpl::race` and wait for one of them to finish. (The outcome here won’t be too -surprising: `fast` wins!) - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-race/src/main.rs:futures}} -``` - - - -One other thing to notice: if you flip the order of the arguments to `race`, the -order of the start messages changes, but the `fast` future always completes -first. That is because the implementation of this particular `race` function is -not *fair*. It always runs the futures passed as arguments in the order they are -passed. That means everything up to the first `.await` in a given future will -run before *any* of the other future gets a chance to run. Other implementations -*are* fair, and will randomly choose which future to start first. - -This dynamic is important to keep in mind! An async runtime can only -switch which future it is executing at await points. That means if you -load up a bunch of really expensive work in an async function, it will -block any other futures from making progress. (You may sometimes hear -this referred to as one future *starving* other futures. The same thing -applies to threads, too!) We can work around this using the `sleep` -function, as in Listing 17-TODO. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs:futures}} -``` - - - - - -However, we do not actually need to sleep to accomplish this. We just -need to hand back control to the runtime. We can actually *yield* -control back to the runtime, using a function named `yield_now`. It does -just what it says: hands control back to the runtime, so that the -runtime can check whether any other tasks are ready to make progress. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-b/src/main.rs:futures}} -``` - - - -This is both clearer about the actual intent and can be significantly faster -than using `sleep`, because timers like the one used by `sleep` often have -limits to how granular they can be. The version of `sleep` we are using, for -example, will always sleep for at least a millisecond, even if we pass it a -`Duration` of one nanosecond. Again, modern computers are *fast*: they can do a -lot in one millisecond! You can see this for yourself by comparing what happens -if you change Listings 17-TODO and 17-TODO to both do 100 or 1,000 iterations -instead of just 5. You will see that the version with `yield_now` is *way* faster! - - - -Many of these patterns are common enough to warrant abstracting over. For -example, the `trpl::timeout` function takes a `Duration` for the maximum time to -run, but also takes a future to run, and produces a new future you can await, -whose `Output` type is a `Result`. Listing 17-TODO shows how we can use it. If -the passed-in future finishes first, the output result will be `Ok`, with the -result of that passed-in future. If the duration elapses before the passed-in -future finishes, the result will be `Err` with the duration that elapsed. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout/src/main.rs:here}} -``` - - - -Here we were using the `timeout` supplied by `trpl`, but we do not have to. We -can implement it ourselves using the - -[collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types -[dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html -[futures]: /ch17-01-futures-and-syntax.html#futures + diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md new file mode 100644 index 0000000000..c8f1a63f65 --- /dev/null +++ b/src/ch17-03-more-futures.md @@ -0,0 +1,351 @@ +## Working With More Futures + +When we switched from using two futures to three in the previous section, we +also had to switch from using `join` to using `join3`. It would be annoying to +do this every time we changed our code. Happily, we have a macro form of `join` +to which we can pass an arbitrary number of arguments. It also handles awaiting +the futures itself. Thus, we could rewrite the code from Listing 17-TODO to use +`join!` instead of `join3`, as in Listing 17-TODO: + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-09b/src/main.rs:here}} +``` + + + +This is definitely a nice improvement over needing to swap between `join` and +`join3` and `join4` and so on! However, both the function nor macro forms of +`join` only work for cases where we know the number of futures ahead of time. If +instead we have a dynamic number of futures, we need a function which works with +a collection type which can grow and shrink dynamically at runtime, such as a +vector. In real-world Rust, pushing futures into a collection and then waiting +on some or all the futures in that collection to complete is a very common +pattern. + +The `trpl::join_all` function accepts any type which implements the `Iterator` +trait, which we learned about back in Chapter 13, so it seems like just the +ticket. Let’s try putting our futures in a vector, so we can swap out our +`join3` call and replace it with `join_all`. + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:here}} +``` + + + +Unfortunately, this does not compile. Instead, we get this error: + + + +```text +error[E0308]: mismatched types + --> src/main.rs:43:37 + | +8 | let tx1_fut = async move { + | _______________________- +9 | | let vals = vec![ +10 | | String::from("hi"), +11 | | String::from("from"), +... | +19 | | } +20 | | }; + | |_________- the expected `async` block +21 | +22 | let rx_fut = async { + | ______________________- +23 | | while let Some(value) = rx.recv().await { +24 | | println!("received '{value}'"); +25 | | } +26 | | }; + | |_________- the found `async` block +... +43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; + | ^^^^^^ expected `async` block, found a different `async` block + | + = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` + found `async` block `{async block@src/main.rs:22:22: 26:10}` +``` + +This error message is admittedly not the most helpful! It only tells us that it +expected one async block and found another—but why is it looking for the async +blocks that it names here, and why does it only reference them by where they +appear in the code? + +One clue is the format of this message. Notice that it is exactly the same as if +we had tried to create a `Vec` with a a number and a string in it: + + + +```rust +let a = 1; +let b = "Hello"; +let vals = vec![a, b]; +``` + +The output there would be: + +```text +error[E0308]: mismatched types + --> src/main.rs:4:24 + | +4 | let vals = vec![a, b]; + | ^ expected integer, found `&str` +``` + +Saying “expected *something*, found *something else*” is Rust’s standard format +for telling us about a type mismatch. As we saw with vectors in [Using an Enum +to Store Multiple Types][collections] back in Chapter 8, we need the type of +each item in a collection to be the same—and `tx1_fut`, `rx_fut`, and `tx_fut` +do not have the same type. + +The underlying issue here is what we learned in the previous section: async +blocks compile to anonymous futures. Under the hood, there is a data structure +corresponding to each of these blocks, and it has its own unique type. This +might be surprising. After all, none of them returns anything, so the `Future` +type in each case is `Future`. However, `Future` is a trait, not a +concrete type. The actual types here are invisible from our point of view as the +person writing the code. + +In Chapter 8, we discussed one way to include multiple types in a single vector: +using an enum to represent each of the different types which can appear in the +vector. We cannot do that here, though. For one thing, we do not even have a way +to name the different types, because they are anonymous. For another, the reason +we reached for a vector and `join_all` in the first place was to be able to work +with a dynamic collection of futures where we do not know what they will all be +until runtime. + +To make this work, we need to use *trait objects*, just as we did for returning +different kinds of errors from the same function in [Returning Errors from the +run function][dyn] back in Chapter 12. Again, we will cover trait objects in +detail in Chapter 17. Here, it lets us treat each of the anonymous futures +produced by these types as interchangeable, since all of them by definition +implement the `Future` trait. + +We can start by wrapping each of the futures in the `vec!` in a `Box::new()`. +Unfortunately, the initial way we might try this, as shown in Listing 17-TODO, +still does not compile. + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:here}} +``` + + + +In fact, we have the same basic error we did before, but we get one for both the +second and third `Box::new` calls, and we also get new errors referring to the +`Unpin` trait. + +We can start by fixing the type error around the `Box::new` calls, by telling +the compiler explicitly that we want to use these types as trait objects. The +clearest way to do that here is by adding a type annotation to the declaration +of `futures`, as we see in Listing 17-TODO. The type we have to write here is a +little involved, so let’s walk through each part of it. + +- The innermost type is the future itself. We note explicitly that it the output + of the future is the unit type `()` by writing `Future`. +- Then we annotate the trait with `dyn` to mark it as dynamic. +- The entire trait is wrapped in a `Box`. +- Finally, we state explicitly that `futures` is a `Vec` containing these items. + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} +``` + + + +That already made a big difference. Now when we run the compiler, we only have +the errors mentioning `Unpin`, each of which is a variation on this same output: + + + +```text +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:33 + | +46 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `Future` +note: required by a bound in `futures_util::future::join_all::JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` +``` + +That is a *lot* to digest, so let’s pull it apart. The first part of the message +tell us that the first async block (`src/main.rs:8:23: 20:10`) does not +implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve +it. The rest of the message tells us *why* that is required: the `JoinAll` +struct, which is itself a `Future`, is also generic over a `Future`, and +`Future` itself requires the `Unpin` trait. Understanding this error means we +need to dive into a little more of how the `Future` type actually works, in +particular the idea of *pinning*. + +### Pinning and the Pin and Unpin Traits + +When we introduced the `Future` trait in the previous chapter, we saw that the +definition of its `poll` method has an unusual way of specifying the `self` +parameter. To review, here is the full definition of `Future`: + +```rust +pub trait Future { + type Output; + + // Required method + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; +} +``` + +We have not seen a method definition like this before, where `self` has a type +annotation rather than simply being named like `self`, `mut self`, `&self`, or +`&mut self`. This syntax means that the method can only be called when the +instance of the type which implements `Future` is behind a `Pin` pointer type. +This syntax is not specific to `Pin`; it also works with `Box` and other smart +pointer types, and we will see it again in Chapter 18. + +Here, the signature tells us that if we want to poll a future to check whether +it is `Pending` or `Ready(Output)`, the type which implements `Future` has to be +behind a `Pin` smart pointer type. Recalling that `.await` is implemented in +terms of calls to `poll()`, this starts to explain the error message we saw +above—but that was in terms of `Unpin`, not `Pin`. So what exactly are `Pin` and +`Unpin`, how do they relate, and why does `Future` need `self` to be in a `Pin` +type to call `poll`? + + + +Remember that any time you write a future, a runtime is ultimately responsible +for executing it. That means that an async block might outlive the function +where you write it, the same way a closure can. + +`Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. +Recall that marker traits have no functionality of their own. They exist only to +tell the compiler that it is safe to use the type which implements a given trait +in certain context. Just like `Send` and `Sync`, the compiler implements `Unpin` +automatically for most types. + +`Unpin`’s job is to tell the compiler that a given type does *not* need to +uphold any particular guarantees about whether the value in question can be +moved. For example, if a future + + + + + +Now we know enough to understand the error message from above. The problem is +that the futures produced by an async block are *not* pinned by default. +Strictly: they implement `!Unpin` to opt out of being copyable by default the +way most types are. We need to pin them explicitly. + +Now that we have an idea what that error message was telling us, we can finally +get our `join_all` call to compile! First, we need to explicitly annotate +`futures` as referring to a pinned `Box` of futures. Second, we actually need to +pin the futures, which we can do using the handy `Box::pin` API, which exists +for exactly this. Putting that together, we end up with the code in Listing +17-TODO. + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:here}} +``` + + + +If we compile and run this, we finally get the output we hoped for: + + + +```text +received 'hi' +received 'more' +received 'from' +received 'messages' +received 'the' +received 'for' +received 'future' +received 'you' +``` + +Phew! + +There is a bit more we can explore here. For one thing, using `Pin>` +comes with a small amount of extra overhead from putting these futures on the +heap with `Box`—and we are only doing that to get the types to line up. We don’t +actually *need* the heap allocation, after all: these futures are local to this +particular function. As noted above, `Pin` is itself a smart pointer, so we can +get the benefit of having a single type in the `Vec`—the original reason we +reached for `Box`—without doing a heap allocation. We can use `Pin` directly +instead. + +The `std::pin::pin` macro exists to do just that for values. However, we must +still be explicit about the type of the pinned reference; otherwise Rust will +still not know to interpret these as dynamic trait objects, which is what we +need them to be in the `Vec`. We therefore `pin!` each future when we define it, +and define `futures` as a `Vec` containing pinned mutable references to the +dynamic `Future` type. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} +``` + + + +This keeps everything on the stack, and that is a nice little performance win, +but it is still a lot of explicit types, which is quite unusual for Rust! There +is another problem, too. We got this far by ignoring the fact that we might have +different `Output` types. For example, in Listing 17-TODO, the anonymous future +type for `a` implements `Future` and the anonymous future type for +`b` implements `Future`. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} +``` + + + +We can use `trpl::join!` to await them together, since it accepts two different +future types, but we cannot use `trpl::join_all` with these futures, because we +will never be able to make them have the same type. (This is the same as working +with any other type in Rust, though: futures are not special, even though we +have some nice syntax for working with them, and that is a good thing!) We have +a basic tradeoff here: we can either deal with a dynamic number of futures with +`join_all`, as long as they all have the same type, or we can deal with a +static number of futures with `join!`, and so on, + + +In practice, you will usually work directly with `async` and `.await`, and only +as a secondary tool reach for the functions like `join` or `join_all`, or their +corresponding macro equivalents. These kinds of tools are really handy for +building frameworks, or especially when you are building a runtime itself. diff --git a/src/ch17-04-TODO.md b/src/ch17-04-TODO.md new file mode 100644 index 0000000000..6ef578bdf2 --- /dev/null +++ b/src/ch17-04-TODO.md @@ -0,0 +1,107 @@ +## TODO: Title This Section! + +### Race + +Thus far, we have only used the `join` family of functions and macros. When we +“join” on some collection of futures, we require *all* of them to finish before +we move on. Sometimes, though, we only need *some* future from a set to finish +before we move on—kind of like racing one future against another. This operation +is often named `race` for exactly that reason. + +In Listing 17-TODO, we use `race` to run two futures, `slow` and `fast` against +each other. First, we introduce the two futures. Each one prints a message when +it starts running, pauses for some amount of time by calling and awaiting +`sleep`, and then prints another message when it finishes. Then we pass both to +`trpl::race` and wait for one of them to finish. (The outcome here won’t be too +surprising: `fast` wins!) + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-race/src/main.rs:here}} +``` + + + +One other thing to notice: if you flip the order of the arguments to `race`, the +order of the start messages changes, but the `fast` future always completes +first. That is because the implementation of this particular `race` function is +not *fair*. It always runs the futures passed as arguments in the order they are +passed. That means everything up to the first `.await` in a given future will +run before *any* of the other future gets a chance to run. Other implementations +*are* fair, and will randomly choose which future to start first. + +This dynamic is important to keep in mind! An async runtime can only switch +which future it is executing at await points. That means if you load up a bunch +of really expensive work in an async function, it will block any other futures +from making progress. (You may sometimes hear this referred to as one future +*starving* other futures. The same thing applies to threads, too!) We can work +around this using the `sleep` function, as in Listing 17-TODO. + + + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs:here}} +``` + + + +However, we do not actually need to sleep to accomplish this. We just need to +hand back control to the runtime. We can actually *yield* control back to the +runtime, using a function named `yield_now`. It does just what it says: hands +control back to the runtime, so that the runtime can check whether any other +tasks are ready to make progress. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-b-yield/src/main.rs:here}} +``` + + + +This is both clearer about the actual intent and can be significantly faster +than using `sleep`, because timers like the one used by `sleep` often have +limits to how granular they can be. The version of `sleep` we are using, for +example, will always sleep for at least a millisecond, even if we pass it a +`Duration` of one nanosecond. Again, modern computers are *fast*: they can do a +lot in one millisecond! + +You can see this for yourself by comparing what happens if you change Listings +17-TODO and 17-TODO to both do 100 or 1,000 iterations instead of just 5. The +version with `yield_now` is *way* faster! + + + + + +Many of these patterns are common enough to warrant abstracting over. For +example, the `trpl::timeout` function takes a `Duration` for the maximum time to +run, but also takes a future to run, and produces a new future you can await, +whose `Output` type is a `Result`. Listing 17-TODO shows how we can use it. If +the passed-in future finishes first, the output result will be `Ok`, with the +result of that passed-in future. If the duration elapses before the passed-in +future finishes, the result will be `Err` with the duration that elapsed. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout-a/src/main.rs:here}} +``` + + + +Here we were using the `timeout` supplied by `trpl`, but we do not have to. We +can implement it ourselves using the + +[collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types +[dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html +[futures]: /ch17-01-futures-and-syntax.html#futures diff --git a/src/ch17-03-futures-tasks-threads.md b/src/ch17-05-futures-tasks-threads.md similarity index 100% rename from src/ch17-03-futures-tasks-threads.md rename to src/ch17-05-futures-tasks-threads.md From 86835d655b4a80097fba8e17ffa72884647ede85 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 6 Jun 2024 11:59:17 -0600 Subject: [PATCH 273/720] Ch. 17: Show worked example of implementing `timeout` --- .../listing-17-timeout-final/src/main.rs | 5 ++ src/ch17-04-TODO.md | 81 +++++++++++++++++-- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/listings/ch17-async-await/listing-17-timeout-final/src/main.rs b/listings/ch17-async-await/listing-17-timeout-final/src/main.rs index dc40b89329..7d8ad2ca47 100644 --- a/listings/ch17-async-await/listing-17-timeout-final/src/main.rs +++ b/listings/ch17-async-await/listing-17-timeout-final/src/main.rs @@ -18,12 +18,17 @@ fn main() { }); } +// ANCHOR: timeout + +// ANCHOR: declaration async fn timeout( max_time: Duration, future: F, ) -> Result { + // ANCHOR_END: declaration match trpl::race(future, trpl::sleep(max_time)).await { Either::Left(output) => Ok(output), Either::Right(_) => Err(max_time), } } +// ANCHOR_END: timeout diff --git a/src/ch17-04-TODO.md b/src/ch17-04-TODO.md index 6ef578bdf2..f934008366 100644 --- a/src/ch17-04-TODO.md +++ b/src/ch17-04-TODO.md @@ -79,9 +79,7 @@ version with `yield_now` is *way* faster! - +### Building Our Own Async Abstractions Many of these patterns are common enough to warrant abstracting over. For example, the `trpl::timeout` function takes a `Duration` for the maximum time to @@ -91,7 +89,7 @@ the passed-in future finishes first, the output result will be `Ok`, with the result of that passed-in future. If the duration elapses before the passed-in future finishes, the result will be `Err` with the duration that elapsed. -+ ```rust {{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout-a/src/main.rs:here}} @@ -100,7 +98,80 @@ future finishes, the result will be `Err` with the duration that elapsed. Here we were using the `timeout` supplied by `trpl`, but we do not have to. We -can implement it ourselves using the +can implement it ourselves using `race` and `sleep`! To begin, let’s think about +the API of `timeout`: + +- Its first parameter is a `std::time::Duration` which specifies the maximum + time to wait. +- Its second parameter is the future to run. +- It returns a `Result`. If the future completes successfully, the `Result` will + be `Ok` with the value produced by the future. If the timeout happens, the + `Result` will be `Err` with the duration that the timeout waited for. + +We can write the same signature ourselves, as in Listing 17-TODO. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout-final/src/main.rs:declaration}} +``` + + + +What about the body of the function? Here, we can `race` whatever future the +caller passes with a `sleep` future. + +When we saw `race` earlier in Listing 17-TODO, we ignored its return type, +because we were just interested in seeing the behavior of `fast` and `slow` when +we ran the program. Here, though, its return value tells us whether the future +or the sleep finished first. With `race`, both futures passed as arguments can +legitimately “win,” so it does not make sense to use a `Result` to represent the +return type. Instead, it returns a similar type called `Either`. Like `Result`, +`Either` can be one of two types, but unlike `Result`, there is no notion of +success or failure baked into the type. Instead, it uses `Left` and `Right` to +indicate “one or the other”. Its implementation looks like this: + +```rust +enum Either { + Left(A), + Right(B) +} +``` + +In the case of `race` specifically, it returns `Left` if the first argument +finishes first, with that future’s output, and `Right` with the second future +argument’s output if *that* one finishes first. + +```rust,ignore +match race(future_a, future_b).await { + Either::Left(output_from_future_a) => /* ... */, + Either::Right(output_from_future_b) => /* ... */, +} +``` + +That gives us enough to be able to implement `timeout` ourselves using `race` +and `sleep`. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout-final/src/main.rs:timeout}} +``` + + + +Let’s walk through the details. Since we know from earlier that `race` is not +fair, and will prefer the first argument to the second, we pass it the future +first so it gets a chance to complete even if the caller passes in a very short +value for `max_time`. Then we match on the result of awaiting the `race`. If the +future passed in by the caller finished first, we will have +`Either::Left(output)`, which we can return as a success with `Ok`. If the sleep +finished first, we will have `Either::Right(())` instead, since `timeout` +returns the unit type `()` if it succeeds. We can ignore that `()` by using `_` +and return `Err` with the duration the user passed in instead. And that’s it! + +Back in `main`, we can call this new `timeout` function exactly like we called +`trpl::timeout` before. [collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html From a364865195cc252fcebcccdc21c1c867bdcc7b84 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 6 Jun 2024 14:09:24 -0600 Subject: [PATCH 274/720] =?UTF-8?q?Ch.=2017=20=C2=A704:=20Show=20perforanc?= =?UTF-8?q?e=20of=20`sleep`=20vs.=20`yield=5Fnow`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-yield-c-performance/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-yield-c-performance/Cargo.toml | 9 + .../src/main.rs | 34 ++ src/ch17-04-TODO.md | 25 +- 4 files changed, 602 insertions(+), 6 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-yield-c-performance/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-yield-c-performance/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-yield-c-performance/src/main.rs diff --git a/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.lock b/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.toml b/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-yield-c-performance/src/main.rs b/listings/ch17-async-await/listing-17-yield-c-performance/src/main.rs new file mode 100644 index 0000000000..ef99235640 --- /dev/null +++ b/listings/ch17-async-await/listing-17-yield-c-performance/src/main.rs @@ -0,0 +1,34 @@ +use std::time::{Duration, Instant}; + +fn main() { + trpl::block_on(async { + // ANCHOR: here + let one_ns = Duration::from_nanos(1); + let start = Instant::now(); + async { + for _ in 1..1000 { + trpl::sleep(one_ns).await; + } + } + .await; + let time = Instant::now() - start; + println!( + "'sleep' version finished after {} seconds.", + time.as_secs_f32() + ); + + let start = Instant::now(); + async { + for _ in 1..1000 { + trpl::yield_now().await; + } + } + .await; + let time = Instant::now() - start; + println!( + "'yield' version finished after {} seconds.", + time.as_secs_f32() + ); + // ANCHOR_END: here + }); +} diff --git a/src/ch17-04-TODO.md b/src/ch17-04-TODO.md index f934008366..3ebab93361 100644 --- a/src/ch17-04-TODO.md +++ b/src/ch17-04-TODO.md @@ -73,11 +73,24 @@ example, will always sleep for at least a millisecond, even if we pass it a `Duration` of one nanosecond. Again, modern computers are *fast*: they can do a lot in one millisecond! -You can see this for yourself by comparing what happens if you change Listings -17-TODO and 17-TODO to both do 100 or 1,000 iterations instead of just 5. The -version with `yield_now` is *way* faster! +You can see this for yourself by setting up a little benchmark, like the one in +Listing 17-TODO. (This is not an especially rigorous way to do performance +testing, but it suffices to show the difference here.) Here, we skip all the +status printing, pass a one-nanosecond `Duration` to `sleep`, let each future +run by itself so that they do not interfere with each other, and get rid of all +the status printing that we did to see the back-and-forth between tasks in +Listings 17-TODO and 17-TODO. Then we run for 1,000 iterations and see how long +`sleep` takes vs. `yield_now`. - ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-c-performance/src/main.rs:here}} +``` + + + +The version with `yield_now` is *way* faster! ### Building Our Own Async Abstractions @@ -118,8 +131,8 @@ We can write the same signature ourselves, as in Listing 17-TODO. -What about the body of the function? Here, we can `race` whatever future the -caller passes with a `sleep` future. +Then, in the body of the function, we can `race` whatever future the caller +passes with a `sleep` future. When we saw `race` earlier in Listing 17-TODO, we ignored its return type, because we were just interested in seeing the behavior of `fast` and `slow` when From f4cd9d2bb6c28dd0643f51df9fa6686db4f0df15 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 7 Jun 2024 07:43:20 -0600 Subject: [PATCH 275/720] =?UTF-8?q?Ch.=2017=20=C2=A701:=20rephrase=20note?= =?UTF-8?q?=20about=20the=20details=20we=20don=E2=80=99t=20get=20into?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-01-futures-and-syntax.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 8e943e3b4a..66242dbaa1 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -293,13 +293,16 @@ executes code. > > The loop as written also wouldn’t compile, because it doesn’t actually satisfy > the contract for a `Future`. In particular, `hello_async_fut` is not *pinned* -> with the `Pin` type and we did not pass along a `Context` argument. +> with the `Pin` type and we did not pass along a `Context` argument. We will +> see a little more about `Pin` later in the chapter, but we will not dig into +> `Context` because you will not normally need them for working with futures in +> day-to-day Rust code. > -> More details here are beyond the scope of this book, but are well worth -> digging into if you want to understand how things work “under the hood.” In -> particular, see [Chapter 2: Under the Hood: Executing Futures and -> Tasks][under-the-hood] and [Chapter 4: Pinning][pinning] in the official -> [_Asynchronous Programming in Rust_][async-book] book. +> If you want to understand how things work “under the hood,” though, the +> official [_Asynchronous Programming in Rust_][async-book] book covers them: +> +> - [Chapter 2: Under the Hood: Executing Futures and Tasks][under-the-hood] +> - [Chapter 4: Pinning][pinning]. Now, that’s a lot of work to just print a string, but we have laid some key foundations for working with async in Rust! Now that you know the basics of how From b5010d1cdde5e9ae6a1220068e3c31d9dc132108 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 7 Jun 2024 07:43:20 -0600 Subject: [PATCH 276/720] =?UTF-8?q?Ch.=2017=20=C2=A701:=20Add=20necessary?= =?UTF-8?q?=20background=20for=20=C2=A704=20to=20make=20sense?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix some infelicitous wording along the way, and leave a TODO item to come back to for making more sense out of the text as it stands at the conclusion of the chapter. --- src/ch17-01-futures-and-syntax.md | 60 +++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 66242dbaa1..983c4e25e8 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -221,12 +221,14 @@ enum Poll { } ``` -You may notice that this `Poll` type is a lot like an `Option`. Having a -dedicated type lets Rust treat `Poll` differently from `Option`, though, which -is important since they have very different meanings! The `Pending` variant -indicates that the future still has work to do, so the caller will need to check -again later. The `Ready` variant indicates that the `Future` has finished its -work and the `T` value is available. +You may notice that this `Poll` type is a lot like an `Option`: it has one +variant which has a value (`Ready(T)` and `Some(T)`), and one which does not +(`Pending` and `None`). Having a dedicated type lets Rust treat `Poll` +differently from `Option`, though, which is important since they have very +different meanings! The `Pending` variant indicates that the future still has +work to do, so the caller will need to check again later. The `Ready` variant +indicates that the `Future` has finished its work and the `T` value is +available. > Note: With most futures, the caller should not call `poll()` again after the > future has returned `Ready`. Many futures will panic if polled after becoming @@ -265,19 +267,47 @@ loop { } ``` -When we use `.await`, Rust actually does compile it to something very similar to -that loop. If Rust compiled it to *exactly* that code, though, every `.await` -would block the computer from doing anything else—the opposite of what we were -going for! Instead, Rust internally makes sure that the loop can hand back -control to the the context of the code where which is awaiting this little bit -of code. +When we use `.await`, Rust compiles it to something fairly similar to that loop. +If Rust compiled it to *exactly* that code, though, every `.await` would block +the computer from doing anything else—the opposite of what we were going for! +Instead, Rust needs makes sure that the loop can hand off control to something +which can pause work on this future and work on other futures and check this one +again later. That “something” is an async runtime, and this scheduling and +coordination work is one of the main jobs for a runtime. + +Every *await point*—that is, every place where the code explicitly calls +`.await`—represents one of those places where control gets handed back to the +runtime. To make that work, Rust needs to keep track of the state involved in +the async block, so that the runtime can kick off some other work and then come +back when it is ready to try advancing this one again. This is an invisible +state machine, as if you wrote something like this: + +```rust +enum MyAsyncStateMachine { + FirstAwaitPoint(/* the state used after the first await point */), + SecondAwaitPoint(/* the state used after the second await point */), + // etc. for each `.await` point... +} +``` + +Writing that out by hand would be tedious and error-prone—especially when making +changes to code later. Async Rust creates that state machine for us, and it +really is an `enum` like this, just an anonymous one you don’t have to name. As +a result, the normal rules around data structures all apply, including for +borrowing and ownership. Happily, the compiler also handles checking that for +us, and has good error messages. We will work through a few of those later in +the chapter! This is enough information to let us keep following the chain back +up to the root of our original problem with running async functions. + + When we follow that chain far enough, eventually we end up back in some non-async function. At that point, something needs to “translate” between the -async and sync worlds. That “something” is the runtime! Whatever runtime you use +async and sync worlds. That “something” is also the runtime! Whatever runtime you use is what handles the top-level `poll()` call, scheduling and handing off between -the different async operations which may be in flight, and often also providing -async versions of functionality like file I/O. +the different async operations which may be in flight as they hand back control +at await points, and often also providing async versions of functionality like +file I/O. Now we can understand why the compiler was stopping us in Listing 17-2 (before we added the `trpl::block_on` function). The `main` function is not `async`—and From 13adef4cfd2d563765876073bcaf395667ed643a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 7 Jun 2024 07:43:20 -0600 Subject: [PATCH 277/720] =?UTF-8?q?Ch.=2017=20=C2=A704:=20Explain=20the=20?= =?UTF-8?q?*implications*=20of=20yielding=20to=20motivate=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-timeout-final/src/main.rs | 2 + src/ch17-04-TODO.md | 83 ++++++++++++++----- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/listings/ch17-async-await/listing-17-timeout-final/src/main.rs b/listings/ch17-async-await/listing-17-timeout-final/src/main.rs index 7d8ad2ca47..eaee49d51b 100644 --- a/listings/ch17-async-await/listing-17-timeout-final/src/main.rs +++ b/listings/ch17-async-await/listing-17-timeout-final/src/main.rs @@ -9,7 +9,9 @@ fn main() { "Finally finished" }; + // ANCHOR: main match timeout(Duration::from_secs(2), slow).await { + // ANCHOR_END: main Ok(message) => println!("Succeeded with '{message}'"), Err(duration) => { println!("Failed after {} seconds", duration.as_secs()) diff --git a/src/ch17-04-TODO.md b/src/ch17-04-TODO.md index 3ebab93361..ca525619e7 100644 --- a/src/ch17-04-TODO.md +++ b/src/ch17-04-TODO.md @@ -1,7 +1,5 @@ ## TODO: Title This Section! -### Race - Thus far, we have only used the `join` family of functions and macros. When we “join” on some collection of futures, we require *all* of them to finish before we move on. Sometimes, though, we only need *some* future from a set to finish @@ -24,19 +22,50 @@ surprising: `fast` wins!) One other thing to notice: if you flip the order of the arguments to `race`, the -order of the start messages changes, but the `fast` future always completes -first. That is because the implementation of this particular `race` function is -not *fair*. It always runs the futures passed as arguments in the order they are -passed. That means everything up to the first `.await` in a given future will -run before *any* of the other future gets a chance to run. Other implementations -*are* fair, and will randomly choose which future to start first. - -This dynamic is important to keep in mind! An async runtime can only switch -which future it is executing at await points. That means if you load up a bunch -of really expensive work in an async function, it will block any other futures -from making progress. (You may sometimes hear this referred to as one future -*starving* other futures. The same thing applies to threads, too!) We can work -around this using the `sleep` function, as in Listing 17-TODO. +order of the start messages changes, even though the `fast` future always +completes first. That is because the implementation of this particular `race` +function is not *fair*. It always runs the futures passed as arguments in the +order they are passed. Other implementations *are* fair, and will randomly +choose which future to start first. + +Regardless of whether the implementation of race we are using is fair, though, +*one* of the futures will run up to the first `.await` in its body before +another task can start. + +To see why, recall from our discussion of [Futures][futures that Rust compiles +async blocks in a way that hands control back to the async runtime at each await +point. That has an important corollary: async runtimes can only switch which +future they are executing at await points. Everything in between await points is +just normal synchronous Rust code. That means if you do a bunch of really +expensive work in an async function without an `.await`, that future will block +any other futures from making progress. + +> Note: You may sometimes hear this referred to as one future *starving* other +> futures. The same thing applies to threads, too! + +That has another important consequence for using `race`, `join`, or other tools +like them. *Some* future is going to run first, and everything up to the first +await point in that future will run before any part of any other futures gets a +chance to run. For simple code, that may not be a big deal. However, if you are +doing some kind of expensive setup or long-running work, or if you have a future +which will keep doing some particular task indefinitely, you will need to think +about when and where to hand control back to the runtime. + +### Yielding + +Let’s consider a long-running operation. Here, we will simulate it using `sleep` +inside the function, but in the real world it could be a network call or +really any operation which might take a while. + + + +Since we know that we hand off control at await points, we also know that we +need a future to await. As a starting point, we could use the `sleep` function, +as in Listing 17-TODO. -Since we know that we hand off control at await points, we also know that we -need a future to await. As a starting point, we could use the `sleep` function, -as in Listing 17-TODO. + - +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-0-blocked/src/main.rs:slow}} +``` + + + +In Listing 17-TODO we have this kind of slow work in a pair of futures which +only hand control back to the runtime *after* carrying out a bunch of slow +operations, represented by calls to `slow`: + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-0-blocked/src/main.rs:slow-futures}} +``` + + + +If you run this, you will see this output: + + + +```text +'a' started. +'a' ran for 300ms +'a' ran for 100ms +'a' ran for 200ms +'a' ran for 900ms +'b' started. +'b' ran for 750ms +'b' ran for 100ms +'b' ran for 150ms +'b' ran for 350ms +'b' ran for 150ms +'a' finished. +``` + +As with our earlier example, `race` still finishes when `a` finishes. There is +no interleaving between the two futures, though. The `a` future does all of its +work until the `trpl::sleep` call is awaited, then the `b` future does all of +its work until its own `trpl::sleep` call is awaited, and then the `a` future +completes. It would be better if both futures could make progress between their +slow tasks. We need some way to hand control back to the runtime there—and we +know that await points are the way to do that. However, that means we need +something we can await! + +However, we can also see the handoff happening in this very example: if we +removed the `trpl::sleep` at the end of the `a` future, it would complete +without the `b` future running *at all*. Given that, maybe we could use the +`sleep` function as a starting point, as in Listing 17-TODO. @@ -81,6 +126,12 @@ as in Listing 17-TODO. +Now the two futures’ work is interleaved. The `a` future still runs for a bit +before handing off control to `b`, because it has some expensive work to do up +front, but after that they just swap back and forth every time one of them hits +an await point. In this case, we have done that after ever call to `slow`, but +we could break up the work however makes the most sense to us. + However, we do not actually need to sleep to accomplish this. We just need to hand back control to the runtime. We can actually *yield* control back to the runtime, using a function named `yield_now`. It does just what it says: hands From e56e906d7e919228946243f628818f233a8b4f50 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 7 Jun 2024 13:39:05 -0600 Subject: [PATCH 279/720] =?UTF-8?q?Ch.=2017=20=C2=A704:=20Add=20a=20good?= =?UTF-8?q?=20transition=20sentence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-04-TODO.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ch17-04-TODO.md b/src/ch17-04-TODO.md index 8a5180c0e8..332df00b1a 100644 --- a/src/ch17-04-TODO.md +++ b/src/ch17-04-TODO.md @@ -172,6 +172,10 @@ Listings 17-TODO and 17-TODO. Then we run for 1,000 iterations and see how long The version with `yield_now` is *way* faster! +In real-world code, you will not usually be alternative regular function calls +with await points on every single line, of course. The underlying dynamic is an +important one to keep in mind, though! + ### Building Our Own Async Abstractions Many of these patterns are common enough to warrant abstracting over. For From 95422ab0118cf5e273a59dd52ec86f8ecfd1ea3e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 7 Jun 2024 13:40:21 -0600 Subject: [PATCH 280/720] =?UTF-8?q?Ch.=2017=20=C2=A704:=20add=20a=20Note?= =?UTF-8?q?=20about=20cooperative=20multitasking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-04-TODO.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ch17-04-TODO.md b/src/ch17-04-TODO.md index 332df00b1a..1b886dc72f 100644 --- a/src/ch17-04-TODO.md +++ b/src/ch17-04-TODO.md @@ -59,12 +59,6 @@ function “slow” will just take a number of milliseconds to run, and sleep t thread for that long. This is intentionally not an async function, because the idea is to represent work that is *not* async. - - ```rust @@ -172,6 +166,14 @@ Listings 17-TODO and 17-TODO. Then we run for 1,000 iterations and see how long The version with `yield_now` is *way* faster! +> Note: This also means that async can be a useful tool even for CPU-bound +> tasks, depending on what else your program is doing, because it provides a +> useful tool for structuring the relationships between different parts of the +> program. This is a form of *cooperative multitasking*, where each future has +> both the power to determine when it hands over control via await points and +> therefore also the *responsibility* to avoid blocking for too long. This is +> how some Rust-based embedded operating systems work! + In real-world code, you will not usually be alternative regular function calls with await points on every single line, of course. The underlying dynamic is an important one to keep in mind, though! From b3931efad3ecc482ab45e814b340f29f327122e6 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 7 Jun 2024 13:40:21 -0600 Subject: [PATCH 281/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20Add=20more=20exp?= =?UTF-8?q?lanatory=20material=20on=20`Pin`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is far from complete, but at least takes another reasonable step toward an explanation, while keeping the level of detail relatively manageable, I think. --- src/ch17-03-more-futures.md | 82 ++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index c8f1a63f65..2ec7d2e221 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -26,8 +26,8 @@ pattern. The `trpl::join_all` function accepts any type which implements the `Iterator` trait, which we learned about back in Chapter 13, so it seems like just the -ticket. Let’s try putting our futures in a vector, so we can swap out our -`join3` call and replace it with `join_all`. +ticket. Let’s try putting our futures in a vector, and replace `join3` with +`join_all`. @@ -227,6 +227,82 @@ type to call `poll`? + + +In [Futures and Syntax: What Are Futures][what-are-futures], we described how +a series of await points in a future get compiled into a state machine—and noted +how the compiler helps make sure that state machine follows all of Rust’s normal +rules around safety, including borrowing and ownership. Consider code like this: + + + +```rust +async { + let mut strings = vec![]; + + let a = trpl::read_to_string("test-data/hello.txt").await.unwrap(); + strings.push(a.trim()); + + let b = trpl::read_to_string("test-data/world.txt").await.unwrap(); + strings.push(b.trim()); + + let combined = strings.join(" "); + println!("{combined}"); +} +``` + +If we think about the state machine that would get compiled to, it might be +something kind of like this: + +```rust,ignore +enum AsyncStateMachine<'a> { + FirstAwait(&'a mut Vec), + SecondAwait(&'a mut Vec), +} +``` + +This could actually be fine, on its own—Rust would keep track of those mutable +references, and if we got something wrong, the borrow checker would tell us. It +gets a bit tricky, though, if we want to move around the future that corresponds +to that block. Remember, we could always do something like this: + +```rust,ignore +let file_reads_future = async { + // snip... +}; + +let some_other_future = async { + // snip... +}; + +trpl::join(file_reads_future, some_other_future).await; +``` + +If we pass those futures into `join`, or return them from a function, or put +them in a data structure to keep track of for some reason, we move the state +machine as well, and that means the `Vec` for the values we read in with +`trpl::read_to_string` moves. But the state machine Rust generated for us has +references to it. Since references point to the actual memory address of the +`Vec`, Rust needs some way to either update them so they are still valid after +the `Vec` moves, or it needs some way to keep `Vec` from getting moved around so +that the references do not need to be updated. Updating all the references to an +object every time it moves could be quite a lot of work for the compiler to add, +especially since there can be a whole web of references that need updating. On +the other hand, making sure the underlying item *does not move in memory* can be +“free” at runtime in exchange for keeping some promises at compile time. That is +where `Pin` and `Unpin` come in. + + + +> Note: This allows a whole class of complex types to be safe in Rust which are +> otherwise difficult to implement. + Remember that any time you write a future, a runtime is ultimately responsible for executing it. That means that an async block might outlive the function where you write it, the same way a closure can. +> Note: The specific mechanics for how `Pin` and `Unpin` work under the hood are +> covered extensively in the API documentation for `std::pin`, so if you would +> like to understand them more fundamentally, that is a great place to start. +> Those details are not at all necessary for working with async Rust day to day, +> though. Here, we will stick to the parts you *do* need to understand to work +> with them in everyday Rust! + +`Pin` is a smart pointer, which only works with *other pointer types*, including +references, `Box`, `Rc`, and so on. (Technically, it works with any type which +implements the `Deref` trait, which we covered in Chapter 15; you can think of +this restriction as equivalent to only working with pointers, though, since +implementing `Deref` means your type behaves like a pointer type.) Wrapping a +pointer type in `Pin` enforces the exact guarantee we need: the value *behind* +the pointer we wrap in `Pin` cannot move. It is “pinned” in its current spot by +the `Pin` wrapper. -> Note: This allows a whole class of complex types to be safe in Rust which are -> otherwise difficult to implement. + Remember that any time you write a future, a runtime is ultimately responsible for executing it. That means that an async block might outlive the function where you write it, the same way a closure can. +need for pinning, or switch to connecting it to *moving*. --> `Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. Recall that marker traits have no functionality of their own. They exist only to @@ -332,6 +345,14 @@ moved. For example, if a future My head hurts. --> +> Note: This combination of `Pin` and `Unpin` allows a whole class of complex +> types to be safe in Rust which are otherwise difficult to implement because +> they are *self-referential*. That is, they are data structures where one part +> of the structure refers to another internally. As we have seen, futures can +> match that description, so self-referential types which require `Pin` show up +> *most* commonly in async Rust today, but you might see it come up in other +> contexts, too. + Now we know enough to understand the error message from above. The problem is that the futures produced by an async block are *not* pinned by default. Strictly: they implement `!Unpin` to opt out of being copyable by default the From a97358e0c1d3933f6b2dcee832caa6d4967facc8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 10 Jun 2024 14:25:58 -0600 Subject: [PATCH 284/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20Finish=20a=20fir?= =?UTF-8?q?st=20pass=20on=20explaining=20`Pin`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-02-concurrency-with-async.md | 23 ++++-- src/ch17-03-more-futures.md | 107 +++++++++++++------------- 2 files changed, 69 insertions(+), 61 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index e80b7605d4..d6189a565d 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -339,16 +339,23 @@ exploration helps us understand why: it is ultimately about *ownership*. We need to move `tx` into the async block so that once that block ends, `tx` will be dropped. -In Chapter 13, we learned how to use the `move` keyword with closures, and in -Chapter 16, we saw that we often need to use closures marked with `move` when -working with threads. As we have discovered, the same dynamics apply to async -blocks—so the `move` keyword also works with async blocks, allowing them to take -ownership of the data they reference. - Since we have seen how `async` blocks borrow the items they reference from their outer scope, we can go ahead and remove the extra block we just added for now, -and switch back from `join3` to `join`. Then we can change the first async block -from an `async` block to an `async move` block, as in Listing 17-TODO: +and switch back from `join3` to `join`. + +The last step here is to figure out how to get ownership of the data instead of +just borrowing it. In Chapter 13, we learned how to use the `move` keyword with +closures, and in Chapter 16, we saw that we often need to use closures marked +with `move` when working with threads. As we have discovered, the same dynamics +apply to async blocks! Hopefully this will make sense if you remember that any +time you write a future, a runtime is ultimately responsible for executing it. +That means that an async block might outlive the function where you write it, +the same way a closure can. When a future takes ownership of the data it +references this way, it needs to move that data into the future—so the `move` +keyword works with async blocks just like it does with closures. + +Thus, we can change the first async block from an `async` block to an `async +move` block, as in Listing 17-TODO: diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index f2be660261..14b0435e57 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -305,53 +305,54 @@ where `Pin` and `Unpin` come in. > though. Here, we will stick to the parts you *do* need to understand to work > with them in everyday Rust! -`Pin` is a smart pointer, which only works with *other pointer types*, including -references, `Box`, `Rc`, and so on. (Technically, it works with any type which -implements the `Deref` trait, which we covered in Chapter 15; you can think of -this restriction as equivalent to only working with pointers, though, since -implementing `Deref` means your type behaves like a pointer type.) Wrapping a -pointer type in `Pin` enforces the exact guarantee we need: the value *behind* -the pointer we wrap in `Pin` cannot move. It is “pinned” in its current spot by -the `Pin` wrapper. - - - -Remember that any time you write a future, a runtime is ultimately responsible -for executing it. That means that an async block might outlive the function -where you write it, the same way a closure can. - -`Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. -Recall that marker traits have no functionality of their own. They exist only to -tell the compiler that it is safe to use the type which implements a given trait -in certain context. Just like `Send` and `Sync`, the compiler implements `Unpin` -automatically for most types. - -`Unpin`’s job is to tell the compiler that a given type does *not* need to -uphold any particular guarantees about whether the value in question can be -moved. For example, if a future - - - - +`Pin` is a smart pointer, much like `Box`, `Rc`, and the others we saw in +Chapter 15. Unlike those, however, `Pin` only works with *other pointer types* +like reference (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To +be precise, `Pin` works with types which implement the `Deref` or `DerefMut` +traits, which we covered in Chapter 15. You can think of this restriction as +equivalent to only working with pointers, though, since implementing `Deref` or +`DerefMut` means your type behaves like a pointer type. including references, +other smart pointers, and so on. + +Wrapping a pointer type in `Pin` enforces the exact guarantee we need: the value +*behind* the pointer we wrap in `Pin` cannot move. It is “pinned” in its current +spot by the `Pin` wrapper. Thus, if you have `Pin>`, you actually +pin the `SomeType` value, *not* the `Box` pointer. In fact, the pinned box +pointer can move around freely. Remember: we care about making sure the data +ultimately being referenced stays in its place. If a pointer moves around, but +the data it points to is in the same place, there is no problem. + +However, most types are perfectly safe to move around, even if they happen to be +behind a `Pin` pointer. Remember: the problem `Pin` addresses is when data +structures have internal references which need to maintained when the structure +moves around, as happens with internal references in futures. Primitive values +like numbers and booleans do not have any internal structure like that, so they +are obviously safe. Neither do most types you normally work with in Rust. A +`Vec`, for example, does not have any internal references it needs to keep up to +date this way, so you can move it around without worrying. But what happens if +you have a `Pin` or a `Pin>`? + +We need a way to tell the compiler that it is actually just fine to move items +around in cases like these where there is nothing to worry about. For that, we +have `Unpin`. `Unpin` is a marker trait, like `Send` and `Sync`, which we saw in +Chapter 16. Recall that marker traits have no functionality of their own. They +exist only to tell the compiler that it is safe to use the type which implements +a given trait in a particular context. `Unpin` informs the compiler that a given +type does *not* need to uphold any particular guarantees about whether the value +in question can be moved. + +Just like `Send` and `Sync`, the compiler implements `Unpin` automatically for +most types, and implementing it manually is unsafe. That is because you have to +make sure that the type for which you are implementing `Unsafe` *never* moves +data out from a reference that *needs* to be stable. > Note: This combination of `Pin` and `Unpin` allows a whole class of complex > types to be safe in Rust which are otherwise difficult to implement because > they are *self-referential*. That is, they are data structures where one part > of the structure refers to another internally. As we have seen, futures can > match that description, so self-referential types which require `Pin` show up -> *most* commonly in async Rust today, but you might see it come up in other -> contexts, too. +> *most* commonly in async Rust today, but you might—very rarely!—see it in +> other contexts, too. Now we know enough to understand the error message from above. The problem is that the futures produced by an async block are *not* pinned by default. @@ -431,20 +432,20 @@ type for `a` implements `Future` and the anonymous future type for We can use `trpl::join!` to await them together, since it accepts two different future types, but we cannot use `trpl::join_all` with these futures, because we -will never be able to make them have the same type. (This is the same as working -with any other type in Rust, though: futures are not special, even though we -have some nice syntax for working with them, and that is a good thing!) We have -a basic tradeoff here: we can either deal with a dynamic number of futures with -`join_all`, as long as they all have the same type, or we can deal with a -static number of futures with `join!`, and so on, +will never be able to make them have the same type. We have a basic tradeoff +here: we can either deal with a dynamic number of futures with `join_all`, as +long as they all have the same type, or we can deal with a set number of futures +with the `join` functions or the `join!` macro, even if they have different +types. This is the same as working with any other type in Rust, though: futures +are not special, even though we have some nice syntax for working with them, and +that is a good thing! - In practice, you will usually work directly with `async` and `.await`, and only as a secondary tool reach for the functions like `join` or `join_all`, or their -corresponding macro equivalents. These kinds of tools are really handy for -building frameworks, or especially when you are building a runtime itself. +corresponding macro equivalents. Likewise, you will only need to reach for `pin` +now and again to use them *with* those APIs. These kinds of tools are mostly +handy for building frameworks, or especially when you are building a runtime +itself, rather than for day to day Rust code. When you see them, though, now you +will know what to do! [what-are-futures]: /ch17-01-futures-and-syntax.html#what-are-futures From 644bc54d0fc189e9f81da2244cb47c7e798d4eb6 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 10 Jun 2024 16:57:22 -0600 Subject: [PATCH 285/720] =?UTF-8?q?Ch.=2017=20=C2=A704:=20Code=20sample=20?= =?UTF-8?q?and=20incomplete=20sentence=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-04-TODO.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ch17-04-TODO.md b/src/ch17-04-TODO.md index 83b74ed876..8c12f079d7 100644 --- a/src/ch17-04-TODO.md +++ b/src/ch17-04-TODO.md @@ -242,7 +242,7 @@ finishes first, with that future’s output, and `Right` with the second future argument’s output if *that* one finishes first. ```rust,ignore -match race(future_a, future_b).await { +match trpl::race(future_a, future_b).await { Either::Left(output_from_future_a) => /* ... */, Either::Right(output_from_future_b) => /* ... */, } @@ -282,7 +282,9 @@ Back in `main`, we can call this new `timeout` function exactly like we called This pattern is quite common and useful. Futures compose with other futures, so you can build really powerful tools using smaller async building blocks. For -example, you can use this same approach to +example, you can use this same approach to combine timeouts with retries, and +in turn use those with things like network calls—the exact example we started +out with at the beginning of the chapter! [collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html From f7861623a15f8d447f4a228bb631337aa101899a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 11 Jun 2024 12:51:35 -0600 Subject: [PATCH 286/720] =?UTF-8?q?Ch.=2017=20=C2=A704:=20Give=20the=20sec?= =?UTF-8?q?tion=20a=20reasonable=20title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SUMMARY.md | 2 +- ...h17-04-TODO.md => ch17-04-more-ways-of-combining-futures.md} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{ch17-04-TODO.md => ch17-04-more-ways-of-combining-futures.md} (99%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index e34b10da22..f161db9097 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -105,7 +105,7 @@ - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) - [Concurrency With Async](ch17-02-concurrency-with-async.md) - [Working With More Futures](ch17-03-more-futures.md) - - [TODO](ch17-04-TODO.md) + - [More Ways of Combining Futures](ch17-04-more-ways-of-combining-futures.md) - [Futures, Tasks, and Threads](ch17-05-futures-tasks-threads.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) diff --git a/src/ch17-04-TODO.md b/src/ch17-04-more-ways-of-combining-futures.md similarity index 99% rename from src/ch17-04-TODO.md rename to src/ch17-04-more-ways-of-combining-futures.md index 8c12f079d7..c5d5fd9c30 100644 --- a/src/ch17-04-TODO.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -1,4 +1,4 @@ -## TODO: Title This Section! +## More Ways of Combining Futures Thus far, we have only used the `join` family of functions and macros. When we “join” on some collection of futures, we require *all* of them to finish before From 617b75559ec74545e300130fe7097678870d4cfb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 12 Jun 2024 11:59:24 -0600 Subject: [PATCH 287/720] =?UTF-8?q?Ch.=2017:=20an=20editing=20pass=20on=20?= =?UTF-8?q?=C2=A700=20and=20the=20start=20of=20=C2=A701?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-00-async-await.md | 31 +++++++------ src/ch17-01-futures-and-syntax.md | 75 ++++++++++++++++++------------- 2 files changed, 62 insertions(+), 44 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 7f97432f95..92928f87a4 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -68,8 +68,8 @@ function calls which interact with files, network sockets, or other resources on the computer, because those are the places where an individual program would benefit from the operation being *non*-blocking. -When doing file downloads, we could work around the fact that the call to write to -a network socket is blocking using threads. If we move the data over to a +When doing file downloads, we could use threads to work around the fact that the +call to write to a network socket is blocking. If we move the data over to a dedicated thread which handles the write operation, it will *not* block the rest of the program. But in many ways, it would be nicer if the call were not blocking in the first place. @@ -87,13 +87,14 @@ network_socket.read_non_blocking(|result| { Or we could register callbacks to run when events happen: ```rust,ignore -network_socket.add_listener(Event::ReadFinished, |data| { +network_socket.add_listener(Event::ReadFinished, |event| { // ... }); ``` Or we could have our functions return a type with `and_then` method, which in -turn accepts a callback which can do more work of the same sort: +turn accepts a callback which can do more work of the same sort (Historically, +this was the way that Rust did async): ```rust,ignore network_socket.read_non_blocking().and_then(|result| { @@ -101,21 +102,23 @@ network_socket.read_non_blocking().and_then(|result| { }); ``` -Historically, this last choice was the way that Rust did async! Each of these -can make the control flow for the program more complicated, though. You can end -up with many nested callbacks, or long chains of callbacks, and understanding -the flow of data through the program can become more difficult as a result. +Each of these can make the control flow for the program more complicated, +though. You can end up with event handler callbacks scattered across the code +base, or groups of deeply nested callbacks, or long chains of `and_then` calls. +Understanding the flow of data through the program can become more difficult as +a result, and dealing with callbacks can also complicate ownership. +There are also no particularly good ways to get data out of those callbacks. With other common types in Rust, we often use pattern-matching in scenarios like this. When we are using callbacks we do not yet have the data at the time we call `read_non_blocking`—and we will not have it until the callback gets called. That means that there is no way to match on the data it will return: it is not here yet! -There are also no particularly good ways to get data out of those callbacks. We -might try something like this, imagining a `read_non_blocking` which has exactly -the kind of `and_then` method described above. If we were to try to use that, -with code something like this, it would not compile: +As an alternative, we might try something like this, imagining a +`read_non_blocking` which has exactly the kind of `and_then` method described +above. If we were to try to do that, though, with code kind of like this, it +would not even compile: ```rust,ignore,does_not_compile let mut data = None; @@ -134,8 +137,8 @@ exit, but if the read *happened* to go fast enough, it is possible it could sometimes print some string data instead. That is *definitely* not what we want! -We also cannot cancel `read_non_blocking`: once it has started, it will run till -it finishes unless the whole program stops. +We also could not cancel `read_non_blocking`: once it has started, it will run +till it finishes unless the whole program stops. What we really want to be able to write is something much more direct, like we would write in blocking code, but with the benefits of getting the data when it diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index a7ea2e2814..c9956bd956 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -49,19 +49,17 @@ questions: ### Async functions -In Rust, `async fn` is equivalent to writing a function which returns a future -of the return type, using the `impl Trait` syntax we discussed back in the -[“Traits as Parameters”][impl-trait] section in Chapter 10. An `async` block -compiles to an anonymous struct which implements the `Future` trait. - -That means these two are roughly equivalent: +In Rust, `async fn` is equivalent to writing a function which returns a *future* +of the return type. That is, when the compiler sees a function like this: ```rust -async fn hello_async() { +async fn hello_async() { println!("Hello, async!"); } ``` +It is basically equivalent to a function defined like this instead: + ```rust fn hello_async() -> impl Future { async { @@ -70,29 +68,45 @@ fn hello_async() -> impl Future { } ``` -That explains why we got the `unused_must_use` warning: writing `async fn` meant -we were actually returning an anonymous `Future`. The compiler will warn us that -“futures do nothing unless you `.await` or poll them”. That is, futures are -*lazy*: they don’t do anything until you ask them to. - -The compiler is telling us that ignoring a `Future` makes it completely useless! -This is different from the behavior we saw when using `thread::spawn` in the -previous chapter, and it is different from how many other languages approach -async. This allows Rust to avoid running async code unless it is actually -needed. We will see why that is later on. For now, let’s start by awaiting the -future returned by `hello_async` to actually have it run. - -> Note: Rust’s `await` keyword goes *after* the expression you are awaiting—that -> is, it is a _postfix keyword_. This is different from what you might be used -> to if you have used async in languages like JavaScript or C#. Rust chose this -> because it makes chains of async and non-async methods much nicer to work -> with. As of now, `await` is the only postfix keyword in the language. +Let’s break that down and see what each part means: + +* It uses the `impl Trait` syntax we discussed back in the [“Traits as + Parameters”][impl-trait] section in Chapter 10 to return a `Future` with an + associated type of `Output`. That tells us that `Future` is a trait, and the + `Output` associated type of `()` matches the original return type from the + async version of the function. + +* It wraps the whole body of the `async fn` in an `async` block. Given that + blocks like this are expressions, and that this is expression is the one which + is returned from the function, we can infer that an `async` block like this + produces some anonymous data type which implements the `Future` trait. + +Combined, those explain that when we called `hello_async` in `main`, it returned +a `Future`. Then Rust warned us that we did not do anything with the future. +This is because futures are *lazy*: they don’t do anything until you ask them +to. This should remind you of our discussion of iterators [back in Chapter +13][iterators-lazy]. With iterators, you have to call `next` to get them to do +anything—whether by using a `for` loop or by using iterator methods like `.iter()` and `.map()` which ultimately call `next()` under the hood. + +With futures, the same basic idea applies, although for different reasons, and +with different syntax and methods. This is different from the behavior we saw +when using `thread::spawn` in the previous chapter, and it is different from how +many other languages approach async. This allows Rust to avoid running async +code unless it is actually needed. We will see why that is later on. For now, +let’s start by awaiting the future returned by `hello_async` to actually have it +run. + +> Note: Rust’s `await` keyword goes after the expression you are awaiting, not +> before it—that is, it is a _postfix keyword_. This is different from what you +> might be used to if you have used async in languages like JavaScript or C#. +> Rust chose this because it makes chains of async and non-async methods much +> nicer to work with. As of now, `await` is Rust’s only postfix keyword. -```rust +```rust,ignore, does_not_compile fn main() { hello_async().await; } @@ -303,11 +317,11 @@ up to the root of our original problem with running async functions. When we follow that chain far enough, eventually we end up back in some non-async function. At that point, something needs to “translate” between the -async and sync worlds. That “something” is also the runtime! Whatever runtime you use -is what handles the top-level `poll()` call, scheduling and handing off between -the different async operations which may be in flight as they hand back control -at await points, and often also providing async versions of functionality like -file I/O. +async and sync worlds. That “something” is also the runtime! Whatever runtime +you use is what handles the top-level `poll()` call, scheduling and handing off +between the different async operations which may be in flight as they hand back +control at await points, and often also providing async versions of +functionality like file I/O. Now we can understand why the compiler was stopping us in Listing 17-2 (before we added the `trpl::block_on` function). The `main` function is not `async`—and @@ -339,6 +353,7 @@ foundations for working with async in Rust! Now that you know the basics of how futures and runtimes work, we can see some of the things we can *do* with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters +[iterators-lazy]: ch13-02-iterators.html [under-the-hood]: https://rust-lang.github.io/async-book/02_execution/01_chapter.html [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html [async-book]: https://rust-lang.github.io/async-book/ From 2360484f63f9f44c88dd53b991430a34257d0d27 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 12 Jun 2024 13:58:46 -0600 Subject: [PATCH 288/720] Ch. 17: reduce dependency list for `trpl` crate This makes compiled output in listings much more reasonable. It may be worth seeing if we can trim it down even further. (Switching to `smol` would do that, I think, but would have other effects.) --- packages/trpl/Cargo.lock | 260 ------------------------ packages/trpl/Cargo.toml | 6 +- packages/trpl/tests/integration/main.rs | 5 +- 3 files changed, 6 insertions(+), 265 deletions(-) diff --git a/packages/trpl/Cargo.lock b/packages/trpl/Cargo.lock index 20893eeaaa..e6e27ec0a4 100644 --- a/packages/trpl/Cargo.lock +++ b/packages/trpl/Cargo.lock @@ -38,18 +38,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.98" @@ -169,16 +157,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -194,17 +172,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -224,29 +191,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -277,36 +221,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -316,22 +236,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.66" @@ -350,27 +254,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -386,148 +271,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/packages/trpl/Cargo.toml b/packages/trpl/Cargo.toml index 046f95da5b..626318db3d 100644 --- a/packages/trpl/Cargo.toml +++ b/packages/trpl/Cargo.toml @@ -7,4 +7,8 @@ edition = "2021" [dependencies] futures = "0.3.30" -tokio = { version = "1", features = ["full"] } +tokio = { version = "1", default-features = false, features = [ + "rt-multi-thread", + "sync", + "time", +] } diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index 9105a5aef0..28421ba5ee 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -9,10 +9,7 @@ //! //! [post]: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html -use std::{ - pin::{pin, Pin}, - time::Duration, -}; +use std::{pin::Pin, time::Duration}; use futures::Future; use trpl::{Either, Receiver, Sender}; From 5458a6a4d4557249b9b7d6240d4f142ad961b554 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 12 Jun 2024 13:58:46 -0600 Subject: [PATCH 289/720] =?UTF-8?q?Ch.=2017:=20correct=20listing=20numbers?= =?UTF-8?q?=20for=20=C2=A701?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ch17-async-await/listing-17-01/Cargo.lock | 533 ----------------- .../ch17-async-await/listing-17-01/Cargo.toml | 3 - .../ch17-async-await/listing-17-01/output.txt | 14 + .../listing-17-01/src/main.rs | 26 +- .../ch17-async-await/listing-17-02/Cargo.lock | 533 ----------------- .../ch17-async-await/listing-17-02/Cargo.toml | 3 - .../ch17-async-await/listing-17-02/output.txt | 12 + .../listing-17-02/src/main.rs | 24 +- .../ch17-async-await/listing-17-03/Cargo.lock | 300 +--------- .../ch17-async-await/listing-17-03/Cargo.toml | 6 +- .../ch17-async-await/listing-17-03/output.txt | 27 + .../listing-17-03/src/main.rs | 26 +- .../listing-S02-17-01/Cargo.lock | 540 ++++++++++++++++++ .../listing-S02-17-01/Cargo.toml | 9 + .../listing-S02-17-01/src/main.rs | 25 + .../listing-S02-17-02/Cargo.lock | 540 ++++++++++++++++++ .../listing-S02-17-02/Cargo.toml | 9 + .../listing-S02-17-02/src/main.rs | 21 + .../listing-S02-17-03/Cargo.lock | 540 ++++++++++++++++++ .../listing-S02-17-03/Cargo.toml | 9 + .../listing-S02-17-03/src/main.rs | 23 + src/ch17-01-futures-and-syntax.md | 58 +- src/ch17-02-concurrency-with-async.md | 8 +- 23 files changed, 1823 insertions(+), 1466 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-01/output.txt create mode 100644 listings/ch17-async-await/listing-17-02/output.txt create mode 100644 listings/ch17-async-await/listing-17-03/output.txt create mode 100644 listings/ch17-async-await/listing-S02-17-01/Cargo.lock create mode 100644 listings/ch17-async-await/listing-S02-17-01/Cargo.toml create mode 100644 listings/ch17-async-await/listing-S02-17-01/src/main.rs create mode 100644 listings/ch17-async-await/listing-S02-17-02/Cargo.lock create mode 100644 listings/ch17-async-await/listing-S02-17-02/Cargo.toml create mode 100644 listings/ch17-async-await/listing-S02-17-02/src/main.rs create mode 100644 listings/ch17-async-await/listing-S02-17-03/Cargo.lock create mode 100644 listings/ch17-async-await/listing-S02-17-03/Cargo.toml create mode 100644 listings/ch17-async-await/listing-S02-17-03/src/main.rs diff --git a/listings/ch17-async-await/listing-17-01/Cargo.lock b/listings/ch17-async-await/listing-17-01/Cargo.lock index 3be4eaaa53..d30b928a6c 100644 --- a/listings/ch17-async-await/listing-17-01/Cargo.lock +++ b/listings/ch17-async-await/listing-17-01/Cargo.lock @@ -2,539 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "async_await" version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-01/Cargo.toml b/listings/ch17-async-await/listing-17-01/Cargo.toml index 349041d3eb..67729afc80 100644 --- a/listings/ch17-async-await/listing-17-01/Cargo.toml +++ b/listings/ch17-async-await/listing-17-01/Cargo.toml @@ -4,6 +4,3 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-01/output.txt b/listings/ch17-async-await/listing-17-01/output.txt new file mode 100644 index 0000000000..9fc69b9ac1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-01/output.txt @@ -0,0 +1,14 @@ +$ cargo run + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-01) +warning: unused implementer of `Future` that must be used + --> src/main.rs:2:5 + | +2 | hello_async(); + | ^^^^^^^^^^^^^ + | + = note: futures do nothing unless you `.await` or poll them + = note: `#[warn(unused_must_use)]` on by default + +warning: `async_await` (bin "async_await") generated 1 warning + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s + Running `target/debug/async_await` diff --git a/listings/ch17-async-await/listing-17-01/src/main.rs b/listings/ch17-async-await/listing-17-01/src/main.rs index 62b08cf5e9..70ce867bf2 100644 --- a/listings/ch17-async-await/listing-17-01/src/main.rs +++ b/listings/ch17-async-await/listing-17-01/src/main.rs @@ -1,25 +1,11 @@ // ANCHOR: all -use std::time::Duration; - fn main() { - // ANCHOR: block_on - trpl::block_on(async { - // ANCHOR_END: block_on - // ANCHOR: task - trpl::spawn_task(async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }); + hello_async(); +} - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - // ANCHOR_END: task - // ANCHOR: block_on - }); - // ANCHOR_END: block_on +// ANCHOR: async-fn +async fn hello_async() { + println!("Hello, async!"); } +// ANCHOR_END: async-fn // ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-02/Cargo.lock b/listings/ch17-async-await/listing-17-02/Cargo.lock index 3be4eaaa53..d30b928a6c 100644 --- a/listings/ch17-async-await/listing-17-02/Cargo.lock +++ b/listings/ch17-async-await/listing-17-02/Cargo.lock @@ -2,539 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "async_await" version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-02/Cargo.toml b/listings/ch17-async-await/listing-17-02/Cargo.toml index 349041d3eb..67729afc80 100644 --- a/listings/ch17-async-await/listing-17-02/Cargo.toml +++ b/listings/ch17-async-await/listing-17-02/Cargo.toml @@ -4,6 +4,3 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-02/output.txt b/listings/ch17-async-await/listing-17-02/output.txt new file mode 100644 index 0000000000..0910145234 --- /dev/null +++ b/listings/ch17-async-await/listing-17-02/output.txt @@ -0,0 +1,12 @@ +$ cargo run + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-02) +error[E0728]: `await` is only allowed inside `async` functions and blocks + --> src/main.rs:3:19 + | +2 | fn main() { + | ---- this is not `async` +3 | hello_async().await; + | ^^^^^ only allowed inside `async` functions and blocks + +For more information about this error, try `rustc --explain E0728`. +error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-02/src/main.rs b/listings/ch17-async-await/listing-17-02/src/main.rs index 079cbe06a9..4ce7800db7 100644 --- a/listings/ch17-async-await/listing-17-02/src/main.rs +++ b/listings/ch17-async-await/listing-17-02/src/main.rs @@ -1,21 +1,9 @@ -use std::time::Duration; - +// ANCHOR: main fn main() { - trpl::block_on(async { - // ANCHOR: handle - let handle = trpl::spawn_task(async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }); - - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; - } + hello_async().await; +} +// ANCHOR_END: main - handle.await; - // ANCHOR_END: handle - }); +async fn hello_async() { + println!("Hello, async!"); } diff --git a/listings/ch17-async-await/listing-17-03/Cargo.lock b/listings/ch17-async-await/listing-17-03/Cargo.lock index 3be4eaaa53..89df255f72 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.lock +++ b/listings/ch17-async-await/listing-17-03/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -32,9 +32,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -45,23 +45,11 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" -version = "1.0.97" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -160,9 +148,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "hermit-abi" @@ -172,19 +160,9 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "memchr" @@ -194,24 +172,13 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -224,36 +191,13 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -268,9 +212,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,27 +243,11 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" -version = "2.0.63" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -352,32 +256,13 @@ dependencies = [ [[package]] name = "tokio" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-03/Cargo.toml b/listings/ch17-async-await/listing-17-03/Cargo.toml index 349041d3eb..5f2e9ac2d0 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.toml +++ b/listings/ch17-async-await/listing-17-03/Cargo.toml @@ -3,7 +3,7 @@ name = "async_await" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -trpl = { path = "../../../packages/trpl" } +trpl = { version = "0.1.0", path = "../../../packages/trpl" } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch17-async-await/listing-17-03/output.txt b/listings/ch17-async-await/listing-17-03/output.txt new file mode 100644 index 0000000000..d0d2eb5d91 --- /dev/null +++ b/listings/ch17-async-await/listing-17-03/output.txt @@ -0,0 +1,27 @@ +cargo run + Compiling proc-macro2 v1.0.85 + Compiling unicode-ident v1.0.12 + Compiling autocfg v1.3.0 + Compiling futures-sink v0.3.30 + Compiling pin-project-lite v0.2.14 + Compiling libc v0.2.155 + Compiling futures-core v0.3.30 + Compiling memchr v2.7.2 + Compiling pin-utils v0.1.0 + Compiling futures-io v0.3.30 + Compiling futures-task v0.3.30 + Compiling futures-channel v0.3.30 + Compiling slab v0.4.9 + Compiling num_cpus v1.16.0 + Compiling tokio v1.38.0 + Compiling quote v1.0.36 + Compiling syn v2.0.66 + Compiling futures-macro v0.3.30 + Compiling futures-util v0.3.30 + Compiling futures-executor v0.3.30 + Compiling futures v0.3.30 + Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-03) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.91s + Running `target/debug/async_await` +Hello, async! \ No newline at end of file diff --git a/listings/ch17-async-await/listing-17-03/src/main.rs b/listings/ch17-async-await/listing-17-03/src/main.rs index 60889f3aed..111f734666 100644 --- a/listings/ch17-async-await/listing-17-03/src/main.rs +++ b/listings/ch17-async-await/listing-17-03/src/main.rs @@ -1,23 +1,9 @@ -use std::time::Duration; - +// ANCHOR: main fn main() { - trpl::block_on(async { - // ANCHOR: join - let fut1 = async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }; - - let fut2 = async { - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }; + trpl::block_on(hello_async()); +} +// ANCHOR_END: main - trpl::join(fut1, fut2).await; - // ANCHOR_END: join - }); +async fn hello_async() { + println!("Hello, async!"); } diff --git a/listings/ch17-async-await/listing-S02-17-01/Cargo.lock b/listings/ch17-async-await/listing-S02-17-01/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-01/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-S02-17-01/Cargo.toml b/listings/ch17-async-await/listing-S02-17-01/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-01/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-S02-17-01/src/main.rs b/listings/ch17-async-await/listing-S02-17-01/src/main.rs new file mode 100644 index 0000000000..62b08cf5e9 --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-01/src/main.rs @@ -0,0 +1,25 @@ +// ANCHOR: all +use std::time::Duration; + +fn main() { + // ANCHOR: block_on + trpl::block_on(async { + // ANCHOR_END: block_on + // ANCHOR: task + trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }); + + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + // ANCHOR_END: task + // ANCHOR: block_on + }); + // ANCHOR_END: block_on +} +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-S02-17-02/Cargo.lock b/listings/ch17-async-await/listing-S02-17-02/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-02/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-S02-17-02/Cargo.toml b/listings/ch17-async-await/listing-S02-17-02/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-02/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-S02-17-02/src/main.rs b/listings/ch17-async-await/listing-S02-17-02/src/main.rs new file mode 100644 index 0000000000..079cbe06a9 --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-02/src/main.rs @@ -0,0 +1,21 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + // ANCHOR: handle + let handle = trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }); + + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + + handle.await; + // ANCHOR_END: handle + }); +} diff --git a/listings/ch17-async-await/listing-S02-17-03/Cargo.lock b/listings/ch17-async-await/listing-S02-17-03/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-03/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-S02-17-03/Cargo.toml b/listings/ch17-async-await/listing-S02-17-03/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-03/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-S02-17-03/src/main.rs b/listings/ch17-async-await/listing-S02-17-03/src/main.rs new file mode 100644 index 0000000000..60889f3aed --- /dev/null +++ b/listings/ch17-async-await/listing-S02-17-03/src/main.rs @@ -0,0 +1,23 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + // ANCHOR: join + let fut1 = async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }; + + let fut2 = async { + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }; + + trpl::join(fut1, fut2).await; + // ANCHOR_END: join + }); +} diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index c9956bd956..6e0696efeb 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -11,13 +11,7 @@ Let’s write our first async function, and call it: ```rust -fn main() { - hello_async(); -} - -async fn hello_async() { - println!("Hello, async!"); -} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:all}} ``` @@ -25,19 +19,7 @@ async fn hello_async() { If we compile and run this… nothing happens, and we get a compiler warning: ```console -$ cargo run -warning: unused implementer of `Future` that must be used - --> src/main.rs:2:5 - | -2 | hello_async(); - | ^^^^^^^^^^^^^ - | - = note: futures do nothing unless you `.await` or poll them - = note: `#[warn(unused_must_use)]` on by default - -warning: `hello-async` (bin "hello-async") generated 1 warning - Finished dev [unoptimized + debuginfo] target(s) in 1.50s - Running `target/debug/hello-async` +{{#include ../listings/ch17-async-await/listing-17-01/output.txt}} ``` The warning tells us that just calling `hello_async()` was not enough: we also @@ -53,9 +35,7 @@ In Rust, `async fn` is equivalent to writing a function which returns a *future* of the return type. That is, when the compiler sees a function like this: ```rust -async fn hello_async() { - println!("Hello, async!"); -} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:async-fn}} ``` It is basically equivalent to a function defined like this instead: @@ -106,24 +86,16 @@ run. -```rust,ignore, does_not_compile -fn main() { - hello_async().await; -} +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-02/src/main.rs:main}} ``` Oh no! We have gone from a compiler warning to an actual error: -```text -error[E0728]: `await` is only allowed inside `async` functions and blocks - --> src/main.rs:2:19 - | -1 | fn main() { - | ---- this is not `async` -2 | hello_async().await; - | ^^^^^ only allowed inside `async` functions and blocks +```console +{{#include ../listings/ch17-async-await/listing-17-02/output.txt}} ``` This time, the compiler is informing us we cannot use `.await` in `main`, @@ -177,27 +149,15 @@ completes. ```rust -fn main() { - trpl::block_on(hello_async()); -} - -async fn hello_async() { - println!("Hello, async!"); -} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-03/src/main.rs:main}} ``` When we run this, we get the behavior we might have expected initially: - - ```console -$ cargo run - Compiling hello-async v0.1.0 (/Users/chris/dev/chriskrycho/async-trpl-fun/hello-async) - Finished dev [unoptimized + debuginfo] target(s) in 4.89s - Running `target/debug/hello-async` -Hello, async! +{{#include ../listings/ch17-async-await/listing-17-03/output.txt}} ``` Phew: we finally have some working async code! Now we can answer that second diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index d6189a565d..1f6ba11dcf 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -21,7 +21,7 @@ to implement the same counting example as with threads. To start, we will set up our `main` function with `trpl::block_on`: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:block_on}} +{{#rustdoc_include ../listings/ch17-async-await/listing-S02-17-01/src/main.rs:block_on}} ``` > Note: From this point forward in the chapter, every example will include this @@ -35,7 +35,7 @@ top-level `for` loop. Notice that we also need to add a `.await` after the `sleep` calls. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:task}} +{{#rustdoc_include ../listings/ch17-async-await/listing-S02-17-01/src/main.rs:task}} ``` This does something very similar to what the thread-based implementation did, as @@ -64,7 +64,7 @@ thread was done running. Here, we can use `await` to do the same thing: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-02/src/main.rs:handle}} +{{#rustdoc_include ../listings/ch17-async-await/listing-S02-17-02/src/main.rs:handle}} ``` @@ -103,7 +103,7 @@ ask the runtime to run them both to completion using `trpl::join`: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-03/src/main.rs:join}} +{{#rustdoc_include ../listings/ch17-async-await/listing-S02-17-03/src/main.rs:join}} ``` From 217645eb3540dbf63fa23d1ecdc1b16a5e62c964 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 12 Jun 2024 15:28:14 -0600 Subject: [PATCH 290/720] =?UTF-8?q?Ch.=2017=20=C2=A701:=20flag=20a=20TODO?= =?UTF-8?q?=20item=20for=20later?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-01-futures-and-syntax.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 6e0696efeb..5c2c74ba4e 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -273,7 +273,9 @@ us, and has good error messages. We will work through a few of those later in the chapter! This is enough information to let us keep following the chain back up to the root of our original problem with running async functions. - + When we follow that chain far enough, eventually we end up back in some non-async function. At that point, something needs to “translate” between the From c310f54aab8a94ca1d36c01aedb830a2a14988d5 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 12 Jun 2024 15:29:16 -0600 Subject: [PATCH 291/720] Ch. 17: Finish (first pass) documentation for `trpl::race` Explain how it relates to `futures::future::select` and why `trpl` uses `race` semantics instead. --- packages/trpl/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index e7ef277c09..2a98c3ac40 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -72,7 +72,16 @@ where time::timeout(duration, future).await.map_err(|_| duration) } -///Run two futures +/// Run two futures, taking whichever finishes first and canceling the other. +/// +/// Notice that this is built on [`futures::future::select`], which has the +/// same overall semantics but does *not* drop the slower future. The idea there +/// is that you can work with the first result and then later *also* continue +/// waiting for the second future. +/// +/// We use the `race` semantics, where the slower future is simply dropped, for +/// the sake of simplicity in the examples: no need to deal with the tuple and +/// intentionally ignore the second future this way! pub async fn race(f1: F1, f2: F2) -> Either where F1: Future, From dc27455c7474ad5cb25562f548b8a9673b5abe43 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 08:14:22 -0600 Subject: [PATCH 292/720] Fix a typo in `ADMIN_TASKS` --- ADMIN_TASKS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADMIN_TASKS.md b/ADMIN_TASKS.md index 2a92eefd26..7e9ba2cc04 100644 --- a/ADMIN_TASKS.md +++ b/ADMIN_TASKS.md @@ -68,7 +68,7 @@ extracted into a file. To do that: - If you only want to show part of the code in the file, use anchor comments (`// ANCHOR: some_tag` and `// ANCHOR_END: some_tag`) to mark the parts of the file you want to show. -- For Rust code, use the `{{#rustdoc_include [fileame:some_tag]}}` directive +- For Rust code, use the `{{#rustdoc_include [filename:some_tag]}}` directive within the code blocks in the text. The `rustdoc_include` directive gives the code that doesn't get displayed to `rustdoc` for `mdbook test` purposes. - For anything else, use the `{{#include [filename:some_tag]}}` directive. From 69323d90da59cac43ef7bcbd0ea19f1ceeccc3e9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 08:14:22 -0600 Subject: [PATCH 293/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listing=2017-04?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-04-orig/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-04-orig/Cargo.toml | 9 + .../listing-17-04-orig/src/main.rs | 17 + .../ch17-async-await/listing-17-04/Cargo.lock | 260 --------- .../listing-17-04/src/main.rs | 16 +- src/ch17-02-concurrency-with-async.md | 13 +- 6 files changed, 576 insertions(+), 279 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-04-orig/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-04-orig/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-04-orig/src/main.rs diff --git a/listings/ch17-async-await/listing-17-04-orig/Cargo.lock b/listings/ch17-async-await/listing-17-04-orig/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-04-orig/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-04-orig/Cargo.toml b/listings/ch17-async-await/listing-17-04-orig/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-04-orig/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-04-orig/src/main.rs b/listings/ch17-async-await/listing-17-04-orig/src/main.rs new file mode 100644 index 0000000000..a6033e5994 --- /dev/null +++ b/listings/ch17-async-await/listing-17-04-orig/src/main.rs @@ -0,0 +1,17 @@ +// ANCHOR: all +fn main() { + trpl::block_on(async { + // ANCHOR: add-channel + let (tx, mut rx) = trpl::channel(); + // ANCHOR_END: add-channel + + // ANCHOR: send-and-receive + let val = String::from("hi"); + tx.send(val).unwrap(); + + let received = rx.recv().await.unwrap(); + println!("Got: {received}"); + // ANCHOR_END: send-and-receive + }); +} +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-04/Cargo.lock b/listings/ch17-async-await/listing-17-04/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.lock +++ b/listings/ch17-async-await/listing-17-04/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-04/src/main.rs b/listings/ch17-async-await/listing-17-04/src/main.rs index a6033e5994..ab559c800f 100644 --- a/listings/ch17-async-await/listing-17-04/src/main.rs +++ b/listings/ch17-async-await/listing-17-04/src/main.rs @@ -1,17 +1,7 @@ -// ANCHOR: all fn main() { + // ANCHOR: block_on trpl::block_on(async { - // ANCHOR: add-channel - let (tx, mut rx) = trpl::channel(); - // ANCHOR_END: add-channel - - // ANCHOR: send-and-receive - let val = String::from("hi"); - tx.send(val).unwrap(); - - let received = rx.recv().await.unwrap(); - println!("Got: {received}"); - // ANCHOR_END: send-and-receive + // our implementation will go here }); + // ANCHOR_END: block_on } -// ANCHOR_END: all diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 1f6ba11dcf..8ac7a59ee7 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -18,15 +18,16 @@ which looks very similar to the `thread::spawn` API, and a `sleep` function which is an async version of the `thread::sleep` API. We can use these together to implement the same counting example as with threads. -To start, we will set up our `main` function with `trpl::block_on`: +Listing 17-4 shows our starting point. We set up our `main` function with `trpl::block_on`, so that our top-level function can be async. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-S02-17-01/src/main.rs:block_on}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:block_on}} ``` > Note: From this point forward in the chapter, every example will include this -> exact same code, so we will often skip it just like we do with `main`. Don’t -> forget to include it in your own code! +> exact same wrapping code with `trpl::block_on` in `main`, so we will often +> skip it just like we do with `main`. Don’t forget to include it in your +> code! Then we can write two loops within that block, each with a `trpl::sleep` call in them. Similar to the threading example, we put one loop in the body of a @@ -169,7 +170,7 @@ single-consumer channel channel API we used with threads back in Chapter 16: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:add-channel}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04-orig/src/main.rs:add-channel}} ``` @@ -182,7 +183,7 @@ using `.await` on the `rx.recv()` call. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:send-and-receive}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04-orig/src/main.rs:send-and-receive}} ``` From ccd68087cd2c5b9f97da43785443ae66bac4037a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 08:35:15 -0600 Subject: [PATCH 294/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listing=2017-05?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-05-orig/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-05-orig/Cargo.toml | 9 + .../listing-17-05-orig/src/main.rs | 31 + .../ch17-async-await/listing-17-05/Cargo.lock | 260 --------- .../listing-17-05/src/main.rs | 34 +- src/ch17-02-concurrency-with-async.md | 10 +- 6 files changed, 600 insertions(+), 284 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-05-orig/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-05-orig/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-05-orig/src/main.rs diff --git a/listings/ch17-async-await/listing-17-05-orig/Cargo.lock b/listings/ch17-async-await/listing-17-05-orig/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-05-orig/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-05-orig/Cargo.toml b/listings/ch17-async-await/listing-17-05-orig/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-05-orig/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-05-orig/src/main.rs b/listings/ch17-async-await/listing-17-05-orig/src/main.rs new file mode 100644 index 0000000000..c1b62d8e66 --- /dev/null +++ b/listings/ch17-async-await/listing-17-05-orig/src/main.rs @@ -0,0 +1,31 @@ +// ANCHOR: all +// ANCHOR: many-messages +use std::time::Duration; +// ANCHOR_END: many-messages + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + // ANCHOR: many-messages + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR_END: many-messages + + // ANCHOR: loop + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR_END: loop + }); +} +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-05/Cargo.lock b/listings/ch17-async-await/listing-17-05/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-05/Cargo.lock +++ b/listings/ch17-async-await/listing-17-05/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-05/src/main.rs b/listings/ch17-async-await/listing-17-05/src/main.rs index c1b62d8e66..36ddedca26 100644 --- a/listings/ch17-async-await/listing-17-05/src/main.rs +++ b/listings/ch17-async-await/listing-17-05/src/main.rs @@ -1,31 +1,19 @@ -// ANCHOR: all -// ANCHOR: many-messages use std::time::Duration; -// ANCHOR_END: many-messages fn main() { trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); + // ANCHOR: task + trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; + } + }); - // ANCHOR: many-messages - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - // ANCHOR_END: many-messages - - // ANCHOR: loop - while let Some(value) = rx.recv().await { - println!("received '{value}'"); + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; } - // ANCHOR_END: loop + // ANCHOR_END: task }); } -// ANCHOR_END: all diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 8ac7a59ee7..c0b82f2c5e 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -35,14 +35,22 @@ them. Similar to the threading example, we put one loop in the body of a top-level `for` loop. Notice that we also need to add a `.await` after the `sleep` calls. ++ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-S02-17-01/src/main.rs:task}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:task}} ``` + + This does something very similar to what the thread-based implementation did, as we can see from the output when we run it. (As with the threading example, you may see a different order in your own terminal output when you run this.) + + ```text hi number 1 from the second task! hi number 1 from the first task! From 4c4ebb7bb549e66103ae3496cb0b2e9f02bf6cef Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 08:35:15 -0600 Subject: [PATCH 295/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listing=2017-06?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-06-orig/src/main.rs | 33 +++ .../ch17-async-await/listing-17-06/Cargo.lock | 260 ------------------ .../listing-17-06/src/main.rs | 36 +-- .../listing-S02-17-02/src/main.rs | 21 -- src/ch17-02-concurrency-with-async.md | 22 +- 7 files changed, 59 insertions(+), 313 deletions(-) rename listings/ch17-async-await/{listing-S02-17-02 => listing-17-06-orig}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-S02-17-02 => listing-17-06-orig}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-06-orig/src/main.rs delete mode 100644 listings/ch17-async-await/listing-S02-17-02/src/main.rs diff --git a/listings/ch17-async-await/listing-S02-17-02/Cargo.lock b/listings/ch17-async-await/listing-17-06-orig/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-S02-17-02/Cargo.lock rename to listings/ch17-async-await/listing-17-06-orig/Cargo.lock diff --git a/listings/ch17-async-await/listing-S02-17-02/Cargo.toml b/listings/ch17-async-await/listing-17-06-orig/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-S02-17-02/Cargo.toml rename to listings/ch17-async-await/listing-17-06-orig/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-06-orig/src/main.rs b/listings/ch17-async-await/listing-17-06-orig/src/main.rs new file mode 100644 index 0000000000..aeeacc5462 --- /dev/null +++ b/listings/ch17-async-await/listing-17-06-orig/src/main.rs @@ -0,0 +1,33 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + // ANCHOR: futures + let tx_fut = async { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + // ANCHOR: loop + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR_END: loop + }; + + trpl::join(tx_fut, rx_fut).await; + // ANCHOR_END: futures + }); +} diff --git a/listings/ch17-async-await/listing-17-06/Cargo.lock b/listings/ch17-async-await/listing-17-06/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-06/Cargo.lock +++ b/listings/ch17-async-await/listing-17-06/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-06/src/main.rs b/listings/ch17-async-await/listing-17-06/src/main.rs index aeeacc5462..dbc2241b96 100644 --- a/listings/ch17-async-await/listing-17-06/src/main.rs +++ b/listings/ch17-async-await/listing-17-06/src/main.rs @@ -2,32 +2,20 @@ use std::time::Duration; fn main() { trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - // ANCHOR: futures - let tx_fut = async { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; + // ANCHOR: handle + let handle = trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; } - }; + }); - let rx_fut = async { - // ANCHOR: loop - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR_END: loop - }; + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; + } - trpl::join(tx_fut, rx_fut).await; - // ANCHOR_END: futures + handle.await.unwrap(); + // ANCHOR_END: handle }); } diff --git a/listings/ch17-async-await/listing-S02-17-02/src/main.rs b/listings/ch17-async-await/listing-S02-17-02/src/main.rs deleted file mode 100644 index 079cbe06a9..0000000000 --- a/listings/ch17-async-await/listing-S02-17-02/src/main.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - // ANCHOR: handle - let handle = trpl::spawn_task(async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }); - - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - - handle.await; - // ANCHOR_END: handle - }); -} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index c0b82f2c5e..570471424d 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -68,17 +68,23 @@ because the task spawned by `spawn_task` is shut down when the main function ends—just like threads are. Thus, if you want to run all the way to the completion of the task, you will need to use a join handle to wait for the first task to complete. With threads, we used the `join` method to “block” until the -thread was done running. Here, we can use `await` to do the same thing: +thread was done running. Here, we can use `await` to do the same thing, and +since the handle’s output is actually a `Result`, we will also unwrap it. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-S02-17-02/src/main.rs:handle}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-06/src/main.rs:handle}} ``` -Now the output again looks like what we saw in the threading example. +Now the output again looks like what we saw in the threading example. (Again, +the exact output may look different for you.) + + ```text hi number 1 from the second task! @@ -217,7 +223,7 @@ as shown in Listing 17-TODO: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:many-messages}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05-orig/src/main.rs:many-messages}} ``` @@ -232,7 +238,7 @@ Listing 17-TODO, and the loop will end when `rx.recv().await` produces a `None`. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:loop}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05-orig/src/main.rs:loop}} ``` @@ -258,7 +264,7 @@ at the whole thing all together. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05-orig/src/main.rs:all}} ``` @@ -279,7 +285,7 @@ above. Listing 17-TODO shows how that looks. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-06/src/main.rs:futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-06-orig/src/main.rs:futures}} ``` From 4c41d8f015a4b9dd3d63b910b616db2695404c3c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 09:12:01 -0600 Subject: [PATCH 296/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20remove=20listing?= =?UTF-8?q?=20that=20I=20split=20into=20multiple=20parts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 6fd549dc22fcb1fca1d9d9983f1e6127b2ab3604 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 09:12:01 -0600 Subject: [PATCH 297/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listing=2017-07?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-07-orig/src/main.rs | 45 ++ .../listing-17-07/src/main.rs | 44 +- .../listing-S02-17-01/src/main.rs | 25 - .../listing-S02-17-03/Cargo.lock | 540 ------------------ .../listing-S02-17-03/Cargo.toml | 9 - .../listing-S02-17-03/src/main.rs | 23 - src/ch17-02-concurrency-with-async.md | 6 +- 9 files changed, 59 insertions(+), 633 deletions(-) rename listings/ch17-async-await/{listing-S02-17-01 => listing-17-07-orig}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-S02-17-01 => listing-17-07-orig}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-07-orig/src/main.rs delete mode 100644 listings/ch17-async-await/listing-S02-17-01/src/main.rs delete mode 100644 listings/ch17-async-await/listing-S02-17-03/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-S02-17-03/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-S02-17-03/src/main.rs diff --git a/listings/ch17-async-await/listing-S02-17-01/Cargo.lock b/listings/ch17-async-await/listing-17-07-orig/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-S02-17-01/Cargo.lock rename to listings/ch17-async-await/listing-17-07-orig/Cargo.lock diff --git a/listings/ch17-async-await/listing-S02-17-01/Cargo.toml b/listings/ch17-async-await/listing-17-07-orig/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-S02-17-01/Cargo.toml rename to listings/ch17-async-await/listing-17-07-orig/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-07-orig/src/main.rs b/listings/ch17-async-await/listing-17-07-orig/src/main.rs new file mode 100644 index 0000000000..e5d8f86066 --- /dev/null +++ b/listings/ch17-async-await/listing-17-07-orig/src/main.rs @@ -0,0 +1,45 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx_fut = async { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(received) = rx.recv().await { + println!("Got: {received}"); + } + }; + + // ANCHOR: updated + let tx_fut2 = async { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + trpl::join3(tx_fut, tx_fut2, rx_fut).await; + // ANCHOR_END: updated + }); +} diff --git a/listings/ch17-async-await/listing-17-07/src/main.rs b/listings/ch17-async-await/listing-17-07/src/main.rs index e5d8f86066..60889f3aed 100644 --- a/listings/ch17-async-await/listing-17-07/src/main.rs +++ b/listings/ch17-async-await/listing-17-07/src/main.rs @@ -2,44 +2,22 @@ use std::time::Duration; fn main() { trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - let tx_fut = async { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(received) = rx.recv().await { - println!("Got: {received}"); + // ANCHOR: join + let fut1 = async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(1)).await; } }; - // ANCHOR: updated - let tx_fut2 = async { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; + let fut2 = async { + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(1)).await; } }; - trpl::join3(tx_fut, tx_fut2, rx_fut).await; - // ANCHOR_END: updated + trpl::join(fut1, fut2).await; + // ANCHOR_END: join }); } diff --git a/listings/ch17-async-await/listing-S02-17-01/src/main.rs b/listings/ch17-async-await/listing-S02-17-01/src/main.rs deleted file mode 100644 index 62b08cf5e9..0000000000 --- a/listings/ch17-async-await/listing-S02-17-01/src/main.rs +++ /dev/null @@ -1,25 +0,0 @@ -// ANCHOR: all -use std::time::Duration; - -fn main() { - // ANCHOR: block_on - trpl::block_on(async { - // ANCHOR_END: block_on - // ANCHOR: task - trpl::spawn_task(async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }); - - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - // ANCHOR_END: task - // ANCHOR: block_on - }); - // ANCHOR_END: block_on -} -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-S02-17-03/Cargo.lock b/listings/ch17-async-await/listing-S02-17-03/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-S02-17-03/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-S02-17-03/Cargo.toml b/listings/ch17-async-await/listing-S02-17-03/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-S02-17-03/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-S02-17-03/src/main.rs b/listings/ch17-async-await/listing-S02-17-03/src/main.rs deleted file mode 100644 index 60889f3aed..0000000000 --- a/listings/ch17-async-await/listing-S02-17-03/src/main.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - // ANCHOR: join - let fut1 = async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }; - - let fut2 = async { - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; - } - }; - - trpl::join(fut1, fut2).await; - // ANCHOR_END: join - }); -} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 570471424d..680e350609 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -115,10 +115,10 @@ concurrency here. Remember that each async block compiles to an anonymous future. That means we can put each of these two loops in an async block and then ask the runtime to run them both to completion using `trpl::join`: -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-S02-17-03/src/main.rs:join}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-07/src/main.rs:join}} ``` @@ -327,7 +327,7 @@ three futures to complete: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-07/src/main.rs:updated}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-07-orig/src/main.rs:updated}} ``` From bd26083b6df2706acc1aa0960bcb0067db9b829b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 09:17:12 -0600 Subject: [PATCH 298/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20leave=20a=20TODO?= =?UTF-8?q?=20about=20one=20bucket=20of=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This one may or may not make sense: the output *order* should be the same regardless, but there will be a *lot* of extra noise in it because of the `cargo build` output before the actual program output, and we do not appear to have a good way to focus on particular subsets of output the way we do for code? --- src/ch17-02-concurrency-with-async.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 680e350609..e12142bf74 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -125,6 +125,8 @@ ask the runtime to run them both to completion using `trpl::join`: When we run this, we see both futures run to completion: + + ```text hi number 1 from the first task! hi number 1 from the second task! From 6d802a08fc7b07d280f9f1656c1178b0a123d6da Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 09:23:20 -0600 Subject: [PATCH 299/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listings=2017-08=20and=2017-09?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-04-orig/src/main.rs | 17 - .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-08-orig/src/main.rs | 34 ++ .../ch17-async-await/listing-17-08/Cargo.lock | 260 --------- .../listing-17-08/src/main.rs | 33 +- .../listing-17-09-orig/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-09-orig/Cargo.toml | 9 + .../listing-17-09-orig/src/main.rs | 46 ++ .../ch17-async-await/listing-17-09/Cargo.lock | 260 --------- .../listing-17-09/src/main.rs | 45 +- src/ch17-02-concurrency-with-async.md | 39 +- 12 files changed, 662 insertions(+), 621 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-04-orig/src/main.rs rename listings/ch17-async-await/{listing-17-04-orig => listing-17-08-orig}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-04-orig => listing-17-08-orig}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-08-orig/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-09-orig/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-09-orig/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-09-orig/src/main.rs diff --git a/listings/ch17-async-await/listing-17-04-orig/src/main.rs b/listings/ch17-async-await/listing-17-04-orig/src/main.rs deleted file mode 100644 index a6033e5994..0000000000 --- a/listings/ch17-async-await/listing-17-04-orig/src/main.rs +++ /dev/null @@ -1,17 +0,0 @@ -// ANCHOR: all -fn main() { - trpl::block_on(async { - // ANCHOR: add-channel - let (tx, mut rx) = trpl::channel(); - // ANCHOR_END: add-channel - - // ANCHOR: send-and-receive - let val = String::from("hi"); - tx.send(val).unwrap(); - - let received = rx.recv().await.unwrap(); - println!("Got: {received}"); - // ANCHOR_END: send-and-receive - }); -} -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-04-orig/Cargo.lock b/listings/ch17-async-await/listing-17-08-orig/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-04-orig/Cargo.lock rename to listings/ch17-async-await/listing-17-08-orig/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-04-orig/Cargo.toml b/listings/ch17-async-await/listing-17-08-orig/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-04-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-08-orig/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-08-orig/src/main.rs b/listings/ch17-async-await/listing-17-08-orig/src/main.rs new file mode 100644 index 0000000000..fa02e21a87 --- /dev/null +++ b/listings/ch17-async-await/listing-17-08-orig/src/main.rs @@ -0,0 +1,34 @@ +// ANCHOR: all +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + // ANCHOR: move + let tx_fut = async move { + // ANCHOR_END: move + + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; + }); +} +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-08/Cargo.lock b/listings/ch17-async-await/listing-17-08/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-08/Cargo.lock +++ b/listings/ch17-async-await/listing-17-08/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-08/src/main.rs b/listings/ch17-async-await/listing-17-08/src/main.rs index fa02e21a87..b7b3eb8b16 100644 --- a/listings/ch17-async-await/listing-17-08/src/main.rs +++ b/listings/ch17-async-await/listing-17-08/src/main.rs @@ -1,34 +1,13 @@ -// ANCHOR: all -use std::time::Duration; - fn main() { trpl::block_on(async { + // ANCHOR: add-channel let (tx, mut rx) = trpl::channel(); + // ANCHOR_END: add-channel - // ANCHOR: move - let tx_fut = async move { - // ANCHOR_END: move - - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); - } - }; + let val = String::from("hi"); + tx.send(val).unwrap(); - trpl::join(tx_fut, rx_fut).await; + let received = rx.recv().await.unwrap(); + println!("Got: {received}"); }); } -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-09-orig/Cargo.lock b/listings/ch17-async-await/listing-17-09-orig/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-09-orig/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-09-orig/Cargo.toml b/listings/ch17-async-await/listing-17-09-orig/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-09-orig/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-09-orig/src/main.rs b/listings/ch17-async-await/listing-17-09-orig/src/main.rs new file mode 100644 index 0000000000..4c5e65da9b --- /dev/null +++ b/listings/ch17-async-await/listing-17-09-orig/src/main.rs @@ -0,0 +1,46 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + // ANCHOR: here + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + trpl::join3(tx1_fut, tx_fut, rx_fut).await; + // ANCHOR_END: here + }); +} diff --git a/listings/ch17-async-await/listing-17-09/Cargo.lock b/listings/ch17-async-await/listing-17-09/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-09/Cargo.lock +++ b/listings/ch17-async-await/listing-17-09/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-09/src/main.rs b/listings/ch17-async-await/listing-17-09/src/main.rs index 4c5e65da9b..4d98d199b6 100644 --- a/listings/ch17-async-await/listing-17-09/src/main.rs +++ b/listings/ch17-async-await/listing-17-09/src/main.rs @@ -1,46 +1,13 @@ -use std::time::Duration; - fn main() { trpl::block_on(async { - // ANCHOR: here let (tx, mut rx) = trpl::channel(); - let tx1 = tx.clone(); - let tx1_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; - - let tx_fut = async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; + // ANCHOR: send-and-receive + let val = String::from("hi"); + tx.send(val).unwrap(); - trpl::join3(tx1_fut, tx_fut, rx_fut).await; - // ANCHOR_END: here + let received = rx.recv().await.unwrap(); + println!("Got: {received}"); + // ANCHOR_END: send-and-receive }); } diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index e12142bf74..c5113a6fa4 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -181,37 +181,40 @@ implementation is that it returns an `Option` of the type sent over the channel instead of a `Result`. We can start by introducing an async version of the multiple-producer, -single-consumer channel channel API we used with threads back in Chapter 16: +single-consumer channel channel API we used with threads back in Chapter 16. The +API is just a little different here in Listing 17-8: we have a mutable receiver +`rx`. Otherwise, this looks pretty much the same as the thread-based approach. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04-orig/src/main.rs:add-channel}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:add-channel}} ``` -Now we can send messages from the sender to the receiver. Unlike in Chapter 16, -where we needed to spawn a separate thread to allow the message passing to -happen asynchronously, here we opt into async behavior on the receiver side by -using `.await` on the `rx.recv()` call. +Now we can send messages from the sender to the receiver. Again, the API is just +a little different from the threaded version in Chapter 16, where we needed to +spawn a separate thread to allow the message passing to happen asynchronously. +In the version in Listing 17-9, we opt into async behavior on the receiver side +by using `.await` on the `rx.recv()` call. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04-orig/src/main.rs:send-and-receive}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-09/src/main.rs:send-and-receive}} ``` The `send` call does not block, since the channel we are sending it into is unbounded. That was true with our threading example back in Chapter 16, too, -though. The difference here is that the `rx.recv()` call here does not block the -rest of the program, whereas the one in Chapter 16 *did* block the main thread. -Instead, once the program hits the `.await` on the `rx.recv()` call, it hands -control back to the runtime, which can go on scheduling other operations until a -message arrives. It might be hard to see that from this code, though, since the -message will arrive right away! +though. However, there is a big difference with the `rx.recv()` calls. The one +back in Chapter 16 blocked the thread it ran on—in that case, the main thread. +This one does not block at all! Instead, once the program hits the `.await` on +the `rx.recv()` call, it hands control back to the runtime, which can go on +scheduling other operations until a message arrives. It might be hard to see +that from this code, though, since the message will arrive right away! > Note: Since this is all wrapped in a `trpl::block_on`, this would effectively > block anything happening outside that. That is the whole point of `block_on`, @@ -377,7 +380,7 @@ move` block, as in Listing 17-TODO: ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:move}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-08-orig/src/main.rs:move}} ``` The result is Listing 17-TODO, and when we run *this* version of the code, it @@ -386,7 +389,7 @@ shuts down gracefully after the last message is sent. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-08-orig/src/main.rs:all}} ``` @@ -400,7 +403,7 @@ block, and switching back to `join3`. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-09/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-09-orig/src/main.rs:here}} ``` From 38ddc49c60528888a8e59f739f6cc0b436a22a37 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 09:45:39 -0600 Subject: [PATCH 300/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listings=2017-10=20and=2017-11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-05-orig/src/main.rs | 31 - .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-10-orig/src/main.rs | 47 ++ .../ch17-async-await/listing-17-10/Cargo.lock | 260 --------- .../listing-17-10/src/main.rs | 51 +- .../listing-17-11-orig/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-11-orig/Cargo.toml | 9 + .../listing-17-11-orig/src/main.rs | 49 ++ .../ch17-async-await/listing-17-11/Cargo.lock | 260 --------- .../listing-17-11/src/main.rs | 58 +- src/ch17-02-concurrency-with-async.md | 36 +- src/ch17-03-more-futures.md | 4 +- 13 files changed, 699 insertions(+), 646 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-05-orig/src/main.rs rename listings/ch17-async-await/{listing-17-05-orig => listing-17-10-orig}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-05-orig => listing-17-10-orig}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-10-orig/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-11-orig/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-11-orig/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-11-orig/src/main.rs diff --git a/listings/ch17-async-await/listing-17-05-orig/src/main.rs b/listings/ch17-async-await/listing-17-05-orig/src/main.rs deleted file mode 100644 index c1b62d8e66..0000000000 --- a/listings/ch17-async-await/listing-17-05-orig/src/main.rs +++ /dev/null @@ -1,31 +0,0 @@ -// ANCHOR: all -// ANCHOR: many-messages -use std::time::Duration; -// ANCHOR_END: many-messages - -fn main() { - trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - // ANCHOR: many-messages - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - // ANCHOR_END: many-messages - - // ANCHOR: loop - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR_END: loop - }); -} -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-05-orig/Cargo.lock b/listings/ch17-async-await/listing-17-10-orig/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-05-orig/Cargo.lock rename to listings/ch17-async-await/listing-17-10-orig/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-05-orig/Cargo.toml b/listings/ch17-async-await/listing-17-10-orig/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-05-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-10-orig/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-10-orig/src/main.rs b/listings/ch17-async-await/listing-17-10-orig/src/main.rs new file mode 100644 index 0000000000..78e17a3846 --- /dev/null +++ b/listings/ch17-async-await/listing-17-10-orig/src/main.rs @@ -0,0 +1,47 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + // ANCHOR: here + let futures = vec![tx1_fut, rx_fut, tx_fut]; + trpl::join_all(futures).await; + // ANCHOR_END: here + }); +} diff --git a/listings/ch17-async-await/listing-17-10/Cargo.lock b/listings/ch17-async-await/listing-17-10/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-10/Cargo.lock +++ b/listings/ch17-async-await/listing-17-10/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-10/src/main.rs b/listings/ch17-async-await/listing-17-10/src/main.rs index 78e17a3846..a9cba44de3 100644 --- a/listings/ch17-async-await/listing-17-10/src/main.rs +++ b/listings/ch17-async-await/listing-17-10/src/main.rs @@ -1,47 +1,26 @@ +// ANCHOR: many-messages use std::time::Duration; +// ANCHOR_END: many-messages fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); - let tx1 = tx.clone(); - let tx1_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; + // ANCHOR: many-messages - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; + // snip... - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - let tx_fut = async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - // ANCHOR: here - let futures = vec![tx1_fut, rx_fut, tx_fut]; - trpl::join_all(futures).await; - // ANCHOR_END: here + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR_END: many-messages }); } diff --git a/listings/ch17-async-await/listing-17-11-orig/Cargo.lock b/listings/ch17-async-await/listing-17-11-orig/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-11-orig/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-11-orig/Cargo.toml b/listings/ch17-async-await/listing-17-11-orig/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-11-orig/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-11-orig/src/main.rs b/listings/ch17-async-await/listing-17-11-orig/src/main.rs new file mode 100644 index 0000000000..beff676dbe --- /dev/null +++ b/listings/ch17-async-await/listing-17-11-orig/src/main.rs @@ -0,0 +1,49 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + // ANCHOR: here + let futures = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + + trpl::join_all(futures).await; + // ANCHOR_END: here + }); +} diff --git a/listings/ch17-async-await/listing-17-11/Cargo.lock b/listings/ch17-async-await/listing-17-11/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-11/Cargo.lock +++ b/listings/ch17-async-await/listing-17-11/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-11/src/main.rs b/listings/ch17-async-await/listing-17-11/src/main.rs index beff676dbe..529a605276 100644 --- a/listings/ch17-async-await/listing-17-11/src/main.rs +++ b/listings/ch17-async-await/listing-17-11/src/main.rs @@ -4,46 +4,22 @@ fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); - let tx1 = tx.clone(); - let tx1_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; - - let tx_fut = async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - // ANCHOR: here - let futures = - vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; - - trpl::join_all(futures).await; - // ANCHOR_END: here + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + + // ANCHOR: loop + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR_END: loop }); } diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index c5113a6fa4..9c3022b8aa 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -223,36 +223,40 @@ that from this code, though, since the message will arrive right away! > `.await` does not block further operations—as we will see! Let’s go ahead and send a whole series of messages, and sleep in between them, -as shown in Listing 17-TODO: +as shown in Listing 17-10: -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05-orig/src/main.rs:many-messages}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:many-messages}} ``` -Then we can wait on each of those messages in a loop. Here, we need to use a -`while let` loop rather than a `for` loop, because Rust does not yet have an -async version of `Iterator`, which is what the `for` loop does. In TODO: SECTION -TITLE, we will see more about two related traits the community has been working -on, `AsyncIterator` and `Stream`. For now, we can stick with `while let`, as in -Listing 17-TODO, and the loop will end when `rx.recv().await` produces a `None`. +This handles sending the messages, but so far we don’t do anything with them, +and the code just silently runs forever. Listing 17-11 shows how we can receive +those messages by waiting for them in a loop. -+Here, we need to use a `while let` loop rather than a `for` loop, because Rust +does not yet have an async version of `Iterator`, which is what the `for` loop +does. In TODO: SECTION TITLE, we will see more about two related traits the +community has been working on, `AsyncIterator` and `Stream`. For now, we can +stick with `while let`, as in Listing 17-11, and the loop will end when +`rx.recv().await` produces a `None`. + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05-orig/src/main.rs:loop}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:loop}} ``` -This code does not do what we want. It does successfully send and receive the -messages, but instead of seeing the messages received at one-second intervals, -we see them arrive all at once, four seconds after we start the program. It -also never stops! You will need to shut it down using -ctrl-c. +This code still does not do exactly what we want. It does successfully send and +receive the messages, but instead of seeing the messages received at one-second +intervals, we see them arrive all at once, four seconds after we start the +program. It also never stops! You will need to shut it down using ctrl-c. Let’s start by understanding why the messages all come in at once after the full delay, rather than coming in with delays in between each one. This highlights an diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 14b0435e57..04b716a41c 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -32,7 +32,7 @@ ticket. Let’s try putting our futures in a vector, and replace `join3` with ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-10-orig/src/main.rs:here}} ``` @@ -132,7 +132,7 @@ still does not compile. ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-11-orig/src/main.rs:here}} ``` From 60cde0097bd9ff911a5e134e26e9459caa162fb2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 09:53:46 -0600 Subject: [PATCH 301/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listing=2017-12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-12-orig/Cargo.lock | 540 ++++++++++++++++++ .../listing-17-12-orig/Cargo.toml | 9 + .../listing-17-12-orig/src/main.rs | 49 ++ .../ch17-async-await/listing-17-12/Cargo.lock | 260 --------- .../listing-17-12/src/main.rs | 60 +- src/ch17-02-concurrency-with-async.md | 6 +- src/ch17-03-more-futures.md | 2 +- 7 files changed, 620 insertions(+), 306 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-12-orig/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-12-orig/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-12-orig/src/main.rs diff --git a/listings/ch17-async-await/listing-17-12-orig/Cargo.lock b/listings/ch17-async-await/listing-17-12-orig/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-12-orig/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-12-orig/Cargo.toml b/listings/ch17-async-await/listing-17-12-orig/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-12-orig/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-12-orig/src/main.rs b/listings/ch17-async-await/listing-17-12-orig/src/main.rs new file mode 100644 index 0000000000..b712d344c0 --- /dev/null +++ b/listings/ch17-async-await/listing-17-12-orig/src/main.rs @@ -0,0 +1,49 @@ +use std::{future::Future, time::Duration}; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + // ANCHOR: here + let futures: Vec>> = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + // ANCHOR_END: here + + trpl::join_all(futures).await; + }); +} diff --git a/listings/ch17-async-await/listing-17-12/Cargo.lock b/listings/ch17-async-await/listing-17-12/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-12/Cargo.lock +++ b/listings/ch17-async-await/listing-17-12/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-12/src/main.rs b/listings/ch17-async-await/listing-17-12/src/main.rs index b712d344c0..cdb982e86c 100644 --- a/listings/ch17-async-await/listing-17-12/src/main.rs +++ b/listings/ch17-async-await/listing-17-12/src/main.rs @@ -1,49 +1,25 @@ -use std::{future::Future, time::Duration}; +// ANCHOR: all +use std::time::Duration; fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); - let tx1 = tx.clone(); - let tx1_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; - - let tx_fut = async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - // ANCHOR: here - let futures: Vec>> = - vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; - // ANCHOR_END: here - - trpl::join_all(futures).await; + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } }); } +// ANCHOR_END: all diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 9c3022b8aa..91c27046f0 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -268,12 +268,12 @@ much easier to follow, because having the order that `.await` keywords appear in the *code* is also the order they happen when running the *program*. With that in mind, we can see why this code behaves the way it does by looking -at the whole thing all together. +at the whole thing all together, in Listing 17-12. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05-orig/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:all}} ``` diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 04b716a41c..1c32bec203 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -156,7 +156,7 @@ little involved, so let’s walk through each part of it. ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-12-orig/src/main.rs:here}} ``` From 7e5b6f2c7db2cadc21afeff3d58586dc2495ee92 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 09:56:43 -0600 Subject: [PATCH 302/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listings=2017-13=20and=2017-14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-06-orig/src/main.rs | 33 ---------- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 34 ++++++---- .../listing-17-13/src/main.rs | 42 ++++-------- .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-14-orig/src/main.rs | 66 +++++++++++++++++++ .../listing-17-14/src/main.rs | 47 ++++--------- src/ch17-02-concurrency-with-async.md | 19 +++--- src/ch17-03-more-futures.md | 4 +- 11 files changed, 123 insertions(+), 122 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-06-orig/src/main.rs rename listings/ch17-async-await/{listing-17-06-orig => listing-17-13-orig}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-06-orig => listing-17-13-orig}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-07-orig => listing-17-13-orig}/src/main.rs (54%) rename listings/ch17-async-await/{listing-17-07-orig => listing-17-14-orig}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-07-orig => listing-17-14-orig}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-14-orig/src/main.rs diff --git a/listings/ch17-async-await/listing-17-06-orig/src/main.rs b/listings/ch17-async-await/listing-17-06-orig/src/main.rs deleted file mode 100644 index aeeacc5462..0000000000 --- a/listings/ch17-async-await/listing-17-06-orig/src/main.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - // ANCHOR: futures - let tx_fut = async { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - // ANCHOR: loop - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR_END: loop - }; - - trpl::join(tx_fut, rx_fut).await; - // ANCHOR_END: futures - }); -} diff --git a/listings/ch17-async-await/listing-17-06-orig/Cargo.lock b/listings/ch17-async-await/listing-17-13-orig/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-06-orig/Cargo.lock rename to listings/ch17-async-await/listing-17-13-orig/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-06-orig/Cargo.toml b/listings/ch17-async-await/listing-17-13-orig/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-06-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-13-orig/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-07-orig/src/main.rs b/listings/ch17-async-await/listing-17-13-orig/src/main.rs similarity index 54% rename from listings/ch17-async-await/listing-17-07-orig/src/main.rs rename to listings/ch17-async-await/listing-17-13-orig/src/main.rs index e5d8f86066..5520a58ca5 100644 --- a/listings/ch17-async-await/listing-17-07-orig/src/main.rs +++ b/listings/ch17-async-await/listing-17-13-orig/src/main.rs @@ -1,10 +1,15 @@ -use std::time::Duration; +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); - let tx_fut = async { + let tx1 = tx.clone(); + let tx1_fut = pin!(async move { let vals = vec![ String::from("hi"), String::from("from"), @@ -13,19 +18,18 @@ fn main() { ]; for val in vals { - tx.send(val).unwrap(); + tx1.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }; + }); - let rx_fut = async { - while let Some(received) = rx.recv().await { - println!("Got: {received}"); + let rx_fut = pin!(async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); } - }; + }); - // ANCHOR: updated - let tx_fut2 = async { + let tx_fut = pin!(async move { let vals = vec![ String::from("more"), String::from("messages"), @@ -37,9 +41,13 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }; + }); + + // ANCHOR: here + let futures: Vec>>> = + vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; + // ANCHOR_END: here - trpl::join3(tx_fut, tx_fut2, rx_fut).await; - // ANCHOR_END: updated + trpl::join_all(futures).await; }); } diff --git a/listings/ch17-async-await/listing-17-13/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs index 5520a58ca5..aeeacc5462 100644 --- a/listings/ch17-async-await/listing-17-13/src/main.rs +++ b/listings/ch17-async-await/listing-17-13/src/main.rs @@ -1,15 +1,11 @@ -use std::{ - future::Future, - pin::{pin, Pin}, - time::Duration, -}; +use std::time::Duration; fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); - let tx1 = tx.clone(); - let tx1_fut = pin!(async move { + // ANCHOR: futures + let tx_fut = async { let vals = vec![ String::from("hi"), String::from("from"), @@ -18,36 +14,20 @@ fn main() { ]; for val in vals { - tx1.send(val).unwrap(); + tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }); + }; - let rx_fut = pin!(async { + let rx_fut = async { + // ANCHOR: loop while let Some(value) = rx.recv().await { println!("received '{value}'"); } - }); - - let tx_fut = pin!(async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }); - - // ANCHOR: here - let futures: Vec>>> = - vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; - // ANCHOR_END: here + // ANCHOR_END: loop + }; - trpl::join_all(futures).await; + trpl::join(tx_fut, rx_fut).await; + // ANCHOR_END: futures }); } diff --git a/listings/ch17-async-await/listing-17-07-orig/Cargo.lock b/listings/ch17-async-await/listing-17-14-orig/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-07-orig/Cargo.lock rename to listings/ch17-async-await/listing-17-14-orig/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-07-orig/Cargo.toml b/listings/ch17-async-await/listing-17-14-orig/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-07-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-14-orig/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-14-orig/src/main.rs b/listings/ch17-async-await/listing-17-14-orig/src/main.rs new file mode 100644 index 0000000000..a22c9570f7 --- /dev/null +++ b/listings/ch17-async-await/listing-17-14-orig/src/main.rs @@ -0,0 +1,66 @@ +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + // ANCHOR: here + let tx1_fut = pin!(async move { + // snip... + // ANCHOR_END: here + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR: here + }); + // ANCHOR_END: here + + // ANCHOR: here + let rx_fut = pin!(async { + // snip... + // ANCHOR_END: here + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR: here + }); + // ANCHOR_END: here + + // ANCHOR: here + let tx_fut = pin!(async move { + // snip... + // ANCHOR_END: here + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR: here + }); + + let futures: Vec>> = + vec![tx1_fut, rx_fut, tx_fut]; + // ANCHOR_END: here + + trpl::join_all(futures).await; + }); +} diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs index a22c9570f7..e5d8f86066 100644 --- a/listings/ch17-async-await/listing-17-14/src/main.rs +++ b/listings/ch17-async-await/listing-17-14/src/main.rs @@ -1,18 +1,10 @@ -use std::{ - future::Future, - pin::{pin, Pin}, - time::Duration, -}; +use std::time::Duration; fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); - let tx1 = tx.clone(); - // ANCHOR: here - let tx1_fut = pin!(async move { - // snip... - // ANCHOR_END: here + let tx_fut = async { let vals = vec![ String::from("hi"), String::from("from"), @@ -21,28 +13,19 @@ fn main() { ]; for val in vals { - tx1.send(val).unwrap(); + tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - // ANCHOR: here - }); - // ANCHOR_END: here + }; - // ANCHOR: here - let rx_fut = pin!(async { - // snip... - // ANCHOR_END: here - while let Some(value) = rx.recv().await { - println!("received '{value}'"); + let rx_fut = async { + while let Some(received) = rx.recv().await { + println!("Got: {received}"); } - // ANCHOR: here - }); - // ANCHOR_END: here + }; - // ANCHOR: here - let tx_fut = pin!(async move { - // snip... - // ANCHOR_END: here + // ANCHOR: updated + let tx_fut2 = async { let vals = vec![ String::from("more"), String::from("messages"), @@ -54,13 +37,9 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - // ANCHOR: here - }); - - let futures: Vec>> = - vec![tx1_fut, rx_fut, tx_fut]; - // ANCHOR_END: here + }; - trpl::join_all(futures).await; + trpl::join3(tx_fut, tx_fut2, rx_fut).await; + // ANCHOR_END: updated }); } diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 91c27046f0..c9c0703585 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -289,12 +289,12 @@ receiving each message, rather than before receiving any message, we need to give put the `tx` and `rx` operations in their own async blocks, so the runtime can execute each of them separately. We also need to tell the runtime to actually run them using `trpl::join`, just like we did for the counting example -above. Listing 17-TODO shows how that looks. +above. Listing 17-13 shows how that looks. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-06-orig/src/main.rs:futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:futures}} ``` @@ -333,10 +333,10 @@ Right now, the async block only borrows `tx`. We can confirm this by adding another async block which uses `tx`, and using `trpl::join3` to wait for all three futures to complete: -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-07-orig/src/main.rs:updated}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:updated}} ``` @@ -346,6 +346,8 @@ which `rx` can then receive. When we run that code, we see the extra output from the new `async` block, and the message it sends being received by the `rx.recv()`. + + ```text Got: hi Got: more @@ -358,10 +360,9 @@ Got: you ``` As before, we also see that the program does not shut down on its own and -requires a ctrl-c, though. This little -exploration helps us understand why: it is ultimately about *ownership*. We need -to move `tx` into the async block so that once that block ends, `tx` will be -dropped. +requires a ctrl-c. This little exploration helps +us understand why: it is ultimately about *ownership*. We need to move `tx` into +the async block so that once that block ends, `tx` will be dropped. Since we have seen how `async` blocks borrow the items they reference from their outer scope, we can go ahead and remove the extra block we just added for now, diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 1c32bec203..1b44191516 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -369,7 +369,7 @@ for exactly this. Putting that together, we end up with the code in Listing ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-13-orig/src/main.rs:here}} ``` @@ -410,7 +410,7 @@ dynamic `Future` type. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-14-orig/src/main.rs:here}} ``` From 766ad04fb28f327fa3cb9ade8a2d7570cbf3fe28 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 10:12:25 -0600 Subject: [PATCH 303/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listings=2017-15=20and=2017-16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-08-orig/src/main.rs | 34 -- .../listing-17-09-orig/Cargo.lock | 540 ------------------ .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-15-orig/src/main.rs | 12 + .../ch17-async-await/listing-17-15/Cargo.lock | 260 --------- .../listing-17-15/src/main.rs | 36 +- .../ch17-async-await/listing-17-16/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../src/main.rs | 0 src/ch17-02-concurrency-with-async.md | 20 +- src/ch17-03-more-futures.md | 2 +- 12 files changed, 328 insertions(+), 856 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-08-orig/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-09-orig/Cargo.lock rename listings/ch17-async-await/{listing-17-08-orig => listing-17-15-orig}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-08-orig => listing-17-15-orig}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-15-orig/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-16/Cargo.lock rename listings/ch17-async-await/{listing-17-09-orig => listing-17-16}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-09-orig => listing-17-16}/src/main.rs (100%) diff --git a/listings/ch17-async-await/listing-17-08-orig/src/main.rs b/listings/ch17-async-await/listing-17-08-orig/src/main.rs deleted file mode 100644 index fa02e21a87..0000000000 --- a/listings/ch17-async-await/listing-17-08-orig/src/main.rs +++ /dev/null @@ -1,34 +0,0 @@ -// ANCHOR: all -use std::time::Duration; - -fn main() { - trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - // ANCHOR: move - let tx_fut = async move { - // ANCHOR_END: move - - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); - } - }; - - trpl::join(tx_fut, rx_fut).await; - }); -} -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-09-orig/Cargo.lock b/listings/ch17-async-await/listing-17-09-orig/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-09-orig/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-08-orig/Cargo.lock b/listings/ch17-async-await/listing-17-15-orig/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-08-orig/Cargo.lock rename to listings/ch17-async-await/listing-17-15-orig/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-08-orig/Cargo.toml b/listings/ch17-async-await/listing-17-15-orig/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-08-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-15-orig/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-15-orig/src/main.rs b/listings/ch17-async-await/listing-17-15-orig/src/main.rs new file mode 100644 index 0000000000..24845f0887 --- /dev/null +++ b/listings/ch17-async-await/listing-17-15-orig/src/main.rs @@ -0,0 +1,12 @@ +fn main() { + trpl::block_on(async { + // ANCHOR: here + let a = async { 1u32 }; + let b = async { "Hello!" }; + let c = async { true }; + // ANCHOR_END: here + + let (a_result, b_result, c_result) = trpl::join!(a, b, c); + println!("{a_result}, {b_result}, {c_result}"); + }); +} diff --git a/listings/ch17-async-await/listing-17-15/Cargo.lock b/listings/ch17-async-await/listing-17-15/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-15/Cargo.lock +++ b/listings/ch17-async-await/listing-17-15/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-15/src/main.rs b/listings/ch17-async-await/listing-17-15/src/main.rs index 24845f0887..652545f09f 100644 --- a/listings/ch17-async-await/listing-17-15/src/main.rs +++ b/listings/ch17-async-await/listing-17-15/src/main.rs @@ -1,12 +1,32 @@ +use std::time::Duration; + fn main() { trpl::block_on(async { - // ANCHOR: here - let a = async { 1u32 }; - let b = async { "Hello!" }; - let c = async { true }; - // ANCHOR_END: here - - let (a_result, b_result, c_result) = trpl::join!(a, b, c); - println!("{a_result}, {b_result}, {c_result}"); + // ANCHOR: with-move + let (tx, mut rx) = trpl::channel(); + + let tx_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; + // ANCHOR_END: with-move }); } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-16/Cargo.lock b/listings/ch17-async-await/listing-17-16/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-16/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-09-orig/Cargo.toml b/listings/ch17-async-await/listing-17-16/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-09-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-16/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-09-orig/src/main.rs b/listings/ch17-async-await/listing-17-16/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-09-orig/src/main.rs rename to listings/ch17-async-await/listing-17-16/src/main.rs diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index c9c0703585..58ecfcbdc3 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -380,35 +380,29 @@ references this way, it needs to move that data into the future—so the `move` keyword works with async blocks just like it does with closures. Thus, we can change the first async block from an `async` block to an `async -move` block, as in Listing 17-TODO: +move` block, like this: -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-08-orig/src/main.rs:move}} -``` - -The result is Listing 17-TODO, and when we run *this* version of the code, it +The result is Listing 17-15, and when we run *this* version of the code, it shuts down gracefully after the last message is sent. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-08-orig/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:with-move}} ``` This async channel is also a multiple-producer channel, so we can call `clone` on `tx` if we want to send messages from multiple futures. For example, we can -make the code from Listing 17-TODO work by cloning the `tx` before moving it +make the code from Listing 17-16 work by cloning the `tx` before moving it into the first async block, moving the original `tx` into the second async block, and switching back to `join3`. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-09-orig/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-16/src/main.rs:here}} ``` diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 1b44191516..ccc306e2cb 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -425,7 +425,7 @@ type for `a` implements `Future` and the anonymous future type for ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-15-orig/src/main.rs:here}} ``` From c308400251c7ee16b4c72fd972fb689fdf974ef9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 10:22:27 -0600 Subject: [PATCH 304/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listings=2017-17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-09b/Cargo.lock | 540 ------------------ .../ch17-async-await/listing-17-17/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../src/main.rs | 0 src/ch17-03-more-futures.md | 8 +- 5 files changed, 284 insertions(+), 544 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-09b/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-17/Cargo.lock rename listings/ch17-async-await/{listing-17-09b => listing-17-17}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-09b => listing-17-17}/src/main.rs (100%) diff --git a/listings/ch17-async-await/listing-17-09b/Cargo.lock b/listings/ch17-async-await/listing-17-09b/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-09b/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-17/Cargo.lock b/listings/ch17-async-await/listing-17-17/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-17/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-09b/Cargo.toml b/listings/ch17-async-await/listing-17-17/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-09b/Cargo.toml rename to listings/ch17-async-await/listing-17-17/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-09b/src/main.rs b/listings/ch17-async-await/listing-17-17/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-09b/src/main.rs rename to listings/ch17-async-await/listing-17-17/src/main.rs diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index ccc306e2cb..860b2d27cb 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -4,13 +4,13 @@ When we switched from using two futures to three in the previous section, we also had to switch from using `join` to using `join3`. It would be annoying to do this every time we changed our code. Happily, we have a macro form of `join` to which we can pass an arbitrary number of arguments. It also handles awaiting -the futures itself. Thus, we could rewrite the code from Listing 17-TODO to use -`join!` instead of `join3`, as in Listing 17-TODO: +the futures itself. Thus, we could rewrite the code from Listing 17-16 to use +`join!` instead of `join3`, as in Listing 17-17: -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-09b/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-17/src/main.rs:here}} ``` From 6035ba4315c203efee9b6c8383dcfa1fcf12991f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 10:26:17 -0600 Subject: [PATCH 305/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listing=2017-18?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-10-orig/Cargo.lock | 540 ------------------ .../ch17-async-await/listing-17-18/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../ch17-async-await/listing-17-18/output.txt | 53 ++ .../src/main.rs | 0 src/ch17-03-more-futures.md | 33 +- 6 files changed, 336 insertions(+), 570 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-10-orig/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-18/Cargo.lock rename listings/ch17-async-await/{listing-17-10-orig => listing-17-18}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-18/output.txt rename listings/ch17-async-await/{listing-17-10-orig => listing-17-18}/src/main.rs (100%) diff --git a/listings/ch17-async-await/listing-17-10-orig/Cargo.lock b/listings/ch17-async-await/listing-17-10-orig/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-10-orig/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-18/Cargo.lock b/listings/ch17-async-await/listing-17-18/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-18/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-10-orig/Cargo.toml b/listings/ch17-async-await/listing-17-18/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-10-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-18/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-18/output.txt b/listings/ch17-async-await/listing-17-18/output.txt new file mode 100644 index 0000000000..4ad945623f --- /dev/null +++ b/listings/ch17-async-await/listing-17-18/output.txt @@ -0,0 +1,53 @@ +$ cargo run + Compiling proc-macro2 v1.0.82 + Compiling unicode-ident v1.0.12 + Compiling autocfg v1.3.0 + Compiling futures-core v0.3.30 + Compiling libc v0.2.154 + Compiling futures-sink v0.3.30 + Compiling pin-project-lite v0.2.14 + Compiling pin-utils v0.1.0 + Compiling futures-io v0.3.30 + Compiling futures-task v0.3.30 + Compiling memchr v2.7.2 + Compiling futures-channel v0.3.30 + Compiling slab v0.4.9 + Compiling num_cpus v1.16.0 + Compiling quote v1.0.36 + Compiling tokio v1.37.0 + Compiling syn v2.0.63 + Compiling futures-macro v0.3.30 + Compiling futures-util v0.3.30 + Compiling futures-executor v0.3.30 + Compiling futures v0.3.30 + Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-18) +error[E0308]: mismatched types + --> src/main.rs:43:37 + | +8 | let tx1_fut = async move { + | _______________________- +9 | | let vals = vec![ +10 | | String::from("hi"), +11 | | String::from("from"), +... | +19 | | } +20 | | }; + | |_________- the expected `async` block +21 | +22 | let rx_fut = async { + | ______________________- +23 | | while let Some(value) = rx.recv().await { +24 | | println!("received '{value}'"); +25 | | } +26 | | }; + | |_________- the found `async` block +... +43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; + | ^^^^^^ expected `async` block, found a different `async` block + | + = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` + found `async` block `{async block@src/main.rs:22:22: 26:10}` + +For more information about this error, try `rustc --explain E0308`. +error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-10-orig/src/main.rs b/listings/ch17-async-await/listing-17-18/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-10-orig/src/main.rs rename to listings/ch17-async-await/listing-17-18/src/main.rs diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 860b2d27cb..5845967f1d 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -29,45 +29,18 @@ trait, which we learned about back in Chapter 13, so it seems like just the ticket. Let’s try putting our futures in a vector, and replace `join3` with `join_all`. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-10-orig/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-18/src/main.rs:here}} ``` Unfortunately, this does not compile. Instead, we get this error: - - ```text -error[E0308]: mismatched types - --> src/main.rs:43:37 - | -8 | let tx1_fut = async move { - | _______________________- -9 | | let vals = vec![ -10 | | String::from("hi"), -11 | | String::from("from"), -... | -19 | | } -20 | | }; - | |_________- the expected `async` block -21 | -22 | let rx_fut = async { - | ______________________- -23 | | while let Some(value) = rx.recv().await { -24 | | println!("received '{value}'"); -25 | | } -26 | | }; - | |_________- the found `async` block -... -43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; - | ^^^^^^ expected `async` block, found a different `async` block - | - = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` - found `async` block `{async block@src/main.rs:22:22: 26:10}` +{{#include ../listings/ch17-async-await/listing-17-18/output.txt}} ``` This error message is admittedly not the most helpful! It only tells us that it From a1eb8ae8e7a732f88dd5b1ba76accda5fea1d3d0 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 10:29:15 -0600 Subject: [PATCH 306/720] Ch. 17: Fix internal links - Align them with the existing format for links. - Add one missing link. --- src/ch17-03-more-futures.md | 14 ++++++++------ src/ch17-04-more-ways-of-combining-futures.md | 10 ++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 5845967f1d..de1e019b49 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -70,8 +70,8 @@ error[E0308]: mismatched types ``` Saying “expected *something*, found *something else*” is Rust’s standard format -for telling us about a type mismatch. As we saw with vectors in [Using an Enum -to Store Multiple Types][collections] back in Chapter 8, we need the type of +for telling us about a type mismatch. As we saw with vectors in [“Using an Enum +to Store Multiple Types”][collections] back in Chapter 8, we need the type of each item in a collection to be the same—and `tx1_fut`, `rx_fut`, and `tx_fut` do not have the same type. @@ -92,8 +92,8 @@ with a dynamic collection of futures where we do not know what they will all be until runtime. To make this work, we need to use *trait objects*, just as we did for returning -different kinds of errors from the same function in [Returning Errors from the -run function][dyn] back in Chapter 12. Again, we will cover trait objects in +different kinds of errors from the same function in [“Returning Errors from the +run function”][dyn] back in Chapter 12. Again, we will cover trait objects in detail in Chapter 17. Here, it lets us treat each of the anonymous futures produced by these types as interchangeable, since all of them by definition implement the `Future` trait. @@ -208,7 +208,7 @@ type to call `poll`? --> -In [Futures and Syntax: What Are Futures][what-are-futures], we described how +In [“Futures and Syntax: What Are Futures”][what-are-futures], we described how a series of await points in a future get compiled into a state machine—and noted how the compiler helps make sure that state machine follows all of Rust’s normal rules around safety, including borrowing and ownership. Consider code like this: @@ -421,4 +421,6 @@ handy for building frameworks, or especially when you are building a runtime itself, rather than for day to day Rust code. When you see them, though, now you will know what to do! -[what-are-futures]: /ch17-01-futures-and-syntax.html#what-are-futures +[collections]: ch08-01-vectors.html#using-an-enum-to-store-multiple-types +[dyn]: ch12-03-improving-error-handling-and-modularity.html +[what-are-futures]: ch17-01-futures-and-syntax.html#what-are-futures diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index c5d5fd9c30..f39e7da7e5 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -31,9 +31,9 @@ Regardless of whether the implementation of race we are using is fair, though, *one* of the futures will run up to the first `.await` in its body before another task can start. -To see why, recall from our discussion in [What Are Futures?][futures] that Rust -compiles async blocks in a way that hands control back to the async runtime at -each await point. That has an important corollary: async runtimes can only +To see why, recall from our discussion in [“What Are Futures?”][futures] that +Rust compiles async blocks in a way that hands control back to the async runtime +at each await point. That has an important corollary: async runtimes can only switch which future they are executing at await points. Everything in between await points is just normal synchronous Rust code. That means if you do a bunch of really expensive work in an async function without an `.await`, that future @@ -286,6 +286,4 @@ example, you can use this same approach to combine timeouts with retries, and in turn use those with things like network calls—the exact example we started out with at the beginning of the chapter! -[collections]: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html#using-an-enum-to-store-multiple-types -[dyn]: https://doc.rust-lang.org/stable/book/ch12-03-improving-error-handling-and-modularity.html -[futures]: /ch17-01-futures-and-syntax.html#what-are-futures +[futures]: ch17-01-futures-and-syntax.html#what-are-futures From 911167d473fdf8fbce70ea1fff8a9a83ac6777b9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 10:29:15 -0600 Subject: [PATCH 307/720] =?UTF-8?q?Ch.=2017:=20Remove=20completed=20`TODO`?= =?UTF-8?q?=20for=20`Pin`=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-03-more-futures.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index de1e019b49..cc7f60da74 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -198,16 +198,6 @@ above—but that was in terms of `Unpin`, not `Pin`. So what exactly are `Pin` a `Unpin`, how do they relate, and why does `Future` need `self` to be in a `Pin` type to call `poll`? - - - - In [“Futures and Syntax: What Are Futures”][what-are-futures], we described how a series of await points in a future get compiled into a state machine—and noted how the compiler helps make sure that state machine follows all of Rust’s normal From b8ecdb5c863b947f7c21903d4b75d5d48b96e7f0 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 10:29:15 -0600 Subject: [PATCH 308/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20extract=20a=20no?= =?UTF-8?q?-listing=20for=20type=20mismatches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../no-listing-type-mismatch/Cargo.lock | 7 +++++++ .../no-listing-type-mismatch/Cargo.toml | 6 ++++++ .../no-listing-type-mismatch/output.txt | 10 ++++++++++ .../no-listing-type-mismatch/src/main.rs | 7 +++++++ src/ch17-03-more-futures.md | 14 +++----------- 5 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 listings/ch17-async-await/no-listing-type-mismatch/Cargo.lock create mode 100644 listings/ch17-async-await/no-listing-type-mismatch/Cargo.toml create mode 100644 listings/ch17-async-await/no-listing-type-mismatch/output.txt create mode 100644 listings/ch17-async-await/no-listing-type-mismatch/src/main.rs diff --git a/listings/ch17-async-await/no-listing-type-mismatch/Cargo.lock b/listings/ch17-async-await/no-listing-type-mismatch/Cargo.lock new file mode 100644 index 0000000000..d30b928a6c --- /dev/null +++ b/listings/ch17-async-await/no-listing-type-mismatch/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "async_await" +version = "0.1.0" diff --git a/listings/ch17-async-await/no-listing-type-mismatch/Cargo.toml b/listings/ch17-async-await/no-listing-type-mismatch/Cargo.toml new file mode 100644 index 0000000000..67729afc80 --- /dev/null +++ b/listings/ch17-async-await/no-listing-type-mismatch/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch17-async-await/no-listing-type-mismatch/output.txt b/listings/ch17-async-await/no-listing-type-mismatch/output.txt new file mode 100644 index 0000000000..5b7dc951b7 --- /dev/null +++ b/listings/ch17-async-await/no-listing-type-mismatch/output.txt @@ -0,0 +1,10 @@ +$ cargo build + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/no-listing-type-mismatch) +error[E0308]: mismatched types + --> src/main.rs:5:24 + | +5 | let vals = vec![a, b]; + | ^ expected integer, found `&str` + +For more information about this error, try `rustc --explain E0308`. +error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/no-listing-type-mismatch/src/main.rs b/listings/ch17-async-await/no-listing-type-mismatch/src/main.rs new file mode 100644 index 0000000000..0c282f4f87 --- /dev/null +++ b/listings/ch17-async-await/no-listing-type-mismatch/src/main.rs @@ -0,0 +1,7 @@ +fn main() { + // ANCHOR: here + let a = 1; + let b = "Hello"; + let vals = vec![a, b]; + // ANCHOR_END: here +} diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index cc7f60da74..343d558e19 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -51,22 +51,14 @@ appear in the code? One clue is the format of this message. Notice that it is exactly the same as if we had tried to create a `Vec` with a a number and a string in it: - - -```rust -let a = 1; -let b = "Hello"; -let vals = vec![a, b]; +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/no-listing-type-mismatch/src/main.rs:here}} ``` The output there would be: ```text -error[E0308]: mismatched types - --> src/main.rs:4:24 - | -4 | let vals = vec![a, b]; - | ^ expected integer, found `&str` +{{#include ../listings/ch17-async-await/no-listing-type-mismatch/output.txt}} ``` Saying “expected *something*, found *something else*” is Rust’s standard format From 2b65e53466338426ad28c57a070fc117b72c5d29 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 12:42:08 -0600 Subject: [PATCH 309/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20correct=20number?= =?UTF-8?q?ing=20and=20content=20for=20Listings=2017-19=20and=2017-20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-11-orig/Cargo.lock | 540 ------------------ .../listing-17-12-orig/Cargo.lock | 540 ------------------ .../ch17-async-await/listing-17-19/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../src/main.rs | 0 .../ch17-async-await/listing-17-20/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../ch17-async-await/listing-17-20/output.txt | 82 +++ .../src/main.rs | 0 src/ch17-03-more-futures.md | 35 +- 10 files changed, 651 insertions(+), 1106 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-11-orig/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-12-orig/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-19/Cargo.lock rename listings/ch17-async-await/{listing-17-11-orig => listing-17-19}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-11-orig => listing-17-19}/src/main.rs (100%) create mode 100644 listings/ch17-async-await/listing-17-20/Cargo.lock rename listings/ch17-async-await/{listing-17-12-orig => listing-17-20}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-20/output.txt rename listings/ch17-async-await/{listing-17-12-orig => listing-17-20}/src/main.rs (100%) diff --git a/listings/ch17-async-await/listing-17-11-orig/Cargo.lock b/listings/ch17-async-await/listing-17-11-orig/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-11-orig/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-12-orig/Cargo.lock b/listings/ch17-async-await/listing-17-12-orig/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-12-orig/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-19/Cargo.lock b/listings/ch17-async-await/listing-17-19/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-19/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-11-orig/Cargo.toml b/listings/ch17-async-await/listing-17-19/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-11-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-19/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-11-orig/src/main.rs b/listings/ch17-async-await/listing-17-19/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-11-orig/src/main.rs rename to listings/ch17-async-await/listing-17-19/src/main.rs diff --git a/listings/ch17-async-await/listing-17-20/Cargo.lock b/listings/ch17-async-await/listing-17-20/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-20/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-12-orig/Cargo.toml b/listings/ch17-async-await/listing-17-20/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-12-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-20/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-20/output.txt b/listings/ch17-async-await/listing-17-20/output.txt new file mode 100644 index 0000000000..1fcc787041 --- /dev/null +++ b/listings/ch17-async-await/listing-17-20/output.txt @@ -0,0 +1,82 @@ +cargo run + Compiling proc-macro2 v1.0.82 + Compiling unicode-ident v1.0.12 + Compiling autocfg v1.3.0 + Compiling futures-core v0.3.30 + Compiling pin-project-lite v0.2.14 + Compiling libc v0.2.154 + Compiling futures-sink v0.3.30 + Compiling memchr v2.7.2 + Compiling futures-task v0.3.30 + Compiling futures-io v0.3.30 + Compiling futures-channel v0.3.30 + Compiling pin-utils v0.1.0 + Compiling slab v0.4.9 + Compiling num_cpus v1.16.0 + Compiling tokio v1.37.0 + Compiling quote v1.0.36 + Compiling syn v2.0.63 + Compiling futures-macro v0.3.30 + Compiling futures-util v0.3.30 + Compiling futures-executor v0.3.30 + Compiling futures v0.3.30 + Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-20) +error[E0277]: `dyn std::future::Future` cannot be unpinned + --> src/main.rs:47:24 + | +47 | trpl::join_all(futures).await; + | -------------- ^^^^^^^ the trait `Unpin` is not implemented for `dyn std::future::Future`, which is required by `Box>: std::future::Future` + | | + | required by a bound introduced by this call + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box>` to implement `std::future::Future` +note: required by a bound in `join_all` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 + | +102 | pub fn join_all(iter: I) -> JoinAll + | -------- required by a bound in this function +... +105 | I::Item: Future, + | ^^^^^^ required by this bound in `join_all` + +error[E0277]: `dyn std::future::Future` cannot be unpinned + --> src/main.rs:47:9 + | +47 | trpl::join_all(futures).await; + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `dyn std::future::Future`, which is required by `Box>: std::future::Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box>` to implement `std::future::Future` +note: required by a bound in `JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` + +error[E0277]: `dyn std::future::Future` cannot be unpinned + --> src/main.rs:47:33 + | +47 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `dyn std::future::Future`, which is required by `Box>: std::future::Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box>` to implement `std::future::Future` +note: required by a bound in `JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` + +For more information about this error, try `rustc --explain E0277`. +error: could not compile `async_await` (bin "async_await") due to 3 previous errors diff --git a/listings/ch17-async-await/listing-17-12-orig/src/main.rs b/listings/ch17-async-await/listing-17-20/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-12-orig/src/main.rs rename to listings/ch17-async-await/listing-17-20/src/main.rs diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 343d558e19..4acce85bd5 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -91,13 +91,13 @@ produced by these types as interchangeable, since all of them by definition implement the `Future` trait. We can start by wrapping each of the futures in the `vec!` in a `Box::new()`. -Unfortunately, the initial way we might try this, as shown in Listing 17-TODO, +Unfortunately, the initial way we might try this, as shown in Listing 17-19, still does not compile. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-11-orig/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} ``` @@ -118,37 +118,20 @@ little involved, so let’s walk through each part of it. - The entire trait is wrapped in a `Box`. - Finally, we state explicitly that `futures` is a `Vec` containing these items. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-12-orig/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} ``` That already made a big difference. Now when we run the compiler, we only have -the errors mentioning `Unpin`, each of which is a variation on this same output: +the errors mentioning `Unpin`. Although there are three of them, notice that +each is very similar in its contets - - -```text -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:33 - | -46 | trpl::join_all(futures).await; - | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: Future` - | - = note: consider using the `pin!` macro - consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `Future` -note: required by a bound in `futures_util::future::join_all::JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 - | -27 | pub struct JoinAll - | ------- required by a bound in this struct -28 | where -29 | F: Future, - | ^^^^^^ required by this bound in `JoinAll` +```console +{{#include ../listings/ch17-async-await/listing-17-20/output.txt}} ``` That is a *lot* to digest, so let’s pull it apart. The first part of the message From 67bd0a08bcdf23adbbe114066947154888ceeb83 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 13:23:51 -0600 Subject: [PATCH 310/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20support=20code?= =?UTF-8?q?=20for=20motivating=20`Pin`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rexport `tokio::fs::read_to_string` as `trpl::read_to_string`. - Add a no-listing example for the mutable borrow example. This will keep us honest that the code there itself compiles just fine! --- .../no-listing-borrow-mutable-vec/Cargo.lock | 280 ++++++++++++++++++ .../no-listing-borrow-mutable-vec/Cargo.toml | 9 + .../no-listing-borrow-mutable-vec/src/main.rs | 18 ++ .../test-data/hello.txt | 1 + .../test-data/punct.txt | 1 + .../test-data/world.txt | 1 + packages/trpl/Cargo.toml | 1 + packages/trpl/src/lib.rs | 1 + packages/trpl/tests/integration/main.rs | 11 + packages/trpl/tests/integration/to-read.txt | 1 + src/ch17-03-more-futures.md | 34 +-- 11 files changed, 338 insertions(+), 20 deletions(-) create mode 100644 listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock create mode 100644 listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.toml create mode 100644 listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs create mode 100644 listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/hello.txt create mode 100644 listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/punct.txt create mode 100644 listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/world.txt create mode 100644 packages/trpl/tests/integration/to-read.txt diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock b/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock new file mode 100644 index 0000000000..9eeeffaff4 --- /dev/null +++ b/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d0d8b92cd8358e8d229c11df9358decae64d137c5be540952c5ca7b25aea768" + +[[package]] +name = "miniz_oxide" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.toml b/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs b/listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs new file mode 100644 index 0000000000..fbba735c3f --- /dev/null +++ b/listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs @@ -0,0 +1,18 @@ +fn main() { + trpl::block_on({ + // ANCHOR: here + async { + let mut strings = vec![]; + + let a = trpl::read_to_string("test-data/hello.txt").await.unwrap(); + strings.push(a.trim()); + + let b = trpl::read_to_string("test-data/world.txt").await.unwrap(); + strings.push(b.trim()); + + let combined = strings.join(" "); + println!("{combined}"); + } + // ANCHOR_END: here + }); +} diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/hello.txt b/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/hello.txt new file mode 100644 index 0000000000..e965047ad7 --- /dev/null +++ b/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/hello.txt @@ -0,0 +1 @@ +Hello diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/punct.txt b/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/punct.txt new file mode 100644 index 0000000000..cdf4cb4feb --- /dev/null +++ b/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/punct.txt @@ -0,0 +1 @@ +! diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/world.txt b/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/world.txt new file mode 100644 index 0000000000..216e97ce08 --- /dev/null +++ b/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/world.txt @@ -0,0 +1 @@ +World diff --git a/packages/trpl/Cargo.toml b/packages/trpl/Cargo.toml index 626318db3d..898dae43f9 100644 --- a/packages/trpl/Cargo.toml +++ b/packages/trpl/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] futures = "0.3.30" tokio = { version = "1", default-features = false, features = [ + "fs", "rt-multi-thread", "sync", "time", diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 2a98c3ac40..4d748d4783 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -20,6 +20,7 @@ pub use futures::{ join, }; pub use tokio::{ + fs::read_to_string, runtime::Runtime, // We use the `unbounded` variants because they most closely match the APIs // from `std::sync::mpsc::channel`. Tokio's API choices are interesting: diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index 28421ba5ee..ecff695515 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -188,3 +188,14 @@ fn yield_now() { assert_eq!(result, "done"); } + +#[test] +fn read_to_string() { + let result = trpl::block_on(async { + trpl::read_to_string("tests/integration/to-read.txt") + .await + .unwrap() + }); + + assert_eq!(result, String::from("This is some text!\n")); +} diff --git a/packages/trpl/tests/integration/to-read.txt b/packages/trpl/tests/integration/to-read.txt new file mode 100644 index 0000000000..2af04f5bdf --- /dev/null +++ b/packages/trpl/tests/integration/to-read.txt @@ -0,0 +1 @@ +This is some text! diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 4acce85bd5..985c9d7384 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -178,21 +178,8 @@ a series of await points in a future get compiled into a state machine—and not how the compiler helps make sure that state machine follows all of Rust’s normal rules around safety, including borrowing and ownership. Consider code like this: - - ```rust -async { - let mut strings = vec![]; - - let a = trpl::read_to_string("test-data/hello.txt").await.unwrap(); - strings.push(a.trim()); - - let b = trpl::read_to_string("test-data/world.txt").await.unwrap(); - strings.push(b.trim()); - - let combined = strings.join(" "); - println!("{combined}"); -} +{{#rustdoc_include ../listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs:here}} ``` If we think about the state machine that would get compiled to, it might be @@ -200,15 +187,22 @@ something kind of like this: ```rust,ignore enum AsyncStateMachine<'a> { - FirstAwait(&'a mut Vec), - SecondAwait(&'a mut Vec), + AfterFirstAwait(&'a mut Vec), + AfterSecondAwait(&'a mut Vec), } ``` -This could actually be fine, on its own—Rust would keep track of those mutable -references, and if we got something wrong, the borrow checker would tell us. It -gets a bit tricky, though, if we want to move around the future that corresponds -to that block. Remember, we could always do something like this: +That is, at each `.await` in the source code, Rust would look at what state is +needed between that await point and the point another `.await` appears or the +async block ends, and create a corresponding variant in the `AsyncStateMachine`. +Each variant has the appropriate kind of reference to the data that will be +referenced in that section. The real implementation is not *exactly* like this, +but it is close enough to give the right mental model. + +And this could actually be fine, on its own—Rust would keep track of those +mutable references, and if we got something wrong, the borrow checker would tell +us. It gets a bit tricky, though, if we want to move around the future that +corresponds to that block. Remember, we could always do something like this: ```rust,ignore let file_reads_future = async { From 686b3e4f6876ac61c0e611f77ccc8e8c068a5a1c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 13:38:41 -0600 Subject: [PATCH 311/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20add=20a=20TODO?= =?UTF-8?q?=20for=20checking=20Pin=20description=20correctness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-03-more-futures.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 985c9d7384..13dad71be8 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -216,19 +216,24 @@ let some_other_future = async { trpl::join(file_reads_future, some_other_future).await; ``` + + If we pass those futures into `join`, or return them from a function, or put -them in a data structure to keep track of for some reason, we move the state -machine as well, and that means the `Vec` for the values we read in with -`trpl::read_to_string` moves. But the state machine Rust generated for us has -references to it. Since references point to the actual memory address of the -`Vec`, Rust needs some way to either update them so they are still valid after -the `Vec` moves, or it needs some way to keep `Vec` from getting moved around so -that the references do not need to be updated. Updating all the references to an -object every time it moves could be quite a lot of work for the compiler to add, -especially since there can be a whole web of references that need updating. On -the other hand, making sure the underlying item *does not move in memory* can be -“free” at runtime in exchange for keeping some promises at compile time. That is -where `Pin` and `Unpin` come in. +them in a data structure to keep track of for some reason, that moves the state +machine as well. That means the reference to `Vec` for the values we +read in with `trpl::read_to_string` moves along with it. Since references point +to the actual memory address of the `Vec`, Rust needs some way to either update +them so they are still valid after the `Vec` moves, or it needs some way to keep +`Vec` from getting moved around so that the references do not need to be +updated. Updating all the references to an object every time it moves could be +quite a lot of work for the compiler to add, especially since there can be a +whole web of references that need updating. On the other hand, making sure the +underlying item *does not move in memory* can be “free” at runtime in exchange +for keeping some promises at compile time. That is where `Pin` and `Unpin` come +in. > Note: The specific mechanics for how `Pin` and `Unpin` work under the hood are > covered extensively in the API documentation for `std::pin`, so if you would From 91565da622d3edb8242352586281f11d469d57cf Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 13:45:20 -0600 Subject: [PATCH 312/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20correct=20listin?= =?UTF-8?q?gs=20and=20wording=20for=20`Pin`=20materials?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-13-orig/Cargo.lock | 540 ------------------ .../listing-17-14-orig/Cargo.lock | 540 ------------------ .../listing-17-15-orig/Cargo.lock | 540 ------------------ .../ch17-async-await/listing-17-21/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../src/main.rs | 0 .../ch17-async-await/listing-17-22/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../src/main.rs | 4 - .../ch17-async-await/listing-17-23/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../src/main.rs | 2 +- src/ch17-03-more-futures.md | 57 +- 13 files changed, 873 insertions(+), 1650 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-13-orig/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-14-orig/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-15-orig/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-21/Cargo.lock rename listings/ch17-async-await/{listing-17-13-orig => listing-17-21}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-13-orig => listing-17-21}/src/main.rs (100%) create mode 100644 listings/ch17-async-await/listing-17-22/Cargo.lock rename listings/ch17-async-await/{listing-17-14-orig => listing-17-22}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-14-orig => listing-17-22}/src/main.rs (93%) create mode 100644 listings/ch17-async-await/listing-17-23/Cargo.lock rename listings/ch17-async-await/{listing-17-15-orig => listing-17-23}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-15-orig => listing-17-23}/src/main.rs (100%) diff --git a/listings/ch17-async-await/listing-17-13-orig/Cargo.lock b/listings/ch17-async-await/listing-17-13-orig/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-13-orig/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-14-orig/Cargo.lock b/listings/ch17-async-await/listing-17-14-orig/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-14-orig/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-15-orig/Cargo.lock b/listings/ch17-async-await/listing-17-15-orig/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-15-orig/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-21/Cargo.lock b/listings/ch17-async-await/listing-17-21/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-21/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-13-orig/Cargo.toml b/listings/ch17-async-await/listing-17-21/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-13-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-21/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-13-orig/src/main.rs b/listings/ch17-async-await/listing-17-21/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-13-orig/src/main.rs rename to listings/ch17-async-await/listing-17-21/src/main.rs diff --git a/listings/ch17-async-await/listing-17-22/Cargo.lock b/listings/ch17-async-await/listing-17-22/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-22/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-14-orig/Cargo.toml b/listings/ch17-async-await/listing-17-22/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-14-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-22/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-14-orig/src/main.rs b/listings/ch17-async-await/listing-17-22/src/main.rs similarity index 93% rename from listings/ch17-async-await/listing-17-14-orig/src/main.rs rename to listings/ch17-async-await/listing-17-22/src/main.rs index a22c9570f7..7e33ab3cc8 100644 --- a/listings/ch17-async-await/listing-17-14-orig/src/main.rs +++ b/listings/ch17-async-await/listing-17-22/src/main.rs @@ -26,9 +26,7 @@ fn main() { } // ANCHOR: here }); - // ANCHOR_END: here - // ANCHOR: here let rx_fut = pin!(async { // snip... // ANCHOR_END: here @@ -37,9 +35,7 @@ fn main() { } // ANCHOR: here }); - // ANCHOR_END: here - // ANCHOR: here let tx_fut = pin!(async move { // snip... // ANCHOR_END: here diff --git a/listings/ch17-async-await/listing-17-23/Cargo.lock b/listings/ch17-async-await/listing-17-23/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-23/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-15-orig/Cargo.toml b/listings/ch17-async-await/listing-17-23/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-15-orig/Cargo.toml rename to listings/ch17-async-await/listing-17-23/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-15-orig/src/main.rs b/listings/ch17-async-await/listing-17-23/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-15-orig/src/main.rs rename to listings/ch17-async-await/listing-17-23/src/main.rs index 24845f0887..6603223a5b 100644 --- a/listings/ch17-async-await/listing-17-15-orig/src/main.rs +++ b/listings/ch17-async-await/listing-17-23/src/main.rs @@ -4,9 +4,9 @@ fn main() { let a = async { 1u32 }; let b = async { "Hello!" }; let c = async { true }; - // ANCHOR_END: here let (a_result, b_result, c_result) = trpl::join!(a, b, c); println!("{a_result}, {b_result}, {c_result}"); + // ANCHOR_END: here }); } diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 13dad71be8..f76a4a8c7b 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -301,19 +301,21 @@ get our `join_all` call to compile! First, we need to explicitly annotate `futures` as referring to a pinned `Box` of futures. Second, we actually need to pin the futures, which we can do using the handy `Box::pin` API, which exists for exactly this. Putting that together, we end up with the code in Listing -17-TODO. +17-21. -+ -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-13-orig/src/main.rs:here}} +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:here}} ``` If we compile and run this, we finally get the output we hoped for: - + ```text received 'hi' @@ -342,40 +344,45 @@ still be explicit about the type of the pinned reference; otherwise Rust will still not know to interpret these as dynamic trait objects, which is what we need them to be in the `Vec`. We therefore `pin!` each future when we define it, and define `futures` as a `Vec` containing pinned mutable references to the -dynamic `Future` type. +dynamic `Future` type, as in Listing 17-22. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-14-orig/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:here}} ``` -This keeps everything on the stack, and that is a nice little performance win, -but it is still a lot of explicit types, which is quite unusual for Rust! There -is another problem, too. We got this far by ignoring the fact that we might have -different `Output` types. For example, in Listing 17-TODO, the anonymous future -type for `a` implements `Future` and the anonymous future type for -`b` implements `Future`. +This keeps everything on the stack, which is a nice little performance win, but +it is still a lot of explicit types, which is quite unusual for Rust! -+There is another, more serious, issue as well. We got this far by ignoring the +fact that we might have different `Output` types. For example, in Listing 17-23, +the anonymous future type for `a` implements `Future`, the +anonymous future type for `b` implements `Future`, and the +anonymous future type for `c` implements `Future`. We can use +`trpl::join!` to await them together, since it accepts futures of different +types. + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-15-orig/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:here}} ``` -We can use `trpl::join!` to await them together, since it accepts two different -future types, but we cannot use `trpl::join_all` with these futures, because we -will never be able to make them have the same type. We have a basic tradeoff -here: we can either deal with a dynamic number of futures with `join_all`, as -long as they all have the same type, or we can deal with a set number of futures -with the `join` functions or the `join!` macro, even if they have different -types. This is the same as working with any other type in Rust, though: futures -are not special, even though we have some nice syntax for working with them, and -that is a good thing! +We cannot use `trpl::join_all` with these futures, though, because +we will never be able to make them have the same type. (Remember, that error is +what got us started on this adventure with `Pin`!) + +We have a basic tradeoff here: we can either deal with a dynamic number of +futures with `join_all`, as long as they all have the same type, or we can deal +with a set number of futures with the `join` functions or the `join!` macro, +even if they have different types. This is the same as working with any other +type in Rust, though: futures are not special, even though we have some nice +syntax for working with them, and that is a good thing! In practice, you will usually work directly with `async` and `.await`, and only as a secondary tool reach for the functions like `join` or `join_all`, or their From c7462f3a15959108a8b69300916a7f5ad68647ed Mon Sep 17 00:00:00 2001 From: bryanzierk Date: Wed, 12 Jun 2024 13:14:18 -0500 Subject: [PATCH 313/720] Revert chapter 15 --- src/ch15-01-box.md | 25 +++++++++++--------- src/ch15-02-deref.md | 38 +++++++++++++++++------------- src/ch15-03-drop.md | 15 +++++++----- src/ch15-04-rc.md | 14 ++++++----- src/ch15-05-interior-mutability.md | 25 ++++++++++++-------- src/ch15-06-reference-cycles.md | 25 ++++++++++++-------- 6 files changed, 83 insertions(+), 59 deletions(-) diff --git a/src/ch15-01-box.md b/src/ch15-01-box.md index ae31195682..53e829a4c3 100644 --- a/src/ch15-01-box.md +++ b/src/ch15-01-box.md @@ -35,13 +35,14 @@ syntax and how to interact with values stored within a `Box`. Listing 15-1 shows how to use a box to store an `i32` value on the heap: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-01/src/main.rs}} ``` - +Listing 15-1: Storing an `i32` value on the heap using a +box We define the variable `b` to have the value of a `Box` that points to the value `5`, which is allocated on the heap. This program will print `b = 5`; in @@ -105,13 +106,14 @@ Listing 15-2 contains an enum definition for a cons list. Note that this code won’t compile yet because the `List` type doesn’t have a known size, which we’ll demonstrate. -+Filename: src/main.rs ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-02/src/main.rs:here}} ``` - +Listing 15-2: The first attempt at defining an enum to +represent a cons list data structure of `i32` values > Note: We’re implementing a cons list that holds only `i32` values for the > purposes of this example. We could have implemented it using generics, as we @@ -121,13 +123,14 @@ we’ll demonstrate. Using the `List` type to store the list `1, 2, 3` would look like the code in Listing 15-3: -+Filename: src/main.rs ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-03/src/main.rs:here}} ``` - +Listing 15-3: Using the `List` enum to store the list `1, +2, 3` The first `Cons` value holds `1` and another `List` value. This `List` value is another `Cons` value that holds `2` and another `List` value. This `List` value @@ -137,13 +140,12 @@ is one more `Cons` value that holds `3` and a `List` value, which is finally If we try to compile the code in Listing 15-3, we get the error shown in Listing 15-4: -- ```console {{#include ../listings/ch15-smart-pointers/listing-15-03/output.txt}} ``` - +Listing 15-4: The error we get when attempting to define +a recursive enum The error shows this type “has infinite size.” The reason is that we’ve defined `List` with a variant that is recursive: it holds another value of itself @@ -213,13 +215,14 @@ rather than inside one another. We can change the definition of the `List` enum in Listing 15-2 and the usage of the `List` in Listing 15-3 to the code in Listing 15-5, which will compile: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-05/src/main.rs}} ``` - +Listing 15-5: Definition of `List` that uses `Box` in +order to have a known size The `Cons` variant needs the size of an `i32` plus the space to store the box’s pointer data. The `Nil` variant stores no values, so it needs less space diff --git a/src/ch15-02-deref.md b/src/ch15-02-deref.md index d8b60f187b..56db7c0a02 100644 --- a/src/ch15-02-deref.md +++ b/src/ch15-02-deref.md @@ -29,13 +29,14 @@ as an arrow to a value stored somewhere else. In Listing 15-6, we create a reference to an `i32` value and then use the dereference operator to follow the reference to the value: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-06/src/main.rs}} ``` - +Listing 15-6: Using the dereference operator to follow a +reference to an `i32` value The variable `x` holds an `i32` value `5`. We set `y` equal to a reference to `x`. We can assert that `x` is equal to `5`. However, if we want to make an @@ -62,13 +63,14 @@ reference; the dereference operator used on the `Box` in Listing 15-7 functions in the same way as the dereference operator used on the reference in Listing 15-6: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-07/src/main.rs}} ``` - +Listing 15-7: Using the dereference operator on a +`Box` The main difference between Listing 15-7 and Listing 15-6 is that here we set `y` to be an instance of a `Box` pointing to a copied value of `x` rather @@ -89,13 +91,13 @@ The `Box` type is ultimately defined as a tuple struct with one element, so Listing 15-8 defines a `MyBox` type in the same way. We’ll also define a `new` function to match the `new` function defined on `Box`. -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-08/src/main.rs:here}} ``` - +Listing 15-8: Defining a `MyBox` type We define a struct named `MyBox` and declare a generic parameter `T`, because we want our type to hold values of any type. The `MyBox` type is a tuple struct @@ -107,13 +109,14 @@ changing it to use the `MyBox` type we’ve defined instead of `Box`. The code in Listing 15-9 won’t compile because Rust doesn’t know how to dereference `MyBox`. -+Filename: src/main.rs ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-09/src/main.rs:here}} ``` - +Listing 15-9: Attempting to use `MyBox` in the same +way we used references and `Box` Here’s the resulting compilation error: @@ -134,13 +137,13 @@ by the standard library, requires us to implement one method named `deref` that borrows `self` and returns a reference to the inner data. Listing 15-10 contains an implementation of `Deref` to add to the definition of `MyBox`: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-10/src/main.rs:here}} ``` - +Listing 15-10: Implementing `Deref` on `MyBox` The `type Target = T;` syntax defines an associated type for the `Deref` trait to use. Associated types are a slightly different way of declaring a @@ -207,25 +210,27 @@ Listing 15-8 as well as the implementation of `Deref` that we added in Listing 15-10. Listing 15-11 shows the definition of a function that has a string slice parameter: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-11/src/main.rs:here}} ``` - +Listing 15-11: A `hello` function that has the parameter +`name` of type `&str` We can call the `hello` function with a string slice as an argument, such as `hello("Rust");` for example. Deref coercion makes it possible to call `hello` with a reference to a value of type `MyBox`, as shown in Listing 15-12: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-12/src/main.rs:here}} ``` - +Listing 15-12: Calling `hello` with a reference to a +`MyBox` value, which works because of deref coercion Here we’re calling the `hello` function with the argument `&m`, which is a reference to a `MyBox` value. Because we implemented the `Deref` trait @@ -239,13 +244,14 @@ If Rust didn’t implement deref coercion, we would have to write the code in Listing 15-13 instead of the code in Listing 15-12 to call `hello` with a value of type `&MyBox`. -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-13/src/main.rs:here}} ``` - +Listing 15-13: The code we would have to write if Rust +didn’t have deref coercion The `(*m)` dereferences the `MyBox` into a `String`. Then the `&` and `[..]` take a string slice of the `String` that is equal to the whole string to diff --git a/src/ch15-03-drop.md b/src/ch15-03-drop.md index 8c402f408f..05ab86873b 100644 --- a/src/ch15-03-drop.md +++ b/src/ch15-03-drop.md @@ -28,13 +28,14 @@ Listing 15-14 shows a `CustomSmartPointer` struct whose only custom functionality is that it will print `Dropping CustomSmartPointer!` when the instance goes out of scope, to show when Rust runs the `drop` function. -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-14/src/main.rs}} ``` - +Listing 15-14: A `CustomSmartPointer` struct that +implements the `Drop` trait where we would put our cleanup code The `Drop` trait is included in the prelude, so we don’t need to bring it into scope. We implement the `Drop` trait on `CustomSmartPointer` and provide an @@ -78,13 +79,14 @@ If we try to call the `Drop` trait’s `drop` method manually by modifying the `main` function from Listing 15-14, as shown in Listing 15-15, we’ll get a compiler error: -+Filename: src/main.rs ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-15/src/main.rs:here}} ``` - +Listing 15-15: Attempting to call the `drop` method from +the `Drop` trait manually to clean up early When we try to compile this code, we’ll get this error: @@ -112,13 +114,14 @@ trait. We call it by passing as an argument the value we want to force drop. The function is in the prelude, so we can modify `main` in Listing 15-15 to call the `drop` function, as shown in Listing 15-16: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-16/src/main.rs:here}} ``` - +Listing 15-16: Calling `std::mem::drop` to explicitly +drop a value before it goes out of scope Running this code will print the following: diff --git a/src/ch15-04-rc.md b/src/ch15-04-rc.md index c5bf9a4897..87a42eb1a5 100644 --- a/src/ch15-04-rc.md +++ b/src/ch15-04-rc.md @@ -48,13 +48,14 @@ words, both lists will share the first list containing 5 and 10. Trying to implement this scenario using our definition of `List` with `Box` won’t work, as shown in Listing 15-17: -+Filename: src/main.rs ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-17/src/main.rs}} ``` - +Listing 15-17: Demonstrating we’re not allowed to have +two lists using `Box` that try to share ownership of a third list When we compile this code, we get this error: @@ -83,13 +84,14 @@ we call `Rc::clone`, the reference count to the data within the `Rc` will increase, and the data won’t be cleaned up unless there are zero references to it. -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-18/src/main.rs}} ``` - +Listing 15-18: A definition of `List` that uses +`Rc` We need to add a `use` statement to bring `Rc` into scope because it’s not in the prelude. In `main`, we create the list holding 5 and 10 and store it in @@ -116,13 +118,13 @@ counts changing as we create and drop references to the `Rc` in `a`. In Listing 15-19, we’ll change `main` so it has an inner scope around list `c`; then we can see how the reference count changes when `c` goes out of scope. -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-19/src/main.rs:here}} ``` - +Listing 15-19: Printing the reference count At each point in the program where the reference count changes, we print the reference count, which we get by calling the `Rc::strong_count` function. This diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index c51302b31c..7b5e825d7e 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -129,13 +129,14 @@ email, send a text message, or something else. The library doesn’t need to kno that detail. All it needs is something that implements a trait we’ll provide called `Messenger`. Listing 15-20 shows the library code: -+Filename: src/lib.rs ```rust,noplayground {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-20/src/lib.rs}} ``` - +Listing 15-20: A library to keep track of how close a +value is to a maximum value and warn when the value is at certain levels One important part of this code is that the `Messenger` trait has one method called `send` that takes an immutable reference to `self` and the text of the @@ -155,13 +156,14 @@ mock object, call the `set_value` method on `LimitTracker`, and then check that the mock object has the messages we expect. Listing 15-21 shows an attempt to implement a mock object to do just that, but the borrow checker won’t allow it: -+Filename: src/lib.rs ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-21/src/lib.rs:here}} ``` - +Listing 15-21: An attempt to implement a `MockMessenger` +that isn’t allowed by the borrow checker This test code defines a `MockMessenger` struct that has a `sent_messages` field with a `Vec` of `String` values to keep track of the messages it’s told @@ -198,13 +200,14 @@ This is a situation in which interior mutability can help! We’ll store the able to modify `sent_messages` to store the messages we’ve seen. Listing 15-22 shows what that looks like: -+Filename: src/lib.rs ```rust,noplayground {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-22/src/lib.rs:here}} ``` - +Listing 15-22: Using `RefCell` to mutate an inner +value while the outer value is considered immutable The `sent_messages` field is now of type `RefCell>` instead of `Vec`. In the `new` function, we create a new `RefCell>` @@ -246,13 +249,14 @@ Listing 15-22. We’re deliberately trying to create two mutable borrows active for the same scope to illustrate that `RefCell` prevents us from doing this at runtime. -+Filename: src/lib.rs ```rust,ignore,panics {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-23/src/lib.rs:here}} ``` - +Listing 15-23: Creating two mutable references in the +same scope to see that `RefCell` will panic We create a variable `one_borrow` for the `RefMut` smart pointer returned from `borrow_mut`. Then we create another mutable borrow in the same way in the @@ -294,13 +298,14 @@ change the values in the lists. Listing 15-24 shows that by using a `RefCell` in the `Cons` definition, we can modify the value stored in all the lists: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-24/src/main.rs}} ``` - +Listing 15-24: Using `Rc>` to create a +`List` that we can mutate We create a value that is an instance of `Rc>` and store it in a variable named `value` so we can access it directly later. Then we create a diff --git a/src/ch15-06-reference-cycles.md b/src/ch15-06-reference-cycles.md index 2ea12edb6f..beb2bc2169 100644 --- a/src/ch15-06-reference-cycles.md +++ b/src/ch15-06-reference-cycles.md @@ -15,13 +15,14 @@ Let’s look at how a reference cycle might happen and how to prevent it, starting with the definition of the `List` enum and a `tail` method in Listing 15-25: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-25/src/main.rs}} ``` - +Listing 15-25: A cons list definition that holds a +`RefCell` so we can modify what a `Cons` variant is referring to We’re using another variation of the `List` definition from Listing 15-5. The second element in the `Cons` variant is now `RefCell>`, meaning that @@ -36,13 +37,14 @@ the list in `a`. Then it modifies the list in `a` to point to `b`, creating a reference cycle. There are `println!` statements along the way to show what the reference counts are at various points in this process. -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-26/src/main.rs:here}} ``` - +Listing 15-26: Creating a reference cycle of two `List` +values pointing to each other We create an `Rc` instance holding a `List` value in the variable `a` with an initial list of `5, Nil`. We then create an `Rc` instance holding @@ -161,13 +163,14 @@ Next, we’ll use our struct definition and create one `Node` instance named `leaf` with the value 3 and no children, and another instance named `branch` with the value 5 and `leaf` as one of its children, as shown in Listing 15-27: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-27/src/main.rs:there}} ``` - +Listing 15-27: Creating a `leaf` node with no children +and a `branch` node with `leaf` as one of its children We clone the `Rc` in `leaf` and store that in `branch`, meaning the `Node` in `leaf` now has two owners: `leaf` and `branch`. We can get from @@ -204,13 +207,14 @@ A node will be able to refer to its parent node but doesn’t own its parent. In Listing 15-28, we update `main` to use this new definition so the `leaf` node will have a way to refer to its parent, `branch`: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-28/src/main.rs:there}} ``` - +Listing 15-28: A `leaf` node with a weak reference to its +parent node `branch` Creating the `leaf` node looks similar to Listing 15-27 with the exception of the `parent` field: `leaf` starts out without a parent, so we create a new, @@ -256,13 +260,14 @@ instances change by creating a new inner scope and moving the creation of created and then dropped when it goes out of scope. The modifications are shown in Listing 15-29: -+Filename: src/main.rs ```rust {{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-29/src/main.rs:here}} ``` - +Listing 15-29: Creating `branch` in an inner scope and +examining strong and weak reference counts After `leaf` is created, its `Rc` has a strong count of 1 and a weak count of 0. In the inner scope, we create `branch` and associate it with From fb683c9965b4a0b810c32fd5a470babb3683ab79 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 13 Jun 2024 13:58:56 -0600 Subject: [PATCH 314/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20correct=20listin?= =?UTF-8?q?gs=20and=20wording=20for=20first=20half=20of=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../ch17-async-await/listing-17-25/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../listing-17-25/src/main.rs | 14 + .../ch17-async-await/listing-17-26/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../ch17-async-await/listing-17-26/output.txt | 38 ++ .../src/main.rs | 2 - .../ch17-async-await/listing-17-27/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../ch17-async-await/listing-17-29/Cargo.toml | 9 + .../src/main.rs | 0 .../listing-17-yield-b-yield/Cargo.lock | 540 ------------------ .../listing-17-yield-c-performance/Cargo.lock | 540 ------------------ src/ch17-04-more-ways-of-combining-futures.md | 86 +-- 22 files changed, 948 insertions(+), 1121 deletions(-) rename listings/ch17-async-await/{listing-17-race => listing-17-24}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-race => listing-17-24}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-race => listing-17-24}/src/main.rs (100%) create mode 100644 listings/ch17-async-await/listing-17-25/Cargo.lock rename listings/ch17-async-await/{listing-17-yield-0-blocked => listing-17-25}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-25/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-26/Cargo.lock rename listings/ch17-async-await/{listing-17-yield-a-sleep => listing-17-26}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-26/output.txt rename listings/ch17-async-await/{listing-17-yield-0-blocked => listing-17-26}/src/main.rs (96%) create mode 100644 listings/ch17-async-await/listing-17-27/Cargo.lock rename listings/ch17-async-await/{listing-17-yield-b-yield => listing-17-27}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-yield-a-sleep => listing-17-27}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-yield-0-blocked => listing-17-28}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-yield-c-performance => listing-17-28}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-yield-b-yield => listing-17-28}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-yield-a-sleep => listing-17-29}/Cargo.lock (100%) create mode 100644 listings/ch17-async-await/listing-17-29/Cargo.toml rename listings/ch17-async-await/{listing-17-yield-c-performance => listing-17-29}/src/main.rs (100%) delete mode 100644 listings/ch17-async-await/listing-17-yield-b-yield/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-yield-c-performance/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-race/Cargo.lock b/listings/ch17-async-await/listing-17-24/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-race/Cargo.lock rename to listings/ch17-async-await/listing-17-24/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-race/Cargo.toml b/listings/ch17-async-await/listing-17-24/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-race/Cargo.toml rename to listings/ch17-async-await/listing-17-24/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-race/src/main.rs b/listings/ch17-async-await/listing-17-24/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-race/src/main.rs rename to listings/ch17-async-await/listing-17-24/src/main.rs diff --git a/listings/ch17-async-await/listing-17-25/Cargo.lock b/listings/ch17-async-await/listing-17-25/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-25/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-yield-0-blocked/Cargo.toml b/listings/ch17-async-await/listing-17-25/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-yield-0-blocked/Cargo.toml rename to listings/ch17-async-await/listing-17-25/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-25/src/main.rs b/listings/ch17-async-await/listing-17-25/src/main.rs new file mode 100644 index 0000000000..9d8dedfb3b --- /dev/null +++ b/listings/ch17-async-await/listing-17-25/src/main.rs @@ -0,0 +1,14 @@ +use std::{thread, time::Duration}; + +fn main() { + trpl::block_on(async { + // We will call `slow` here later + }); +} + +// ANCHOR: slow +fn slow(name: &str, ms: u64) { + thread::sleep(Duration::from_millis(ms)); + println!("'{name}' ran for {ms}ms"); +} +// ANCHOR_END: slow diff --git a/listings/ch17-async-await/listing-17-26/Cargo.lock b/listings/ch17-async-await/listing-17-26/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-26/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-yield-a-sleep/Cargo.toml b/listings/ch17-async-await/listing-17-26/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-yield-a-sleep/Cargo.toml rename to listings/ch17-async-await/listing-17-26/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-26/output.txt b/listings/ch17-async-await/listing-17-26/output.txt new file mode 100644 index 0000000000..22cbc4fad4 --- /dev/null +++ b/listings/ch17-async-await/listing-17-26/output.txt @@ -0,0 +1,38 @@ +$ cargo run + Compiling proc-macro2 v1.0.82 + Compiling unicode-ident v1.0.12 + Compiling autocfg v1.3.0 + Compiling futures-sink v0.3.30 + Compiling futures-core v0.3.30 + Compiling libc v0.2.154 + Compiling pin-project-lite v0.2.14 + Compiling futures-io v0.3.30 + Compiling memchr v2.7.2 + Compiling futures-task v0.3.30 + Compiling futures-channel v0.3.30 + Compiling pin-utils v0.1.0 + Compiling slab v0.4.9 + Compiling num_cpus v1.16.0 + Compiling tokio v1.37.0 + Compiling quote v1.0.36 + Compiling syn v2.0.63 + Compiling futures-macro v0.3.30 + Compiling futures-util v0.3.30 + Compiling futures-executor v0.3.30 + Compiling futures v0.3.30 + Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-26) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.32s + Running `target/debug/async_await` +'a' started. +'a' ran for 300ms +'a' ran for 100ms +'a' ran for 200ms +'a' ran for 900ms +'b' started. +'b' ran for 750ms +'b' ran for 100ms +'b' ran for 150ms +'b' ran for 350ms +'b' ran for 150ms +'a' finished. diff --git a/listings/ch17-async-await/listing-17-yield-0-blocked/src/main.rs b/listings/ch17-async-await/listing-17-26/src/main.rs similarity index 96% rename from listings/ch17-async-await/listing-17-yield-0-blocked/src/main.rs rename to listings/ch17-async-await/listing-17-26/src/main.rs index aac0f70fa3..9948c79e57 100644 --- a/listings/ch17-async-await/listing-17-yield-0-blocked/src/main.rs +++ b/listings/ch17-async-await/listing-17-26/src/main.rs @@ -29,9 +29,7 @@ fn main() { }); } -// ANCHOR: slow fn slow(name: &str, ms: u64) { thread::sleep(Duration::from_millis(ms)); println!("'{name}' ran for {ms}ms"); } -// ANCHOR_END: slow diff --git a/listings/ch17-async-await/listing-17-27/Cargo.lock b/listings/ch17-async-await/listing-17-27/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-27/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-yield-b-yield/Cargo.toml b/listings/ch17-async-await/listing-17-27/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-yield-b-yield/Cargo.toml rename to listings/ch17-async-await/listing-17-27/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs b/listings/ch17-async-await/listing-17-27/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs rename to listings/ch17-async-await/listing-17-27/src/main.rs diff --git a/listings/ch17-async-await/listing-17-yield-0-blocked/Cargo.lock b/listings/ch17-async-await/listing-17-28/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-yield-0-blocked/Cargo.lock rename to listings/ch17-async-await/listing-17-28/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.toml b/listings/ch17-async-await/listing-17-28/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-yield-c-performance/Cargo.toml rename to listings/ch17-async-await/listing-17-28/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-yield-b-yield/src/main.rs b/listings/ch17-async-await/listing-17-28/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-yield-b-yield/src/main.rs rename to listings/ch17-async-await/listing-17-28/src/main.rs diff --git a/listings/ch17-async-await/listing-17-yield-a-sleep/Cargo.lock b/listings/ch17-async-await/listing-17-29/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-yield-a-sleep/Cargo.lock rename to listings/ch17-async-await/listing-17-29/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-29/Cargo.toml b/listings/ch17-async-await/listing-17-29/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-29/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-yield-c-performance/src/main.rs b/listings/ch17-async-await/listing-17-29/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-yield-c-performance/src/main.rs rename to listings/ch17-async-await/listing-17-29/src/main.rs diff --git a/listings/ch17-async-await/listing-17-yield-b-yield/Cargo.lock b/listings/ch17-async-await/listing-17-yield-b-yield/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-yield-b-yield/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.lock b/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-yield-c-performance/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index f39e7da7e5..647a8b5ecc 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -6,16 +6,16 @@ we move on. Sometimes, though, we only need *some* future from a set to finish before we move on—kind of like racing one future against another. This operation is often named `race` for exactly that reason. -In Listing 17-TODO, we use `race` to run two futures, `slow` and `fast`, against +In Listing 17-24, we use `race` to run two futures, `slow` and `fast`, against each other. Each one prints a message when it starts running, pauses for some amount of time by calling and awaiting `sleep`, and then prints another message when it finishes. Then we pass both to `trpl::race` and wait for one of them to finish. (The outcome here won’t be too surprising: `fast` wins!) -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-race/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:here}} ``` @@ -59,43 +59,30 @@ function “slow” will just take a number of milliseconds to run, and sleep t thread for that long. This is intentionally not an async function, because the idea is to represent work that is *not* async. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-0-blocked/src/main.rs:slow}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:slow}} ``` -In Listing 17-TODO we have this kind of slow work in a pair of futures which -only hand control back to the runtime *after* carrying out a bunch of slow -operations, represented by calls to `slow`: +In Listing 17-26, we use `slow` to emulate doing this kind of CPU-bound work in +a pair of futures. To begin, each future only hands control back to the runtime +*after* carrying out a bunch of slow operations. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-0-blocked/src/main.rs:slow-futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:slow-futures}} ``` If you run this, you will see this output: - - -```text -'a' started. -'a' ran for 300ms -'a' ran for 100ms -'a' ran for 200ms -'a' ran for 900ms -'b' started. -'b' ran for 750ms -'b' ran for 100ms -'b' ran for 150ms -'b' ran for 350ms -'b' ran for 150ms -'a' finished. +```console +{{#include ../listings/ch17-async-await/listing-17-26/output.txt}} ``` As with our earlier example, `race` still finishes when `a` finishes. There is @@ -110,21 +97,42 @@ something we can await! However, we can also see the handoff happening in this very example: if we removed the `trpl::sleep` at the end of the `a` future, it would complete without the `b` future running *at all*. Given that, maybe we could use the -`sleep` function as a starting point, as in Listing 17-TODO. +`sleep` function as a starting point, as in Listing 17-27. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-a-sleep/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:here}} ``` -Now the two futures’ work is interleaved. The `a` future still runs for a bit -before handing off control to `b`, because it has some expensive work to do up -front, but after that they just swap back and forth every time one of them hits -an await point. In this case, we have done that after ever call to `slow`, but -we could break up the work however makes the most sense to us. +Now the two futures’ work is interleaved, as we can see if we run it. + + + +```text +'a' started. +'a' ran for 300ms +'b' started. +'b' ran for 750ms +'a' ran for 100ms +'b' ran for 100ms +'a' ran for 200ms +'b' ran for 150ms +'a' ran for 900ms +'b' ran for 350ms +'a' finished. +``` + + +The `a` future still runs for a bit before handing off control to `b`, because +it has some expensive work to do up front, but after that they just swap back +and forth every time one of them hits an await point. In this case, we have done +that after every call to `slow`, but we could break up the work however makes +the most sense to us. However, we do not actually need to sleep to accomplish this. We just need to hand back control to the runtime. We can actually *yield* control back to the @@ -132,10 +140,10 @@ runtime, using a function named `yield_now`. It does just what it says: hands control back to the runtime, so that the runtime can check whether any other tasks are ready to make progress. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-b-yield/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:here}} ``` @@ -148,18 +156,18 @@ example, will always sleep for at least a millisecond, even if we pass it a lot in one millisecond! You can see this for yourself by setting up a little benchmark, like the one in -Listing 17-TODO. (This is not an especially rigorous way to do performance +Listing 17-29. (This is not an especially rigorous way to do performance testing, but it suffices to show the difference here.) Here, we skip all the status printing, pass a one-nanosecond `Duration` to `sleep`, let each future run by itself so that they do not interfere with each other, and get rid of all the status printing that we did to see the back-and-forth between tasks in -Listings 17-TODO and 17-TODO. Then we run for 1,000 iterations and see how long +Listings 17-27 and 17-28. Then we run for 1,000 iterations and see how long `sleep` takes vs. `yield_now`. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-yield-c-performance/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:here}} ``` From 9d8f2c5fa7b7add21222d13973f936d86edf29c6 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 14 Jun 2024 09:22:51 -0600 Subject: [PATCH 315/720] Ch. 17: renumber listings to eliminate `no-listing` listings --- .../ch17-async-await/listing-17-19/Cargo.lock | 273 --------- .../ch17-async-await/listing-17-19/Cargo.toml | 3 - .../output.txt | 0 .../listing-17-19/src/main.rs | 52 +- .../listing-17-20/src/main.rs | 6 +- .../output.txt | 0 .../listing-17-21/src/main.rs | 22 +- .../ch17-async-await/listing-17-22/Cargo.lock | 44 +- .../listing-17-22/src/main.rs | 64 +-- .../test-data/hello.txt | 0 .../test-data/punct.txt | 0 .../test-data/world.txt | 0 .../listing-17-23/src/main.rs | 53 +- .../ch17-async-await/listing-17-24/Cargo.lock | 260 --------- .../listing-17-24/src/main.rs | 69 ++- .../listing-17-25/src/main.rs | 18 +- .../ch17-async-await/listing-17-26/Cargo.lock | 260 +++++++++ .../listing-17-26/src/main.rs | 36 +- .../listing-17-27/src/main.rs | 36 +- .../ch17-async-await/listing-17-28/Cargo.lock | 260 --------- .../output.txt | 0 .../listing-17-28/src/main.rs | 15 +- .../ch17-async-await/listing-17-29/Cargo.lock | 260 --------- .../listing-17-29/src/main.rs | 62 +- .../ch17-async-await/listing-17-30/Cargo.lock | 540 ++++++++++++++++++ .../Cargo.toml | 0 .../listing-17-30/src/main.rs | 42 ++ .../ch17-async-await/listing-17-31/Cargo.lock | 540 ++++++++++++++++++ .../Cargo.toml | 3 + .../listing-17-31/src/main.rs | 34 ++ .../no-listing-borrow-mutable-vec/Cargo.lock | 280 --------- .../no-listing-borrow-mutable-vec/src/main.rs | 18 - .../no-listing-type-mismatch/Cargo.lock | 7 - .../no-listing-type-mismatch/src/main.rs | 7 - src/ch17-03-more-futures.md | 52 +- src/ch17-04-more-ways-of-combining-futures.md | 36 +- 36 files changed, 1681 insertions(+), 1671 deletions(-) rename listings/ch17-async-await/{no-listing-type-mismatch => listing-17-19}/output.txt (100%) rename listings/ch17-async-await/{listing-17-20 => listing-17-21}/output.txt (100%) rename listings/ch17-async-await/{no-listing-borrow-mutable-vec => listing-17-22}/test-data/hello.txt (100%) rename listings/ch17-async-await/{no-listing-borrow-mutable-vec => listing-17-22}/test-data/punct.txt (100%) rename listings/ch17-async-await/{no-listing-borrow-mutable-vec => listing-17-22}/test-data/world.txt (100%) rename listings/ch17-async-await/{listing-17-26 => listing-17-28}/output.txt (100%) create mode 100644 listings/ch17-async-await/listing-17-30/Cargo.lock rename listings/ch17-async-await/{no-listing-borrow-mutable-vec => listing-17-30}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-30/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-31/Cargo.lock rename listings/ch17-async-await/{no-listing-type-mismatch => listing-17-31}/Cargo.toml (73%) create mode 100644 listings/ch17-async-await/listing-17-31/src/main.rs delete mode 100644 listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock delete mode 100644 listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs delete mode 100644 listings/ch17-async-await/no-listing-type-mismatch/Cargo.lock delete mode 100644 listings/ch17-async-await/no-listing-type-mismatch/src/main.rs diff --git a/listings/ch17-async-await/listing-17-19/Cargo.lock b/listings/ch17-async-await/listing-17-19/Cargo.lock index c0e8bb2b3f..d30b928a6c 100644 --- a/listings/ch17-async-await/listing-17-19/Cargo.lock +++ b/listings/ch17-async-await/listing-17-19/Cargo.lock @@ -2,279 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "async_await" version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-19/Cargo.toml b/listings/ch17-async-await/listing-17-19/Cargo.toml index 349041d3eb..67729afc80 100644 --- a/listings/ch17-async-await/listing-17-19/Cargo.toml +++ b/listings/ch17-async-await/listing-17-19/Cargo.toml @@ -4,6 +4,3 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/no-listing-type-mismatch/output.txt b/listings/ch17-async-await/listing-17-19/output.txt similarity index 100% rename from listings/ch17-async-await/no-listing-type-mismatch/output.txt rename to listings/ch17-async-await/listing-17-19/output.txt diff --git a/listings/ch17-async-await/listing-17-19/src/main.rs b/listings/ch17-async-await/listing-17-19/src/main.rs index beff676dbe..0c282f4f87 100644 --- a/listings/ch17-async-await/listing-17-19/src/main.rs +++ b/listings/ch17-async-await/listing-17-19/src/main.rs @@ -1,49 +1,7 @@ -use std::time::Duration; - fn main() { - trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - let tx1 = tx.clone(); - let tx1_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; - - let tx_fut = async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - // ANCHOR: here - let futures = - vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; - - trpl::join_all(futures).await; - // ANCHOR_END: here - }); + // ANCHOR: here + let a = 1; + let b = "Hello"; + let vals = vec![a, b]; + // ANCHOR_END: here } diff --git a/listings/ch17-async-await/listing-17-20/src/main.rs b/listings/ch17-async-await/listing-17-20/src/main.rs index b712d344c0..beff676dbe 100644 --- a/listings/ch17-async-await/listing-17-20/src/main.rs +++ b/listings/ch17-async-await/listing-17-20/src/main.rs @@ -1,4 +1,4 @@ -use std::{future::Future, time::Duration}; +use std::time::Duration; fn main() { trpl::block_on(async { @@ -40,10 +40,10 @@ fn main() { }; // ANCHOR: here - let futures: Vec>> = + let futures = vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; - // ANCHOR_END: here trpl::join_all(futures).await; + // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-20/output.txt b/listings/ch17-async-await/listing-17-21/output.txt similarity index 100% rename from listings/ch17-async-await/listing-17-20/output.txt rename to listings/ch17-async-await/listing-17-21/output.txt diff --git a/listings/ch17-async-await/listing-17-21/src/main.rs b/listings/ch17-async-await/listing-17-21/src/main.rs index 5520a58ca5..b712d344c0 100644 --- a/listings/ch17-async-await/listing-17-21/src/main.rs +++ b/listings/ch17-async-await/listing-17-21/src/main.rs @@ -1,15 +1,11 @@ -use std::{ - future::Future, - pin::{pin, Pin}, - time::Duration, -}; +use std::{future::Future, time::Duration}; fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); - let tx1_fut = pin!(async move { + let tx1_fut = async move { let vals = vec![ String::from("hi"), String::from("from"), @@ -21,15 +17,15 @@ fn main() { tx1.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }); + }; - let rx_fut = pin!(async { + let rx_fut = async { while let Some(value) = rx.recv().await { println!("received '{value}'"); } - }); + }; - let tx_fut = pin!(async move { + let tx_fut = async move { let vals = vec![ String::from("more"), String::from("messages"), @@ -41,11 +37,11 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }); + }; // ANCHOR: here - let futures: Vec>>> = - vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; + let futures: Vec>> = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; // ANCHOR_END: here trpl::join_all(futures).await; diff --git a/listings/ch17-async-await/listing-17-22/Cargo.lock b/listings/ch17-async-await/listing-17-22/Cargo.lock index c0e8bb2b3f..9eeeffaff4 100644 --- a/listings/ch17-async-await/listing-17-22/Cargo.lock +++ b/listings/ch17-async-await/listing-17-22/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -32,9 +32,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -47,9 +47,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.97" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -148,9 +148,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "hermit-abi" @@ -160,21 +160,21 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "6d0d8b92cd8358e8d229c11df9358decae64d137c5be540952c5ca7b25aea768" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -191,9 +191,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -212,9 +212,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -245,9 +245,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.63" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -256,9 +256,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "num_cpus", diff --git a/listings/ch17-async-await/listing-17-22/src/main.rs b/listings/ch17-async-await/listing-17-22/src/main.rs index 7e33ab3cc8..fbba735c3f 100644 --- a/listings/ch17-async-await/listing-17-22/src/main.rs +++ b/listings/ch17-async-await/listing-17-22/src/main.rs @@ -1,62 +1,18 @@ -use std::{ - future::Future, - pin::{pin, Pin}, - time::Duration, -}; - fn main() { - trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - let tx1 = tx.clone(); + trpl::block_on({ // ANCHOR: here - let tx1_fut = pin!(async move { - // snip... - // ANCHOR_END: here - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - // ANCHOR: here - }); + async { + let mut strings = vec![]; - let rx_fut = pin!(async { - // snip... - // ANCHOR_END: here - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR: here - }); + let a = trpl::read_to_string("test-data/hello.txt").await.unwrap(); + strings.push(a.trim()); - let tx_fut = pin!(async move { - // snip... - // ANCHOR_END: here - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; + let b = trpl::read_to_string("test-data/world.txt").await.unwrap(); + strings.push(b.trim()); - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - // ANCHOR: here - }); - - let futures: Vec>> = - vec![tx1_fut, rx_fut, tx_fut]; + let combined = strings.join(" "); + println!("{combined}"); + } // ANCHOR_END: here - - trpl::join_all(futures).await; }); } diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/hello.txt b/listings/ch17-async-await/listing-17-22/test-data/hello.txt similarity index 100% rename from listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/hello.txt rename to listings/ch17-async-await/listing-17-22/test-data/hello.txt diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/punct.txt b/listings/ch17-async-await/listing-17-22/test-data/punct.txt similarity index 100% rename from listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/punct.txt rename to listings/ch17-async-await/listing-17-22/test-data/punct.txt diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/world.txt b/listings/ch17-async-await/listing-17-22/test-data/world.txt similarity index 100% rename from listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/world.txt rename to listings/ch17-async-await/listing-17-22/test-data/world.txt diff --git a/listings/ch17-async-await/listing-17-23/src/main.rs b/listings/ch17-async-await/listing-17-23/src/main.rs index 6603223a5b..5520a58ca5 100644 --- a/listings/ch17-async-await/listing-17-23/src/main.rs +++ b/listings/ch17-async-await/listing-17-23/src/main.rs @@ -1,12 +1,53 @@ +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; + fn main() { trpl::block_on(async { - // ANCHOR: here - let a = async { 1u32 }; - let b = async { "Hello!" }; - let c = async { true }; + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = pin!(async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }); + + let rx_fut = pin!(async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }); - let (a_result, b_result, c_result) = trpl::join!(a, b, c); - println!("{a_result}, {b_result}, {c_result}"); + let tx_fut = pin!(async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }); + + // ANCHOR: here + let futures: Vec>>> = + vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; // ANCHOR_END: here + + trpl::join_all(futures).await; }); } diff --git a/listings/ch17-async-await/listing-17-24/Cargo.lock b/listings/ch17-async-await/listing-17-24/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-24/Cargo.lock +++ b/listings/ch17-async-await/listing-17-24/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-24/src/main.rs b/listings/ch17-async-await/listing-17-24/src/main.rs index eb86c1a486..7e33ab3cc8 100644 --- a/listings/ch17-async-await/listing-17-24/src/main.rs +++ b/listings/ch17-async-await/listing-17-24/src/main.rs @@ -1,21 +1,62 @@ -use std::time::Duration; +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; fn main() { trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); // ANCHOR: here - let slow = async { - println!("'slow' started."); - trpl::sleep(Duration::from_millis(100)).await; - println!("'slow' finished."); - }; - - let fast = async { - println!("'fast' started."); - trpl::sleep(Duration::from_millis(50)).await; - println!("'fast' finished."); - }; - - trpl::race(slow, fast).await; + let tx1_fut = pin!(async move { + // snip... + // ANCHOR_END: here + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR: here + }); + + let rx_fut = pin!(async { + // snip... + // ANCHOR_END: here + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR: here + }); + + let tx_fut = pin!(async move { + // snip... + // ANCHOR_END: here + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR: here + }); + + let futures: Vec>> = + vec![tx1_fut, rx_fut, tx_fut]; // ANCHOR_END: here + + trpl::join_all(futures).await; }); } diff --git a/listings/ch17-async-await/listing-17-25/src/main.rs b/listings/ch17-async-await/listing-17-25/src/main.rs index 9d8dedfb3b..6603223a5b 100644 --- a/listings/ch17-async-await/listing-17-25/src/main.rs +++ b/listings/ch17-async-await/listing-17-25/src/main.rs @@ -1,14 +1,12 @@ -use std::{thread, time::Duration}; - fn main() { trpl::block_on(async { - // We will call `slow` here later - }); -} + // ANCHOR: here + let a = async { 1u32 }; + let b = async { "Hello!" }; + let c = async { true }; -// ANCHOR: slow -fn slow(name: &str, ms: u64) { - thread::sleep(Duration::from_millis(ms)); - println!("'{name}' ran for {ms}ms"); + let (a_result, b_result, c_result) = trpl::join!(a, b, c); + println!("{a_result}, {b_result}, {c_result}"); + // ANCHOR_END: here + }); } -// ANCHOR_END: slow diff --git a/listings/ch17-async-await/listing-17-26/Cargo.lock b/listings/ch17-async-await/listing-17-26/Cargo.lock index c0e8bb2b3f..3be4eaaa53 100644 --- a/listings/ch17-async-await/listing-17-26/Cargo.lock +++ b/listings/ch17-async-await/listing-17-26/Cargo.lock @@ -45,6 +45,18 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + [[package]] name = "cc" version = "1.0.97" @@ -164,6 +176,16 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "memchr" version = "2.7.2" @@ -179,6 +201,17 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -198,6 +231,29 @@ dependencies = [ "memchr", ] +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -228,12 +284,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.9" @@ -243,6 +323,22 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "syn" version = "2.0.63" @@ -261,8 +357,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", + "bytes", + "libc", + "mio", "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -278,3 +393,148 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-26/src/main.rs b/listings/ch17-async-await/listing-17-26/src/main.rs index 9948c79e57..eb86c1a486 100644 --- a/listings/ch17-async-await/listing-17-26/src/main.rs +++ b/listings/ch17-async-await/listing-17-26/src/main.rs @@ -1,35 +1,21 @@ -use std::{thread, time::Duration}; +use std::time::Duration; fn main() { trpl::block_on(async { - // ANCHOR: slow-futures - let a = async { - println!("'a' started."); - slow("a", 300); - slow("a", 100); - slow("a", 200); - slow("a", 900); - trpl::sleep(Duration::from_millis(50)).await; - println!("'a' finished."); + // ANCHOR: here + let slow = async { + println!("'slow' started."); + trpl::sleep(Duration::from_millis(100)).await; + println!("'slow' finished."); }; - let b = async { - println!("'b' started."); - slow("b", 750); - slow("b", 100); - slow("b", 150); - slow("b", 350); - slow("b", 150); + let fast = async { + println!("'fast' started."); trpl::sleep(Duration::from_millis(50)).await; - println!("'b' finished."); + println!("'fast' finished."); }; - trpl::race(a, b).await; - // ANCHOR_END: slow-futures + trpl::race(slow, fast).await; + // ANCHOR_END: here }); } - -fn slow(name: &str, ms: u64) { - thread::sleep(Duration::from_millis(ms)); - println!("'{name}' ran for {ms}ms"); -} diff --git a/listings/ch17-async-await/listing-17-27/src/main.rs b/listings/ch17-async-await/listing-17-27/src/main.rs index d5c90e0226..9d8dedfb3b 100644 --- a/listings/ch17-async-await/listing-17-27/src/main.rs +++ b/listings/ch17-async-await/listing-17-27/src/main.rs @@ -2,43 +2,13 @@ use std::{thread, time::Duration}; fn main() { trpl::block_on(async { - // ANCHOR: here - let one_ms = Duration::from_millis(1); - - let a = async { - println!("'a' started."); - slow("a", 300); - trpl::sleep(one_ms).await; - slow("a", 100); - trpl::sleep(one_ms).await; - slow("a", 200); - trpl::sleep(one_ms).await; - slow("a", 900); - trpl::sleep(one_ms).await; - println!("'a' finished."); - }; - - let b = async { - println!("'b' started."); - slow("b", 750); - trpl::sleep(one_ms).await; - slow("b", 100); - trpl::sleep(one_ms).await; - slow("b", 150); - trpl::sleep(one_ms).await; - slow("b", 350); - trpl::sleep(one_ms).await; - slow("b", 150); - trpl::sleep(one_ms).await; - println!("'b' finished."); - }; - // ANCHOR_END: here - - trpl::race(a, b).await; + // We will call `slow` here later }); } +// ANCHOR: slow fn slow(name: &str, ms: u64) { thread::sleep(Duration::from_millis(ms)); println!("'{name}' ran for {ms}ms"); } +// ANCHOR_END: slow diff --git a/listings/ch17-async-await/listing-17-28/Cargo.lock b/listings/ch17-async-await/listing-17-28/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-28/Cargo.lock +++ b/listings/ch17-async-await/listing-17-28/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-26/output.txt b/listings/ch17-async-await/listing-17-28/output.txt similarity index 100% rename from listings/ch17-async-await/listing-17-26/output.txt rename to listings/ch17-async-await/listing-17-28/output.txt diff --git a/listings/ch17-async-await/listing-17-28/src/main.rs b/listings/ch17-async-await/listing-17-28/src/main.rs index d4552dace7..9948c79e57 100644 --- a/listings/ch17-async-await/listing-17-28/src/main.rs +++ b/listings/ch17-async-await/listing-17-28/src/main.rs @@ -2,37 +2,30 @@ use std::{thread, time::Duration}; fn main() { trpl::block_on(async { - // ANCHOR: here + // ANCHOR: slow-futures let a = async { println!("'a' started."); slow("a", 300); - trpl::yield_now().await; slow("a", 100); - trpl::yield_now().await; slow("a", 200); - trpl::yield_now().await; slow("a", 900); - trpl::yield_now().await; + trpl::sleep(Duration::from_millis(50)).await; println!("'a' finished."); }; let b = async { println!("'b' started."); slow("b", 750); - trpl::yield_now().await; slow("b", 100); - trpl::yield_now().await; slow("b", 150); - trpl::yield_now().await; slow("b", 350); - trpl::yield_now().await; slow("b", 150); - trpl::yield_now().await; + trpl::sleep(Duration::from_millis(50)).await; println!("'b' finished."); }; - // ANCHOR_end: here trpl::race(a, b).await; + // ANCHOR_END: slow-futures }); } diff --git a/listings/ch17-async-await/listing-17-29/Cargo.lock b/listings/ch17-async-await/listing-17-29/Cargo.lock index 3be4eaaa53..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-29/Cargo.lock +++ b/listings/ch17-async-await/listing-17-29/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -393,148 +278,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-29/src/main.rs b/listings/ch17-async-await/listing-17-29/src/main.rs index ef99235640..d5c90e0226 100644 --- a/listings/ch17-async-await/listing-17-29/src/main.rs +++ b/listings/ch17-async-await/listing-17-29/src/main.rs @@ -1,34 +1,44 @@ -use std::time::{Duration, Instant}; +use std::{thread, time::Duration}; fn main() { trpl::block_on(async { // ANCHOR: here - let one_ns = Duration::from_nanos(1); - let start = Instant::now(); - async { - for _ in 1..1000 { - trpl::sleep(one_ns).await; - } - } - .await; - let time = Instant::now() - start; - println!( - "'sleep' version finished after {} seconds.", - time.as_secs_f32() - ); + let one_ms = Duration::from_millis(1); - let start = Instant::now(); - async { - for _ in 1..1000 { - trpl::yield_now().await; - } - } - .await; - let time = Instant::now() - start; - println!( - "'yield' version finished after {} seconds.", - time.as_secs_f32() - ); + let a = async { + println!("'a' started."); + slow("a", 300); + trpl::sleep(one_ms).await; + slow("a", 100); + trpl::sleep(one_ms).await; + slow("a", 200); + trpl::sleep(one_ms).await; + slow("a", 900); + trpl::sleep(one_ms).await; + println!("'a' finished."); + }; + + let b = async { + println!("'b' started."); + slow("b", 750); + trpl::sleep(one_ms).await; + slow("b", 100); + trpl::sleep(one_ms).await; + slow("b", 150); + trpl::sleep(one_ms).await; + slow("b", 350); + trpl::sleep(one_ms).await; + slow("b", 150); + trpl::sleep(one_ms).await; + println!("'b' finished."); + }; // ANCHOR_END: here + + trpl::race(a, b).await; }); } + +fn slow(name: &str, ms: u64) { + thread::sleep(Duration::from_millis(ms)); + println!("'{name}' ran for {ms}ms"); +} diff --git a/listings/ch17-async-await/listing-17-30/Cargo.lock b/listings/ch17-async-await/listing-17-30/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-30/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.toml b/listings/ch17-async-await/listing-17-30/Cargo.toml similarity index 100% rename from listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.toml rename to listings/ch17-async-await/listing-17-30/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-30/src/main.rs b/listings/ch17-async-await/listing-17-30/src/main.rs new file mode 100644 index 0000000000..d4552dace7 --- /dev/null +++ b/listings/ch17-async-await/listing-17-30/src/main.rs @@ -0,0 +1,42 @@ +use std::{thread, time::Duration}; + +fn main() { + trpl::block_on(async { + // ANCHOR: here + let a = async { + println!("'a' started."); + slow("a", 300); + trpl::yield_now().await; + slow("a", 100); + trpl::yield_now().await; + slow("a", 200); + trpl::yield_now().await; + slow("a", 900); + trpl::yield_now().await; + println!("'a' finished."); + }; + + let b = async { + println!("'b' started."); + slow("b", 750); + trpl::yield_now().await; + slow("b", 100); + trpl::yield_now().await; + slow("b", 150); + trpl::yield_now().await; + slow("b", 350); + trpl::yield_now().await; + slow("b", 150); + trpl::yield_now().await; + println!("'b' finished."); + }; + // ANCHOR_end: here + + trpl::race(a, b).await; + }); +} + +fn slow(name: &str, ms: u64) { + thread::sleep(Duration::from_millis(ms)); + println!("'{name}' ran for {ms}ms"); +} diff --git a/listings/ch17-async-await/listing-17-31/Cargo.lock b/listings/ch17-async-await/listing-17-31/Cargo.lock new file mode 100644 index 0000000000..3be4eaaa53 --- /dev/null +++ b/listings/ch17-async-await/listing-17-31/Cargo.lock @@ -0,0 +1,540 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/no-listing-type-mismatch/Cargo.toml b/listings/ch17-async-await/listing-17-31/Cargo.toml similarity index 73% rename from listings/ch17-async-await/no-listing-type-mismatch/Cargo.toml rename to listings/ch17-async-await/listing-17-31/Cargo.toml index 67729afc80..349041d3eb 100644 --- a/listings/ch17-async-await/no-listing-type-mismatch/Cargo.toml +++ b/listings/ch17-async-await/listing-17-31/Cargo.toml @@ -4,3 +4,6 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-31/src/main.rs b/listings/ch17-async-await/listing-17-31/src/main.rs new file mode 100644 index 0000000000..ef99235640 --- /dev/null +++ b/listings/ch17-async-await/listing-17-31/src/main.rs @@ -0,0 +1,34 @@ +use std::time::{Duration, Instant}; + +fn main() { + trpl::block_on(async { + // ANCHOR: here + let one_ns = Duration::from_nanos(1); + let start = Instant::now(); + async { + for _ in 1..1000 { + trpl::sleep(one_ns).await; + } + } + .await; + let time = Instant::now() - start; + println!( + "'sleep' version finished after {} seconds.", + time.as_secs_f32() + ); + + let start = Instant::now(); + async { + for _ in 1..1000 { + trpl::yield_now().await; + } + } + .await; + let time = Instant::now() - start; + println!( + "'yield' version finished after {} seconds.", + time.as_secs_f32() + ); + // ANCHOR_END: here + }); +} diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock b/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock deleted file mode 100644 index 9eeeffaff4..0000000000 --- a/listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock +++ /dev/null @@ -1,280 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "memchr" -version = "2.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d0d8b92cd8358e8d229c11df9358decae64d137c5be540952c5ca7b25aea768" - -[[package]] -name = "miniz_oxide" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs b/listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs deleted file mode 100644 index fbba735c3f..0000000000 --- a/listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs +++ /dev/null @@ -1,18 +0,0 @@ -fn main() { - trpl::block_on({ - // ANCHOR: here - async { - let mut strings = vec![]; - - let a = trpl::read_to_string("test-data/hello.txt").await.unwrap(); - strings.push(a.trim()); - - let b = trpl::read_to_string("test-data/world.txt").await.unwrap(); - strings.push(b.trim()); - - let combined = strings.join(" "); - println!("{combined}"); - } - // ANCHOR_END: here - }); -} diff --git a/listings/ch17-async-await/no-listing-type-mismatch/Cargo.lock b/listings/ch17-async-await/no-listing-type-mismatch/Cargo.lock deleted file mode 100644 index d30b928a6c..0000000000 --- a/listings/ch17-async-await/no-listing-type-mismatch/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "async_await" -version = "0.1.0" diff --git a/listings/ch17-async-await/no-listing-type-mismatch/src/main.rs b/listings/ch17-async-await/no-listing-type-mismatch/src/main.rs deleted file mode 100644 index 0c282f4f87..0000000000 --- a/listings/ch17-async-await/no-listing-type-mismatch/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - // ANCHOR: here - let a = 1; - let b = "Hello"; - let vals = vec![a, b]; - // ANCHOR_END: here -} diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index f76a4a8c7b..08144b647c 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -51,14 +51,18 @@ appear in the code? One clue is the format of this message. Notice that it is exactly the same as if we had tried to create a `Vec` with a a number and a string in it: ++ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/no-listing-type-mismatch/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} ``` + + The output there would be: ```text -{{#include ../listings/ch17-async-await/no-listing-type-mismatch/output.txt}} +{{#include ../listings/ch17-async-await/listing-17-19/output.txt}} ``` Saying “expected *something*, found *something else*” is Rust’s standard format @@ -91,13 +95,13 @@ produced by these types as interchangeable, since all of them by definition implement the `Future` trait. We can start by wrapping each of the futures in the `vec!` in a `Box::new()`. -Unfortunately, the initial way we might try this, as shown in Listing 17-19, +Unfortunately, the initial way we might try this, as shown in Listing 17-20, still does not compile. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} ``` @@ -109,7 +113,7 @@ second and third `Box::new` calls, and we also get new errors referring to the We can start by fixing the type error around the `Box::new` calls, by telling the compiler explicitly that we want to use these types as trait objects. The clearest way to do that here is by adding a type annotation to the declaration -of `futures`, as we see in Listing 17-TODO. The type we have to write here is a +of `futures`, as we see in Listing 17-21. The type we have to write here is a little involved, so let’s walk through each part of it. - The innermost type is the future itself. We note explicitly that it the output @@ -118,20 +122,20 @@ little involved, so let’s walk through each part of it. - The entire trait is wrapped in a `Box`. - Finally, we state explicitly that `futures` is a `Vec` containing these items. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:here}} ``` That already made a big difference. Now when we run the compiler, we only have the errors mentioning `Unpin`. Although there are three of them, notice that -each is very similar in its contets +each is very similar in its contents. ```console -{{#include ../listings/ch17-async-await/listing-17-20/output.txt}} +{{#include ../listings/ch17-async-await/listing-17-21/output.txt}} ``` That is a *lot* to digest, so let’s pull it apart. The first part of the message @@ -176,12 +180,18 @@ type to call `poll`? In [“Futures and Syntax: What Are Futures”][what-are-futures], we described how a series of await points in a future get compiled into a state machine—and noted how the compiler helps make sure that state machine follows all of Rust’s normal -rules around safety, including borrowing and ownership. Consider code like this: +rules around safety, including borrowing and ownership. Consider code which has +a mutable `Vec` of strings, which asynchronously reads strings from files and +pushes those strings into the `Vec`: + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:here}} ``` + + If we think about the state machine that would get compiled to, it might be something kind of like this: @@ -301,12 +311,12 @@ get our `join_all` call to compile! First, we need to explicitly annotate `futures` as referring to a pinned `Box` of futures. Second, we actually need to pin the futures, which we can do using the handy `Box::pin` API, which exists for exactly this. Putting that together, we end up with the code in Listing -17-21. +17-23. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:here}} ``` @@ -344,12 +354,12 @@ still be explicit about the type of the pinned reference; otherwise Rust will still not know to interpret these as dynamic trait objects, which is what we need them to be in the `Vec`. We therefore `pin!` each future when we define it, and define `futures` as a `Vec` containing pinned mutable references to the -dynamic `Future` type, as in Listing 17-22. +dynamic `Future` type, as in Listing 17-24. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:here}} ``` @@ -358,17 +368,17 @@ This keeps everything on the stack, which is a nice little performance win, but it is still a lot of explicit types, which is quite unusual for Rust! There is another, more serious, issue as well. We got this far by ignoring the -fact that we might have different `Output` types. For example, in Listing 17-23, +fact that we might have different `Output` types. For example, in Listing 17-25, the anonymous future type for `a` implements `Future`, the anonymous future type for `b` implements `Future`, and the anonymous future type for `c` implements `Future`. We can use `trpl::join!` to await them together, since it accepts futures of different types. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:here}} ``` diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index 647a8b5ecc..b5a96fa7a1 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -6,16 +6,16 @@ we move on. Sometimes, though, we only need *some* future from a set to finish before we move on—kind of like racing one future against another. This operation is often named `race` for exactly that reason. -In Listing 17-24, we use `race` to run two futures, `slow` and `fast`, against +In Listing 17-26, we use `race` to run two futures, `slow` and `fast`, against each other. Each one prints a message when it starts running, pauses for some amount of time by calling and awaiting `sleep`, and then prints another message when it finishes. Then we pass both to `trpl::race` and wait for one of them to finish. (The outcome here won’t be too surprising: `fast` wins!) -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:here}} ``` @@ -59,22 +59,22 @@ function “slow” will just take a number of milliseconds to run, and sleep t thread for that long. This is intentionally not an async function, because the idea is to represent work that is *not* async. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:slow}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:slow}} ``` -In Listing 17-26, we use `slow` to emulate doing this kind of CPU-bound work in +In Listing 17-28, we use `slow` to emulate doing this kind of CPU-bound work in a pair of futures. To begin, each future only hands control back to the runtime *after* carrying out a bunch of slow operations. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:slow-futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:slow-futures}} ``` @@ -82,7 +82,7 @@ a pair of futures. To begin, each future only hands control back to the runtime If you run this, you will see this output: ```console -{{#include ../listings/ch17-async-await/listing-17-26/output.txt}} +{{#include ../listings/ch17-async-await/listing-17-28/output.txt}} ``` As with our earlier example, `race` still finishes when `a` finishes. There is @@ -97,12 +97,12 @@ something we can await! However, we can also see the handoff happening in this very example: if we removed the `trpl::sleep` at the end of the `a` future, it would complete without the `b` future running *at all*. Given that, maybe we could use the -`sleep` function as a starting point, as in Listing 17-27. +`sleep` function as a starting point, as in Listing 17-29. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:here}} ``` @@ -140,10 +140,10 @@ runtime, using a function named `yield_now`. It does just what it says: hands control back to the runtime, so that the runtime can check whether any other tasks are ready to make progress. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-30/src/main.rs:here}} ``` @@ -156,18 +156,18 @@ example, will always sleep for at least a millisecond, even if we pass it a lot in one millisecond! You can see this for yourself by setting up a little benchmark, like the one in -Listing 17-29. (This is not an especially rigorous way to do performance +Listing 17-31. (This is not an especially rigorous way to do performance testing, but it suffices to show the difference here.) Here, we skip all the status printing, pass a one-nanosecond `Duration` to `sleep`, let each future run by itself so that they do not interfere with each other, and get rid of all the status printing that we did to see the back-and-forth between tasks in -Listings 17-27 and 17-28. Then we run for 1,000 iterations and see how long +Listings 17-29 and 17-30. Then we run for 1,000 iterations and see how long `sleep` takes vs. `yield_now`. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs:here}} ``` From 4f93e8b19fafb6ea00b7cc135f9496f07c088542 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 14 Jun 2024 09:41:02 -0600 Subject: [PATCH 316/720] =?UTF-8?q?Ch.=2017:=20finish=20listing=20numbers?= =?UTF-8?q?=20for=20=C2=A704?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../ch17-async-await/listing-17-33/Cargo.lock | 280 +++++++++ .../Cargo.toml | 0 .../listing-17-33/src/main.rs | 21 + .../ch17-async-await/listing-17-34/Cargo.lock | 280 +++++++++ .../ch17-async-await/listing-17-34/Cargo.toml | 9 + .../listing-17-34/src/main.rs | 31 + .../ch17-async-await/listing-17-35/Cargo.lock | 280 +++++++++ .../ch17-async-await/listing-17-35/Cargo.toml | 9 + .../src/main.rs | 5 - .../listing-17-timeout-final/Cargo.lock | 540 ------------------ src/ch17-04-more-ways-of-combining-futures.md | 22 +- 14 files changed, 921 insertions(+), 556 deletions(-) rename listings/ch17-async-await/{listing-17-timeout-a => listing-17-32}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-timeout-a => listing-17-32}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-timeout-a => listing-17-32}/src/main.rs (100%) create mode 100644 listings/ch17-async-await/listing-17-33/Cargo.lock rename listings/ch17-async-await/{listing-17-timeout-final => listing-17-33}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-33/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-34/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-34/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-34/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-35/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-35/Cargo.toml rename listings/ch17-async-await/{listing-17-timeout-final => listing-17-35}/src/main.rs (89%) delete mode 100644 listings/ch17-async-await/listing-17-timeout-final/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-timeout-a/Cargo.lock b/listings/ch17-async-await/listing-17-32/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-timeout-a/Cargo.lock rename to listings/ch17-async-await/listing-17-32/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-timeout-a/Cargo.toml b/listings/ch17-async-await/listing-17-32/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-timeout-a/Cargo.toml rename to listings/ch17-async-await/listing-17-32/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-timeout-a/src/main.rs b/listings/ch17-async-await/listing-17-32/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-timeout-a/src/main.rs rename to listings/ch17-async-await/listing-17-32/src/main.rs diff --git a/listings/ch17-async-await/listing-17-33/Cargo.lock b/listings/ch17-async-await/listing-17-33/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-33/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-timeout-final/Cargo.toml b/listings/ch17-async-await/listing-17-33/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-timeout-final/Cargo.toml rename to listings/ch17-async-await/listing-17-33/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-33/src/main.rs b/listings/ch17-async-await/listing-17-33/src/main.rs new file mode 100644 index 0000000000..17d2f985f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-33/src/main.rs @@ -0,0 +1,21 @@ +use std::{future::Future, time::Duration}; + +fn main() { + trpl::block_on(async { + let slow = async { + trpl::sleep(Duration::from_secs(5)).await; + "Finally finished" + }; + + // Here we will actually use the new `timeout` with `slow`. + }); +} + +// ANCHOR: declaration +async fn timeout( + max_time: Duration, + future: F, +) -> Result { + // ANCHOR_END: declaration + unimplemented!() +} diff --git a/listings/ch17-async-await/listing-17-34/Cargo.lock b/listings/ch17-async-await/listing-17-34/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-34/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-34/Cargo.toml b/listings/ch17-async-await/listing-17-34/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-34/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-34/src/main.rs b/listings/ch17-async-await/listing-17-34/src/main.rs new file mode 100644 index 0000000000..7ff4a59390 --- /dev/null +++ b/listings/ch17-async-await/listing-17-34/src/main.rs @@ -0,0 +1,31 @@ +use std::{future::Future, time::Duration}; + +// ANCHOR: timeout +use trpl::Either; +// ANCHOR_END: timeout + +fn main() { + trpl::block_on(async { + let slow = async { + trpl::sleep(Duration::from_secs(5)).await; + "Finally finished" + }; + + // Here we will actually use the new `timeout` with `slow`. + }); +} + +// Note for maintainers: the extra space after the `ANCHOR` is intentional: it +// makes this render more nicely! +// ANCHOR: timeout + +async fn timeout( + max_time: Duration, + future: F, +) -> Result { + match trpl::race(future, trpl::sleep(max_time)).await { + Either::Left(output) => Ok(output), + Either::Right(_) => Err(max_time), + } +} +// ANCHOR_END: timeout diff --git a/listings/ch17-async-await/listing-17-35/Cargo.lock b/listings/ch17-async-await/listing-17-35/Cargo.lock new file mode 100644 index 0000000000..c0e8bb2b3f --- /dev/null +++ b/listings/ch17-async-await/listing-17-35/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-35/Cargo.toml b/listings/ch17-async-await/listing-17-35/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-35/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-timeout-final/src/main.rs b/listings/ch17-async-await/listing-17-35/src/main.rs similarity index 89% rename from listings/ch17-async-await/listing-17-timeout-final/src/main.rs rename to listings/ch17-async-await/listing-17-35/src/main.rs index eaee49d51b..2e389a6509 100644 --- a/listings/ch17-async-await/listing-17-timeout-final/src/main.rs +++ b/listings/ch17-async-await/listing-17-35/src/main.rs @@ -20,17 +20,12 @@ fn main() { }); } -// ANCHOR: timeout - -// ANCHOR: declaration async fn timeout( max_time: Duration, future: F, ) -> Result { - // ANCHOR_END: declaration match trpl::race(future, trpl::sleep(max_time)).await { Either::Left(output) => Ok(output), Either::Right(_) => Err(max_time), } } -// ANCHOR_END: timeout diff --git a/listings/ch17-async-await/listing-17-timeout-final/Cargo.lock b/listings/ch17-async-await/listing-17-timeout-final/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-timeout-final/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index b5a96fa7a1..e488341314 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -191,15 +191,15 @@ important one to keep in mind, though! Many of these patterns are common enough to warrant abstracting over. For example, the `trpl::timeout` function takes a `Duration` for the maximum time to run, but also takes a future to run, and produces a new future you can await, -whose `Output` type is a `Result`. Listing 17-TODO shows how we can use it. If +whose `Output` type is a `Result`. Listing 17-32 shows how we can use it. If the passed-in future finishes first, the output result will be `Ok`, with the result of that passed-in future. If the duration elapses before the passed-in future finishes, the result will be `Err` with the duration that elapsed. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout-a/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs:here}} ``` @@ -215,12 +215,12 @@ the API of `timeout`: be `Ok` with the value produced by the future. If the timeout happens, the `Result` will be `Err` with the duration that the timeout waited for. -We can write the same signature ourselves, as in Listing 17-TODO. +We can write the same signature ourselves, as in Listing 17-33. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout-final/src/main.rs:declaration}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-33/src/main.rs:declaration}} ``` @@ -228,7 +228,7 @@ We can write the same signature ourselves, as in Listing 17-TODO. Then, in the body of the function, we can `race` whatever future the caller passes with a `sleep` future. -When we saw `race` earlier in Listing 17-TODO, we ignored its return type, +When we saw `race` earlier in Listing 17-26, we ignored its return type, because we were just interested in seeing the behavior of `fast` and `slow` when we ran the program. Here, though, its return value tells us whether the future or the sleep finished first. With `race`, both futures passed as arguments can @@ -259,10 +259,10 @@ match trpl::race(future_a, future_b).await { That gives us enough to be able to implement `timeout` ourselves using `race` and `sleep`. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout-final/src/main.rs:timeout}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-34/src/main.rs:timeout}} ``` @@ -280,10 +280,10 @@ duration the user passed in instead. And that’s it! Back in `main`, we can call this new `timeout` function exactly like we called `trpl::timeout` before, but without the `trpl::` namespace: -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-timeout-final/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-35/src/main.rs:main}} ``` From 4598e2cb4fddb75e4cc9893e06d56d99ee417f98 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 14 Jun 2024 10:28:34 -0600 Subject: [PATCH 317/720] =?UTF-8?q?Ch.=2017=20=C2=A701:=20make=20the=20con?= =?UTF-8?q?clusion=20section=20coherent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-01-futures-and-syntax.md | 34 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 5c2c74ba4e..dc63fd0c4a 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -84,8 +84,6 @@ run. - - ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch17-async-await/listing-17-02/src/main.rs:main}} ``` @@ -124,8 +122,8 @@ helper functions we supply are doing. > ### The `futures` and `tokio` Crates > > Whenever you see code from the `trpl` crate throughout the rest of the -> chapter, it will be re-exporting code from the `futures` and [`tokio`][tokio] -> crates. +> chapter, it will be re-exporting code from the [`futures`][futures-crate] and +> [`tokio`][tokio] crates. > > - The `futures` crate is an official home for Rust experimentation for async > code, and is actually where the `Future` type was originally designed. @@ -179,6 +177,12 @@ pub trait Future { } ``` +Notice that this is a normal trait. While we often interact with futures via +async blocks, you can also implement this yourself on your own data types when +you need to. Many of the functions we will see throughout this chapter return +types which have their own implementations of `Future`. Those implementations +can compose together nicely + `Future` has an associated type, `Output`, which says what the result of the future will be when it resolves. (This is analogous to the `Item` associated type for the `Iterator` trait, which we saw back in Chapter 13.) Beyond that, @@ -270,20 +274,12 @@ really is an `enum` like this, just an anonymous one you don’t have to name. A a result, the normal rules around data structures all apply, including for borrowing and ownership. Happily, the compiler also handles checking that for us, and has good error messages. We will work through a few of those later in -the chapter! This is enough information to let us keep following the chain back -up to the root of our original problem with running async functions. - - +the chapter! -When we follow that chain far enough, eventually we end up back in some -non-async function. At that point, something needs to “translate” between the -async and sync worlds. That “something” is also the runtime! Whatever runtime -you use is what handles the top-level `poll()` call, scheduling and handing off -between the different async operations which may be in flight as they hand back -control at await points, and often also providing async versions of -functionality like file I/O. +Once all of that compilation work is done, though, we need a runtime to actually +poll the futures, coordinate between different futures as they hand off control +at await points, and even provide async versions of common functionality like +file or network I/O. Now we can understand why the compiler was stopping us in Listing 17-2 (before we added the `trpl::block_on` function). The `main` function is not `async`—and @@ -319,7 +315,9 @@ futures and runtimes work, we can see some of the things we can *do* with async. [under-the-hood]: https://rust-lang.github.io/async-book/02_execution/01_chapter.html [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html [async-book]: https://rust-lang.github.io/async-book/ + [crate-source]: https://github.com/rust-lang/book/tree/main/packages/trpl +[futures-crate]: https://crates.io/crates/futures [tokio]: https://tokio.rs - + From c0c24e2c868566709ce0830c59acae1ac6ebc61c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 17 Jun 2024 11:25:37 -0600 Subject: [PATCH 318/720] =?UTF-8?q?Ch.=2017=20=C2=A702:=20transition=20for?= =?UTF-8?q?=20=C2=A703=20and=20TODO=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-02-concurrency-with-async.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 58ecfcbdc3..e69bc4526d 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -125,7 +125,9 @@ ask the runtime to run them both to completion using `trpl::join`: When we run this, we see both futures run to completion: - + ```text hi number 1 from the first task! @@ -346,7 +348,9 @@ which `rx` can then receive. When we run that code, we see the extra output from the new `async` block, and the message it sends being received by the `rx.recv()`. - + ```text Got: hi @@ -407,7 +411,12 @@ block, and switching back to `join3`. -Both of these blocks need to be `async move` blocks, or else we will end up back -in the same infinite loop we started out in. +*Both* of these blocks need to be `async move` blocks, or else we will end up +back in the same infinite loop we started out in. With that done, though, we get +all the messages we expected, with little delays between them. Notice that since +each of the sending futures do a one-second delay after sending, the messages +come in right after each other at one-second intervals. The delays are +concurrent, not sequential, just as we would expect. - +This is a good start, but it limits us to just a handful of futures: two with +`join`, or three with `join3`. Let’s see how we might work with more futures. From 74df84eaedd6d05e5be4bb4ae7d11a1877242541 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 17 Jun 2024 11:36:40 -0600 Subject: [PATCH 319/720] =?UTF-8?q?Ch.=2017:=20Add=20a=20new=20=C2=A705=20?= =?UTF-8?q?on=20Stream=20and=20AsyncIterator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This pushes back the Tasks, Futures, and Threads discussion one more spot, to become §06. --- src/SUMMARY.md | 3 +- src/ch17-04-more-ways-of-combining-futures.md | 2 + src/ch17-05-futures-tasks-threads.md | 102 ------------------ src/ch17-05-streams-async-iterators.md | 13 +++ src/ch17-06-futures-tasks-threads.md | 1 + 5 files changed, 18 insertions(+), 103 deletions(-) delete mode 100644 src/ch17-05-futures-tasks-threads.md create mode 100644 src/ch17-05-streams-async-iterators.md create mode 100644 src/ch17-06-futures-tasks-threads.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index f161db9097..4a9779468a 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -106,7 +106,8 @@ - [Concurrency With Async](ch17-02-concurrency-with-async.md) - [Working With More Futures](ch17-03-more-futures.md) - [More Ways of Combining Futures](ch17-04-more-ways-of-combining-futures.md) - - [Futures, Tasks, and Threads](ch17-05-futures-tasks-threads.md) + - [Streams and Async Iterators](ch17-05-streams-async-iterators.md) + - [Futures, Tasks, and Threads](ch17-06-futures-tasks-threads.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index e488341314..aa623af9d7 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -294,4 +294,6 @@ example, you can use this same approach to combine timeouts with retries, and in turn use those with things like network calls—the exact example we started out with at the beginning of the chapter! +Up next, let’s look at how we can work with *sequences* of futures. + [futures]: ch17-01-futures-and-syntax.html#what-are-futures diff --git a/src/ch17-05-futures-tasks-threads.md b/src/ch17-05-futures-tasks-threads.md deleted file mode 100644 index 230289d086..0000000000 --- a/src/ch17-05-futures-tasks-threads.md +++ /dev/null @@ -1,102 +0,0 @@ -## Futures, Tasks, and Threads - - - -As we saw in the previous chapter, threads provide one approach to concurrency, -and they let us solve some of these issues. However, they also have some -tradeoffs. On many operating systems, they use a fair bit of memory for each -thread, and they come with some overhead for starting up and shutting down. -Threads are also only an option when your operating system and hardware support -them! While mainstream desktop and mobile operating systems have all had -threading for many years, many embedded operating systems, like those used on -some microcontrollers, do not. - -The async model provides a different—and ultimately complementary—set of -tradeoffs. In the async model, concurrent operations do not require their own -threads. Instead, they can run on *tasks*. A task is a bit like a thread, but -instead of being managed by the operating system, it is managed by code that -lives at the level of libraries. - - - -### Parallelism and Concurrency - -First, though, we need to dig a little deeper into the differences between -parallelism and concurrency. In the previous chapter we treated them as mostly -interchangeable. Now we need to distinguish between the two a little more, -because the differences will show up as we start working: - -* *Parallelism* is when operations can happen simultaneously. - -* *Concurrency* is when operations can make progress without having to wait for - all other operations to complete. - -One common analogy for thinking about the difference between concurrency and -parallelism is cooking in a kitchen. Parallelism is like having two cooks: one -working on cooking eggs, and the other working on preparing fruit bowls. Those -can happen at the same time, without either affecting the other. Concurrency is -like having a single cook who can start cooking some eggs, start dicing up some -vegetables to use in the omelette, adding seasoning and whatever vegetables are -ready to the eggs at certain points, and switching back and forth between those -tasks. - -(This analogy breaks down if you think about it too hard. The eggs keep cooking -while the cook is chopping up the vegetables, after all. That is parallelism, -not just concurrency! The focus of the analogy is the *cook*, not the food, -though, and as long as you keep that in mind, it mostly works.) - -On a machine with multiple CPU cores, we can actually do work in parallel. One -core can be doing one thing while another core does something completely -unrelated, and those actually happen at the same time. On a machine with a -single CPU core, the CPU can only do one operation at a time, but we can still -have concurrency. Using tools like threads, processes, and async, the computer -can pause one activity and switch to others before eventually cycling back to -that first activity again. So all parallel operations are also concurrent, but -not all concurrent operations happen in parallel! - -When working with async in Rust, we are always dealing with concurrency. -Depending on the hardware, the operating system, and the async runtime we are -using, that concurrency may use some degree of parallelism under the hood, or it -may not. (More about async runtimes later!) - -A big difference between the cooking analogy and Rust’s async model for -concurrency is that in the cooking example, the cook makes the decision about -when to switch tasks. In Rust’s async model, the tasks are in control of that. -To see how, let’s look at how Rust actually uses async. - -## Misc. other stuff - - -The `async` keyword does not yet work with closures directly. That is, there is -no direct equivalent to `async fn` for anonymous functions. As a result, you -cannot write code like these function calls: - -```rust,ignore -example_1(async || { ... }); -example_2(async move || { ... }); -``` - -However, since async blocks themselves can be marked with `move`, this ends up -not being a problem. Because `async` blocks compile to anonymous futures, you -can write calls like this instead: - -```rust,ignore -example_1(|| async { ... }); -example_2(|| async move { ... }); -``` - -These closures now return anonymous futures, meaning they work basically the -same way that an async function does. - - - -> Note: This is how closures work, too, but we did not have to talk about it -> back in Chapter 13, because the details did not bubble up to the surface the -> way they do here! - - diff --git a/src/ch17-05-streams-async-iterators.md b/src/ch17-05-streams-async-iterators.md new file mode 100644 index 0000000000..2372dfd1a4 --- /dev/null +++ b/src/ch17-05-streams-async-iterators.md @@ -0,0 +1,13 @@ +## Streams and Async Iterators + + diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md new file mode 100644 index 0000000000..53b122978f --- /dev/null +++ b/src/ch17-06-futures-tasks-threads.md @@ -0,0 +1 @@ +# Futures, Tasks, and Threads From f0825ad05c20122bbcaa4a655f5eb15b33b422ae Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 17 Jun 2024 13:29:44 -0600 Subject: [PATCH 320/720] =?UTF-8?q?Ch.=2017=20S=C2=A702:=20introduce=20and?= =?UTF-8?q?=20explain=20`while=20let`=20syntax.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is actually the first time it appears in the book, to my great surprise! We will also need to update Chapter 19 to account for having introduced this form already, following the example for how it handles Chapter 6’s introduction of `if let`. --- src/ch17-02-concurrency-with-async.md | 60 ++++++++++++++++++--------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index e69bc4526d..4373036419 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -175,12 +175,12 @@ Sharing data between futures will look familiar. We can again use async versions of Rust’s types for message-passing. Instead of `std::sync:mpsc::channel`, we will use a `tprl::channel`, for example. -The `Receiver::recv()` method in the `std` channel blocks until it receives a -message. The `trpl::Receiver::recv()` method, by contrast, is an `async` -function. Instead of blocking, it sleeps until a message is received or the send -side of the channel closes. One other difference with this particular `recv()` -implementation is that it returns an `Option` of the type sent over the channel -instead of a `Result`. +The synchronous `Receiver::recv()` method in `std::mpsc::channel` blocks until +it receives a message. The `trpl::Receiver::recv()` method, by contrast, is an +`async` function. Instead of blocking, it waits until a message is received or +the send side of the channel closes. One other difference with this particular +`recv()` implementation is that it returns an `Option` of the type sent over the +channel instead of a `Result`. We can start by introducing an async version of the multiple-producer, single-consumer channel channel API we used with threads back in Chapter 16. The @@ -236,15 +236,22 @@ as shown in Listing 17-10: This handles sending the messages, but so far we don’t do anything with them, -and the code just silently runs forever. Listing 17-11 shows how we can receive -those messages by waiting for them in a loop. - -Here, we need to use a `while let` loop rather than a `for` loop, because Rust -does not yet have an async version of `Iterator`, which is what the `for` loop -does. In TODO: SECTION TITLE, we will see more about two related traits the -community has been working on, `AsyncIterator` and `Stream`. For now, we can -stick with `while let`, as in Listing 17-11, and the loop will end when -`rx.recv().await` produces a `None`. +and the code just silently runs forever. We need to actually *receive* the +messages. In this case, we could do that manually, because we know how many +messages are coming in. In the real world, though, we will generally be waiting +on some *unknown* number of messages. In that case, we need to keep waiting +until we determine that there are no more messages. + +That sounds like a good job for a loop! In synchronous code, we might use a +`for` loop to process a sequence of items, regardless of how many items are in +the loop. However, Rust does not yet have a way to write a `for` loop over an +*asynchronous* series of items. Instead, we need to use a new kind of loop we +haven’t seen before, the `while let` conditional loop. A `while let` loop is the +loop version of the `if let` construct we saw back in Chapter 6. It continues as +long as the condition it relies on is true. Listing 17-11 shows how we can use +this with `rx.recv` to print all the messages send by the `tx` transmitter. + + @@ -254,10 +261,23 @@ stick with `while let`, as in Listing 17-11, and the loop will end when -This code still does not do exactly what we want. It does successfully send and -receive the messages, but instead of seeing the messages received at one-second -intervals, we see them arrive all at once, four seconds after we start the -program. It also never stops! You will need to shut it down using ctrl-c. Let’s start by understanding why the messages all come in at once after the full @@ -420,3 +440,5 @@ concurrent, not sequential, just as we would expect. This is a good start, but it limits us to just a handful of futures: two with `join`, or three with `join3`. Let’s see how we might work with more futures. + +[streams]: /ch17-05-streams.md From a05c34eaa91d44cb88a7339cd3c192b654ccf21e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 17 Jun 2024 13:29:44 -0600 Subject: [PATCH 321/720] =?UTF-8?q?Ch.=2017=20=C2=A705:=20Introduce=20`Str?= =?UTF-8?q?eam`=20and=20drop=20`AsyncIterator`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SUMMARY.md | 2 +- src/ch17-04-more-ways-of-combining-futures.md | 4 +- src/ch17-05-streams-async-iterators.md | 13 --- src/ch17-05-streams.md | 105 ++++++++++++++++++ 4 files changed, 109 insertions(+), 15 deletions(-) delete mode 100644 src/ch17-05-streams-async-iterators.md create mode 100644 src/ch17-05-streams.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 4a9779468a..5a6dbfc377 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -106,7 +106,7 @@ - [Concurrency With Async](ch17-02-concurrency-with-async.md) - [Working With More Futures](ch17-03-more-futures.md) - [More Ways of Combining Futures](ch17-04-more-ways-of-combining-futures.md) - - [Streams and Async Iterators](ch17-05-streams-async-iterators.md) + - [Streams](ch17-05-streams.md) - [Futures, Tasks, and Threads](ch17-06-futures-tasks-threads.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index aa623af9d7..fb0cb56c3c 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -294,6 +294,8 @@ example, you can use this same approach to combine timeouts with retries, and in turn use those with things like network calls—the exact example we started out with at the beginning of the chapter! -Up next, let’s look at how we can work with *sequences* of futures. +Over the last two sections, we have seen how to work with multiple futures at +the same time. Up next, let’s look at how we can work with multiple futures in a +sequence over time, with *streams*. [futures]: ch17-01-futures-and-syntax.html#what-are-futures diff --git a/src/ch17-05-streams-async-iterators.md b/src/ch17-05-streams-async-iterators.md deleted file mode 100644 index 2372dfd1a4..0000000000 --- a/src/ch17-05-streams-async-iterators.md +++ /dev/null @@ -1,13 +0,0 @@ -## Streams and Async Iterators - - diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md new file mode 100644 index 0000000000..3628191d6b --- /dev/null +++ b/src/ch17-05-streams.md @@ -0,0 +1,105 @@ +## Streams + +In Chapter 13, we looked at the `Iterator` trait, and we saw how we could work +with a sequence of items in turn. So far in this chapter, we have mostly stuck +with individual futures. The one big exception was the async channel we used. +Recall how we used the receiver for our async channel in the [“Message +Passing”][17-02-messages] earlier in the chapter: + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:loop}} +``` + +This is because the `rx` receiver actually represents a *stream* of messages: a +sequence over time. + +Unlike `Iterator` and `Future`, there is no definition of a `Stream` type in the +standard library yet but there *is* a +very common definition used throughout the ecosystem. If we start with the +definition of the `Iterator` and `Trait` types, we can figure out what a trait +that merges them together might look like. + +The `Iterator` trait defines an associated type `Item` and a function `next`, +which produces `Some(Item)` until the underlying iterator is empty, and then +produces `None`. + + + +```rust +trait Iterator { + type Item; + + fn next(&mut self) -> Option; +} +``` + +As we saw earlier in this chapter, the `Future` trait defines an associated item +`Output` and a function `poll`, which produces `Poll::Pending` while waiting and +then `Poll::Ready(Output)` once the future is ready. + +```rust +trait Future { + type Output; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; +} +``` + +From `Iterator`, we have the idea of a sequence; its `next` method provides an +`Option`. From `Future`, we have the idea of readiness; its `poll` +method provides a `Poll`. To get a stream, a sequence of items +which become ready over time, we can define a `Stream` as a trait which has all +of those features put together: + +* An associated type `Item` for the type of the items, just like in `Iterator`. + Unlike in `Future`, where there was a single `Output`, we use `Item` here to + indicate that it is more like `Iterator`: there may be zero to many of these. + +* A method to get those items. We can call it `poll_next`, to make it clear that + it is polling like a future and producing a sequence of items one after another + like an iterator. + +* A return type from `poll_next` which uses both `Poll` and `Option`. The outer + type is `Poll`, since it has to be checked for readiness as a kind of future. + The inner type is `Option`, since it needs to signal whether there are more + messages, just like an iterator. + +When we put those all together, we end up with the same definition for a +`Stream` trait as the one used by the Rust ecosystem: + +```rust +trait Stream { + type Item; + + fn poll_next( + self: Pin<&mut Self>, + cx: &mut Context<'_> + ) -> Poll>; +} +``` + +Something very similar to this will likely end up standardized as part of Rust’s +standard library, just the way `Future` was. + +### Working With Streams + +Now that we have seen the API, we can see that `rx.recv` is a good model for how +we will use streams. + +> Note: As mentioned in the [“Message Passing”][17-02-messages] section, there +> is not yet an async version of `for` loops. There may well be in the future, +> though, and if so it will be built on something a lot like `Stream`. + + + +[17-02-messages]: /ch17-02-concurrency-with-async.md#message-passing From ad360d7fe4632d1771f1abb7d7be3715538e7556 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 18 Jun 2024 08:16:11 -0600 Subject: [PATCH 322/720] =?UTF-8?q?Ch=2017.=20=C2=A701:=20leave=20a=20TODO?= =?UTF-8?q?=20about=20`IntoFuture`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-01-futures-and-syntax.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index dc63fd0c4a..681727d387 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -214,7 +214,8 @@ available. > documentation. Under the hood, when you call `.await`, Rust compiles that to code which calls -`poll`, kind of like this: +`poll`, kind of (although not exactly ) +like this: ```rust,ignore match hello_async().poll() { From 52c516c59369b5e0a7b2ea49bed731dd3d742d60 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 18 Jun 2024 08:16:11 -0600 Subject: [PATCH 323/720] =?UTF-8?q?Ch.=2017=20=C2=A705:=20start=20explaini?= =?UTF-8?q?ng=20how=20we=20work=20with=20streams?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-05-streams.md | 53 ++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index 3628191d6b..a56ed79ae0 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -56,8 +56,8 @@ of those features put together: indicate that it is more like `Iterator`: there may be zero to many of these. * A method to get those items. We can call it `poll_next`, to make it clear that - it is polling like a future and producing a sequence of items one after another - like an iterator. + it is polling like a future and producing a sequence of items one after + another, just like an iterator. * A return type from `poll_next` which uses both `Poll` and `Option`. The outer type is `Poll`, since it has to be checked for readiness as a kind of future. @@ -79,27 +79,50 @@ trait Stream { ``` Something very similar to this will likely end up standardized as part of Rust’s -standard library, just the way `Future` was. +standard library, just the way `Future` was. In the meantime, it is part of the +toolkit of most runtimes, so you can rely on it, and everything we cover below +should generally apply! ### Working With Streams -Now that we have seen the API, we can see that `rx.recv` is a good model for how -we will use streams. +We *could* work directly in terms of the `poll_next` API by hand-writing our own +`Stream` state machines. However, just as we do not generally work with futures +directly via their `poll` method, we generally also do not work directly with +the `poll_next` method for streams. Instead, we usually use a `next` method, +which is defined roughly like this: -> Note: As mentioned in the [“Message Passing”][17-02-messages] section, there -> is not yet an async version of `for` loops. There may well be in the future, -> though, and if so it will be built on something a lot like `Stream`. +```rust +trait Stream { + async fn next(&mut self) -> Option; +} +``` -- Motivation: you can do a lot with `while let` but it would be nice to be able - to use `for` loops, even `async for`. (But we don’t get those from the - ecosystem traits… so maybe only call them out in a `Note: …` context?) - -- The basic API, with `poll_next()`, plus the “surface” syntax, `.next().await`. - -- How to use it, with a worked example from . +> Note: The actual definition we will use looks slightly different than this, +> because it supports versions of Rust which did not yet support using async +> functions in traits. As a result, it looks like this: +> +> ```rust +> fn next(&mut self) -> Next<'_, Self> where Self: Unpin; +> ``` +> +> That `Next` type is just a simple `struct` which implements `Future`, so that +> `.await` can work with this! + +Working with this API will be kind of like working with iterators without the +convenience of a `for` loop. In fact, it will look a lot like the way we used +`rx.recv` back in the [“Message Passing”][17-02-messages] section, using `while +let` loops. + [17-02-messages]: /ch17-02-concurrency-with-async.md#message-passing From 1e41a9a52a96c3e8e0e1462440dc264e460bb89d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 19 Jun 2024 10:47:13 -0600 Subject: [PATCH 324/720] infra: ignore Nova configuration directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4c699f440a..17127d1142 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ book/ target tmp +.nova From e3ab302d2787f9cd38a49adc55d83662f191e7d8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 19 Jun 2024 10:47:13 -0600 Subject: [PATCH 325/720] Ch. 17: Remove a now-properly-numbered listing I moved this into dedicated listings appropriately but forgot to remove the original. --- .../listing-17-timeout-b/Cargo.lock | 540 ------------------ .../listing-17-timeout-b/Cargo.toml | 9 - .../listing-17-timeout-b/src/main.rs | 19 - 3 files changed, 568 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-timeout-b/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-timeout-b/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-timeout-b/src/main.rs diff --git a/listings/ch17-async-await/listing-17-timeout-b/Cargo.lock b/listings/ch17-async-await/listing-17-timeout-b/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-timeout-b/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-timeout-b/Cargo.toml b/listings/ch17-async-await/listing-17-timeout-b/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-timeout-b/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-timeout-b/src/main.rs b/listings/ch17-async-await/listing-17-timeout-b/src/main.rs deleted file mode 100644 index 5d10b86764..0000000000 --- a/listings/ch17-async-await/listing-17-timeout-b/src/main.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - // ANCHOR: fast - let fast = async { - trpl::sleep(Duration::from_secs(1)).await; - "I finished!" - }; - // ANCHOR_END: fast - - match trpl::timeout(Duration::from_secs(2), fast).await { - Ok(message) => println!("Succeeded with '{message}'"), - Err(duration) => { - println!("Failed after {} seconds", duration.as_secs()) - } - } - }); -} From bf5e4aa687033d39d8e59295500e568ac38b3d3e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 19 Jun 2024 10:47:13 -0600 Subject: [PATCH 326/720] Ch. 17 (infra): add a base listing to use when generating new ones --- .../listing-17-base/Cargo.lock | 280 ++++++++++++++++++ .../listing-17-base/Cargo.toml | 8 + .../listing-17-base/src/main.rs | 5 + 3 files changed, 293 insertions(+) create mode 100644 listings/ch17-async-await/listing-17-base/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-base/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-base/src/main.rs diff --git a/listings/ch17-async-await/listing-17-base/Cargo.lock b/listings/ch17-async-await/listing-17-base/Cargo.lock new file mode 100644 index 0000000000..53a9a9dde6 --- /dev/null +++ b/listings/ch17-async-await/listing-17-base/Cargo.lock @@ -0,0 +1,280 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-base/Cargo.toml b/listings/ch17-async-await/listing-17-base/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-base/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-base/src/main.rs b/listings/ch17-async-await/listing-17-base/src/main.rs new file mode 100644 index 0000000000..3c247f888f --- /dev/null +++ b/listings/ch17-async-await/listing-17-base/src/main.rs @@ -0,0 +1,5 @@ +fn main() { + trpl::block_on(async { + // TODO: use this! + }) +} From e790c2cc9008b2135c63db7382f1ac71fac8e261 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 19 Jun 2024 10:47:13 -0600 Subject: [PATCH 327/720] Ch. 17: re-export `Stream`, `StreamExt`, and `stream_iter` in `trpl` --- packages/trpl/Cargo.lock | 12 ++++++++++++ packages/trpl/Cargo.toml | 1 + packages/trpl/src/lib.rs | 2 ++ packages/trpl/tests/integration/main.rs | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/packages/trpl/Cargo.lock b/packages/trpl/Cargo.lock index e6e27ec0a4..03bebc8dd8 100644 --- a/packages/trpl/Cargo.lock +++ b/packages/trpl/Cargo.lock @@ -258,12 +258,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/packages/trpl/Cargo.toml b/packages/trpl/Cargo.toml index 898dae43f9..c842170443 100644 --- a/packages/trpl/Cargo.toml +++ b/packages/trpl/Cargo.toml @@ -13,3 +13,4 @@ tokio = { version = "1", default-features = false, features = [ "sync", "time", ] } +tokio-stream = "0.1.15" diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 4d748d4783..b572b0a17b 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -41,6 +41,8 @@ pub use tokio::{ time::sleep, }; +pub use tokio_stream::{iter as stream_from_iter, Stream, StreamExt}; + /// Run a single future to completion on a bespoke Tokio `Runtime`. /// /// Every time you call this, a new instance of `tokio::runtime::Runtime` will diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index ecff695515..e067732500 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -199,3 +199,23 @@ fn read_to_string() { assert_eq!(result, String::from("This is some text!\n")); } + +#[test] +fn stream_iter() { + use trpl::StreamExt; + + let result = trpl::block_on(async { + let ns = vec![1, 2, 3]; + let mut stream = trpl::stream_from_iter(ns); + let mut result = vec![]; + while let Some(n) = stream.next().await { + result.push(format!("{n}")); + } + result + }); + + assert_eq!( + result, + vec![String::from("1"), String::from("2"), String::from("3")] + ) +} From ce9b286b8fc404ec2815b89bf003c3ea4839a97b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 20 Jun 2024 13:45:50 -0600 Subject: [PATCH 328/720] =?UTF-8?q?Ch.=2017=20=C2=A705:=20describe=20how?= =?UTF-8?q?=20to=20use=20`Stream`s=20with=20`Iterator`s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also start laying the foundation for (a) showing how that interacts with previous material, e.g. around slow operations; and (b) showing how it composes nicely with other async operations, e.g. timeouts, throttling, and (maybe!) even merging streams. --- .../ch17-async-await/listing-17-36/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-36/Cargo.toml | 8 + .../listing-17-36/src/main.rs | 8 + .../ch17-async-await/listing-17-37/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-37/Cargo.toml | 8 + .../listing-17-37/src/main.rs | 9 + .../ch17-async-await/listing-17-38/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-38/Cargo.toml | 8 + .../ch17-async-await/listing-17-38/output.txt | 51 +++ .../listing-17-38/src/main.rs | 13 + .../ch17-async-await/listing-17-39/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-39/Cargo.toml | 8 + .../listing-17-39/src/main.rs | 15 + .../ch17-async-await/listing-17-40/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-40/Cargo.toml | 8 + .../listing-17-40/src/main.rs | 19 ++ src/ch17-05-streams.md | 96 +++++- 17 files changed, 1707 insertions(+), 4 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-36/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-36/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-36/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-37/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-37/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-37/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-38/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-38/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-38/output.txt create mode 100644 listings/ch17-async-await/listing-17-38/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-39/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-39/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-39/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-40/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-40/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-40/src/main.rs diff --git a/listings/ch17-async-await/listing-17-36/Cargo.lock b/listings/ch17-async-await/listing-17-36/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-36/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-36/Cargo.toml b/listings/ch17-async-await/listing-17-36/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-36/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-36/src/main.rs b/listings/ch17-async-await/listing-17-36/src/main.rs new file mode 100644 index 0000000000..afe325e6d6 --- /dev/null +++ b/listings/ch17-async-await/listing-17-36/src/main.rs @@ -0,0 +1,8 @@ +fn main() { + trpl::block_on(async { + // ANCHOR: range + let values = 1..101; + let iter = values.map(|n| n * 2); + // ANCHOR_END: range + }); +} diff --git a/listings/ch17-async-await/listing-17-37/Cargo.lock b/listings/ch17-async-await/listing-17-37/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-37/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-37/Cargo.toml b/listings/ch17-async-await/listing-17-37/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-37/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-37/src/main.rs b/listings/ch17-async-await/listing-17-37/src/main.rs new file mode 100644 index 0000000000..5bc9e01ac5 --- /dev/null +++ b/listings/ch17-async-await/listing-17-37/src/main.rs @@ -0,0 +1,9 @@ +fn main() { + trpl::block_on(async { + let values = 1..101; + let iter = values.map(|n| n * 2); + // ANCHOR: stream + let mut stream = trpl::stream_from_iter(iter); + // ANCHOR_END: stream + }); +} diff --git a/listings/ch17-async-await/listing-17-38/Cargo.lock b/listings/ch17-async-await/listing-17-38/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-38/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-38/Cargo.toml b/listings/ch17-async-await/listing-17-38/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-38/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-38/output.txt b/listings/ch17-async-await/listing-17-38/output.txt new file mode 100644 index 0000000000..6e6886fb5c --- /dev/null +++ b/listings/ch17-async-await/listing-17-38/output.txt @@ -0,0 +1,51 @@ +$ cargo run + Compiling proc-macro2 v1.0.85 + Compiling unicode-ident v1.0.12 + Compiling autocfg v1.3.0 + Compiling pin-project-lite v0.2.14 + Compiling futures-core v0.3.30 + Compiling libc v0.2.155 + Compiling futures-sink v0.3.30 + Compiling futures-task v0.3.30 + Compiling pin-utils v0.1.0 + Compiling futures-io v0.3.30 + Compiling memchr v2.7.4 + Compiling futures-channel v0.3.30 + Compiling slab v0.4.9 + Compiling num_cpus v1.16.0 + Compiling quote v1.0.36 + Compiling tokio v1.38.0 + Compiling syn v2.0.66 + Compiling tokio-stream v0.1.15 + Compiling futures-macro v0.3.30 + Compiling futures-util v0.3.30 + Compiling futures-executor v0.3.30 + Compiling futures v0.3.30 + Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-38) +error[E0599]: no method named `next` found for struct `Iter` in the current scope + --> src/main.rs:8:40 + | +8 | while let Some(value) = stream.next().await { + | ^^^^ + | + = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-38/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-17453505919820464996.txt' + = note: consider using `--verbose` to print the full type name to the console + = help: items from traits can only be used if the trait is in scope +help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them + | +1 + use futures_util::stream::stream::StreamExt; + | +1 + use std::iter::Iterator; + | +1 + use std::str::pattern::Searcher; + | +1 + use trpl::StreamExt; + | +help: there is a method `try_next` with a similar name + | +8 | while let Some(value) = stream.try_next().await { + | ~~~~~~~~ + +For more information about this error, try `rustc --explain E0599`. +error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-38/src/main.rs b/listings/ch17-async-await/listing-17-38/src/main.rs new file mode 100644 index 0000000000..08bd4b0b72 --- /dev/null +++ b/listings/ch17-async-await/listing-17-38/src/main.rs @@ -0,0 +1,13 @@ +fn main() { + trpl::block_on(async { + let values = 1..101; + let iter = values.map(|n| n * 2); + let mut stream = trpl::stream_from_iter(iter); + + // ANCHOR: next + while let Some(value) = stream.next().await { + println!("The value was: {value}"); + } + // ANCHOR_END: next + }); +} diff --git a/listings/ch17-async-await/listing-17-39/Cargo.lock b/listings/ch17-async-await/listing-17-39/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-39/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-39/Cargo.toml b/listings/ch17-async-await/listing-17-39/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-39/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-39/src/main.rs b/listings/ch17-async-await/listing-17-39/src/main.rs new file mode 100644 index 0000000000..317677eba1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-39/src/main.rs @@ -0,0 +1,15 @@ +// ANCHOR: all +use trpl::StreamExt; + +fn main() { + trpl::block_on(async { + let values = 1..101; + let iter = values.map(|n| n * 2); + let mut stream = trpl::stream_from_iter(iter); + + while let Some(value) = stream.next().await { + println!("The value was: {value}"); + } + }); +} +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-40/Cargo.lock b/listings/ch17-async-await/listing-17-40/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-40/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-40/Cargo.toml b/listings/ch17-async-await/listing-17-40/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-40/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-40/src/main.rs b/listings/ch17-async-await/listing-17-40/src/main.rs new file mode 100644 index 0000000000..8c98a66dfe --- /dev/null +++ b/listings/ch17-async-await/listing-17-40/src/main.rs @@ -0,0 +1,19 @@ +use trpl::StreamExt; + +fn main() { + trpl::block_on(async { + let values = 1..101; + let iter = values.map(|n| n * 2); + let stream = trpl::stream_from_iter(iter); + + // ANCHOR: filter + let mut filtered = + stream.filter(|value| value % 3 == 0 || value % 5 == 0); + + while let Some(value) = filtered.next().await { + println!("The value was: {value}"); + } + // ANCHOR_END: filter + }); +} +// ANCHOR_END: all diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index a56ed79ae0..ace132f8f5 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -118,11 +118,99 @@ convenience of a `for` loop. In fact, it will look a lot like the way we used `rx.recv` back in the [“Message Passing”][17-02-messages] section, using `while let` loops. +Let’s start with a very simple example: using an iterator *as* a stream. Let’s +start by creating a range of numbers, including every integer from 1 to 100, +using the `..` range operator. Then we can double all of those values with the +`map` method, as Listing 17-36 shows: + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-36/src/main.rs:range}} +``` + + + +We can convert this iterator to a stream using the `trpl::stream_from_iter` +function. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-37/src/main.rs:stream}} +``` + + + +This gives us the stream. Now, to work with it, we want to use the `next` method +with a `while let` loop as described above, as in Listing 17-38: + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-38/src/main.rs:next}} +``` + + + +Unfortunately, this does not yet work. When we try to run the code, it does not +compile. Instead, as we can see in the output, it reports that there is no +`next` method available. + +```console +{{#include ../listings/ch17-async-await/listing-17-38/output.txt}} +``` + +As the output suggests, the problem is that we need the right trait in scope to +be able to use it. In this case, that trait is `StreamExt`. (The `Ext` there is +for “extension”: this is a common pattern in the Rust community for extending +one trait with another.) `StreamExt` is automatically implemented for every type +which implements `Stream`, but they are separated out so that the community can +iterate on the foundational trait distinctly from the convenience APIs. All we +need to do, then, is add a `use` statement for `trpl::StreamExt`, as in Listing +17-39. + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-39/src/main.rs:all}} +``` + + + + With all those pieces put together, things work the way we want! There is a lot + of output, though, since we told it to print all of the 100 numbers in the + iterator. We can filter that down, to, say, multiples of three and five by using + the `filter` method, which conveniently also comes from `StreamExt`. + + + + ```rust,ignore,does_not_compile + {{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:filter}} + ``` + + + +Of course, in the real world, the only time we would be directly converting an +iterator to a stream like this is to help break up longer chunks of work, like +we discussed in the previous section. There are more interesting things we can +do with streams, though! + +For one thing, lots of things are naturally represented as streams—items +becoming available in a queue over time, for example, or working with more data +than can fit in a computer’s memory by only pulling chunks of it from the file +system at a time, or data arriving over the network over time. For another +thing, since streams are futures, we can use them with any other kind of +future, and we can combine them in interesting ways. + +This is the kind of thing we might actually do to help break up longer chunks of +work, like we discussed in the previous section—though of course, presumably +with more interesting iterators than this one! + [17-02-messages]: /ch17-02-concurrency-with-async.md#message-passing From 40f5ec3c6205daab12a451abae6499ce96a05c03 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:59:36 -0300 Subject: [PATCH 329/720] Update ch10-00-generics.md --- src/ch10-00-generics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch10-00-generics.md b/src/ch10-00-generics.md index bd18a5e525..56ceee20dc 100644 --- a/src/ch10-00-generics.md +++ b/src/ch10-00-generics.md @@ -78,7 +78,7 @@ have to remember to update the code in multiple places when we want to change it. To eliminate this duplication, we’ll create an abstraction by defining a -function that operates on any list of integers passed in a parameter. This +function that operates on any list of integers passed in as a parameter. This solution makes our code clearer and lets us express the concept of finding the largest number in a list abstractly. From b4f5763368f441fb9c6f1c838c1db7cb67b68311 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 24 Jun 2024 14:00:08 -0600 Subject: [PATCH 330/720] =?UTF-8?q?Ch.=2017:=20final=20example=20for=20?= =?UTF-8?q?=C2=A705,=20with=20more=20re-exported=20streams?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use `IntervalStream` and `ReceiverStream` to show the composition of multiple streams, along with throttling and timeouts. This will also provide a useful foundation for discussing the relationships between futures, tasks, and threads in the final sections of the book, since you can accomplish the same basic API by simply substituting threads for tasks—but with different tradeoffs! --- .../listing-17-s05-final/Cargo.lock | 292 ++++++++++++++++++ .../listing-17-s05-final/Cargo.toml | 8 + .../listing-17-s05-final/src/main.rs | 80 +++++ packages/trpl/src/lib.rs | 8 +- packages/trpl/tests/integration/main.rs | 33 ++ src/ch17-06-futures-tasks-threads.md | 86 ++++++ 6 files changed, 505 insertions(+), 2 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-s05-final/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-s05-final/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-s05-final/src/main.rs diff --git a/listings/ch17-async-await/listing-17-s05-final/Cargo.lock b/listings/ch17-async-await/listing-17-s05-final/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-s05-final/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-s05-final/Cargo.toml b/listings/ch17-async-await/listing-17-s05-final/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-s05-final/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-s05-final/src/main.rs b/listings/ch17-async-await/listing-17-s05-final/src/main.rs new file mode 100644 index 0000000000..e8ee79e4a4 --- /dev/null +++ b/listings/ch17-async-await/listing-17-s05-final/src/main.rs @@ -0,0 +1,80 @@ +use std::{pin::pin, time::Duration}; + +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let messages = get_messages().timeout(Duration::from_millis(200)); + let intervals = get_intervals() + .map(|count| format!("Interval #{count}")) + .throttle(Duration::from_millis(500)) + .timeout(Duration::from_secs(10)); + + let mut merged = pin!(messages.merge(intervals).take(20)); + + while let Some(result) = merged.next().await { + match result { + Ok(item) => println!("{item}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} + +// ANCHOR: errors +fn get_messages() -> impl Stream { + // --snip-- + + // ANCHOR_END: errors + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + // ANCHOR: errors + if let Err(send_error) = + tx.send(format!("Message: '{message}' after {time_to_sleep}ms")) + { + eprintln!("Cannot send message '{message}': {send_error}"); + break; + } + // ANCHOR_END: errors + } + }); + + ReceiverStream::new(rx) + // ANCHOR: errors + + // --snip-- +} + +fn get_intervals() -> impl Stream { + // --snip-- + + // ANCHOR_END: errors + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let mut count = 0; + loop { + trpl::sleep(Duration::from_millis(1)).await; + count += 1; + // ANCHOR: errors + if let Err(send_error) = tx.send(count) { + eprintln!("Could not send interval {count}: {send_error}"); + break; + }; + // ANCHOR_END: errors + } + }); + + ReceiverStream::new(rx) + // ANCHOR: errors + + // --snip-- +} +// ANCHOR_END: errors diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index b572b0a17b..4ffdbc365b 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -38,10 +38,14 @@ pub use tokio::{ UnboundedSender as Sender, }, task::{spawn as spawn_task, yield_now}, - time::sleep, + time::{interval, sleep}, }; -pub use tokio_stream::{iter as stream_from_iter, Stream, StreamExt}; +pub use tokio_stream::{ + iter as stream_from_iter, + wrappers::{IntervalStream, UnboundedReceiverStream as ReceiverStream}, + Stream, StreamExt, +}; /// Run a single future to completion on a bespoke Tokio `Runtime`. /// diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index e067732500..a46533534a 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -219,3 +219,36 @@ fn stream_iter() { vec![String::from("1"), String::from("2"), String::from("3")] ) } + +#[test] +fn receiver_stream() { + use trpl::ReceiverStream; + use trpl::StreamExt; + + let result: Vec = trpl::block_on(async { + println!("startup"); + let (tx, rx) = trpl::channel(); + let rx_stream = ReceiverStream::new(rx); + println!("sending 123"); + tx.send(123).unwrap(); + drop(tx); // So the receiver channel closes! + + rx_stream.collect().await + }); + + assert_eq!(result, vec![123]); +} + +#[test] +fn re_exported_interval_stream_works() { + use trpl::{IntervalStream, StreamExt}; + + trpl::block_on(async { + let mut interval_stream = + IntervalStream::new(trpl::interval(Duration::from_millis(1))) + .take(1); + + assert!(interval_stream.next().await.is_some()); + assert!(interval_stream.next().await.is_none()); + }); +} diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 53b122978f..70baf0ce67 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -1 +1,87 @@ # Futures, Tasks, and Threads + +Working code from end of previous section: + +```rust +use std::{pin::pin, time::Duration}; + +use trpl::{interval, IntervalStream, ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let messages = pin!(get_messages()); + + let deciseconds = + pin!(IntervalStream::new(interval(Duration::from_millis(1))) + .throttle(Duration::from_millis(100)) + .map(|interval| { + let duration = interval.elapsed(); + format!("milliseconds elapsed: {}", duration.as_millis()) + })); + + let mut merged = messages.merge(deciseconds).take(10); + while let Some(alternative) = merged.next().await { + println!("Got: {alternative:?}"); + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + for message in [String::from("Hello"), String::from("Goodbye")] { + tx.send(message).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + }); + + ReceiverStream::new(rx) +} +``` + +We can also do this using `std::thread`: + +```rust +use std::{pin::pin, thread, time::Duration}; + +use trpl::{interval, IntervalStream, ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let messages = pin!(get_messages()); + + let deciseconds = + pin!(IntervalStream::new(interval(Duration::from_millis(1))) + .throttle(Duration::from_millis(100)) + .map(|interval| { + let duration = interval.elapsed(); + format!("milliseconds elapsed: {}", duration.as_millis()) + })); + + let mut merged = messages.merge(deciseconds).take(10); + while let Some(alternative) = merged.next().await { + println!("Got: {alternative:?}"); + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + // ANCHOR: thread + thread::spawn(move || { + for message in [String::from("Hello"), String::from("Goodbye")] { + tx.send(message).unwrap(); + thread::sleep(Duration::from_millis(500)); + } + }); + // ANCHOR_END: thread + + ReceiverStream::new(rx) +} +``` + +Notice that very little changes here from the perspective of the calling code! +That is as we might expect, given that async tasks are kind of like lightweight, +runtime-managed threads. From e71b6678065602c91a582747f46e9b4784fd65ee Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 20 Jun 2024 13:45:50 -0600 Subject: [PATCH 331/720] =?UTF-8?q?Ch.=2017=20=C2=A705:=20First=20part=20o?= =?UTF-8?q?f=20final=20example,=20with=20`ReceiverStream`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ch17-async-await/listing-17-41/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-41/Cargo.toml | 8 + .../listing-17-41/src/main.rs | 17 + .../ch17-async-await/listing-17-42/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-42/Cargo.toml | 8 + .../listing-17-42/src/main.rs | 24 ++ .../ch17-async-await/listing-17-43/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-43/Cargo.toml | 8 + .../listing-17-43/src/main.rs | 32 ++ .../ch17-async-await/listing-17-44/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-44/Cargo.toml | 8 + .../listing-17-44/src/main.rs | 33 ++ .../ch17-async-await/listing-17-45/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-45/Cargo.toml | 8 + .../listing-17-45/src/main.rs | 35 +++ src/ch17-05-streams.md | 179 ++++++++++- 16 files changed, 1810 insertions(+), 10 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-41/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-41/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-41/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-42/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-42/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-42/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-43/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-43/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-43/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-44/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-44/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-44/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-45/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-45/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-45/src/main.rs diff --git a/listings/ch17-async-await/listing-17-41/Cargo.lock b/listings/ch17-async-await/listing-17-41/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-41/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-41/Cargo.toml b/listings/ch17-async-await/listing-17-41/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-41/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-41/src/main.rs b/listings/ch17-async-await/listing-17-41/src/main.rs new file mode 100644 index 0000000000..4ca575988a --- /dev/null +++ b/listings/ch17-async-await/listing-17-41/src/main.rs @@ -0,0 +1,17 @@ +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let mut messages = get_messages(); + + while let Some(message) = messages.next().await { + println!("{message}"); + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + ReceiverStream::new(rx) +} diff --git a/listings/ch17-async-await/listing-17-42/Cargo.lock b/listings/ch17-async-await/listing-17-42/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-42/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-42/Cargo.toml b/listings/ch17-async-await/listing-17-42/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-42/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-42/src/main.rs b/listings/ch17-async-await/listing-17-42/src/main.rs new file mode 100644 index 0000000000..d503a4c77d --- /dev/null +++ b/listings/ch17-async-await/listing-17-42/src/main.rs @@ -0,0 +1,24 @@ +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let mut messages = get_messages(); + + while let Some(message) = messages.next().await { + println!("{message}"); + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + // ANCHOR: send + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for message in messages { + tx.send(format!("Message: '{message}'")).unwrap(); + } + // ANCHOR_END: send + + ReceiverStream::new(rx) +} diff --git a/listings/ch17-async-await/listing-17-43/Cargo.lock b/listings/ch17-async-await/listing-17-43/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-43/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-43/Cargo.toml b/listings/ch17-async-await/listing-17-43/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-43/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-43/src/main.rs b/listings/ch17-async-await/listing-17-43/src/main.rs new file mode 100644 index 0000000000..2ec150b9ac --- /dev/null +++ b/listings/ch17-async-await/listing-17-43/src/main.rs @@ -0,0 +1,32 @@ +// ANCHOR: timeout +use std::time::Duration; +// --snip-- +// ANCHOR_END: timeout +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + // ANCHOR: timeout + + let mut messages = get_messages().timeout(Duration::from_millis(200)); + + while let Some(result) = messages.next().await { + match result { + Ok(message) => println!("{message}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + // ANCHOR_END: timeout + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for message in messages { + tx.send(format!("Message: '{message}'")).unwrap(); + } + + ReceiverStream::new(rx) +} diff --git a/listings/ch17-async-await/listing-17-44/Cargo.lock b/listings/ch17-async-await/listing-17-44/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-44/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-44/Cargo.toml b/listings/ch17-async-await/listing-17-44/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-44/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-44/src/main.rs b/listings/ch17-async-await/listing-17-44/src/main.rs new file mode 100644 index 0000000000..986d0419e9 --- /dev/null +++ b/listings/ch17-async-await/listing-17-44/src/main.rs @@ -0,0 +1,33 @@ +// ANCHOR: pin +use std::{pin::pin, time::Duration}; +// --snip-- + +// ANCHOR_END: pin +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + // ANCHOR: pin + let mut messages = + pin!(get_messages().timeout(Duration::from_millis(200))); + // ANCHOR_END: pin + + while let Some(result) = messages.next().await { + match result { + Ok(message) => println!("{message}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for message in messages { + tx.send(format!("Message: '{message}'")).unwrap(); + } + + ReceiverStream::new(rx) +} diff --git a/listings/ch17-async-await/listing-17-45/Cargo.lock b/listings/ch17-async-await/listing-17-45/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-45/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-45/Cargo.toml b/listings/ch17-async-await/listing-17-45/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-45/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-45/src/main.rs b/listings/ch17-async-await/listing-17-45/src/main.rs new file mode 100644 index 0000000000..f044684113 --- /dev/null +++ b/listings/ch17-async-await/listing-17-45/src/main.rs @@ -0,0 +1,35 @@ +use std::{pin::pin, time::Duration}; + +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let mut messages = + pin!(get_messages().timeout(Duration::from_millis(200))); + + while let Some(result) = messages.next().await { + match result { + Ok(message) => println!("{message}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + // ANCHOR: messages + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + tx.send(format!("Message: '{message}'")).unwrap(); + } + }); + // ANCHOR_END: messages + + ReceiverStream::new(rx) +} diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index ace132f8f5..7b1527a5e0 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -183,7 +183,7 @@ need to do, then, is add a `use` statement for `trpl::StreamExt`, as in Listing iterator. We can filter that down, to, say, multiples of three and five by using the `filter` method, which conveniently also comes from `StreamExt`. - + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:filter}} @@ -192,10 +192,12 @@ need to do, then, is add a `use` statement for `trpl::StreamExt`, as in Listing Of course, in the real world, the only time we would be directly converting an -iterator to a stream like this is to help break up longer chunks of work, like +iterator to a stream like this is to help break up longer chunks of work, like we discussed in the previous section. There are more interesting things we can do with streams, though! +### Composing Streams + For one thing, lots of things are naturally represented as streams—items becoming available in a queue over time, for example, or working with more data than can fit in a computer’s memory by only pulling chunks of it from the file @@ -203,14 +205,171 @@ system at a time, or data arriving over the network over time. For another thing, since streams are futures, we can use them with any other kind of future, and we can combine them in interesting ways. -This is the kind of thing we might actually do to help break up longer chunks of -work, like we discussed in the previous section—though of course, presumably -with more interesting iterators than this one! +In the real world, we can use this to do things like debounce events to avoid +triggering too many network calls, set timeouts on sequences of long-running +operations, or throttle user interface events to avoid doing needless work. +Let’s start by building a little stream of messages. This is similar to what we +might see from a WebSocket or some other real-time communication protocol. To +begin, we will create a function, `get_messages()`, which returns `impl +Stream`, and use a `while let` loop to print all the messages +from the stream. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-41/src/main.rs}} +``` + + + +In Listing 17-41, we also use a new type: `ReceiverStream`. This converts the +`rx` receiver from the `trpl::channel` into a stream. This is pretty easy, since +the API for a receiver like this already has the same basic shape as a `Stream`. + +So far this will compile just fine, but we are not sending any messages, so +nothing will happen when we run the program. We can change that by looping over +the first ten letters of the English alphabet, and sending those across the +channel. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-42/src/main.rs:send}} +``` + + + +When we run the code in Listing 17-42, we get exactly the results we would +expect: + + + +```text +Message: 'a' +Message: 'b' +Message: 'c' +Message: 'd' +Message: 'e' +Message: 'f' +Message: 'g' +Message: 'h' +Message: 'i' +Message: 'j' +``` + +Thus far, we have not seen anything we could not do with the regular `recv` API. +Since this is a stream, though, we can do things like add a timeout which +applies to every item in the stream, as in Listing 17-43. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-43/src/main.rs:timeout}} +``` + + + +First, we add a timeout to the stream itself, using the the `timeout` method, +which is available on the stream because we already have `StreamExt` in scope. +Second, we update the the `while let` loop because the stream now returns a +`Result`, where the `Ok` variant indicates a message arrived in time and the +`Err` variant indicates that the timeout elapsed before any message arrived. We +can use a `match` to either print the message when we receive it successfully, +or to notify about a problem if the timeout happened. + +Unfortunately, this does not compile. It is our old friend `Unpin` again! Both +the `next()` method and the `await` tell us that that type `PhantomPin` cannot +be unpinned. (This `PhantomPin` is just a special type that the runtime is using +to keep track of what needs to be pinned in a way that *only* shows up at +compile time, but has no cost when actually running the program.) The solution +is exactly the same as what we saw earlier in the chapter: to pin the `messages` +with the `pin` macro. Once we add that, as in Listing 17-44, the program +compiles again. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-44/src/main.rs:pin}} +``` + + + +However, since there are no delays between messages, this timeout does not +change the behavior of the program yet. To see the timeout actually have an +effect, we will add a delay to the messages we send. We will use the `enumerate` +iterator method to get the index of the items we are sending, and apply a 100 +millisecond delay to even-index items and a 300 millisecond delay to odd-index +items, to simulate the different delays we might see from a stream of messages +in the real world. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-45/src/main.rs:messages}} +``` + + + +To do that without blocking the `get_messages` function, we need to use async. +However, we cannot just turn `get_messages` itself into an async function, +because then we would return a `Future>` instead +of just a `Stream>`. In practical terms, we would end up sending +all the messages and sleeping repeatedly before finally returning the receiver +stream. The caller would end up getting all the messages immediately, *without* +the sleep in between them, because the caller would not even be able to *start* +processing the stream until all of the await points in `get_messages` had been +hit. + +Instead, we leave `get_messages` as a regular function which returns a stream, +and spawn a task to handle the async `sleep` calls. + +> Note: calling `spawn_task` like this works because we already set up our +> runtime. Calling this particular implementation of `spawn_task` *without* +> first setting up a runtime will cause a panic. Other implementations choose +> different tradeoffs: they might spawn a new runtime and so avoid the panic but +> end up with a bit of extra overhead, or simply not provide a standalone way to +> spawn tasks without reference to a runtime. You should make sure you know what +> tradeoff your runtime has chosen and write your code accordingly! + +Now our code has a much more interesting result! Between the messages, we see an +error reported: `Problem: Elapsed(())`. Notice that it does not prevent the +messages from arriving in the end—we still get all of the original messages. +This is because our channel is unbounded: it can hold as many messages as we can +fit in memory. If the message does not arrive before the timeout, our stream +handler will account for that, but when it polls the stream again, the message +may now have arrived. + + + +```text +Message: 'a' +Problem: Elapsed(()) +Message: 'b' +Message: 'c' +Problem: Elapsed(()) +Message: 'd' +Message: 'e' +Problem: Elapsed(()) +Message: 'f' +Message: 'g' +Problem: Elapsed(()) +Message: 'h' +Message: 'i' +Problem: Elapsed(()) +Message: 'j' +``` + +You can get different behavior if needed by using other kinds of channels, or +other kinds of streams more generally. Let’s see one of those in practice in our +final example for this section, by combining a stream of time intervals with +this stream of messages. + +### Merging Streams + - [17-02-messages]: /ch17-02-concurrency-with-async.md#message-passing From 3c6c32cbe30ced543e08012dcf5aacfe2993018b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 25 Jun 2024 10:58:54 -0600 Subject: [PATCH 332/720] =?UTF-8?q?Ch.=2017=20=C2=A705:=20complete=20examp?= =?UTF-8?q?le=20with=20`throttle`=20and=20`take`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../listing-17-46/src/main.rs | 50 +++ .../ch17-async-await/listing-17-47/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-47/Cargo.toml | 8 + .../listing-17-47/src/main.rs | 52 ++++ .../ch17-async-await/listing-17-48/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-48/Cargo.toml | 8 + .../listing-17-48/src/main.rs | 54 ++++ .../ch17-async-await/listing-17-49/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-49/Cargo.toml | 8 + .../listing-17-49/src/main.rs | 55 ++++ .../ch17-async-await/listing-17-50/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-50/Cargo.toml | 8 + .../src/main.rs | 0 src/ch17-05-streams.md | 139 +++++++++ 16 files changed, 1550 insertions(+) rename listings/ch17-async-await/{listing-17-s05-final => listing-17-46}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-s05-final => listing-17-46}/Cargo.toml (100%) create mode 100644 listings/ch17-async-await/listing-17-46/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-47/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-47/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-47/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-48/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-48/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-48/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-49/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-49/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-49/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-50/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-50/Cargo.toml rename listings/ch17-async-await/{listing-17-s05-final => listing-17-50}/src/main.rs (100%) diff --git a/listings/ch17-async-await/listing-17-s05-final/Cargo.lock b/listings/ch17-async-await/listing-17-46/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-s05-final/Cargo.lock rename to listings/ch17-async-await/listing-17-46/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-s05-final/Cargo.toml b/listings/ch17-async-await/listing-17-46/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-s05-final/Cargo.toml rename to listings/ch17-async-await/listing-17-46/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-46/src/main.rs b/listings/ch17-async-await/listing-17-46/src/main.rs new file mode 100644 index 0000000000..5dbcb1d96e --- /dev/null +++ b/listings/ch17-async-await/listing-17-46/src/main.rs @@ -0,0 +1,50 @@ +use std::{pin::pin, time::Duration}; + +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let mut messages = + pin!(get_messages().timeout(Duration::from_millis(200))); + + while let Some(result) = messages.next().await { + match result { + Ok(message) => println!("{message}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + tx.send(format!("Message: '{message}'")).unwrap(); + } + }); + + ReceiverStream::new(rx) +} + +// ANCHOR: intervals +fn get_intervals() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let mut count = 0; + loop { + trpl::sleep(Duration::from_millis(1)).await; + count += 1; + tx.send(count).unwrap(); + } + }); + + ReceiverStream::new(rx) +} +// ANCHOR_END: intervals diff --git a/listings/ch17-async-await/listing-17-47/Cargo.lock b/listings/ch17-async-await/listing-17-47/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-47/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-47/Cargo.toml b/listings/ch17-async-await/listing-17-47/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-47/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-47/src/main.rs b/listings/ch17-async-await/listing-17-47/src/main.rs new file mode 100644 index 0000000000..62a93fc0f6 --- /dev/null +++ b/listings/ch17-async-await/listing-17-47/src/main.rs @@ -0,0 +1,52 @@ +use std::{pin::pin, time::Duration}; + +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + // ANCHOR: main + let messages = get_messages().timeout(Duration::from_millis(200)); + let intervals = get_intervals(); + + let merged = messages.merge(intervals); + // ANCHOR_END: main + + while let Some(result) = merged.next().await { + match result { + Ok(message) => println!("{message}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + tx.send(format!("Message: '{message}'")).unwrap(); + } + }); + + ReceiverStream::new(rx) +} + +fn get_intervals() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let mut count = 0; + loop { + trpl::sleep(Duration::from_millis(1)).await; + count += 1; + tx.send(count).unwrap(); + } + }); + + ReceiverStream::new(rx) +} diff --git a/listings/ch17-async-await/listing-17-48/Cargo.lock b/listings/ch17-async-await/listing-17-48/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-48/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-48/Cargo.toml b/listings/ch17-async-await/listing-17-48/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-48/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-48/src/main.rs b/listings/ch17-async-await/listing-17-48/src/main.rs new file mode 100644 index 0000000000..30d0928ea9 --- /dev/null +++ b/listings/ch17-async-await/listing-17-48/src/main.rs @@ -0,0 +1,54 @@ +use std::{pin::pin, time::Duration}; + +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + // ANCHOR: main + let messages = get_messages().timeout(Duration::from_millis(200)); + let intervals = get_intervals() + .map(|count| format!("Interval #{count}")) + .timeout(Duration::from_secs(10)); + + let mut merged = pin!(messages.merge(intervals)); + // ANCHOR_END: main + + while let Some(result) = merged.next().await { + match result { + Ok(message) => println!("{message}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + tx.send(format!("Message: '{message}'")).unwrap(); + } + }); + + ReceiverStream::new(rx) +} + +fn get_intervals() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let mut count = 0; + loop { + trpl::sleep(Duration::from_millis(1)).await; + count += 1; + tx.send(count).unwrap(); + } + }); + + ReceiverStream::new(rx) +} diff --git a/listings/ch17-async-await/listing-17-49/Cargo.lock b/listings/ch17-async-await/listing-17-49/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-49/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-49/Cargo.toml b/listings/ch17-async-await/listing-17-49/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-49/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-49/src/main.rs b/listings/ch17-async-await/listing-17-49/src/main.rs new file mode 100644 index 0000000000..48e4ceea43 --- /dev/null +++ b/listings/ch17-async-await/listing-17-49/src/main.rs @@ -0,0 +1,55 @@ +use std::{pin::pin, time::Duration}; + +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let messages = get_messages().timeout(Duration::from_millis(200)); + // ANCHOR: throttle + let intervals = get_intervals() + .map(|count| format!("Interval #{count}")) + .throttle(Duration::from_millis(100)) + .timeout(Duration::from_secs(10)); + + let mut merged = pin!(messages.merge(intervals).take(20)); + // ANCHOR_END: throttle + + while let Some(result) = merged.next().await { + match result { + Ok(message) => println!("{message}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + tx.send(format!("Message: '{message}'")).unwrap(); + } + }); + + ReceiverStream::new(rx) +} + +fn get_intervals() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let mut count = 0; + loop { + trpl::sleep(Duration::from_millis(1)).await; + count += 1; + tx.send(count).unwrap(); + } + }); + + ReceiverStream::new(rx) +} diff --git a/listings/ch17-async-await/listing-17-50/Cargo.lock b/listings/ch17-async-await/listing-17-50/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-50/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-50/Cargo.toml b/listings/ch17-async-await/listing-17-50/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-50/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-s05-final/src/main.rs b/listings/ch17-async-await/listing-17-50/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-s05-final/src/main.rs rename to listings/ch17-async-await/listing-17-50/src/main.rs diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index 7b1527a5e0..d52334ce02 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -370,6 +370,145 @@ this stream of messages. ### Merging Streams +First, let’s create another stream, called `get_intervals`, which will emit an +item every millisecond if we let it run directly. For simplicity, we can use the +`sleep` function to send a message on that delay, and combine it with the same +approach of creating a stream from a channel that we used for `get_messages`. +(There are, of course, many other ways to build streams, including some +dedicated to working with intervals!) The difference is that this time, we are +going to send back the count of intervals, rather than a string, so the +resulting stream will have the type `Stream`. + +In Listing 17-46, we start by defining a `count` in the task. (We could define +it outside the task, too, but it is clearer to limit the scope of any given +variable.) Then we create a an infinite loop. Each iteration of the loop +asynchronously sleeps for one millisecond, increments the count, and then sends +it over the channel. Since this is all wrapped in the task created by +`spawn_task`, all of it will get cleaned up along with the runtime, including +the infinite loop. + + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-46/src/main.rs:intervals}} +``` + + + +This kind of infinite loop, which only ends when the whole runtime gets torn +down, is a fairly common pattern when dealing with many different kinds of async +operations in Rust. That is because there are many kinds of programs which need +to keep running until something actually ends the program. + +Now we need to use these intervals! Back in our main function’s async block, we +start by getting the intervals. Then we can try to create a merged stream using +`messages` and `intervals`, and loop over that combined stream instead of over +`messages` (Listing 17-47). At this point, neither `messages` nor `intervals` +needs to be pinned or mutable, because both will be combined into the single +`merged` stream. However, this call to `merge` does not type check! (Neither +does the `next` call in the `while let` loop, but we will come back to that +after fixing this first.) + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-47/src/main.rs:main}} +``` + + + +The problem is that our two streams have different types. The `messages` stream +has the type `Timeout>`. The `Timeout` is the type +which implements `Stream` for a `timeout` call! Meanwhile, the `intervals` stream has +the type `impl Stream`. To merge these two streams, we need to transform one of +them to match the other. Let’s work with the `intervals`, since `messages` is +already in the basic format we want and has to handle timeout errors. + +Listing 17-48 shows the transformations we need. First, we can use the `map` +helper method to transform the `intervals` into a string. Second, we need to +match the `Timeout` from `messages`. Since we do not actually *want* a timeout +for `intervals`, though, we can just create a timeout which is longer than the +other durations we are using. Here, we create a 10-second time out with +`Duration::from_secs(10)`. Finally, we need to make `merged` both mutable, so +that the `while let` loop’s `next` calls can iterate through the stream, and +pinned, so that it is safe to do so. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-48/src/main.rs:main}} +``` + + + +That gets us *almost* to where we need to be. Everything type checks! If you run +this, though, the messages from the English alphabet will be buried in the midst +of all the interval counter messages: + + + +```text +--snip-- +Interval #38 +Interval #39 +Interval #40 +Message: 'a' +Interval #41 +Interval #42 +Interval #43 +--snip-- +``` + +This is no good; we need to only take *some* of those intervals—say, once every +hundred milliseconds. For that, we can use the `throttle` method. Throttling is +a way of limiting the rate at which a function will be called—or, in this case, +how often the stream will be polled. We also don’t want to keep going +indefinitely! We can use the `take` method to limit how many items we pull from +a stream. In Listing 17-49, we apply `throttle` to the `intervals` stream, +because we want to avoid overwhelming the stream of messages, but we apply the +`take` method to the *merged* messages, because we want to limit the final +output, not just one stream or the other. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-49/src/main.rs:throttle}} +``` + + + +There is one last thing we need to handle: errors! With both of these +channel-based streams, the `send` calls could fail when the other side of the +channel closes—and that is just a matter of how the runtime executes the futures +which make up the stream. Up till now we have ignored this by calling `unwrap`, +but in a well-behaved app, we should explicitly handle the error, at minimum by +ending the loop so we do not try to send any more messages! Listing 17-50 shows +a simple error strategy: print the issue and then `break` from the loops. As +usual, the correct behavior on a message send error will vary—just make sure you +do in fact have a strategy. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-50/src/main.rs:errors}} +``` + + + +Notice that we do not get `Interval #100` or `Interval #200` or so on, but +instead simply get `Interval #1`, `Interval #2`, and so on—even though we have a +source stream which *can* produce an event every millisecond. That is because +the `throttle` call produces a new stream, wrapping the original stream, so that +the original stream only gets polled at the throttle rate, not its own “native” +rate. We do not have a bunch of unhandled interval messages we are simply +choosing to ignore. Instead, we never produce those interval messages in the +first place! This is the inherent “laziness” of Rust’s futures at work again, +allowing us to choose our performance characteristics. + +That is a good note to turn to our final section and wrap up this walk through +async in Rust, by discussing how futures (including streams), tasks, and threads +relate to each other, and how you can use them together. [17-02-messages]: /ch17-02-concurrency-with-async.md#message-passing From bea85577081fefda53271593a793e59cd224f96a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 25 Jun 2024 15:10:22 -0600 Subject: [PATCH 333/720] =?UTF-8?q?Ch.=2017=20=C2=A706:=20Start=20discussi?= =?UTF-8?q?ng=20future/task/thread=20tradeoffs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Reintroduce accidentally-dropped content. I meant to simply carry this over in 74df84ea, but failed to, perhaps because I had `mdbook serve` running and it tries to be helpful about generating files which are referenced in `SUMMARY.md` but do not exist on disk. Either way, this is back now and we can use it to explain these concepts. - Start on an example showing how `thread::spawn` and `spawn_task` are basically interchangeable from an API POV, so that we can then see how they differ in terms of runtime consequences. --- .../ch17-async-await/listing-17-51/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-51/Cargo.toml | 8 + .../listing-17-51/src/main.rs | 64 ++++ src/ch17-06-futures-tasks-threads.md | 155 +++++----- 4 files changed, 441 insertions(+), 78 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-51/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-51/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-51/src/main.rs diff --git a/listings/ch17-async-await/listing-17-51/Cargo.lock b/listings/ch17-async-await/listing-17-51/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-51/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-51/Cargo.toml b/listings/ch17-async-await/listing-17-51/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-51/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-51/src/main.rs b/listings/ch17-async-await/listing-17-51/src/main.rs new file mode 100644 index 0000000000..7298362527 --- /dev/null +++ b/listings/ch17-async-await/listing-17-51/src/main.rs @@ -0,0 +1,64 @@ +use std::{pin::pin, thread, time::Duration}; + +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::block_on(async { + let messages = get_messages().timeout(Duration::from_millis(200)); + let intervals = get_intervals() + .map(|count| format!("Interval #{count}")) + .throttle(Duration::from_millis(500)) + .timeout(Duration::from_secs(10)); + + let mut merged = pin!(messages.merge(intervals).take(20)); + + while let Some(result) = merged.next().await { + match result { + Ok(item) => println!("{item}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} + +// ANCHOR: thread +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + thread::spawn(move || { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + thread::sleep(Duration::from_millis(time_to_sleep)); + + if let Err(send_error) = + tx.send(format!("Message: '{message}' after {time_to_sleep}ms")) + { + eprintln!("Cannot send message '{message}': {send_error}"); + break; + } + } + }); + + ReceiverStream::new(rx) +} + +fn get_intervals() -> impl Stream { + let (tx, rx) = trpl::channel(); + + thread::spawn(move || { + let mut count = 0; + loop { + thread::sleep(Duration::from_millis(1)); + count += 1; + if let Err(send_error) = tx.send(count) { + eprintln!("Could not send interval {count}: {send_error}"); + break; + }; + } + }); + + ReceiverStream::new(rx) +} +// ANCHOR_END: thread diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 70baf0ce67..dbfbc2a461 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -1,87 +1,86 @@ # Futures, Tasks, and Threads -Working code from end of previous section: +As we saw in the previous chapter, threads provide one approach to concurrency, +and they let us solve some of these issues. However, they also have some +tradeoffs. On many operating systems, they use a fair bit of memory for each +thread, and they come with some overhead for starting up and shutting down. +Threads are also only an option when your operating system and hardware support +them! While mainstream desktop and mobile operating systems have all had +threading for many years, many embedded operating systems, like those used on +some microcontrollers, do not. + +The async model provides a different—and ultimately complementary—set of +tradeoffs. In the async model, concurrent operations do not require their own +threads. Instead, they can run on *tasks*. A task is a bit like a thread, but +instead of being managed by the operating system, it is managed by code that +lives at the level of libraries. + +In the previous section, we saw that we could build a `Stream` by using a +channel and spawning an async task which we could call from synchronous code. +We could do the exact same thing with a thread! We’ll use a simpler version of +the streams example so we can focus on the differences. Back in Listing 17-45, we used +`trpl::spawn_task` and `trpl::sleep`. In Listing 17-51, we replace those with +the `thread::spawn` and `thread::sleep` APIs from the standard library. + + + + ```rust -use std::{pin::pin, time::Duration}; - -use trpl::{interval, IntervalStream, ReceiverStream, Stream, StreamExt}; - -fn main() { - trpl::block_on(async { - let messages = pin!(get_messages()); - - let deciseconds = - pin!(IntervalStream::new(interval(Duration::from_millis(1))) - .throttle(Duration::from_millis(100)) - .map(|interval| { - let duration = interval.elapsed(); - format!("milliseconds elapsed: {}", duration.as_millis()) - })); - - let mut merged = messages.merge(deciseconds).take(10); - while let Some(alternative) = merged.next().await { - println!("Got: {alternative:?}"); - } - }) -} - -fn get_messages() -> impl Stream { - let (tx, rx) = trpl::channel(); - - trpl::spawn_task(async move { - for message in [String::from("Hello"), String::from("Goodbye")] { - tx.send(message).unwrap(); - trpl::sleep(Duration::from_millis(500)).await; - } - }); - - ReceiverStream::new(rx) -} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-51/src/main.rs:thread}} ``` -We can also do this using `std::thread`: - -```rust -use std::{pin::pin, thread, time::Duration}; - -use trpl::{interval, IntervalStream, ReceiverStream, Stream, StreamExt}; - -fn main() { - trpl::block_on(async { - let messages = pin!(get_messages()); - - let deciseconds = - pin!(IntervalStream::new(interval(Duration::from_millis(1))) - .throttle(Duration::from_millis(100)) - .map(|interval| { - let duration = interval.elapsed(); - format!("milliseconds elapsed: {}", duration.as_millis()) - })); - - let mut merged = messages.merge(deciseconds).take(10); - while let Some(alternative) = merged.next().await { - println!("Got: {alternative:?}"); - } - }) -} - -fn get_messages() -> impl Stream { - let (tx, rx) = trpl::channel(); - - // ANCHOR: thread - thread::spawn(move || { - for message in [String::from("Hello"), String::from("Goodbye")] { - tx.send(message).unwrap(); - thread::sleep(Duration::from_millis(500)); - } - }); - // ANCHOR_END: thread - - ReceiverStream::new(rx) -} -``` + Notice that very little changes here from the perspective of the calling code! That is as we might expect, given that async tasks are kind of like lightweight, -runtime-managed threads. +runtime-managed threads. However, there is a meaningful difference in the way +this system behaves, though we might have a hard time measuring it in this very +simple example. A run + +### Parallelism and Concurrency + + + +First, though, we need to dig a little deeper into the differences between +parallelism and concurrency. In the previous chapter we treated them as mostly +interchangeable. Now we need to distinguish between the two a little more, +because the differences will show up as we start working: + +* *Parallelism* is when operations can happen simultaneously. + +* *Concurrency* is when operations can make progress without having to wait for + all other operations to complete. + +One common analogy for thinking about the difference between concurrency and +parallelism is cooking in a kitchen. Parallelism is like having two cooks: one +working on cooking eggs, and the other working on preparing fruit bowls. Those +can happen at the same time, without either affecting the other. Concurrency is +like having a single cook who can start cooking some eggs, start dicing up some +vegetables to use in the omelette, adding seasoning and whatever vegetables are +ready to the eggs at certain points, and switching back and forth between those +tasks. + +(This analogy breaks down if you think about it too hard. The eggs keep cooking +while the cook is chopping up the vegetables, after all. That is parallelism, +not just concurrency! The focus of the analogy is the *cook*, not the food, +though, and as long as you keep that in mind, it mostly works.) + +On a machine with multiple CPU cores, we can actually do work in parallel. One +core can be doing one thing while another core does something completely +unrelated, and those actually happen at the same time. On a machine with a +single CPU core, the CPU can only do one operation at a time, but we can still +have concurrency. Using tools like threads, processes, and async, the computer +can pause one activity and switch to others before eventually cycling back to +that first activity again. So all parallel operations are also concurrent, but +not all concurrent operations happen in parallel! + +When working with async in Rust, we are always dealing with concurrency. +Depending on the hardware, the operating system, and the async runtime we are +using, that concurrency may use some degree of parallelism under the hood, or it +may not. (More about async runtimes later!) + +A big difference between the cooking analogy and Rust’s async model for +concurrency is that in the cooking example, the cook makes the decision about +when to switch tasks. In Rust’s async model, the tasks are in control of that. +To see how, let’s look at how Rust actually uses async. From bdd8f3e62fa767a7324d53e783be9097f84642fe Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 26 Jun 2024 11:54:31 -0600 Subject: [PATCH 334/720] =?UTF-8?q?Ch.=2017=20=C2=A706:=20more=20on=20task?= =?UTF-8?q?s=20and=20threads,=20better=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-51/src/main.rs | 14 ++-- src/ch17-06-futures-tasks-threads.md | 70 +++++++++++++------ 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/listings/ch17-async-await/listing-17-51/src/main.rs b/listings/ch17-async-await/listing-17-51/src/main.rs index 7298362527..4b44ab723e 100644 --- a/listings/ch17-async-await/listing-17-51/src/main.rs +++ b/listings/ch17-async-await/listing-17-51/src/main.rs @@ -1,4 +1,4 @@ -use std::{pin::pin, thread, time::Duration}; +use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; @@ -21,16 +21,15 @@ fn main() { }) } -// ANCHOR: thread fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); - thread::spawn(move || { + trpl::spawn_task(async move { let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; for (index, message) in messages.into_iter().enumerate() { let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; - thread::sleep(Duration::from_millis(time_to_sleep)); + trpl::sleep(Duration::from_millis(time_to_sleep)).await; if let Err(send_error) = tx.send(format!("Message: '{message}' after {time_to_sleep}ms")) @@ -44,13 +43,14 @@ fn get_messages() -> impl Stream { ReceiverStream::new(rx) } +// ANCHOR: threads fn get_intervals() -> impl Stream { let (tx, rx) = trpl::channel(); - thread::spawn(move || { + trpl::spawn_task(async move { let mut count = 0; loop { - thread::sleep(Duration::from_millis(1)); + trpl::sleep(Duration::from_millis(1)).await; count += 1; if let Err(send_error) = tx.send(count) { eprintln!("Could not send interval {count}: {send_error}"); @@ -61,4 +61,4 @@ fn get_intervals() -> impl Stream { ReceiverStream::new(rx) } -// ANCHOR_END: thread +// ANCHOR_END: threads diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index dbfbc2a461..dd8eab2173 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -1,42 +1,66 @@ # Futures, Tasks, and Threads -As we saw in the previous chapter, threads provide one approach to concurrency, -and they let us solve some of these issues. However, they also have some -tradeoffs. On many operating systems, they use a fair bit of memory for each -thread, and they come with some overhead for starting up and shutting down. -Threads are also only an option when your operating system and hardware support -them! While mainstream desktop and mobile operating systems have all had -threading for many years, many embedded operating systems, like those used on -some microcontrollers, do not. +As we saw in the previous chapter, threads provide one approach to concurrency. +We have seen another approach to concurrency in this chapter, using async with +futures and streams. You might be wondering why you would choose one or the +other. The answer is: it depends! And in many cases, it is not threads *vs.* +async but rather threads *and* async. + +Threads are an older and more common tool for concurrency. Many operating +systems have supplied threading-based concurrency models for decades now, and +many programming languages have support for them as a result. However, they are +not without their tradeoffs. On many operating systems, they use a fair bit of +memory for each thread, and they come with some overhead for starting up and +shutting down. Threads are also only an option when your operating system and +hardware support them! Unlike mainstream desktop and mobile operating systems, +many embedded operating systems, like those used on some microcontrollers, do +not have OS-level threads at all. The async model provides a different—and ultimately complementary—set of tradeoffs. In the async model, concurrent operations do not require their own -threads. Instead, they can run on *tasks*. A task is a bit like a thread, but -instead of being managed by the operating system, it is managed by code that -lives at the level of libraries. +threads. Instead, they can run on tasks, as when we used `trpl::spawn_task` to +kick off work from a synchronous function throughout the streams section. A task +is a lot like a thread—but instead of being managed by the operating system, it +is managed by library-level code: the runtime. In the previous section, we saw that we could build a `Stream` by using a -channel and spawning an async task which we could call from synchronous code. -We could do the exact same thing with a thread! We’ll use a simpler version of -the streams example so we can focus on the differences. Back in Listing 17-45, we used +channel and spawning an async task which we could call from synchronous code. We +could do the exact same thing with a thread! We’ll use a simpler version of the +streams example so we can focus on the differences. In Listing 17-50, we used `trpl::spawn_task` and `trpl::sleep`. In Listing 17-51, we replace those with -the `thread::spawn` and `thread::sleep` APIs from the standard library. - - +the `thread::spawn` and `thread::sleep` APIs from the standard library, in just +the `get_intervals` function. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-51/src/main.rs:thread}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-51/src/main.rs:threads}} ``` -Notice that very little changes here from the perspective of the calling code! -That is as we might expect, given that async tasks are kind of like lightweight, -runtime-managed threads. However, there is a meaningful difference in the way -this system behaves, though we might have a hard time measuring it in this very -simple example. A run +If you run this, the output is identical. And notice how little changes here +from the perspective of the calling code! What is more, even though one of our +functions spawned an async task on the runtime and the other spawned an +operating system thread, they worked exactly the same way as far as processing +the stream was concerned. + +This highlights that async tasks are kind of like lightweight, runtime-managed +threads. However, there is a meaningful difference in the way this system +behaves, although we might have a hard time measuring it in this very simple +example. We could spawn hundreds of thousands or even millions of async tasks on +any modern personal computer. If we tried to do that with threads, we would +literally run out of memory! + +However, this does not mean that async tasks are always better than threads. In +fact, they often work very well *together*. We have not mentioned it up until +now, but under the hood the `Runtime` we have been using, including the +`spawn_blocking` and `spawn_task` functions, are multithreaded by default! Many +runtimes can transparently move tasks around between threads based on the +current utilization of the threads, to hopefully improve the overall performance +of the system. + + ### Parallelism and Concurrency From ffb2d1ba29bf66ffc9820e10d63aef16b25bb508 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 26 Jun 2024 12:22:48 -0600 Subject: [PATCH 335/720] =?UTF-8?q?Ch.=2017:=20Most=20of=20=C2=A706=20draf?= =?UTF-8?q?ted,=20needs=20a=20conclusion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added a discussion of the relationship between futures, tasks, and threads—I am not in love with it, but it is a starting point. - Moved the still-to-be-rewritten 'Parallelism and Concurrency' back to §01, where it can be rewritten after getting some feedback. --- src/ch17-00-async-await.md | 45 ++++++++++++ src/ch17-06-futures-tasks-threads.md | 100 +++++++++++---------------- 2 files changed, 87 insertions(+), 58 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 92928f87a4..c974eb32f9 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -153,3 +153,48 @@ println!("{data}"); That is exactly what Rust’s async abstraction gives us. It is designed to help us solve all of these issues. In the next section, we will see how this works in practice. + +### Parallelism and Concurrency + +First, though, we need to dig a little deeper into the differences between +parallelism and concurrency. In the previous chapter we treated them as mostly +interchangeable. Now we need to distinguish between the two a little more, +because the differences will show up as we start working: + +* *Parallelism* is when operations can happen simultaneously. + +* *Concurrency* is when operations can make progress without having to wait for + all other operations to complete. + +One common analogy for thinking about the difference between concurrency and +parallelism is cooking in a kitchen. Parallelism is like having two cooks: one +working on cooking eggs, and the other working on preparing fruit bowls. Those +can happen at the same time, without either affecting the other. Concurrency is +like having a single cook who can start cooking some eggs, start dicing up some +vegetables to use in the omelette, adding seasoning and whatever vegetables are +ready to the eggs at certain points, and switching back and forth between those +tasks. + +(This analogy breaks down if you think about it too hard. The eggs keep cooking +while the cook is chopping up the vegetables, after all. That is parallelism, +not just concurrency! The focus of the analogy is the *cook*, not the food, +though, and as long as you keep that in mind, it mostly works.) + +On a machine with multiple CPU cores, we can actually do work in parallel. One +core can be doing one thing while another core does something completely +unrelated, and those actually happen at the same time. On a machine with a +single CPU core, the CPU can only do one operation at a time, but we can still +have concurrency. Using tools like threads, processes, and async, the computer +can pause one activity and switch to others before eventually cycling back to +that first activity again. So all parallel operations are also concurrent, but +not all concurrent operations happen in parallel! + +When working with async in Rust, we are always dealing with concurrency. +Depending on the hardware, the operating system, and the async runtime we are +using, that concurrency may use some degree of parallelism under the hood, or it +may not. (More about async runtimes later!) + +A big difference between the cooking analogy and Rust’s async model for +concurrency is that in the cooking example, the cook makes the decision about +when to switch tasks. In Rust’s async model, the tasks are in control of that. +To see how, let’s look at how async programming in Rust actually works. diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index dd8eab2173..74a032df99 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -45,66 +45,50 @@ functions spawned an async task on the runtime and the other spawned an operating system thread, they worked exactly the same way as far as processing the stream was concerned. -This highlights that async tasks are kind of like lightweight, runtime-managed -threads. However, there is a meaningful difference in the way this system +However, there is a meaningful difference in the way this system behaves, although we might have a hard time measuring it in this very simple example. We could spawn hundreds of thousands or even millions of async tasks on any modern personal computer. If we tried to do that with threads, we would literally run out of memory! -However, this does not mean that async tasks are always better than threads. In -fact, they often work very well *together*. We have not mentioned it up until -now, but under the hood the `Runtime` we have been using, including the -`spawn_blocking` and `spawn_task` functions, are multithreaded by default! Many -runtimes can transparently move tasks around between threads based on the -current utilization of the threads, to hopefully improve the overall performance -of the system. - - - -### Parallelism and Concurrency - - - -First, though, we need to dig a little deeper into the differences between -parallelism and concurrency. In the previous chapter we treated them as mostly -interchangeable. Now we need to distinguish between the two a little more, -because the differences will show up as we start working: - -* *Parallelism* is when operations can happen simultaneously. - -* *Concurrency* is when operations can make progress without having to wait for - all other operations to complete. - -One common analogy for thinking about the difference between concurrency and -parallelism is cooking in a kitchen. Parallelism is like having two cooks: one -working on cooking eggs, and the other working on preparing fruit bowls. Those -can happen at the same time, without either affecting the other. Concurrency is -like having a single cook who can start cooking some eggs, start dicing up some -vegetables to use in the omelette, adding seasoning and whatever vegetables are -ready to the eggs at certain points, and switching back and forth between those -tasks. - -(This analogy breaks down if you think about it too hard. The eggs keep cooking -while the cook is chopping up the vegetables, after all. That is parallelism, -not just concurrency! The focus of the analogy is the *cook*, not the food, -though, and as long as you keep that in mind, it mostly works.) - -On a machine with multiple CPU cores, we can actually do work in parallel. One -core can be doing one thing while another core does something completely -unrelated, and those actually happen at the same time. On a machine with a -single CPU core, the CPU can only do one operation at a time, but we can still -have concurrency. Using tools like threads, processes, and async, the computer -can pause one activity and switch to others before eventually cycling back to -that first activity again. So all parallel operations are also concurrent, but -not all concurrent operations happen in parallel! - -When working with async in Rust, we are always dealing with concurrency. -Depending on the hardware, the operating system, and the async runtime we are -using, that concurrency may use some degree of parallelism under the hood, or it -may not. (More about async runtimes later!) - -A big difference between the cooking analogy and Rust’s async model for -concurrency is that in the cooking example, the cook makes the decision about -when to switch tasks. In Rust’s async model, the tasks are in control of that. -To see how, let’s look at how Rust actually uses async. +However, there is a reason these APIs are so similar. Threads act as a boundary +for sets of synchronous operations; concurrency is possible *between* threads. +Tasks act as a boundary for sets of *asynchronous* operations; concurrency is +possible both *between* and *within* tasks. In that regard, tasks are kind of +like lightweight, runtime-managed threads with added capabilities that come from +being managed by a runtime instead of by the operating system. + +However, this does not mean that async tasks are always better than threads, any +more than that threads are always better than tasks. + +On the one hand, concurrency with threads is in some ways a simpler programming +model than concurrency with `async`. Threads are somewhat “fire and forget”, and +they only allow interaction with the rest of the program via tools like channels +or their final result via `join`. On the other hand, they have no native +equivalent to a future, so they simply run to completion, without interruption +except by the operating system itself. Threads also have no mechanisms for +cancellation—a subject we have not covered in depth in this chapter, but which +is implicit in the fact that whenever we ended a future, its state got cleaned +up correctly. + +These limitations make threads harder to compose than futures. It +is much more difficult, for example, to build something like the `timeout` we +built in [“Building Our Own Async Abstractions”][combining-futures], or the +`throttle` method we used with streams in [“Working With Streams”][streams]. The fact +that futures are richer data structures means they *can* be composed together +more naturally, as we have seen. + +Tasks then give *additional* control over futures, allowing you to choose where +and how to group them. And it turns out that threads and tasks often work very +well together, because tasks can (at least in some runtimes) be moved around +between threads. We have not mentioned it up until now, but under the hood the +`Runtime` we have been using, including the `spawn_blocking` and `spawn_task` +functions, are multithreaded by default! Many runtimes can transparently move +tasks around between threads based on the current utilization of the threads, to +hopefully improve the overall performance of the system. To build that actually +requires threads *and* tasks, and therefore futures. + + + +[combining-futures]: /ch17-04-more-ways-of-combining-futures.md#building-our-own-async-abstractions +[streams]: /ch17-05-streams.md#working-with-streams From 63214c3fb2b9c67f8757446e4046be469f1f17e9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 26 Jun 2024 15:40:06 -0600 Subject: [PATCH 336/720] =?UTF-8?q?Ch.=2017=20=C2=A700:=20rewrite=20the=20?= =?UTF-8?q?parallelism=20and=20concurrency=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-00-async-await.md | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index c974eb32f9..182edf2ac1 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -166,19 +166,31 @@ because the differences will show up as we start working: * *Concurrency* is when operations can make progress without having to wait for all other operations to complete. -One common analogy for thinking about the difference between concurrency and -parallelism is cooking in a kitchen. Parallelism is like having two cooks: one -working on cooking eggs, and the other working on preparing fruit bowls. Those -can happen at the same time, without either affecting the other. Concurrency is -like having a single cook who can start cooking some eggs, start dicing up some -vegetables to use in the omelette, adding seasoning and whatever vegetables are -ready to the eggs at certain points, and switching back and forth between those -tasks. - -(This analogy breaks down if you think about it too hard. The eggs keep cooking -while the cook is chopping up the vegetables, after all. That is parallelism, -not just concurrency! The focus of the analogy is the *cook*, not the food, -though, and as long as you keep that in mind, it mostly works.) +One way to think about the difference between parallelism and concurrency is to +think about working on a software project as a team. When you agree to split up +a group of tasks between a group of people, with each person working on one task +and delivering them separately, this is *parallelism*. Each person on the team +can be making progress at the exact same time. + +On the other hand, when an individual works on several different tasks before +any of them is complete, this is *concurrency*. Maybe you have two different +projects checked out on your computer, and when you get bored or stuck on one +project, you switch to the other. You are just one person, and you cannot make +progress on both tasks at the exact same time. + +With both of these situations, you might have to coordinate between different +tasks. Maybe you *thought* the task that one person was working on was totally +independent from everyone else’s work, but it actually needs something finished +by another person on the team. *Some* of the work could be done in parallel, but +some of it was actually *serial*: it could only happen in a series, one thing +after the other. Likewise, maybe with the two projects you were +switching between yourself, you realize that one of them needs the result from +the other, so now your concurrent work has also become *serial*. + +Parallelism and concurrency can intersect with each other, too. For example, if +it turns out your coworker is waiting on one of your projects to finish, then +you might need to focus on that project and not give any time to the other one +until it is done, so your own work stops being concurrent. On a machine with multiple CPU cores, we can actually do work in parallel. One core can be doing one thing while another core does something completely From 6914bc41a4be98e01d1198729ba8b9d838c036f5 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 26 Jun 2024 16:35:45 -0600 Subject: [PATCH 337/720] =?UTF-8?q?Ch.=2017=20=C2=A700:=20no=20more=20cook?= =?UTF-8?q?s!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-00-async-await.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 182edf2ac1..17541b4d85 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -204,9 +204,4 @@ not all concurrent operations happen in parallel! When working with async in Rust, we are always dealing with concurrency. Depending on the hardware, the operating system, and the async runtime we are using, that concurrency may use some degree of parallelism under the hood, or it -may not. (More about async runtimes later!) - -A big difference between the cooking analogy and Rust’s async model for -concurrency is that in the cooking example, the cook makes the decision about -when to switch tasks. In Rust’s async model, the tasks are in control of that. -To see how, let’s look at how async programming in Rust actually works. +may not. Let’s dive into how async programming in Rust actually works! From e774613c8e4308013aa4860c0cb64d9b35089ea6 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 1 Jul 2024 12:30:18 -0600 Subject: [PATCH 338/720] Ch. 17: remove 'base' listing --- .../listing-17-base/Cargo.lock | 280 ------------------ .../listing-17-base/Cargo.toml | 8 - .../listing-17-base/src/main.rs | 5 - 3 files changed, 293 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-base/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-base/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-base/src/main.rs diff --git a/listings/ch17-async-await/listing-17-base/Cargo.lock b/listings/ch17-async-await/listing-17-base/Cargo.lock deleted file mode 100644 index 53a9a9dde6..0000000000 --- a/listings/ch17-async-await/listing-17-base/Cargo.lock +++ /dev/null @@ -1,280 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-base/Cargo.toml b/listings/ch17-async-await/listing-17-base/Cargo.toml deleted file mode 100644 index e094f067f1..0000000000 --- a/listings/ch17-async-await/listing-17-base/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-base/src/main.rs b/listings/ch17-async-await/listing-17-base/src/main.rs deleted file mode 100644 index 3c247f888f..0000000000 --- a/listings/ch17-async-await/listing-17-base/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - trpl::block_on(async { - // TODO: use this! - }) -} From f039ca3c7da6295501c2d10ab987658c67566086 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 27 Jun 2024 13:22:53 -0600 Subject: [PATCH 339/720] Ch. 17: Transition materials from Ch. 16 and into Ch. 18 - Rewrite the end of Ch. 16 to account for the fact that it no longer transitions to the OOP/etc. chapter. - Add a summary to the end of Ch. 17, pulling over a bunch of the text that was previously in the end of Ch. 16. - Rewrite the introduction to Ch. 17, for a more seamless shift from Ch. 16 and contextualizing async in the broader software ecosystem. --- ...16-04-extensible-concurrency-sync-and-send.md | 9 ++------- src/ch17-00-async-await.md | 14 +++++++++++--- src/ch17-06-futures-tasks-threads.md | 16 +++++++++++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/ch16-04-extensible-concurrency-sync-and-send.md b/src/ch16-04-extensible-concurrency-sync-and-send.md index 4586b8d2c4..1b74554341 100644 --- a/src/ch16-04-extensible-concurrency-sync-and-send.md +++ b/src/ch16-04-extensible-concurrency-sync-and-send.md @@ -62,10 +62,6 @@ uphold them. ## Summary -This isn’t the last you’ll see of concurrency in this book: the project in -Chapter 20 will use the concepts in this chapter in a more realistic situation -than the smaller examples discussed here. - As mentioned earlier, because very little of how Rust handles concurrency is part of the language, many concurrency solutions are implemented as crates. These evolve more quickly than the standard library, so be sure to search @@ -81,9 +77,8 @@ run on multiple threads without the kinds of hard-to-track-down bugs common in other languages. Concurrent programming is no longer a concept to be afraid of: go forth and make your programs concurrent, fearlessly! -Next, we’ll talk about idiomatic ways to model problems and structure solutions -as your Rust programs get bigger. In addition, we’ll discuss how Rust’s idioms -relate to those you might be familiar with from object-oriented programming. +This is just your first step into Rust’s concurrency story. In the next chapter, +we will explore a complementary approach, asynchronous programming. [sharing-a-mutext-between-multiple-threads]: ch16-03-shared-state.html#sharing-a-mutext-between-multiple-threads diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 17541b4d85..049dddc384 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -1,8 +1,16 @@ ## Async and Await -In Chapter 16, we saw one of Rust’s approaches to concurrency: using threads. -Since Rust 1.39, there has been another option for concurrency: asynchronous -programming, or *async*. +The threading-based concurrency model is one of the oldest concurrency models in +computing, and it was present and well-supported in Rust since 1.0. In the past +few decades, though, many programming languages have been experimenting with +other approaches to concurrency, especially asynchronous programming, or +*async*. + +It took a few years to work out the right design for async in Rust. After a +bunch of experimentation and design work in the library ecosystem, Rust added +language-level support for async in Rust 1.39, in 2019, and there is a thriving +ecosystem of crates supporting all sorts of interesting capabilities offered by +those language primitives. In the rest of this chapter, we will: diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 74a032df99..a723a022e9 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -88,7 +88,21 @@ tasks around between threads based on the current utilization of the threads, to hopefully improve the overall performance of the system. To build that actually requires threads *and* tasks, and therefore futures. - +## Summary + +This isn’t the last you’ll see of concurrency in this book: the project in +Chapter 21 will use the concepts in this chapter in a more realistic situation +than the smaller examples discussed here—and compare more directly what it looks +like to solve these kinds of problems with threading vs. with tasks and futures. + +Whether with threads or with futures and tasks, or combining them for greatest +performance, Rust gives you the tools you need to write safe, fast, concurrent +code—whether for a high-throughput web server or an embedded operating system. + +Next, we’ll talk about idiomatic ways to model problems and structure solutions +as your Rust programs get bigger. In addition, we’ll discuss how Rust’s idioms +relate to those you might be familiar with from object-oriented programming. + [combining-futures]: /ch17-04-more-ways-of-combining-futures.md#building-our-own-async-abstractions [streams]: /ch17-05-streams.md#working-with-streams From 5fdd92ceea95a1d2527593011045dd94cfd98993 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 1 Jul 2024 14:11:27 -0600 Subject: [PATCH 340/720] =?UTF-8?q?Ch.=2017=C2=A700=20initial=20edits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-00-async-await.md | 171 ++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 86 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 049dddc384..bc1a301a6c 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -26,61 +26,60 @@ First, though, let’s explore what async gives us. Many operations we ask the computer to do can take a while to finish. For example, if you used a video editor to create a video of a family celebration, -exporting it could take anywhere from minutes to hours. Similarly, when you -download a video shared by someone in your family, that download process might -take a long time. It would be nice if we could do something else while we are -waiting for those long-running processes to complete. +exporting it could take anywhere from minutes to hours. Similarly, downloading a +video shared by someone in your family might take a long time. It would be nice +if we could do something else while we are waiting for those long-running +processes to complete. The video export will use as much CPU and GPU power as it can. If you only had one CPU core, and your operating system never paused that export until it completed, you could not do anything else on your computer while it was running. -That would be a pretty frustrating experience, though, so instead your computer +That would be a pretty frustrating experience, though. Instead, your computer can (and does!) invisibly interrupt the export often enough to let you get other -small amounts of work done along the way. - -The file download is different. It does not take up very much CPU time. Instead, -you are mostly waiting on data to transfer across the network. You can start -reading from a network socket, but it might take a while for all the data to -arrive and be fed into the socket by the network controller. Moreover, even once -the data has all arrived, videos can be quite large, so it might take some time -to load all the data from the socket. Even if “some time” here is just a second -or two, that is a very long time for a modern processor, which can do billions -of operations every second. You could choose to wait for all of that to finish, -but you might be waiting for a while… with your CPU doing not much! Thus, even -if your specific program cannot do anything until it finishes reading data from -a network socket, your computer will once again invisibly interrupt your -program so other things can happen at the same time as the network operation. +work done along the way. + +The file download is different. It does not take up very much CPU time. You are +mostly waiting on data to transfer across the network. You can start reading +from a network socket, but it might take a while for all the data to arrive and +be fed into the socket by the network controller. Even once the data has all +arrived, videos can be quite large, so it might take some time to load all the +data from the socket. Maybe it only takes a second or two—but that is a very +long time for a modern processor, which can do billions of operations every +second. It would be nice to be able to put the CPU to use for other work while +waiting for the network call to finish—so, again, your computer will once again +invisibly interrupt your program so other things can happen while the network +operation is still ongoing. > Note: The video export is the kind of operation which is often described as -> “CPU-bound”. It is limited by the speed of the computer’s CPU (and GPU), and -> how much of that power it can use. The video download is the kind of operation +> “CPU-bound”. It is limited by the speed of the computer’s *CPU and GPU*, and +> how much of that speed it can use. The video download is the kind of operation > which is often described as “IO-bound,” because it is limited by the speed of > the computer’s *input and output*. It can only go as fast as the data can be > sent across the network, which means that it can only go as fast as the data > can be written to the socket by the network controller. -In both of these examples, the concurrency happens at the level of the whole -program. The operating system decides to interrupt the program to let other +In both of these examples, the concurrency only happens at the level of a whole +program. The operating system interrupts one program to let other programs get work done. In many cases, since we understand our programs at a -much more granular level than the operating system does, we can lots of -opportunities for concurrency that the operating system cannot see. For example, -if we are building a tool to manage file downloads, it is important that the -user interface stay responsive while a download is happening. In fact, we should -even be able to start multiple downloads at the same time. - -However, many operating system APIs for interacting with network sockets are -*blocking*. That is, the function calls block further progress in the program -when they are called until they return. This is how *most* function calls work, -if you think about it! However, we normally reserve the term “blocking” for -function calls which interact with files, network sockets, or other resources on -the computer, because those are the places where an individual program would -benefit from the operation being *non*-blocking. - -When doing file downloads, we could use threads to work around the fact that the -call to write to a network socket is blocking. If we move the data over to a -dedicated thread which handles the write operation, it will *not* block the rest -of the program. But in many ways, it would be nicer if the call were not -blocking in the first place. +much more granular level than the operating system does, we can spot lots of +opportunities for concurrency that the operating system cannot see. + +For example, if we are building a tool to manage file downloads, we should be +able to write our program in such a way that starting one download does not lock +up the UI, and users should be able to start multiple downloads at the same +time. Many operating system APIs for interacting with network sockets are +*blocking*, though. That is, the function calls block further progress in the +program when they are called until they return. + +> Note: This is how *most* function calls work, if you think about it! However, +we normally reserve the term “blocking” for function calls which interact with +files, network sockets, or other resources on the computer, because those are +the places where an individual program would benefit from the operation being +*non*-blocking. + +We could use threads to avoid blocking while downloading files, by using a +dedicated thread. But it would be nicer if the call were not blocking in the +first place. One way to accomplish that would be to use an API built around callbacks. For each blocking operation, we could pass in a function to call once the operation @@ -110,11 +109,10 @@ network_socket.read_non_blocking().and_then(|result| { }); ``` -Each of these can make the control flow for the program more complicated, -though. You can end up with event handler callbacks scattered across the code -base, or groups of deeply nested callbacks, or long chains of `and_then` calls. -Understanding the flow of data through the program can become more difficult as -a result, and dealing with callbacks can also complicate ownership. +Each of these makes it harder to understand both the control flow and the flow +of data through the program. You can end up with event handler callbacks +scattered across the code base, or groups of deeply nested callbacks, or long +chains of `and_then` calls. There are also no particularly good ways to get data out of those callbacks. With other common types in Rust, we often use pattern-matching in scenarios like @@ -136,17 +134,18 @@ network_socket.read_non_blocking().and_then(|result| { println!("{data:?}"); ``` -The callback passed to `and_then` needs a mutable reference to `data`, but the -`load` function tries to return `data` to the caller. Rust would helpfully tell -us that we cannot borrow `data` immutably to print it because it is still -borrowed mutably for the `and_then` callback. This is not just Rust being fussy, -either: the result of this would normally always just print the `None` value and -exit, but if the read *happened* to go fast enough, it is possible it could -sometimes print some string data instead. That is *definitely* not what we -want! +In this very broken code, the callback passed to `and_then` needs a mutable +reference to `data`, but the `println` macro needs to borrow a reference to +`data` to be able to print it. Rust would helpfully tell us that we cannot +borrow `data` immutably to print it because it is still borrowed mutably for the +`and_then` callback. This is not just Rust being fussy, either: the result of +this would normally always just print the `None` value, but if the read +*happened* to go fast enough, it is possible it could sometimes print some +string data instead. That is *definitely* not what we want! We also could not cancel `read_non_blocking`: once it has started, it will run -till it finishes unless the whole program stops. +till it finishes unless the whole program stops. What we really want to be able to write is something much more direct, like we would write in blocking code, but with the benefits of getting the data when it @@ -159,57 +158,57 @@ println!("{data}"); ``` That is exactly what Rust’s async abstraction gives us. It is designed to help -us solve all of these issues. In the next section, we will see how this works in -practice. +us solve all of these issues. Before we will see how this works in practice, +though, we need to dig a little deeper into the differences between parallelism +and concurrency. ### Parallelism and Concurrency -First, though, we need to dig a little deeper into the differences between -parallelism and concurrency. In the previous chapter we treated them as mostly -interchangeable. Now we need to distinguish between the two a little more, -because the differences will show up as we start working: +In the previous chapter we treated parallelism and concurrency as mostly +interchangeable. Now we need to distinguish between them more precisely, because +the differences will show up as we start working: * *Parallelism* is when operations can happen simultaneously. * *Concurrency* is when operations can make progress without having to wait for all other operations to complete. -One way to think about the difference between parallelism and concurrency is to -think about working on a software project as a team. When you agree to split up +Think about working on a software project as a team. When you agree to split up a group of tasks between a group of people, with each person working on one task and delivering them separately, this is *parallelism*. Each person on the team -can be making progress at the exact same time. - -On the other hand, when an individual works on several different tasks before -any of them is complete, this is *concurrency*. Maybe you have two different -projects checked out on your computer, and when you get bored or stuck on one -project, you switch to the other. You are just one person, and you cannot make -progress on both tasks at the exact same time. +can be making progress at the exact same time. On the other hand, when an +individual works on several different tasks before any of them is complete, this +is *concurrency*. Maybe you have two different projects checked out on your +computer, and when you get bored or stuck on one project, you switch to the +other. You are just one person, and you cannot make progress on both tasks at +the exact same time—but you can multi-task, making progress on multiple tasks by +switching between them. Work on one does not necessarily *block* working on the +other. With both of these situations, you might have to coordinate between different tasks. Maybe you *thought* the task that one person was working on was totally independent from everyone else’s work, but it actually needs something finished -by another person on the team. *Some* of the work could be done in parallel, but +by another person on the team. Some of the work could be done in parallel, but some of it was actually *serial*: it could only happen in a series, one thing -after the other. Likewise, maybe with the two projects you were -switching between yourself, you realize that one of them needs the result from -the other, so now your concurrent work has also become *serial*. +after the other. Likewise, you might realize that one of the tasks you were +working on needs the result from another of your tasks. Now your concurrent work +has also become serial. Parallelism and concurrency can intersect with each other, too. For example, if it turns out your coworker is waiting on one of your projects to finish, then -you might need to focus on that project and not give any time to the other one +you might need to focus on that project and not give any time to your other task until it is done, so your own work stops being concurrent. -On a machine with multiple CPU cores, we can actually do work in parallel. One -core can be doing one thing while another core does something completely -unrelated, and those actually happen at the same time. On a machine with a -single CPU core, the CPU can only do one operation at a time, but we can still -have concurrency. Using tools like threads, processes, and async, the computer -can pause one activity and switch to others before eventually cycling back to -that first activity again. So all parallel operations are also concurrent, but -not all concurrent operations happen in parallel! +On a machine with a single CPU core, the CPU can only do one operation at a +time, but we can still have concurrency. Using tools like threads, processes, +and async, the computer can pause one activity and switch to others before +eventually cycling back to that first activity again. On a machine with multiple +CPU cores, we can actually do work in parallel. One core can be doing one thing +while another core does something completely unrelated, and those actually +happen at the same time. When working with async in Rust, we are always dealing with concurrency. Depending on the hardware, the operating system, and the async runtime we are -using, that concurrency may use some degree of parallelism under the hood, or it -may not. Let’s dive into how async programming in Rust actually works! +using—more on async runtimes shortly!—that concurrency may or may not also use +parallelism under the hood. Now, let’s dive into how async programming in Rust +actually works! From f023032403e5ace5ea0bfa78059cea20e6ffd024 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 1 Jul 2024 15:33:45 -0600 Subject: [PATCH 341/720] Ch. 17: add some more explanatory comments to `trpl` --- packages/trpl/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 4ffdbc365b..c661ffd459 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -12,9 +12,11 @@ //! never be broken by upstream changes, e.g. if Tokio does a breaking 2.0 //! release at some point. +// For direct use within the `trpl` crate, *not* re-exported. use std::{future::Future, pin::pin, time::Duration}; use tokio::time; +// Re-exports, to be used like `trpl::join`. pub use futures::{ future::{self, join, join3, join_all, Either}, join, From eec174540a6c87d7fc2f89c00c93cf80e1f19545 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 1 Jul 2024 15:33:45 -0600 Subject: [PATCH 342/720] =?UTF-8?q?Ch.=2017=C2=A701=20initial=20edits=20fo?= =?UTF-8?q?r=20the=20first=20subsection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ch17-async-await/listing-17-01/output.txt | 8 +- .../listing-17-01/src/main.rs | 9 +- .../ch17-async-await/listing-17-02/output.txt | 6 +- .../listing-17-02/src/main.rs | 7 +- .../listing-17-03-fix/Cargo.lock | 7 + .../listing-17-03-fix/Cargo.toml | 6 + .../listing-17-03-fix/output.txt | 10 + .../listing-17-03-fix/src/main.rs | 10 + .../ch17-async-await/listing-17-03/Cargo.lock | 12 + .../listing-17-03/src/main.rs | 9 +- .../ch17-async-await/listing-17-04/Cargo.lock | 12 + src/ch17-01-futures-and-syntax.md | 206 ++++++++++-------- 12 files changed, 193 insertions(+), 109 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-03-fix/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-03-fix/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-03-fix/output.txt create mode 100644 listings/ch17-async-await/listing-17-03-fix/src/main.rs diff --git a/listings/ch17-async-await/listing-17-01/output.txt b/listings/ch17-async-await/listing-17-01/output.txt index 9fc69b9ac1..46e6cd3111 100644 --- a/listings/ch17-async-await/listing-17-01/output.txt +++ b/listings/ch17-async-await/listing-17-01/output.txt @@ -1,14 +1,14 @@ $ cargo run Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-01) warning: unused implementer of `Future` that must be used - --> src/main.rs:2:5 + --> src/main.rs:3:5 | -2 | hello_async(); - | ^^^^^^^^^^^^^ +3 | hello("async"); + | ^^^^^^^^^^^^^^ | = note: futures do nothing unless you `.await` or poll them = note: `#[warn(unused_must_use)]` on by default warning: `async_await` (bin "async_await") generated 1 warning - Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s Running `target/debug/async_await` diff --git a/listings/ch17-async-await/listing-17-01/src/main.rs b/listings/ch17-async-await/listing-17-01/src/main.rs index 70ce867bf2..68c82536aa 100644 --- a/listings/ch17-async-await/listing-17-01/src/main.rs +++ b/listings/ch17-async-await/listing-17-01/src/main.rs @@ -1,11 +1,10 @@ // ANCHOR: all fn main() { - hello_async(); + hello("async"); } -// ANCHOR: async-fn -async fn hello_async() { - println!("Hello, async!"); +async fn hello(name: &str) { + let greeting = format!("Hello, {name}!"); + println!("{greeting}"); } -// ANCHOR_END: async-fn // ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-02/output.txt b/listings/ch17-async-await/listing-17-02/output.txt index 0910145234..5400d6f5e1 100644 --- a/listings/ch17-async-await/listing-17-02/output.txt +++ b/listings/ch17-async-await/listing-17-02/output.txt @@ -1,12 +1,12 @@ $ cargo run Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-02) error[E0728]: `await` is only allowed inside `async` functions and blocks - --> src/main.rs:3:19 + --> src/main.rs:3:20 | 2 | fn main() { | ---- this is not `async` -3 | hello_async().await; - | ^^^^^ only allowed inside `async` functions and blocks +3 | hello("async").await; + | ^^^^^ only allowed inside `async` functions and blocks For more information about this error, try `rustc --explain E0728`. error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-02/src/main.rs b/listings/ch17-async-await/listing-17-02/src/main.rs index 4ce7800db7..153458bc0a 100644 --- a/listings/ch17-async-await/listing-17-02/src/main.rs +++ b/listings/ch17-async-await/listing-17-02/src/main.rs @@ -1,9 +1,10 @@ // ANCHOR: main fn main() { - hello_async().await; + hello("async").await; } // ANCHOR_END: main -async fn hello_async() { - println!("Hello, async!"); +async fn hello(name: &str) { + let greeting = format!("Hello, {name}!"); + println!("{greeting}"); } diff --git a/listings/ch17-async-await/listing-17-03-fix/Cargo.lock b/listings/ch17-async-await/listing-17-03-fix/Cargo.lock new file mode 100644 index 0000000000..d30b928a6c --- /dev/null +++ b/listings/ch17-async-await/listing-17-03-fix/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "async_await" +version = "0.1.0" diff --git a/listings/ch17-async-await/listing-17-03-fix/Cargo.toml b/listings/ch17-async-await/listing-17-03-fix/Cargo.toml new file mode 100644 index 0000000000..67729afc80 --- /dev/null +++ b/listings/ch17-async-await/listing-17-03-fix/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch17-async-await/listing-17-03-fix/output.txt b/listings/ch17-async-await/listing-17-03-fix/output.txt new file mode 100644 index 0000000000..17922a261c --- /dev/null +++ b/listings/ch17-async-await/listing-17-03-fix/output.txt @@ -0,0 +1,10 @@ +$ cargo run + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-03-fix) +error[E0752]: `main` function is not allowed to be `async` + --> src/main.rs:2:1 + | +2 | async fn main() { + | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` + +For more information about this error, try `rustc --explain E0752`. +error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-03-fix/src/main.rs b/listings/ch17-async-await/listing-17-03-fix/src/main.rs new file mode 100644 index 0000000000..443cadcc0e --- /dev/null +++ b/listings/ch17-async-await/listing-17-03-fix/src/main.rs @@ -0,0 +1,10 @@ +// ANCHOR: main +async fn main() { + hello("async").await; +} +// ANCHOR_END: main + +async fn hello(name: &str) { + let greeting = format!("Hello, {name}!"); + println!("{greeting}"); +} diff --git a/listings/ch17-async-await/listing-17-03/Cargo.lock b/listings/ch17-async-await/listing-17-03/Cargo.lock index 89df255f72..b6971aa2e9 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.lock +++ b/listings/ch17-async-await/listing-17-03/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-03/src/main.rs b/listings/ch17-async-await/listing-17-03/src/main.rs index 111f734666..6974137d66 100644 --- a/listings/ch17-async-await/listing-17-03/src/main.rs +++ b/listings/ch17-async-await/listing-17-03/src/main.rs @@ -1,9 +1,12 @@ // ANCHOR: main fn main() { - trpl::block_on(hello_async()); + trpl::block_on(async { + hello("async").await; + }); } // ANCHOR_END: main -async fn hello_async() { - println!("Hello, async!"); +async fn hello(name: &str) { + let greeting = format!("Hello, {name}!"); + println!("{greeting}"); } diff --git a/listings/ch17-async-await/listing-17-04/Cargo.lock b/listings/ch17-async-await/listing-17-04/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.lock +++ b/listings/ch17-async-await/listing-17-04/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 681727d387..1eae9e69e8 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -1,10 +1,10 @@ ## Futures and the Async Syntax -Like other languages with async, Rust uses the `async` and `await` -keywords—though with some important differences from how other languages do -things, as we will see. Blocks and functions can be marked `async`, and you can -wait on the result of an `async` function or block to resolve using the `await` -keyword. +Like other languages with async, Rust uses the `async` and `await` keywords for +async programming. (If you are familiar with other languages’ approach to async, +you may notice some significant differences, though.) In Rust, blocks and +functions can be marked `async`, and you can wait on the result of an `async` +function or block to resolve using the `await` keyword. Let’s write our first async function, and call it: @@ -22,65 +22,75 @@ If we compile and run this… nothing happens, and we get a compiler warning: {{#include ../listings/ch17-async-await/listing-17-01/output.txt}} ``` -The warning tells us that just calling `hello_async()` was not enough: we also -need to `.await` or poll the future it returns. This raises two important -questions: +The warning tells us that just calling `hello` was not enough: we also need to +`.await` or poll the future it returns. This raises some important questions: - Given there is no return type on the function, how is it returning a future? -- What is a future? +- What exactly is a future? +- Why do we need to `.await` or poll futures to make them do something? +- How do `.await` and polling relate to each other? -### Async functions - -In Rust, `async fn` is equivalent to writing a function which returns a *future* -of the return type. That is, when the compiler sees a function like this: +We will work through each of these in turn. We can answer the first question by +learning what the syntax means, so let’s start there. -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:async-fn}} -``` +### Async functions -It is basically equivalent to a function defined like this instead: +In Rust, writing `async fn` is equivalent to writing a function which returns a +*future* of the return type. That is, when the compiler sees a function like +`async fn hello` in Listing 17-1, it is basically equivalent to a function +defined like this instead: ```rust -fn hello_async() -> impl Future { +fn hello(name: &str) -> impl Future { async { - println!("Hello, async!"); + let greeting = format!("Hello, {name}!"); + println!("{greeting}"); } } ``` -Let’s break that down and see what each part means: +Let’s walk through each part of the transformed version: * It uses the `impl Trait` syntax we discussed back in the [“Traits as - Parameters”][impl-trait] section in Chapter 10 to return a `Future` with an - associated type of `Output`. That tells us that `Future` is a trait, and the - `Output` associated type of `()` matches the original return type from the - async version of the function. - -* It wraps the whole body of the `async fn` in an `async` block. Given that - blocks like this are expressions, and that this is expression is the one which - is returned from the function, we can infer that an `async` block like this - produces some anonymous data type which implements the `Future` trait. - -Combined, those explain that when we called `hello_async` in `main`, it returned -a `Future`. Then Rust warned us that we did not do anything with the future. -This is because futures are *lazy*: they don’t do anything until you ask them -to. This should remind you of our discussion of iterators [back in Chapter -13][iterators-lazy]. With iterators, you have to call `next` to get them to do -anything—whether by using a `for` loop or by using iterator methods like `.iter()` and `.map()` which ultimately call `next()` under the hood. - -With futures, the same basic idea applies, although for different reasons, and -with different syntax and methods. This is different from the behavior we saw -when using `thread::spawn` in the previous chapter, and it is different from how -many other languages approach async. This allows Rust to avoid running async -code unless it is actually needed. We will see why that is later on. For now, -let’s start by awaiting the future returned by `hello_async` to actually have it -run. - -> Note: Rust’s `await` keyword goes after the expression you are awaiting, not -> before it—that is, it is a _postfix keyword_. This is different from what you -> might be used to if you have used async in languages like JavaScript or C#. -> Rust chose this because it makes chains of async and non-async methods much -> nicer to work with. As of now, `await` is Rust’s only postfix keyword. + Parameters”][impl-trait] section in Chapter 10. +* The returned trait is a `Future`, with an associated type of `Output`. Notice + that the `Output` type is `()`, which is the same as the the original return + type from the `async fn` version of `hello`. +* The whole body of the function is wrapped in an `async` block. Remember that + blocks are expressions. This whole block is the expression returned from the + function. +* The async block itself has the “unit” value `()`, since it ends with a + `println!` statement. That value matches the `Output` type in the return type. + +An `async` block corresponds to a data type which implements the `Future` trait, +and the result of the async block will be the `Output` of the `Future`. Thus, an +`async fn`’s return type is an anonymous data type the compiler creates for us, +which implements `Future`. The associated `Output` type for the `Future` is the +return type of the original `async fn`. Thus, calling `hello` in Listing 17-1 +returned a `Future`. + +Then Rust warned us that we did not do anything with the future. This is because +futures are *lazy*: they don’t do anything until you ask them to. This should +remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. +Iterators do nothing unless you call their `.next()` method—whether directly, or +using `for` loops or methods like `.map()` which use `.next()` under the hood. + +With futures, the same basic idea applies: they do nothing unless you explicitly +ask them to. This laziness allows Rust to avoid running async code until it is +actually needed. + +> Note: This is different from the behavior we saw when using `thread::spawn` in +> the previous chapter, where the closure we passed to another thread started +> running immediately. It is also different from how many other languages +> approach async! But it is important for Rust. We will see why that is later. + + +For now, let’s start by awaiting the future returned by `hello` to actually have +it run. Rust’s `await` keyword goes after the expression you are awaiting, not +before it. That is, it is a *postfix keyword*. (This is different from what you +might be used to if you have used async in languages like JavaScript or C#. Rust +chose this because it makes chains of methods much nicer to work with.) In +Listing 17-2, we add `.await` to the `hello` call in `main`. @@ -97,52 +107,67 @@ Oh no! We have gone from a compiler warning to an actual error: ``` This time, the compiler is informing us we cannot use `.await` in `main`, -because `main` is not an `async` function. That is because async code needs a -*runtime*: a Rust crate which manages the details of executing asynchronous -code. - -Most languages which support async, including C#, JavaScript, Go, Kotlin, -Erlang, and Swift, bundle a runtime with the language. At least for now, Rust -does not. Instead, there are many different async runtimes available, each of -which makes different tradeoffs suitable to the use case they target. For -example, a high-throughput web server with dozens of CPU cores and terabytes of -RAM has very different different needs than a microcontroller with a single -core, one gigabyte of RAM, and no ability to do heap allocations. - -To keep this chapter focused on learning async, rather than juggling parts of -the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust -Programming Language”). It re-exports all the types, traits, and functions you -will need, and in a couple cases wires up a few things for you which are less -relevant to the subject of the book. There is no magic involved, though! If you -want to understand what the crate does, we encourage you to check out [its -source code][crate-source]. You will be able to see what crate each re-export -comes from, and we have left extensive comments explaining what the handful of -helper functions we supply are doing. - -> ### The `futures` and `tokio` Crates +because `main` is not an `async` function. Your first thought might be to make +`main` an async function then, as in Listing 17-TODO-3. + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-03-fix/src/main.rs:main}} +``` + + + +However, we get another compiler error here: + +```console +{{#include ../listings/ch17-async-await/listing-17-03-fix/output.txt}} +``` + +The problem is that async code needs a *runtime*: a Rust crate which manages the +details of executing asynchronous code. + +Most languages which support async bundle a runtime with the language. At least +for now, Rust does not. Instead, there are many different async runtimes +available, each of which makes different tradeoffs suitable to the use case they +target. For example, a high-throughput web server with dozens of CPU cores and +terabytes of RAM has very different different needs than a microcontroller with +a single core, one gigabyte of RAM, and no ability to do heap allocations. + +> ### The `trpl` Crate > -> Whenever you see code from the `trpl` crate throughout the rest of the -> chapter, it will be re-exporting code from the [`futures`][futures-crate] and -> [`tokio`][tokio] crates. +> To keep this chapter focused on learning async, rather than juggling parts of +> the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust +> Programming Language”). It re-exports all the types, traits, and functions you +> will need, primarily from the [`futures`][futures-crate] and [`tokio`][tokio] +> crates. > > - The `futures` crate is an official home for Rust experimentation for async > code, and is actually where the `Future` type was originally designed. > > - Tokio is the most widely used async runtime in Rust today, especially (but -> not only!) for web applications. There are other great options out there, -> too, and they may be more suitable for your purposes. We are using Tokio -> because it is the most widely-used runtime—not as a judgment call on whether -> it is the *best* runtime! +> not only!) for web applications. There are other great runtimes out there, +> and they may be more suitable for your purposes. We use Tokio under the hood +> for `trpl` because it good and widely used. +> +> In some cases, `trpl` also renames or wraps the original APIs to let us stay +> focused on the details relevant to chapter. If you want to understand what the +> crate does, we encourage you to check out [its source code][crate-source]. You +> will be able to see what crate each re-export comes from, and we have left +> extensive comments explaining what the crate does. -For now, go ahead and add the `trpl` crate to your `hello-async` project: +Go ahead and add the `trpl` crate to your `hello-async` project: ```console $ cargo add trpl ``` -Then, in our `main` function, let’s wrap the call to `hello_async` with the +Then, in our `main` function, let’s wrap the call to `hello` with the `trpl::block_on` function, which takes in a `Future` and runs it until it -completes. +completes. Since `hello` returns a `Future`, we could simply wrap it directly in +`trpl::block_on`. However, for most of the examples in the chapter, we will be +doing more than just one async function call, so instead we will pass an `async` +block and explicitly await the result of calling `hello`. @@ -158,9 +183,8 @@ When we run this, we get the behavior we might have expected initially: {{#include ../listings/ch17-async-await/listing-17-03/output.txt}} ``` -Phew: we finally have some working async code! Now we can answer that second -question: what is a future anyway? That will also help us understand why we need -that `trpl::block_on` call to make this work. +Phew: we finally have some working async code! Now we can turn our attention to +how the `Future` trait works. ### What Are Futures? @@ -218,7 +242,7 @@ Under the hood, when you call `.await`, Rust compiles that to code which calls like this: ```rust,ignore -match hello_async().poll() { +match hello("async").poll() { Ready(_) => { // We’re done! } @@ -233,9 +257,9 @@ the `Future` is still `Pending`? We need some way to try again. We would need to have something like this instead: ```rust,ignore -let hello_async_fut = hello_async(); +let hello_fut = hello("async"); loop { - match hello_async_fut.poll() { + match hello_fut.poll() { Ready(_) => { break; } @@ -286,7 +310,7 @@ Now we can understand why the compiler was stopping us in Listing 17-2 (before we added the `trpl::block_on` function). The `main` function is not `async`—and it really cannot be: if it were, something would need to call `poll()` on whatever `main` returned! Instead, we use the `trpl::block_on` function, which -polls the `Future` returned by `hello_async` until it returns `Ready`. Every +polls the `Future` returned by `hello` until it returns `Ready`. Every async program in Rust has at least one place where it sets up an executor and executes code. @@ -295,7 +319,7 @@ executes code. > you never have to think about it when writing Rust. > > The loop as written also wouldn’t compile, because it doesn’t actually satisfy -> the contract for a `Future`. In particular, `hello_async_fut` is not *pinned* +> the contract for a `Future`. In particular, `hello_fut` is not *pinned* > with the `Pin` type and we did not pass along a `Context` argument. We will > see a little more about `Pin` later in the chapter, but we will not dig into > `Context` because you will not normally need them for working with futures in From e23834292e72416478c5c8c34cf7fc270d42921b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 2 Jul 2024 09:12:39 -0600 Subject: [PATCH 343/720] =?UTF-8?q?Ch.=2017=C2=A701=20initial=20edits=20fo?= =?UTF-8?q?r=20the=20second=20subsection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-01-futures-and-syntax.md | 127 +++++++++++++----------------- 1 file changed, 55 insertions(+), 72 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 1eae9e69e8..eed28f8c20 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -188,10 +188,10 @@ how the `Future` trait works. ### What Are Futures? -A *future* is a data structure which represents the state of some async -operation. More precisely, a Rust `Future` is a trait; it allows many different -data structures to represent different async operations in different ways, but -with a common interface. Here is the definition of the trait: +A *future* is a data structure which manages the state of some async operation. +Rust provides the `Future` trait as a building block so different async +operations can be implemented with different data, but with a common interface. +Here is the definition of the trait: ```rust pub trait Future { @@ -201,20 +201,18 @@ pub trait Future { } ``` -Notice that this is a normal trait. While we often interact with futures via -async blocks, you can also implement this yourself on your own data types when -you need to. Many of the functions we will see throughout this chapter return -types which have their own implementations of `Future`. Those implementations -can compose together nicely - -`Future` has an associated type, `Output`, which says what the result of the -future will be when it resolves. (This is analogous to the `Item` associated -type for the `Iterator` trait, which we saw back in Chapter 13.) Beyond that, -`Future` has only one method: `poll`, which takes a special `Pin` reference for -its `self` parameter and a mutable reference to some `Context` type, and returns -a `Poll`. We will talk a little more about `Pin` and `Context` -later in the chapter. For now, let’s focus on what the method returns, the -`Poll` type: +While we often interact with the futures created via async blocks, you can also +implement `Future` on your own data types. Indeed, many of the functions we will +see throughout this chapter return types with their own implementations of +`Future`. + +As we learned earlier, `Future`’s associated type `Output` says what the future +will resolves to. (This is analogous to the `Item` associated type for the +`Iterator` trait.) Beyond that, `Future` also has the `poll` method, which takes +a special `Pin` reference for its `self` parameter and a mutable reference to a +`Context` type, and returns a `Poll`. We will talk a little more +about `Pin` and `Context` later in the chapter. For now, let’s focus on what the +method returns, the `Poll` type: ```rust enum Poll { @@ -223,19 +221,17 @@ enum Poll { } ``` -You may notice that this `Poll` type is a lot like an `Option`: it has one -variant which has a value (`Ready(T)` and `Some(T)`), and one which does not -(`Pending` and `None`). Having a dedicated type lets Rust treat `Poll` -differently from `Option`, though, which is important since they have very -different meanings! The `Pending` variant indicates that the future still has +This `Poll` type is a lot like an `Option`: it has one variant which has a value +(`Ready(T)`), and one which does not (`Pending`). It means something quite +different, though! The `Pending` variant indicates that the future still has work to do, so the caller will need to check again later. The `Ready` variant indicates that the `Future` has finished its work and the `T` value is available. > Note: With most futures, the caller should not call `poll()` again after the -> future has returned `Ready`. Many futures will panic if polled after becoming -> ready! Futures which are safe to poll again will say so explicitly in their -> documentation. +> future has returned `Ready`. Many futures will panic if polled again after +> becoming ready! Futures which are safe to poll again will say so explicitly in +> their documentation. Under the hood, when you call `.await`, Rust compiles that to code which calls `poll`, kind of (although not exactly ) @@ -252,9 +248,9 @@ match hello("async").poll() { } ``` -As you can see from this sample, though, there is a question: what happens when -the `Future` is still `Pending`? We need some way to try again. We would need to -have something like this instead: +What should we do when the `Future` is still `Pending`? We need some way to try +again… and again, and again, until the future is finally ready. In other words, +a loop: ```rust,ignore let hello_fut = hello("async"); @@ -270,16 +266,15 @@ loop { } ``` -When we use `.await`, Rust compiles it to something fairly similar to that loop. -If Rust compiled it to *exactly* that code, though, every `.await` would block -the computer from doing anything else—the opposite of what we were going for! -Instead, Rust needs makes sure that the loop can hand off control to something -which can pause work on this future and work on other futures and check this one -again later. That “something” is an async runtime, and this scheduling and -coordination work is one of the main jobs for a runtime. +If Rust compiled it to exactly that code, though, every `.await` would be +blocking—exactly the opposite of what we were going for! Instead, Rust needs +makes sure that the loop can hand off control to something which can pause work +on this future and work on other futures and check this one again later. That +“something” is an async runtime, and this scheduling and coordination work is +one of the main jobs for a runtime. -Every *await point*—that is, every place where the code explicitly calls -`.await`—represents one of those places where control gets handed back to the +Every *await point*—that is, every place where the code explicitly applies the +`.await` keyword—represents a place where control gets handed back to the runtime. To make that work, Rust needs to keep track of the state involved in the async block, so that the runtime can kick off some other work and then come back when it is ready to try advancing this one again. This is an invisible @@ -293,37 +288,26 @@ enum MyAsyncStateMachine { } ``` -Writing that out by hand would be tedious and error-prone—especially when making -changes to code later. Async Rust creates that state machine for us, and it -really is an `enum` like this, just an anonymous one you don’t have to name. As -a result, the normal rules around data structures all apply, including for -borrowing and ownership. Happily, the compiler also handles checking that for -us, and has good error messages. We will work through a few of those later in -the chapter! - -Once all of that compilation work is done, though, we need a runtime to actually -poll the futures, coordinate between different futures as they hand off control -at await points, and even provide async versions of common functionality like -file or network I/O. - -Now we can understand why the compiler was stopping us in Listing 17-2 (before -we added the `trpl::block_on` function). The `main` function is not `async`—and -it really cannot be: if it were, something would need to call `poll()` on -whatever `main` returned! Instead, we use the `trpl::block_on` function, which -polls the `Future` returned by `hello` until it returns `Ready`. Every -async program in Rust has at least one place where it sets up an executor and -executes code. - -> Note: Under the hood, Rust uses *generators* so that it can hand off control -> between different functions. These are an implementation detail, though, and -> you never have to think about it when writing Rust. -> -> The loop as written also wouldn’t compile, because it doesn’t actually satisfy -> the contract for a `Future`. In particular, `hello_fut` is not *pinned* -> with the `Pin` type and we did not pass along a `Context` argument. We will -> see a little more about `Pin` later in the chapter, but we will not dig into -> `Context` because you will not normally need them for working with futures in -> day-to-day Rust code. +Writing that out by hand would be tedious and error-prone, especially when +making changes to code later. Instead, async Rust creates and manages the state +machine data structures for us. (If you’re wondering: yep, the normal borrowing +and ownership rules around data structures all apply. Happily, the compiler also +handles checking those for us, and has good error messages. We will work through +a few of those later in the chapter!) + +Now we can understand why the compiler stopped us from making `main` itself an +async function in Listing 17-3. If `main` were an async function, something else +would need to call `poll()` on whatever `main` returned, but main is the +starting point for the program! Instead, we use the `trpl::block_on` function, +which sets up a runtime and polls the `Future` returned by `hello` until it +returns `Ready`. + +Every async program in Rust has at least one place where it sets up a runtime and +executes the futures. Those runtimes also often supply async versions of common +functionality like file or network I/O. + +> Note: We have skipped over some interesting implementation details in this +> discussion, because you should not have to think about them when writing Rust. > > If you want to understand how things work “under the hood,” though, the > official [_Asynchronous Programming in Rust_][async-book] book covers them: @@ -331,9 +315,8 @@ executes code. > - [Chapter 2: Under the Hood: Executing Futures and Tasks][under-the-hood] > - [Chapter 4: Pinning][pinning]. -Now, that’s a lot of work to just print a string, but we have laid some key -foundations for working with async in Rust! Now that you know the basics of how -futures and runtimes work, we can see some of the things we can *do* with async. +Now that you know the basics of how futures and runtimes work, we can see some +of the things we can *do* with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters [iterators-lazy]: ch13-02-iterators.html From 09b80f9934b604aa355b2ec654ae84d128ae8aa3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 2 Jul 2024 14:24:10 -0600 Subject: [PATCH 344/720] =?UTF-8?q?Ch.=2017=C2=A702=20initial=20edits=20on?= =?UTF-8?q?=20'Counting'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revise the text itself, of course; but also fold together Listings 04 and 05, which also lets us expand Listing 03 into two listings (which I did not do previously because I knew this kind of thing would come up later!). --- .../listing-17-03-fix/Cargo.lock | 7 - .../listing-17-03-fix/Cargo.toml | 6 - .../listing-17-03-fix/output.txt | 10 - .../listing-17-03-fix/src/main.rs | 10 - .../ch17-async-await/listing-17-03/Cargo.lock | 285 ------------------ .../ch17-async-await/listing-17-03/Cargo.toml | 3 - .../ch17-async-await/listing-17-03/output.txt | 37 +-- .../listing-17-03/src/main.rs | 6 +- .../ch17-async-await/listing-17-04/Cargo.lock | 40 +-- .../ch17-async-await/listing-17-04/Cargo.toml | 6 +- .../ch17-async-await/listing-17-04/output.txt | 27 ++ .../listing-17-04/src/main.rs | 11 +- .../listing-17-05/src/main.rs | 2 - src/ch17-01-futures-and-syntax.md | 14 +- src/ch17-02-concurrency-with-async.md | 92 +++--- 15 files changed, 120 insertions(+), 436 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-03-fix/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-03-fix/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-03-fix/output.txt delete mode 100644 listings/ch17-async-await/listing-17-03-fix/src/main.rs create mode 100644 listings/ch17-async-await/listing-17-04/output.txt diff --git a/listings/ch17-async-await/listing-17-03-fix/Cargo.lock b/listings/ch17-async-await/listing-17-03-fix/Cargo.lock deleted file mode 100644 index d30b928a6c..0000000000 --- a/listings/ch17-async-await/listing-17-03-fix/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "async_await" -version = "0.1.0" diff --git a/listings/ch17-async-await/listing-17-03-fix/Cargo.toml b/listings/ch17-async-await/listing-17-03-fix/Cargo.toml deleted file mode 100644 index 67729afc80..0000000000 --- a/listings/ch17-async-await/listing-17-03-fix/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch17-async-await/listing-17-03-fix/output.txt b/listings/ch17-async-await/listing-17-03-fix/output.txt deleted file mode 100644 index 17922a261c..0000000000 --- a/listings/ch17-async-await/listing-17-03-fix/output.txt +++ /dev/null @@ -1,10 +0,0 @@ -$ cargo run - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-03-fix) -error[E0752]: `main` function is not allowed to be `async` - --> src/main.rs:2:1 - | -2 | async fn main() { - | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` - -For more information about this error, try `rustc --explain E0752`. -error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-03-fix/src/main.rs b/listings/ch17-async-await/listing-17-03-fix/src/main.rs deleted file mode 100644 index 443cadcc0e..0000000000 --- a/listings/ch17-async-await/listing-17-03-fix/src/main.rs +++ /dev/null @@ -1,10 +0,0 @@ -// ANCHOR: main -async fn main() { - hello("async").await; -} -// ANCHOR_END: main - -async fn hello(name: &str) { - let greeting = format!("Hello, {name}!"); - println!("{greeting}"); -} diff --git a/listings/ch17-async-await/listing-17-03/Cargo.lock b/listings/ch17-async-await/listing-17-03/Cargo.lock index b6971aa2e9..d30b928a6c 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.lock +++ b/listings/ch17-async-await/listing-17-03/Cargo.lock @@ -2,291 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "async_await" version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "tokio-stream" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", - "tokio-stream", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-03/Cargo.toml b/listings/ch17-async-await/listing-17-03/Cargo.toml index 5f2e9ac2d0..67729afc80 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.toml +++ b/listings/ch17-async-await/listing-17-03/Cargo.toml @@ -3,7 +3,4 @@ name = "async_await" version = "0.1.0" edition = "2021" -[dependencies] -trpl = { version = "0.1.0", path = "../../../packages/trpl" } - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch17-async-await/listing-17-03/output.txt b/listings/ch17-async-await/listing-17-03/output.txt index d0d2eb5d91..17922a261c 100644 --- a/listings/ch17-async-await/listing-17-03/output.txt +++ b/listings/ch17-async-await/listing-17-03/output.txt @@ -1,27 +1,10 @@ -cargo run - Compiling proc-macro2 v1.0.85 - Compiling unicode-ident v1.0.12 - Compiling autocfg v1.3.0 - Compiling futures-sink v0.3.30 - Compiling pin-project-lite v0.2.14 - Compiling libc v0.2.155 - Compiling futures-core v0.3.30 - Compiling memchr v2.7.2 - Compiling pin-utils v0.1.0 - Compiling futures-io v0.3.30 - Compiling futures-task v0.3.30 - Compiling futures-channel v0.3.30 - Compiling slab v0.4.9 - Compiling num_cpus v1.16.0 - Compiling tokio v1.38.0 - Compiling quote v1.0.36 - Compiling syn v2.0.66 - Compiling futures-macro v0.3.30 - Compiling futures-util v0.3.30 - Compiling futures-executor v0.3.30 - Compiling futures v0.3.30 - Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-03) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.91s - Running `target/debug/async_await` -Hello, async! \ No newline at end of file +$ cargo run + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-03-fix) +error[E0752]: `main` function is not allowed to be `async` + --> src/main.rs:2:1 + | +2 | async fn main() { + | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` + +For more information about this error, try `rustc --explain E0752`. +error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-03/src/main.rs b/listings/ch17-async-await/listing-17-03/src/main.rs index 6974137d66..443cadcc0e 100644 --- a/listings/ch17-async-await/listing-17-03/src/main.rs +++ b/listings/ch17-async-await/listing-17-03/src/main.rs @@ -1,8 +1,6 @@ // ANCHOR: main -fn main() { - trpl::block_on(async { - hello("async").await; - }); +async fn main() { + hello("async").await; } // ANCHOR_END: main diff --git a/listings/ch17-async-await/listing-17-04/Cargo.lock b/listings/ch17-async-await/listing-17-04/Cargo.lock index 2e0f3ebedb..b6971aa2e9 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.lock +++ b/listings/ch17-async-await/listing-17-04/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -32,9 +32,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -47,9 +47,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.97" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -148,9 +148,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "hermit-abi" @@ -160,9 +160,9 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "memchr" @@ -172,9 +172,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -191,9 +191,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -212,9 +212,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -245,9 +245,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.63" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -256,9 +256,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "num_cpus", diff --git a/listings/ch17-async-await/listing-17-04/Cargo.toml b/listings/ch17-async-await/listing-17-04/Cargo.toml index 349041d3eb..5f2e9ac2d0 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.toml +++ b/listings/ch17-async-await/listing-17-04/Cargo.toml @@ -3,7 +3,7 @@ name = "async_await" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -trpl = { path = "../../../packages/trpl" } +trpl = { version = "0.1.0", path = "../../../packages/trpl" } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch17-async-await/listing-17-04/output.txt b/listings/ch17-async-await/listing-17-04/output.txt new file mode 100644 index 0000000000..d0d2eb5d91 --- /dev/null +++ b/listings/ch17-async-await/listing-17-04/output.txt @@ -0,0 +1,27 @@ +cargo run + Compiling proc-macro2 v1.0.85 + Compiling unicode-ident v1.0.12 + Compiling autocfg v1.3.0 + Compiling futures-sink v0.3.30 + Compiling pin-project-lite v0.2.14 + Compiling libc v0.2.155 + Compiling futures-core v0.3.30 + Compiling memchr v2.7.2 + Compiling pin-utils v0.1.0 + Compiling futures-io v0.3.30 + Compiling futures-task v0.3.30 + Compiling futures-channel v0.3.30 + Compiling slab v0.4.9 + Compiling num_cpus v1.16.0 + Compiling tokio v1.38.0 + Compiling quote v1.0.36 + Compiling syn v2.0.66 + Compiling futures-macro v0.3.30 + Compiling futures-util v0.3.30 + Compiling futures-executor v0.3.30 + Compiling futures v0.3.30 + Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-03) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.91s + Running `target/debug/async_await` +Hello, async! \ No newline at end of file diff --git a/listings/ch17-async-await/listing-17-04/src/main.rs b/listings/ch17-async-await/listing-17-04/src/main.rs index ab559c800f..6974137d66 100644 --- a/listings/ch17-async-await/listing-17-04/src/main.rs +++ b/listings/ch17-async-await/listing-17-04/src/main.rs @@ -1,7 +1,12 @@ +// ANCHOR: main fn main() { - // ANCHOR: block_on trpl::block_on(async { - // our implementation will go here + hello("async").await; }); - // ANCHOR_END: block_on +} +// ANCHOR_END: main + +async fn hello(name: &str) { + let greeting = format!("Hello, {name}!"); + println!("{greeting}"); } diff --git a/listings/ch17-async-await/listing-17-05/src/main.rs b/listings/ch17-async-await/listing-17-05/src/main.rs index 36ddedca26..4af024741e 100644 --- a/listings/ch17-async-await/listing-17-05/src/main.rs +++ b/listings/ch17-async-await/listing-17-05/src/main.rs @@ -2,7 +2,6 @@ use std::time::Duration; fn main() { trpl::block_on(async { - // ANCHOR: task trpl::spawn_task(async { for i in 1..10 { println!("hi number {i} from the first task!"); @@ -14,6 +13,5 @@ fn main() { println!("hi number {i} from the second task!"); trpl::sleep(Duration::from_millis(1)).await; } - // ANCHOR_END: task }); } diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index eed28f8c20..d3e08bc01b 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -108,12 +108,12 @@ Oh no! We have gone from a compiler warning to an actual error: This time, the compiler is informing us we cannot use `.await` in `main`, because `main` is not an `async` function. Your first thought might be to make -`main` an async function then, as in Listing 17-TODO-3. +`main` an async function then, as in Listing 17-3. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-03-fix/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-03/src/main.rs:main}} ``` @@ -121,7 +121,7 @@ because `main` is not an `async` function. Your first thought might be to make However, we get another compiler error here: ```console -{{#include ../listings/ch17-async-await/listing-17-03-fix/output.txt}} +{{#include ../listings/ch17-async-await/listing-17-03/output.txt}} ``` The problem is that async code needs a *runtime*: a Rust crate which manages the @@ -169,10 +169,10 @@ completes. Since `hello` returns a `Future`, we could simply wrap it directly in doing more than just one async function call, so instead we will pass an `async` block and explicitly await the result of calling `hello`. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-03/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:main}} ``` @@ -180,7 +180,7 @@ block and explicitly await the result of calling `hello`. When we run this, we get the behavior we might have expected initially: ```console -{{#include ../listings/ch17-async-await/listing-17-03/output.txt}} +{{#include ../listings/ch17-async-await/listing-17-04/output.txt}} ``` Phew: we finally have some working async code! Now we can turn our attention to diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 4373036419..9470eac86c 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -16,36 +16,30 @@ The first task we tackled in Chapter 16 was counting up on two separate threads. Let’s do the same using async. The `trpl` crate supplies a `spawn_task` function which looks very similar to the `thread::spawn` API, and a `sleep` function which is an async version of the `thread::sleep` API. We can use these together -to implement the same counting example as with threads. +to implement the same counting example as with threads, in Listing 17-5. -Listing 17-4 shows our starting point. We set up our `main` function with `trpl::block_on`, so that our top-level function can be async. + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:block_on}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs}} ``` + + +As our starting point, we set up our `main` function with `trpl::block_on`, so that our top-level function can be async. + > Note: From this point forward in the chapter, every example will include this > exact same wrapping code with `trpl::block_on` in `main`, so we will often > skip it just like we do with `main`. Don’t forget to include it in your > code! -Then we can write two loops within that block, each with a `trpl::sleep` call in -them. Similar to the threading example, we put one loop in the body of a -`trpl::spawn_task`, the same way we did with `thread::spawn`, and the other in a -top-level `for` loop. Notice that we also need to add a `.await` after the -`sleep` calls. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:task}} -``` - - +Then we write two loops within that block, each with a `trpl::sleep` call in it. +We put one loop in the body of a `trpl::spawn_task` and the other in a top-level +`for` loop. We also add an `.await` after the `sleep` calls. -This does something very similar to what the thread-based implementation did, as -we can see from the output when we run it. (As with the threading example, you -may see a different order in your own terminal output when you run this.) +This does something similar to the thread-based implementation—including the +fact that you may see the messages appear in a different order in your own +terminal when you run it. @@ -147,16 +142,15 @@ hi number 9 from the first task! Here, you will see the exact same order every time, which is very different from what we saw with threads. That is because the `trpl::join` function is *fair*, -meaning it checks both futures equally, rather than letting one race ahead. With -threads, the operating system decides which thread to check, and that is -ultimately out of our control. With an async runtime, the runtime itself decides -which future to check, so it has the final say. In practice, the details get -complicated because an async runtime might use operating system threads under -the hood as part of how it manages concurrency, but a runtime can still choose -to guarantee fairness even so. However, runtimes do not have to guarantee -fairness for any given operation, and even within a given runtime, different -APIs sometimes exist to let you choose whether fairness is something you care -about as a caller. +meaning it checks each future equally often, alternating between them, and never +lets one race ahead if the other is ready. With threads, the operating system +decides which thread to check and how long to let it run. With async Rust, the +runtime decides which future to check. (In practice, the details get complicated +because an async runtime might use operating system threads under the hood as +part of how it manages concurrency, so guaranteeing fairness can be more work +for a runtime—but it is still possible!) Runtimes do not have to guarantee +fairness for any given operation, and runtimes often offer different APIs to let +you choose whether you want fairness or not. Try some of these different variations on awaiting the futures and see what they do: From e5c9afd8916c81e1c1796df06f06e029c2ba765d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 2 Jul 2024 16:15:20 -0600 Subject: [PATCH 345/720] =?UTF-8?q?Ch.=2017=C2=A702=20initial=20edits=20on?= =?UTF-8?q?=20'Message=20Passing'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The usual kinds of clarifications, cleaning up redundancies, etc. - Fold together listings: - 8 and 9 → 8 - 10, 11, 12 → 9 - 13 → 10 - 15 → 11 - 16 → 12 - Tweak the durations used for the listings throughout this section, including making the durations *differ* between the two sending blocks in the final example. --- .../ch17-async-await/listing-17-05/Cargo.lock | 12 + .../listing-17-05/src/main.rs | 4 +- .../ch17-async-await/listing-17-06/Cargo.lock | 12 + .../listing-17-06/src/main.rs | 4 +- .../ch17-async-await/listing-17-07/Cargo.lock | 262 +-------- .../listing-17-07/src/main.rs | 4 +- .../ch17-async-await/listing-17-08/Cargo.lock | 12 + .../listing-17-08/src/main.rs | 4 +- .../ch17-async-await/listing-17-09/Cargo.lock | 12 + .../listing-17-09/src/main.rs | 24 +- .../ch17-async-await/listing-17-10/Cargo.lock | 12 + .../listing-17-10/src/main.rs | 37 +- .../ch17-async-await/listing-17-11/Cargo.lock | 12 + .../listing-17-11/src/main.rs | 37 +- .../ch17-async-await/listing-17-12/Cargo.lock | 12 + .../listing-17-12/src/main.rs | 51 +- .../ch17-async-await/listing-17-13/Cargo.lock | 540 ------------------ .../ch17-async-await/listing-17-13/Cargo.toml | 9 - .../listing-17-13/src/main.rs | 33 -- .../ch17-async-await/listing-17-14/Cargo.lock | 540 ------------------ .../ch17-async-await/listing-17-14/Cargo.toml | 9 - .../listing-17-14/src/main.rs | 45 -- .../ch17-async-await/listing-17-15/Cargo.lock | 280 --------- .../ch17-async-await/listing-17-15/Cargo.toml | 9 - .../listing-17-15/src/main.rs | 32 -- .../ch17-async-await/listing-17-16/Cargo.lock | 280 --------- .../ch17-async-await/listing-17-16/Cargo.toml | 9 - .../listing-17-16/src/main.rs | 46 -- src/ch17-02-concurrency-with-async.md | 305 ++++------ 29 files changed, 310 insertions(+), 2338 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-13/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-13/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-13/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-14/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-14/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-14/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-15/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-15/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-15/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-16/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-16/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-16/src/main.rs diff --git a/listings/ch17-async-await/listing-17-05/Cargo.lock b/listings/ch17-async-await/listing-17-05/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-05/Cargo.lock +++ b/listings/ch17-async-await/listing-17-05/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-05/src/main.rs b/listings/ch17-async-await/listing-17-05/src/main.rs index 4af024741e..1a727a9a09 100644 --- a/listings/ch17-async-await/listing-17-05/src/main.rs +++ b/listings/ch17-async-await/listing-17-05/src/main.rs @@ -5,13 +5,13 @@ fn main() { trpl::spawn_task(async { for i in 1..10 { println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; + trpl::sleep(Duration::from_millis(500)).await; } }); for i in 1..5 { println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; + trpl::sleep(Duration::from_millis(500)).await; } }); } diff --git a/listings/ch17-async-await/listing-17-06/Cargo.lock b/listings/ch17-async-await/listing-17-06/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-06/Cargo.lock +++ b/listings/ch17-async-await/listing-17-06/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-06/src/main.rs b/listings/ch17-async-await/listing-17-06/src/main.rs index dbc2241b96..c7e74c8233 100644 --- a/listings/ch17-async-await/listing-17-06/src/main.rs +++ b/listings/ch17-async-await/listing-17-06/src/main.rs @@ -6,13 +6,13 @@ fn main() { let handle = trpl::spawn_task(async { for i in 1..10 { println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; + trpl::sleep(Duration::from_millis(500)).await; } }); for i in 1..5 { println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; + trpl::sleep(Duration::from_millis(500)).await; } handle.await.unwrap(); diff --git a/listings/ch17-async-await/listing-17-07/Cargo.lock b/listings/ch17-async-await/listing-17-07/Cargo.lock index 3be4eaaa53..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-07/Cargo.lock +++ b/listings/ch17-async-await/listing-17-07/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", ] [[package]] -name = "tokio-macros" -version = "2.2.0" +name = "tokio-stream" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ - "proc-macro2", - "quote", - "syn", + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] @@ -386,6 +282,7 @@ version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] @@ -393,148 +290,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-07/src/main.rs b/listings/ch17-async-await/listing-17-07/src/main.rs index 60889f3aed..7f38d5ebdf 100644 --- a/listings/ch17-async-await/listing-17-07/src/main.rs +++ b/listings/ch17-async-await/listing-17-07/src/main.rs @@ -6,14 +6,14 @@ fn main() { let fut1 = async { for i in 1..10 { println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(1)).await; + trpl::sleep(Duration::from_millis(500)).await; } }; let fut2 = async { for i in 1..5 { println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(1)).await; + trpl::sleep(Duration::from_millis(500)).await; } }; diff --git a/listings/ch17-async-await/listing-17-08/Cargo.lock b/listings/ch17-async-await/listing-17-08/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-08/Cargo.lock +++ b/listings/ch17-async-await/listing-17-08/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-08/src/main.rs b/listings/ch17-async-await/listing-17-08/src/main.rs index b7b3eb8b16..bd19c58886 100644 --- a/listings/ch17-async-await/listing-17-08/src/main.rs +++ b/listings/ch17-async-await/listing-17-08/src/main.rs @@ -1,13 +1,13 @@ fn main() { trpl::block_on(async { - // ANCHOR: add-channel + // ANCHOR: channel let (tx, mut rx) = trpl::channel(); - // ANCHOR_END: add-channel let val = String::from("hi"); tx.send(val).unwrap(); let received = rx.recv().await.unwrap(); println!("Got: {received}"); + // ANCHOR_END: channel }); } diff --git a/listings/ch17-async-await/listing-17-09/Cargo.lock b/listings/ch17-async-await/listing-17-09/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-09/Cargo.lock +++ b/listings/ch17-async-await/listing-17-09/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-09/src/main.rs b/listings/ch17-async-await/listing-17-09/src/main.rs index 4d98d199b6..7a96259e29 100644 --- a/listings/ch17-async-await/listing-17-09/src/main.rs +++ b/listings/ch17-async-await/listing-17-09/src/main.rs @@ -1,13 +1,25 @@ +use std::time::Duration; + fn main() { trpl::block_on(async { + // ANCHOR: many-messages let (tx, mut rx) = trpl::channel(); - // ANCHOR: send-and-receive - let val = String::from("hi"); - tx.send(val).unwrap(); + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } - let received = rx.recv().await.unwrap(); - println!("Got: {received}"); - // ANCHOR_END: send-and-receive + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR_END: many-messages }); } diff --git a/listings/ch17-async-await/listing-17-10/Cargo.lock b/listings/ch17-async-await/listing-17-10/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-10/Cargo.lock +++ b/listings/ch17-async-await/listing-17-10/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-10/src/main.rs b/listings/ch17-async-await/listing-17-10/src/main.rs index a9cba44de3..cbcd9ee60b 100644 --- a/listings/ch17-async-await/listing-17-10/src/main.rs +++ b/listings/ch17-async-await/listing-17-10/src/main.rs @@ -1,26 +1,33 @@ -// ANCHOR: many-messages use std::time::Duration; -// ANCHOR_END: many-messages fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); - // ANCHOR: many-messages + // ANCHOR: futures + let tx_fut = async { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - // snip... + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + }; - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; + let rx_fut = async { + // ANCHOR: loop + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR_END: loop + }; - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - // ANCHOR_END: many-messages + trpl::join(tx_fut, rx_fut).await; + // ANCHOR_END: futures }); } diff --git a/listings/ch17-async-await/listing-17-11/Cargo.lock b/listings/ch17-async-await/listing-17-11/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-11/Cargo.lock +++ b/listings/ch17-async-await/listing-17-11/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-11/src/main.rs b/listings/ch17-async-await/listing-17-11/src/main.rs index 529a605276..626999e4f8 100644 --- a/listings/ch17-async-await/listing-17-11/src/main.rs +++ b/listings/ch17-async-await/listing-17-11/src/main.rs @@ -2,24 +2,31 @@ use std::time::Duration; fn main() { trpl::block_on(async { + // ANCHOR: with-move let (tx, mut rx) = trpl::channel(); - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; + let tx_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + }; - // ANCHOR: loop - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR_END: loop + let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; + // ANCHOR_END: with-move }); } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-12/Cargo.lock b/listings/ch17-async-await/listing-17-12/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-12/Cargo.lock +++ b/listings/ch17-async-await/listing-17-12/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-12/src/main.rs b/listings/ch17-async-await/listing-17-12/src/main.rs index cdb982e86c..e51b82ac8a 100644 --- a/listings/ch17-async-await/listing-17-12/src/main.rs +++ b/listings/ch17-async-await/listing-17-12/src/main.rs @@ -1,25 +1,46 @@ -// ANCHOR: all use std::time::Duration; fn main() { trpl::block_on(async { + // ANCHOR: here let (tx, mut rx) = trpl::channel(); - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + }; - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(1500)).await; + } + }; + + trpl::join3(tx1_fut, tx_fut, rx_fut).await; + // ANCHOR_END: here }); } -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-13/Cargo.lock b/listings/ch17-async-await/listing-17-13/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-13/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-13/Cargo.toml b/listings/ch17-async-await/listing-17-13/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-13/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-13/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs deleted file mode 100644 index aeeacc5462..0000000000 --- a/listings/ch17-async-await/listing-17-13/src/main.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - // ANCHOR: futures - let tx_fut = async { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - // ANCHOR: loop - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR_END: loop - }; - - trpl::join(tx_fut, rx_fut).await; - // ANCHOR_END: futures - }); -} diff --git a/listings/ch17-async-await/listing-17-14/Cargo.lock b/listings/ch17-async-await/listing-17-14/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-14/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-14/Cargo.toml b/listings/ch17-async-await/listing-17-14/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-14/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs deleted file mode 100644 index e5d8f86066..0000000000 --- a/listings/ch17-async-await/listing-17-14/src/main.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - let tx_fut = async { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(received) = rx.recv().await { - println!("Got: {received}"); - } - }; - - // ANCHOR: updated - let tx_fut2 = async { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - trpl::join3(tx_fut, tx_fut2, rx_fut).await; - // ANCHOR_END: updated - }); -} diff --git a/listings/ch17-async-await/listing-17-15/Cargo.lock b/listings/ch17-async-await/listing-17-15/Cargo.lock deleted file mode 100644 index c0e8bb2b3f..0000000000 --- a/listings/ch17-async-await/listing-17-15/Cargo.lock +++ /dev/null @@ -1,280 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-15/Cargo.toml b/listings/ch17-async-await/listing-17-15/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-15/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-15/src/main.rs b/listings/ch17-async-await/listing-17-15/src/main.rs deleted file mode 100644 index 652545f09f..0000000000 --- a/listings/ch17-async-await/listing-17-15/src/main.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - // ANCHOR: with-move - let (tx, mut rx) = trpl::channel(); - - let tx_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); - } - }; - - trpl::join(tx_fut, rx_fut).await; - // ANCHOR_END: with-move - }); -} -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-16/Cargo.lock b/listings/ch17-async-await/listing-17-16/Cargo.lock deleted file mode 100644 index c0e8bb2b3f..0000000000 --- a/listings/ch17-async-await/listing-17-16/Cargo.lock +++ /dev/null @@ -1,280 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-16/Cargo.toml b/listings/ch17-async-await/listing-17-16/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-16/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-16/src/main.rs b/listings/ch17-async-await/listing-17-16/src/main.rs deleted file mode 100644 index 4c5e65da9b..0000000000 --- a/listings/ch17-async-await/listing-17-16/src/main.rs +++ /dev/null @@ -1,46 +0,0 @@ -use std::time::Duration; - -fn main() { - trpl::block_on(async { - // ANCHOR: here - let (tx, mut rx) = trpl::channel(); - - let tx1 = tx.clone(); - let tx1_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; - - let tx_fut = async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - }; - - trpl::join3(tx1_fut, tx_fut, rx_fut).await; - // ANCHOR_END: here - }); -} diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 9470eac86c..40b2927e42 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -26,16 +26,18 @@ to implement the same counting example as with threads, in Listing 17-5. -As our starting point, we set up our `main` function with `trpl::block_on`, so that our top-level function can be async. +As our starting point, we set up our `main` function with `trpl::block_on`, so +that our top-level function can be async. > Note: From this point forward in the chapter, every example will include this > exact same wrapping code with `trpl::block_on` in `main`, so we will often > skip it just like we do with `main`. Don’t forget to include it in your > code! -Then we write two loops within that block, each with a `trpl::sleep` call in it. -We put one loop in the body of a `trpl::spawn_task` and the other in a top-level -`for` loop. We also add an `.await` after the `sleep` calls. +Then we write two loops within that block, each with a `trpl::sleep` call in it, +which waits for half a second (500 milliseconds) before sending the next +message. We put one loop in the body of a `trpl::spawn_task` and the other in a +top-level `for` loop. We also add an `.await` after the `sleep` calls. This does something similar to the thread-based implementation—including the fact that you may see the messages appear in a different order in your own @@ -165,52 +167,30 @@ each case *before* running the code! ### Message Passing -Sharing data between futures will look familiar. We can again use async versions -of Rust’s types for message-passing. Instead of `std::sync:mpsc::channel`, we -will use a `tprl::channel`, for example. - -The synchronous `Receiver::recv()` method in `std::mpsc::channel` blocks until -it receives a message. The `trpl::Receiver::recv()` method, by contrast, is an -`async` function. Instead of blocking, it waits until a message is received or -the send side of the channel closes. One other difference with this particular -`recv()` implementation is that it returns an `Option` of the type sent over the -channel instead of a `Result`. - -We can start by introducing an async version of the multiple-producer, -single-consumer channel channel API we used with threads back in Chapter 16. The -API is just a little different here in Listing 17-8: we have a mutable receiver -`rx`. Otherwise, this looks pretty much the same as the thread-based approach. +Sharing data between futures will also be familiar: we will use message passing, +again, but this with async versions of the types and functions. ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:add-channel}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:channel}} ``` -Now we can send messages from the sender to the receiver. Again, the API is just -a little different from the threaded version in Chapter 16, where we needed to -spawn a separate thread to allow the message passing to happen asynchronously. -In the version in Listing 17-9, we opt into async behavior on the receiver side -by using `.await` on the `rx.recv()` call. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-09/src/main.rs:send-and-receive}} -``` - - +We start by using `trpl::channel`, an async version of the multiple-producer, +single-consumer channel API we used with threads back in Chapter 16. The async +version of the API is only a little different: we have a mutable receiver `rx`. +With the channel in place, we can send messages from the sender to the receiver. +Again, the API is just a little different from the threaded version. Instead of +spawning a separate thread, we await the `rx.recv()` call. -The `send` call does not block, since the channel we are sending it into is -unbounded. That was true with our threading example back in Chapter 16, too, -though. However, there is a big difference with the `rx.recv()` calls. The one -back in Chapter 16 blocked the thread it ran on—in that case, the main thread. -This one does not block at all! Instead, once the program hits the `.await` on -the `rx.recv()` call, it hands control back to the runtime, which can go on -scheduling other operations until a message arrives. It might be hard to see -that from this code, though, since the message will arrive right away! +The synchronous `Receiver::recv()` method in `std::mpsc::channel` blocks until +it receives a message. The `trpl::Receiver::recv()` method does not, because it +is async. Instead of blocking, it will return `Poll::Pending` until a message is +received or the send side of the channel closes. By contrast, we do not await +the `send` call, because it does not block. It does not need to, because the +channel we are sending it into is unbounded. > Note: Since this is all wrapped in a `trpl::block_on`, this would effectively > block anything happening outside that. That is the whole point of `block_on`, @@ -218,23 +198,23 @@ that from this code, though, since the message will arrive right away! > transition between sync and async code. However, *within* this block, the > `.await` does not block further operations—as we will see! -Let’s go ahead and send a whole series of messages, and sleep in between them, -as shown in Listing 17-10: +It is hard to see the effect of async in Listing 17-8, though, since the message +will arrive right away! Let’s go ahead and send a whole series of messages, and +sleep in between them, as shown in Listing 17-9: -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:many-messages}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-09/src/main.rs:many-messages}} ``` -This handles sending the messages, but so far we don’t do anything with them, -and the code just silently runs forever. We need to actually *receive* the -messages. In this case, we could do that manually, because we know how many -messages are coming in. In the real world, though, we will generally be waiting -on some *unknown* number of messages. In that case, we need to keep waiting -until we determine that there are no more messages. +In addition to sending the messages, we need to receive them. In this case, we +could do that manually, by just doing `rx.recv().await` four times, because we +know how many messages are coming in. In the real world, though, we will +generally be waiting on some *unknown* number of messages. In that case, we need +to keep waiting until we determine that there are no more messages. That sounds like a good job for a loop! In synchronous code, we might use a `for` loop to process a sequence of items, regardless of how many items are in @@ -242,88 +222,60 @@ the loop. However, Rust does not yet have a way to write a `for` loop over an *asynchronous* series of items. Instead, we need to use a new kind of loop we haven’t seen before, the `while let` conditional loop. A `while let` loop is the loop version of the `if let` construct we saw back in Chapter 6. It continues as -long as the condition it relies on is true. Listing 17-11 shows how we can use -this with `rx.recv` to print all the messages send by the `tx` transmitter. +long as the condition it relies on is true. -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:loop}} -``` - - - -The `rx.recv()` call produces a `Future`. The `Output` of the future is an -`Option` of the message type. While waiting on messages, it will respond with -`Poll::Pending`, so the runtime will pause it until it is time to check it -again. Once a message arrives, it will respond with -`Poll::Ready(Some(message))`. When the channel closes, it will instead respond -with `Poll::Ready(None)`, which we can use to know that it is done. The `while -let` pulls all of this together. If the result of calling `rx.recv().await` is -`Some(message)`, we get access to the message and we can use it in the loop -body, just like we could with `if let`. If the result is `None`, the loop ends. -Every time the loop completes, it hits the await point again, so the runtime -pauses it again until another message arrives. - -With the `while let` loop in place, the code now successfully sends and receives -the messages. Unfortunately, there are still a couple problems. For one thing, -the messages do not arrive at one-second intervals, we see them arrive all at -once, four seconds after we start the program. For another, this program also -never stops! You will need to shut it down using ctrl-c. +The `rx.recv()` call produces a `Future`, which we await. While waiting on +messages to arrive, the future will produce `Poll::Pending`, so the runtime will +pause it until it is time to check it again. Once a message arrives, `rx.recv()` +will respond with `Poll::Ready(Some(message))`. When the channel closes, +`rx.recv()` will respond with `Poll::Ready(None)` to indicate that there are no +more values, and we should stop polling—that is, stop awaiting. + +The `while let` loop pulls all of this together. If the result of calling +`rx.recv().await` is `Some(message)`, we get access to the message and we can +use it in the loop body, just like we could with `if let`. If the result is +`None`, the loop ends. Every time the loop completes, it hits the await point +again, so the runtime pauses it again until another message arrives. + +The code now successfully sends and receives all of the messages. Unfortunately, +there are still a couple problems. For one thing, the messages do not arrive at +half-second intervals. They arrive all at once, two seconds (2,000 milliseconds) +after we start the program. For another, this program also never stops! You will +need to shut it down using ctrl-c. Let’s start by understanding why the messages all come in at once after the full -delay, rather than coming in with delays in between each one. This highlights an -important point about the way that async works in Rust. Within any given async -block, the await points are sequential: each one happens one after another. That -is, after all, one of the big motivations for using this syntax instead of -callbacks, event handlers, or chains of methods: the flow through the program is -much easier to follow, because having the order that `.await` keywords appear in -the *code* is also the order they happen when running the *program*. - -With that in mind, we can see why this code behaves the way it does by looking -at the whole thing all together, in Listing 17-12. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:all}} -``` - - +delay, rather than coming in with delays in between each one. Within a given +async block, the order that `.await` keywords appear in the code is also the +order they happen when running the program. -There is just one async block here, so everything here will proceed linearly. -Every one of the `.await` points for the `trpl::sleep` calls appears before the -`.await` points on the `rx.recv()`, so all the `tx.send` calls happen, -interspersed with all of the `trpl::sleep` calls. Only then does the `while let` -loop get to go through all of the `.await` points on the `recv` calls. +There is only one async block in Listing 17-9, so everything in it runs +linearly. All the `tx.send` calls happen, interspersed with all of the +`trpl::sleep` calls and their associated await points. Only then does the `while +let` loop get to go through any of the `.await` points on the `recv` calls. -To get the behavior we actually want, where the delay happens in between -receiving each message, rather than before receiving any message, we need to -give put the `tx` and `rx` operations in their own async blocks, so the runtime -can execute each of them separately. We also need to tell the runtime to -actually run them using `trpl::join`, just like we did for the counting example -above. Listing 17-13 shows how that looks. +To get the behavior we want, where the sleep delay happens between receiving +each message, we need to put the `tx` and `rx` operations in their own async +blocks. Then the runtime can execute each of them separately using `trpl::join`, +just like in the counting example. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:futures}} ``` -With these changes made, the messages get printed at one-second intervals, -rather than all in a rush after four seconds. +With the updated code in Listing 17-10, the messages get printed at +500-millisecond intervals, rather than all in a rush after two seconds. -The program still never stops running, though. That’s because of the combination -of the `while let` loop and the `trpl::join` call. Let’s consider the way this -loop works: +The program still never stops, because of the way `while let` loop interacts +with `trpl::join`: -* The `trpl::join` future only completes once *both* futures passed to it - have completed. +* The future returned from `trpl::join` only completes once *both* futures + passed to it have completed. * The `tx` future completes once it finishes sleeping after sending the last message in `vals`. * The `rx` future will not complete until the `while let` loop ends. @@ -337,101 +289,70 @@ loop works: * The block cannot end because it is blocked on `trpl::join` completing, which takes us back to the top of this list! -We need to make sure the channel gets closed so that `trpl::join` will complete. -We could manually close `rx` somewhere by calling `rx.close()`, but that does -not make much sense in this case. The idea is that `rx` should keep listening -until `tx` is done sending. Stopping after handling some arbitrary number of -messages would make the program shut down, but it would mean we could miss -messages if the sending side changed. Given that we cannot use `rx.close()`, we -need to make sure that `tx` gets dropped *before* the end of the function. +We could manually close `rx` by calling `rx.close()` somewhere, but that does +not make much sense. Stopping after handling some arbitrary number of messages +would make the program shut down, but we could miss messages. We need some other +way to make sure that `tx` gets dropped *before* the end of the function. -Right now, the async block only borrows `tx`. We can confirm this by adding -another async block which uses `tx`, and using `trpl::join3` to wait for all -three futures to complete: +Right now, the async block where we send the messages only borrows `tx`, but if +we could move `tx` into that async block, it would be dropped once that block +ends. In Chapter 13, we learned how to use the `move` keyword with closures, and +in Chapter 16, we saw that we often need to use move data into closures when +working with threads. The same basic dynamics apply to async blocks, so the +`move` keyword works with async blocks just like it does with closures. -+In Listing 17-11, we change the async block for sending messages an `async move` +block. When we run *this* version of the code, it shuts down gracefully after +the last message is sent. + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:updated}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:with-move}} ``` -Now both blocks borrow `tx`, so they are both able to use it to send messages, -which `rx` can then receive. When we run that code, we see the extra output from -the new `async` block, and the message it sends being received by the -`rx.recv()`. - - - -```text -Got: hi -Got: more -Got: from -Got: messages -Got: the -Got: for -Got: future -Got: you -``` - -As before, we also see that the program does not shut down on its own and -requires a ctrl-c. This little exploration helps -us understand why: it is ultimately about *ownership*. We need to move `tx` into -the async block so that once that block ends, `tx` will be dropped. - -Since we have seen how `async` blocks borrow the items they reference from their -outer scope, we can go ahead and remove the extra block we just added for now, -and switch back from `join3` to `join`. - -The last step here is to figure out how to get ownership of the data instead of -just borrowing it. In Chapter 13, we learned how to use the `move` keyword with -closures, and in Chapter 16, we saw that we often need to use closures marked -with `move` when working with threads. As we have discovered, the same dynamics -apply to async blocks! Hopefully this will make sense if you remember that any -time you write a future, a runtime is ultimately responsible for executing it. -That means that an async block might outlive the function where you write it, -the same way a closure can. When a future takes ownership of the data it -references this way, it needs to move that data into the future—so the `move` -keyword works with async blocks just like it does with closures. - -Thus, we can change the first async block from an `async` block to an `async -move` block, like this: +This async channel is also a multiple-producer channel, so we can call `clone` +on `tx` if we want to send messages from multiple futures. In Listing 17-12, we +clone `tx`, creating `tx1` outside the first async block. We move `tx1` into +that block just as we did before with `tx`. Then, later, we move the original +`tx` into a *new* async block, where we send more messages on a slightly +slower delay. (We happen to put this new async block after the async block +for receiving messages, but it could go before it just as well.) -The result is Listing 17-15, and when we run *this* version of the code, it -shuts down gracefully after the last message is sent. +Both of the async blocks for sending messages need to be `async move` blocks, so +that both `tx` and `tx1` get dropped when those blocks finish. Otherwise we will +end up back in the same infinite loop we started out in. Finally, we switch from +`trpl::join` to `trpl::join3` to handle the additional future. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:with-move}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} ``` -This async channel is also a multiple-producer channel, so we can call `clone` -on `tx` if we want to send messages from multiple futures. For example, we can -make the code from Listing 17-16 work by cloning the `tx` before moving it -into the first async block, moving the original `tx` into the second async -block, and switching back to `join3`. +Now we see all the messages from both sending futures. Because the sending +futures use slightly different delays after sending, the messages are also +received at those different intervals. -+ -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-16/src/main.rs:here}} +```text +received 'hi' +received 'more' +received 'from' +received 'the' +received 'messages' +received 'future' +received 'for' +received 'you' ``` - - -*Both* of these blocks need to be `async move` blocks, or else we will end up -back in the same infinite loop we started out in. With that done, though, we get -all the messages we expected, with little delays between them. Notice that since -each of the sending futures do a one-second delay after sending, the messages -come in right after each other at one-second intervals. The delays are -concurrent, not sequential, just as we would expect. - This is a good start, but it limits us to just a handful of futures: two with `join`, or three with `join3`. Let’s see how we might work with more futures. From 89920d5a52072baab0a576b7a5e687ae42ac2988 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 3 Jul 2024 11:14:16 -0600 Subject: [PATCH 346/720] =?UTF-8?q?Ch.=2017=C2=A703=20Initial=20edits=20on?= =?UTF-8?q?=20opening=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the listings, eliminating them where possible and adding notes about manual regeneration as necessary. Also clean up a *lot* of issues with wording, phrasing, etc.! --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 12 + .../Cargo.toml | 0 .../output.txt | 17 +- .../src/main.rs | 0 .../Cargo.lock | 12 + .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../output.txt | 0 .../src/main.rs | 0 .../ch17-async-await/listing-17-19/Cargo.lock | 7 - .../ch17-async-await/listing-17-19/Cargo.toml | 6 - .../ch17-async-await/listing-17-19/output.txt | 10 - .../listing-17-19/src/main.rs | 7 - src/ch17-03-more-futures.md | 261 ++++++++++++------ 19 files changed, 206 insertions(+), 126 deletions(-) rename listings/ch17-async-await/{listing-17-17 => listing-17-13}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-17 => listing-17-13}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-17 => listing-17-13}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-20 => listing-17-14}/Cargo.lock (96%) rename listings/ch17-async-await/{listing-17-18 => listing-17-14}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-18 => listing-17-14}/output.txt (87%) rename listings/ch17-async-await/{listing-17-18 => listing-17-14}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-21 => listing-17-15}/Cargo.lock (96%) rename listings/ch17-async-await/{listing-17-20 => listing-17-15}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-20 => listing-17-15}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-18 => listing-17-16}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-21 => listing-17-16}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-21 => listing-17-16}/output.txt (100%) rename listings/ch17-async-await/{listing-17-21 => listing-17-16}/src/main.rs (100%) delete mode 100644 listings/ch17-async-await/listing-17-19/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-19/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-19/output.txt delete mode 100644 listings/ch17-async-await/listing-17-19/src/main.rs diff --git a/listings/ch17-async-await/listing-17-17/Cargo.lock b/listings/ch17-async-await/listing-17-13/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-17/Cargo.lock rename to listings/ch17-async-await/listing-17-13/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-17/Cargo.toml b/listings/ch17-async-await/listing-17-13/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-17/Cargo.toml rename to listings/ch17-async-await/listing-17-13/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-17/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-17/src/main.rs rename to listings/ch17-async-await/listing-17-13/src/main.rs diff --git a/listings/ch17-async-await/listing-17-20/Cargo.lock b/listings/ch17-async-await/listing-17-14/Cargo.lock similarity index 96% rename from listings/ch17-async-await/listing-17-20/Cargo.lock rename to listings/ch17-async-await/listing-17-14/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-20/Cargo.lock +++ b/listings/ch17-async-await/listing-17-14/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-18/Cargo.toml b/listings/ch17-async-await/listing-17-14/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-18/Cargo.toml rename to listings/ch17-async-await/listing-17-14/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-18/output.txt b/listings/ch17-async-await/listing-17-14/output.txt similarity index 87% rename from listings/ch17-async-await/listing-17-18/output.txt rename to listings/ch17-async-await/listing-17-14/output.txt index 4ad945623f..365d1f0145 100644 --- a/listings/ch17-async-await/listing-17-18/output.txt +++ b/listings/ch17-async-await/listing-17-14/output.txt @@ -1,14 +1,15 @@ $ cargo run + Updating crates.io index Compiling proc-macro2 v1.0.82 Compiling unicode-ident v1.0.12 Compiling autocfg v1.3.0 - Compiling futures-core v0.3.30 + Compiling pin-project-lite v0.2.14 Compiling libc v0.2.154 + Compiling futures-core v0.3.30 Compiling futures-sink v0.3.30 - Compiling pin-project-lite v0.2.14 - Compiling pin-utils v0.1.0 - Compiling futures-io v0.3.30 Compiling futures-task v0.3.30 + Compiling futures-io v0.3.30 + Compiling pin-utils v0.1.0 Compiling memchr v2.7.2 Compiling futures-channel v0.3.30 Compiling slab v0.4.9 @@ -16,12 +17,13 @@ $ cargo run Compiling quote v1.0.36 Compiling tokio v1.37.0 Compiling syn v2.0.63 + Compiling tokio-stream v0.1.15 Compiling futures-macro v0.3.30 Compiling futures-util v0.3.30 Compiling futures-executor v0.3.30 Compiling futures v0.3.30 Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-18) + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-14) error[E0308]: mismatched types --> src/main.rs:43:37 | @@ -48,6 +50,5 @@ error[E0308]: mismatched types | = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` found `async` block `{async block@src/main.rs:22:22: 26:10}` - -For more information about this error, try `rustc --explain E0308`. -error: could not compile `async_await` (bin "async_await") due to 1 previous error + = note: no two async blocks, even if identical, have the same type + = help: consider pinning your async block and and casting it to a trait object diff --git a/listings/ch17-async-await/listing-17-18/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-18/src/main.rs rename to listings/ch17-async-await/listing-17-14/src/main.rs diff --git a/listings/ch17-async-await/listing-17-21/Cargo.lock b/listings/ch17-async-await/listing-17-15/Cargo.lock similarity index 96% rename from listings/ch17-async-await/listing-17-21/Cargo.lock rename to listings/ch17-async-await/listing-17-15/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-21/Cargo.lock +++ b/listings/ch17-async-await/listing-17-15/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-20/Cargo.toml b/listings/ch17-async-await/listing-17-15/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-20/Cargo.toml rename to listings/ch17-async-await/listing-17-15/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-20/src/main.rs b/listings/ch17-async-await/listing-17-15/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-20/src/main.rs rename to listings/ch17-async-await/listing-17-15/src/main.rs diff --git a/listings/ch17-async-await/listing-17-18/Cargo.lock b/listings/ch17-async-await/listing-17-16/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-18/Cargo.lock rename to listings/ch17-async-await/listing-17-16/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-21/Cargo.toml b/listings/ch17-async-await/listing-17-16/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-21/Cargo.toml rename to listings/ch17-async-await/listing-17-16/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-21/output.txt b/listings/ch17-async-await/listing-17-16/output.txt similarity index 100% rename from listings/ch17-async-await/listing-17-21/output.txt rename to listings/ch17-async-await/listing-17-16/output.txt diff --git a/listings/ch17-async-await/listing-17-21/src/main.rs b/listings/ch17-async-await/listing-17-16/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-21/src/main.rs rename to listings/ch17-async-await/listing-17-16/src/main.rs diff --git a/listings/ch17-async-await/listing-17-19/Cargo.lock b/listings/ch17-async-await/listing-17-19/Cargo.lock deleted file mode 100644 index d30b928a6c..0000000000 --- a/listings/ch17-async-await/listing-17-19/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "async_await" -version = "0.1.0" diff --git a/listings/ch17-async-await/listing-17-19/Cargo.toml b/listings/ch17-async-await/listing-17-19/Cargo.toml deleted file mode 100644 index 67729afc80..0000000000 --- a/listings/ch17-async-await/listing-17-19/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch17-async-await/listing-17-19/output.txt b/listings/ch17-async-await/listing-17-19/output.txt deleted file mode 100644 index 5b7dc951b7..0000000000 --- a/listings/ch17-async-await/listing-17-19/output.txt +++ /dev/null @@ -1,10 +0,0 @@ -$ cargo build - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/no-listing-type-mismatch) -error[E0308]: mismatched types - --> src/main.rs:5:24 - | -5 | let vals = vec![a, b]; - | ^ expected integer, found `&str` - -For more information about this error, try `rustc --explain E0308`. -error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-19/src/main.rs b/listings/ch17-async-await/listing-17-19/src/main.rs deleted file mode 100644 index 0c282f4f87..0000000000 --- a/listings/ch17-async-await/listing-17-19/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - // ANCHOR: here - let a = 1; - let b = "Hello"; - let vals = vec![a, b]; - // ANCHOR_END: here -} diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 08144b647c..7057e02cb2 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -4,148 +4,233 @@ When we switched from using two futures to three in the previous section, we also had to switch from using `join` to using `join3`. It would be annoying to do this every time we changed our code. Happily, we have a macro form of `join` to which we can pass an arbitrary number of arguments. It also handles awaiting -the futures itself. Thus, we could rewrite the code from Listing 17-16 to use -`join!` instead of `join3`, as in Listing 17-17: +the futures itself. Thus, we could rewrite the code from Listing 17-12 to use +`join!` instead of `join3`, as in Listing 17-13: -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-17/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:here}} ``` This is definitely a nice improvement over needing to swap between `join` and -`join3` and `join4` and so on! However, both the function nor macro forms of -`join` only work for cases where we know the number of futures ahead of time. If -instead we have a dynamic number of futures, we need a function which works with -a collection type which can grow and shrink dynamically at runtime, such as a -vector. In real-world Rust, pushing futures into a collection and then waiting -on some or all the futures in that collection to complete is a very common -pattern. +`join3` and `join4` and so on! However, even this macro form only works when we +know the number of futures ahead of time. In real-world Rust, though, pushing +futures into a collection and then waiting on some or all the futures in that +collection to complete is a very common pattern. -The `trpl::join_all` function accepts any type which implements the `Iterator` -trait, which we learned about back in Chapter 13, so it seems like just the -ticket. Let’s try putting our futures in a vector, and replace `join3` with -`join_all`. +To check all the futures in some collection, we will need to iterate over and +join on *all* of them. The `trpl::join_all` function accepts any type which +implements the `Iterator` trait, which we learned about back in Chapter 13, so +it seems like just the ticket. Let’s try putting our futures in a vector, and +replace `join3` with `join_all`. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-18/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} ``` Unfortunately, this does not compile. Instead, we get this error: -```text -{{#include ../listings/ch17-async-await/listing-17-18/output.txt}} -``` + -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} -``` - + -The output there would be: +> Note: Beta readers, the error version shown here is landing in Rust 1.81.0! +> If you are using an earlier version, you will see a *much* less helpful error +> message here. We fixed it as part of writing this chapter! ```text -{{#include ../listings/ch17-async-await/listing-17-19/output.txt}} +error[E0308]: mismatched types + --> src/main.rs:43:37 + | +8 | let tx1_fut = async move { + | _______________________- +9 | | let vals = vec![ +10 | | String::from("hi"), +11 | | String::from("from"), +... | +19 | | } +20 | | }; + | |_________- the expected `async` block +21 | +22 | let rx_fut = async { + | ______________________- +23 | | while let Some(value) = rx.recv().await { +24 | | println!("received '{value}'"); +25 | | } +26 | | }; + | |_________- the found `async` block +... +43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; + | ^^^^^^ expected `async` block, found a different `async` block + | + = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` + found `async` block `{async block@src/main.rs:22:22: 26:10}` + = note: no two async blocks, even if identical, have the same type + = help: consider pinning your async block and and casting it to a trait object ``` -Saying “expected *something*, found *something else*” is Rust’s standard format -for telling us about a type mismatch. As we saw with vectors in [“Using an Enum -to Store Multiple Types”][collections] back in Chapter 8, we need the type of -each item in a collection to be the same—and `tx1_fut`, `rx_fut`, and `tx_fut` -do not have the same type. - -The underlying issue here is what we learned in the previous section: async -blocks compile to anonymous futures. Under the hood, there is a data structure -corresponding to each of these blocks, and it has its own unique type. This -might be surprising. After all, none of them returns anything, so the `Future` -type in each case is `Future`. However, `Future` is a trait, not a -concrete type. The actual types here are invisible from our point of view as the -person writing the code. - -In Chapter 8, we discussed one way to include multiple types in a single vector: -using an enum to represent each of the different types which can appear in the -vector. We cannot do that here, though. For one thing, we do not even have a way -to name the different types, because they are anonymous. For another, the reason -we reached for a vector and `join_all` in the first place was to be able to work -with a dynamic collection of futures where we do not know what they will all be -until runtime. - -To make this work, we need to use *trait objects*, just as we did for returning -different kinds of errors from the same function in [“Returning Errors from the -run function”][dyn] back in Chapter 12. Again, we will cover trait objects in -detail in Chapter 17. Here, it lets us treat each of the anonymous futures -produced by these types as interchangeable, since all of them by definition +This might be surprising. After all, none of them returns anything, so each +block produces a `Future`. However, `Future` is a trait, not a +concrete type. The concrete types are the individual data structures generated +by the compiler for async blocks. You cannot put two different hand-written +structs in a `Vec`, and the same thing applies to the different structs +generated by the compiler. + +To make this work, we need to use *trait objects*, just as we did in [“Returning +Errors from the run function”][dyn] in Chapter 12. (We will cover trait objects +in detail in Chapter 18.) Using trait objects lets us treat each of the +anonymous futures produced by these types as the same type, since all of them implement the `Future` trait. -We can start by wrapping each of the futures in the `vec!` in a `Box::new()`. -Unfortunately, the initial way we might try this, as shown in Listing 17-20, -still does not compile. +> Note: In Chapter 8, we discussed another way to include multiple types in a +> `Vec`: using an enum to represent each of the different types which can +> appear in the vector. We cannot do that here, though. For one thing, we have +> no way to name the different types, because they are anonymous. For another, +> the reason we reached for a vector and `join_all` in the first place was to be +> able to work with a dynamic collection of futures where we do not know what +> they will all be until runtime. -+We start by wrapping each of the futures in the `vec!` in a `Box::new()`, as +shown in Listing 17-15. + + ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} ``` -In fact, we have the same basic error we did before, but we get one for both the -second and third `Box::new` calls, and we also get new errors referring to the -`Unpin` trait. - -We can start by fixing the type error around the `Box::new` calls, by telling -the compiler explicitly that we want to use these types as trait objects. The -clearest way to do that here is by adding a type annotation to the declaration -of `futures`, as we see in Listing 17-21. The type we have to write here is a -little involved, so let’s walk through each part of it. +Unfortunately, this still does not compile. In fact, we have the same basic +error we did before, but we get one for both the second and third `Box::new` +calls, and we also get new errors referring to the `Unpin` trait. We will come +back to the `Unpin` errors in a moment. First, let’s fix the type errors on the +`Box::new` calls, by explicitly providing the type of `futures` as a trait +object (Listing 17-16). -- The innermost type is the future itself. We note explicitly that it the output - of the future is the unit type `()` by writing `Future`. -- Then we annotate the trait with `dyn` to mark it as dynamic. -- The entire trait is wrapped in a `Box`. -- Finally, we state explicitly that `futures` is a `Vec` containing these items. - -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-16/src/main.rs:here}} ``` +The type we had to write here is a little involved, so let’s walk through it: + +* The innermost type is the future itself. We note explicitly that it the output + of the future is the unit type `()` by writing `Future`. +* Then we annotate the trait with `dyn` to mark it as dynamic. +* The entire trait is wrapped in a `Box`. +* Finally, we state explicitly that `futures` is a `Vec` containing these items. + That already made a big difference. Now when we run the compiler, we only have the errors mentioning `Unpin`. Although there are three of them, notice that each is very similar in its contents. -```console -{{#include ../listings/ch17-async-await/listing-17-21/output.txt}} + + +```text +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:24 + | +46 | trpl::join_all(futures).await; + | -------------- ^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + | | + | required by a bound introduced by this call + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` +note: required by a bound in `join_all` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 + | +102 | pub fn join_all(iter: I) -> JoinAll + | -------- required by a bound in this function +... +105 | I::Item: Future, + | ^^^^^^ required by this bound in `join_all` + +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:9 + | +46 | trpl::join_all(futures).await; + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` +note: required by a bound in `JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` + +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:33 + | +46 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` +note: required by a bound in `JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. ``` That is a *lot* to digest, so let’s pull it apart. The first part of the message tell us that the first async block (`src/main.rs:8:23: 20:10`) does not implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve it. The rest of the message tells us *why* that is required: the `JoinAll` -struct, which is itself a `Future`, is also generic over a `Future`, and -`Future` itself requires the `Unpin` trait. Understanding this error means we -need to dive into a little more of how the `Future` type actually works, in -particular the idea of *pinning*. +struct returned by `trpl::join_all` is generic over a type `F` which must +implement the `Future` trait, directly awaiting a Future requires that the +future implement the `Unpin` trait. Understanding this error means we need to +dive into a little more of how the `Future` type actually works, in particular +the idea of *pinning*. ### Pinning and the Pin and Unpin Traits From 655526a90472b1d1fd29bb0b46983603cd7131eb Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 5 Jul 2024 13:25:47 -0400 Subject: [PATCH 347/720] Upgrade to Rust 1.79.0 --- .github/workflows/main.yml | 8 ++++---- .../listing-02-04/output.txt | 2 +- .../output.txt | 4 ++-- .../output.txt | 4 ++-- .../listing-10-20/output.txt | 20 +------------------ .../listing-11-03/src/lib.rs | 2 +- .../no-listing-04-bug-in-add-two/output.txt | 1 + .../listing-13-04/output.txt | 2 ++ .../listing-13-05/output.txt | 2 ++ .../listing-13-08/output.txt | 5 +++++ .../listing-15-21/output.txt | 10 +++++++--- .../listing-16-09/output.txt | 4 ---- .../listing-16-13/output.txt | 10 ++++++++++ .../listing-16-14/output.txt | 2 +- .../listing-19-05/output.txt | 2 ++ .../ch20-web-server/listing-20-17/output.txt | 6 ++++++ .../ch20-web-server/listing-20-22/output.txt | 2 +- .../output.txt | 2 +- rust-toolchain | 2 +- src/title-page.md | 2 +- 20 files changed, 51 insertions(+), 41 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 69ec7ef21c..77495c09aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.78 -c rust-docs - rustup default 1.78 + rustup toolchain install 1.79 -c rust-docs + rustup default 1.79 - name: Install mdbook run: | mkdir bin @@ -36,8 +36,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.76 -c rust-docs - rustup default 1.76 + rustup toolchain install 1.79 -c rust-docs + rustup default 1.79 - name: Run `tools` package tests run: | cargo test diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 4a36350c20..bb997866a2 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,7 +18,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/cmp.rs:836:8 + --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/cmp.rs:840: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/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt index fa202e6212..dde05f4b3b 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt +++ b/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>> + > + 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/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 7d9a661963..5232f90378 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/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/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:572:1 - ::: /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:576:5 + --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/option.rs:571:1 + ::: /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/option.rs:575:5 | = note: not covered = note: the matched value is of type `Option` diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt index 1af8bd5f1b..a6783b2ccd 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt @@ -12,23 +12,5 @@ help: consider introducing a named lifetime parameter 9 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { | ++++ ++ ++ ++ -error: lifetime may not live long enough - --> src/main.rs:11:9 - | -9 | fn longest(x: &str, y: &str) -> &str { - | - let's call the lifetime of this reference `'1` -10 | if x.len() > y.len() { -11 | x - | ^ returning this value requires that `'1` must outlive `'static` - -error: lifetime may not live long enough - --> src/main.rs:13:9 - | -9 | fn longest(x: &str, y: &str) -> &str { - | - let's call the lifetime of this reference `'2` -... -13 | y - | ^ returning this value requires that `'2` must outlive `'static` - For more information about this error, try `rustc --explain E0106`. -error: could not compile `chapter10` (bin "chapter10") due to 3 previous errors +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs index 67b6552c71..0db269085f 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs @@ -12,7 +12,7 @@ mod tests { let result = add(2, 2); assert_eq!(result, 4); } - + #[test] fn another() { panic!("Make this test fail"); diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt index 01b58572bd..eb925aa9b9 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt @@ -9,6 +9,7 @@ test tests::it_adds_two ... FAILED failures: ---- tests::it_adds_two stdout ---- +thread 'tests::it_adds_two' panicked at src/lib.rs:11:9: assertion `left == right` failed left: 5 right: 4 diff --git a/listings/ch13-functional-features/listing-13-04/output.txt b/listings/ch13-functional-features/listing-13-04/output.txt index fd33cb71fe..b04a1a36c2 100644 --- a/listings/ch13-functional-features/listing-13-04/output.txt +++ b/listings/ch13-functional-features/listing-13-04/output.txt @@ -1,4 +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) 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/listings/ch13-functional-features/listing-13-05/output.txt b/listings/ch13-functional-features/listing-13-05/output.txt index af22182a18..1fddf5a982 100644 --- a/listings/ch13-functional-features/listing-13-05/output.txt +++ b/listings/ch13-functional-features/listing-13-05/output.txt @@ -1,4 +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) 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/listings/ch13-functional-features/listing-13-08/output.txt b/listings/ch13-functional-features/listing-13-08/output.txt index 7f5ce888d6..979868dc39 100644 --- a/listings/ch13-functional-features/listing-13-08/output.txt +++ b/listings/ch13-functional-features/listing-13-08/output.txt @@ -10,6 +10,11 @@ error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` clos | --- captured by this `FnMut` closure 18 | sort_operations.push(value); | ^^^^^ move occurs because `value` has type `String`, which does not implement the `Copy` trait + | +help: consider cloning the value if the performance cost is acceptable + | +18 | sort_operations.push(value.clone()); + | ++++++++ For more information about this error, try `rustc --explain E0507`. error: could not compile `rectangles` (bin "rectangles") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-21/output.txt b/listings/ch15-smart-pointers/listing-15-21/output.txt index 3f00da3607..3509e8ec62 100644 --- a/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/listings/ch15-smart-pointers/listing-15-21/output.txt @@ -6,10 +6,14 @@ error[E0596]: cannot borrow `self.sent_messages` as mutable, as it is behind a ` 58 | self.sent_messages.push(String::from(message)); | ^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable | -help: consider changing this to be a mutable reference +help: consider changing this to be a mutable reference in the `impl` method and the `trait` definition + | +2 ~ fn send(&mut self, msg: &str); +3 | } + ... +56 | impl Messenger for MockMessenger { +57 ~ fn send(&mut self, message: &str) { | -2 | fn send(&mut self, msg: &str); - | ~~~~~~~~~ For more information about this error, try `rustc --explain E0596`. error: could not compile `limit-tracker` (lib test) due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-09/output.txt b/listings/ch16-fearless-concurrency/listing-16-09/output.txt index ed4797f165..2e95105fef 100644 --- a/listings/ch16-fearless-concurrency/listing-16-09/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-09/output.txt @@ -11,10 +11,6 @@ error[E0382]: borrow of moved value: `val` | ^^^^^ value borrowed here after move | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider cloning the value if the performance cost is acceptable - | -9 | tx.send(val.clone()).unwrap(); - | ++++++++ For more information about this error, try `rustc --explain E0382`. error: could not compile `message-passing` (bin "message-passing") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-13/output.txt b/listings/ch16-fearless-concurrency/listing-16-13/output.txt index 5405f76bcf..a4db0dcc3f 100644 --- a/listings/ch16-fearless-concurrency/listing-16-13/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-13/output.txt @@ -6,11 +6,21 @@ error[E0382]: borrow of moved value: `counter` 5 | let counter = Mutex::new(0); | ------- move occurs because `counter` has type `Mutex`, which does not implement the `Copy` trait ... +8 | for _ in 0..10 { + | -------------- inside of this loop 9 | let handle = thread::spawn(move || { | ------- value moved into closure here, in previous iteration of loop ... 21 | println!("Result: {}", *counter.lock().unwrap()); | ^^^^^^^ value borrowed here after move + | +help: consider moving the expression out of the loop so it is only moved once + | +8 ~ let mut value = counter.lock(); +9 ~ for _ in 0..10 { +10 | let handle = thread::spawn(move || { +11 ~ let mut num = value.unwrap(); + | For more information about this error, try `rustc --explain E0382`. error: could not compile `shared-state` (bin "shared-state") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index 011e662c01..cb4167a5b8 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/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/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/thread/mod.rs:677:1 + --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/thread/mod.rs:691: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/listings/ch19-advanced-features/listing-19-05/output.txt b/listings/ch19-advanced-features/listing-19-05/output.txt index 44bcc09135..514e25331c 100644 --- a/listings/ch19-advanced-features/listing-19-05/output.txt +++ b/listings/ch19-advanced-features/listing-19-05/output.txt @@ -12,6 +12,8 @@ error[E0499]: cannot borrow `*values` as mutable more than once at a time | | | second mutable borrow occurs here | | first mutable borrow occurs here | returning this value requires that `*values` is borrowed for `'1` + | + = help: use `.split_at_mut(position)` to obtain two mutable non-overlapping sub-slices For more information about this error, try `rustc --explain E0499`. error: could not compile `unsafe-example` (bin "unsafe-example") due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-17/output.txt b/listings/ch20-web-server/listing-20-17/output.txt index cd06ca1b60..2768265514 100644 --- a/listings/ch20-web-server/listing-20-17/output.txt +++ b/listings/ch20-web-server/listing-20-17/output.txt @@ -16,6 +16,12 @@ note: consider changing this parameter type in method `new` to borrow instead if | 47 | fn new(id: usize, receiver: mpsc::Receiver) -> Worker { | --- in this method ^^^^^^^^^^^^^^^^^^^ this parameter takes ownership of the value +help: consider moving the expression out of the loop so it is only moved once + | +25 ~ let mut value = Worker::new(id, receiver); +26 ~ for id in 0..size { +27 ~ workers.push(value); + | For more information about this error, try `rustc --explain E0382`. error: could not compile `hello` (lib) due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 08a28cc323..84ebe928b0 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/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/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/thread/mod.rs:1657:17 + --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/thread/mod.rs:1718: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/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index ed97073266..1ffe5206b1 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/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/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/thread/mod.rs:1657:5 + --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/thread/mod.rs:1718: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/rust-toolchain b/rust-toolchain index 8e95c75dac..17420a571f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.78 +1.79 diff --git a/src/title-page.md b/src/title-page.md index 44741589bc..dee3c84cb8 100644 --- a/src/title-page.md +++ b/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.78.0 (released 2024-05-02) +This version of the text assumes you’re using Rust 1.79.0 (released 2024-06-13) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From 8c59066d9c589e56e991644e40ddaaf5062f2509 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 31 May 2024 16:37:44 -0400 Subject: [PATCH 348/720] Backport changes to chapter 11 --- src/ch11-00-testing.md | 11 ++++---- src/ch11-01-writing-tests.md | 32 +++++++++++------------ src/ch11-02-running-tests.md | 26 +++++++++---------- src/ch11-03-test-organization.md | 44 +++++++++++++++----------------- 4 files changed, 55 insertions(+), 58 deletions(-) diff --git a/src/ch11-00-testing.md b/src/ch11-00-testing.md index 7f11ec1494..ea85a14101 100644 --- a/src/ch11-00-testing.md +++ b/src/ch11-00-testing.md @@ -25,8 +25,9 @@ We can write tests that assert, for example, that when we pass `3` to the we make changes to our code to make sure any existing correct behavior has not changed. -Testing is a complex skill: although we can’t cover every detail about how to -write good tests in one chapter, we’ll discuss the mechanics of Rust’s testing -facilities. We’ll talk about the annotations and macros available to you when -writing your tests, the default behavior and options provided for running your -tests, and how to organize tests into unit tests and integration tests. +Testing is a complex skill: although we can’t cover in one chapter every detail +about how to write good tests, in this chapter we will discuss the mechanics of +Rust’s testing facilities. We’ll talk about the annotations and macros +available to you when writing your tests, the default behavior and options +provided for running your tests, and how to organize tests into unit tests and +integration tests. diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index 03bf244c69..12baf6f49b 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -4,9 +4,9 @@ Tests are Rust functions that verify that the non-test code is functioning in the expected manner. The bodies of test functions typically perform these three actions: -1. Set up any needed data or state. -2. Run the code you want to test. -3. Assert the results are what you expect. +* Set up any needed data or state. +* Run the code you want to test. +* Assert that the results are what you expect. Let’s look at the features Rust provides specifically for writing tests that take these actions, which include the `test` attribute, a few macros, and the @@ -19,8 +19,8 @@ attribute. Attributes are metadata about pieces of Rust code; one example is the `derive` attribute we used with structs in Chapter 5. To change a function into a test function, add `#[test]` on the line before `fn`. When you run your tests with the `cargo test` command, Rust builds a test runner binary that runs -the annotated functions and reports on whether each -test function passes or fails. +the annotated functions and reports on whether each test function passes or +fails. Whenever we make a new library project with Cargo, a test module with a test function in it is automatically generated for us. This module gives you a @@ -61,9 +61,9 @@ cd ../../.. -For now, let’s focus solely on the `it_works()` function. Note the -`#[test]` annotation: this attribute indicates this is a test function, so the -test runner knows to treat this function as a test. We might also have non-test +For now, let’s focus solely on the `it_works` function. Note the `#[test]` +annotation: this attribute indicates this is a test function, so the test +runner knows to treat this function as a test. We might also have non-test functions in the `tests` module to help set up common scenarios or perform common operations, so we always need to indicate which functions are tests. @@ -95,7 +95,7 @@ Requested”][ignoring] section later in this chapter. Because we haven’t done that here, the summary shows `0 ignored`. We can also pass an argument to the `cargo test` command to run only tests whose name matches a string; this is called *filtering* and we’ll cover that in the [“Running a -Subset of Tests by Name”][subset] section. We also haven’t +Subset of Tests by Name”][subset] section. Here we haven’t filtered the tests being run, so the end of the summary shows `0 filtered out`. The `0 measured` statistic is for benchmark tests that measure performance. @@ -110,7 +110,7 @@ write documentation tests in the [“Documentation Comments as Tests”][doc-comments] section of Chapter 14. For now, we’ll ignore the `Doc-tests` output. -Let’s start to customize the test to our own needs. First change the name of +Let’s start to customize the test to our own needs. First, change the name of the `it_works` function to a different name, such as `exploration`, like so: Filename: src/lib.rs @@ -210,7 +210,7 @@ we covered in Chapter 7 in the [“Paths for Referring to an Item in the Module Tree”][paths-for-referring-to-an-item-in-the-module-tree] section. Because the `tests` module is an inner module, we need to bring the code under test in the outer module into the scope of the inner module. We use -a glob here so anything we define in the outer module is available to this +a glob here, so anything we define in the outer module is available to this `tests` module. We’ve named our test `larger_can_hold_smaller`, and we’ve created the two @@ -254,16 +254,16 @@ Running the tests now produces the following: {{#include ../listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt}} ``` -Our tests caught the bug! Because `larger.width` is 8 and `smaller.width` is -5, the comparison of the widths in `can_hold` now returns `false`: 8 is not +Our tests caught the bug! Because `larger.width` is `8` and `smaller.width` is +`5`, the comparison of the widths in `can_hold` now returns `false`: 8 is not less than 5. ### Testing Equality with the `assert_eq!` and `assert_ne!` Macros A common way to verify functionality is to test for equality between the result of the code under test and the value you expect the code to return. You could -do this using the `assert!` macro and passing it an expression using the `==` -operator. However, this is such a common test that the standard library +do this by using the `assert!` macro and passing it an expression using the +`==` operator. However, this is such a common test that the standard library provides a pair of macros—`assert_eq!` and `assert_ne!`—to perform this test more conveniently. These macros compare two arguments for equality or inequality, respectively. They’ll also print the two values if the assertion @@ -471,7 +471,7 @@ This test will pass because the value we put in the `should_panic` attribute’s `expected` parameter is a substring of the message that the `Guess::new` function panics with. We could have specified the entire panic message that we expect, which in this case would be `Guess value must be less than or equal to -100, got 200.` What you choose to specify depends on how much of the panic +100, got 200`. What you choose to specify depends on how much of the panic message is unique or dynamic and how precise you want your test to be. In this case, a substring of the panic message is enough to ensure that the code in the test function executes the `else if value > 100` case. diff --git a/src/ch11-02-running-tests.md b/src/ch11-02-running-tests.md index 6445826eff..053c1a88ec 100644 --- a/src/ch11-02-running-tests.md +++ b/src/ch11-02-running-tests.md @@ -1,14 +1,14 @@ ## Controlling How Tests Are Run -Just as `cargo run` compiles your code and then runs the resulting binary, -`cargo test` compiles your code in test mode and runs the resulting test +Just as `cargo run` compiles your code and then runs the resultant binary, +`cargo test` compiles your code in test mode and runs the resultant test binary. The default behavior of the binary produced by `cargo test` is to run all the tests in parallel and capture output generated during test runs, preventing the output from being displayed and making it easier to read the output related to the test results. You can, however, specify command line options to change this default behavior. -Some command line options go to `cargo test`, and some go to the resulting test +Some command line options go to `cargo test`, and some go to the resultant test binary. To separate these two types of arguments, you list the arguments that go to `cargo test` followed by the separator `--` and then the ones that go to the test binary. Running `cargo test --help` displays the options you can use @@ -72,13 +72,13 @@ When we run these tests with `cargo test`, we’ll see the following output: {{#include ../listings/ch11-writing-automated-tests/listing-11-10/output.txt}} ``` -Note that nowhere in this output do we see `I got the value 4`, which is what -is printed when the test that passes runs. That output has been captured. The +Note that nowhere in this output do we see `I got the value 4`, which is +printed when the test that passes runs. That output has been captured. The output from the test that failed, `I got the value 8`, appears in the section of the test summary output, which also shows the cause of the test failure. -If we want to see printed values for passing tests as well, we can tell Rust -to also show the output of successful tests with `--show-output`. +If we want to see printed values for passing tests as well, we can tell Rust to +also show the output of successful tests with `--show-output`: ```console $ cargo test -- --show-output @@ -160,8 +160,8 @@ here: {{#rustdoc_include ../listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/src/lib.rs}} ``` -After `#[test]` we add the `#[ignore]` line to the test we want to exclude. Now -when we run our tests, `it_works` runs, but `expensive_test` doesn’t: +After `#[test]`, we add the `#[ignore]` line to the test we want to exclude. +Now when we run our tests, `it_works` runs, but `expensive_test` doesn’t: ```console {{#include ../listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt}} @@ -175,7 +175,7 @@ the ignored tests, we can use `cargo test -- --ignored`: ``` By controlling which tests run, you can make sure your `cargo test` results -will be fast. When you’re at a point where it makes sense to check the results -of the `ignored` tests and you have time to wait for the results, you can run -`cargo test -- --ignored` instead. If you want to run all tests whether they’re -ignored or not, you can run `cargo test -- --include-ignored`. +will be returned quickly. When you’re at a point where it makes sense to check +the results of the `ignored` tests and you have time to wait for the results, +you can run `cargo test -- --ignored` instead. If you want to run all tests +whether they’re ignored or not, you can run `cargo test -- --include-ignored`. diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index a8c19b6a6c..48f37c4395 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -23,14 +23,14 @@ in each file to contain the test functions and to annotate the module with #### The Tests Module and `#[cfg(test)]` -The `#[cfg(test)]` annotation on the tests module tells Rust to compile and run -the test code only when you run `cargo test`, not when you run `cargo build`. -This saves compile time when you only want to build the library and saves space -in the resulting compiled artifact because the tests are not included. You’ll -see that because integration tests go in a different directory, they don’t need -the `#[cfg(test)]` annotation. However, because unit tests go in the same files -as the code, you’ll use `#[cfg(test)]` to specify that they shouldn’t be -included in the compiled result. +The `#[cfg(test)]` annotation on the `tests` module tells Rust to compile and +run the test code only when you run `cargo test`, not when you run `cargo +build`. This saves compile time when you only want to build the library and +saves space in the resultant compiled artifact because the tests are not +included. You’ll see that because integration tests go in a different +directory, they don’t need the `#[cfg(test)]` annotation. However, because unit +tests go in the same files as the code, you’ll use `#[cfg(test)]` to specify +that they shouldn’t be included in the compiled result. Recall that when we generated the new `adder` project in the first section of this chapter, Cargo generated this code for us: @@ -41,7 +41,7 @@ this chapter, Cargo generated this code for us: {{#rustdoc_include ../listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs}} ``` -This code is the automatically generated test module. The attribute `cfg` +This code is the automatically generated `tests` module. The attribute `cfg` stands for *configuration* and tells Rust that the following item should only be included given a certain configuration option. In this case, the configuration option is `test`, which is provided by Rust for compiling and @@ -106,7 +106,7 @@ adder └── integration_test.rs ``` -Enter the code in Listing 11-13 into the *tests/integration_test.rs* file: +Enter the code in Listing 11-13 into the *tests/integration_test.rs* file. @@ -116,13 +116,12 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file: -Each file in the `tests` directory is a separate crate, so we need to bring our +Each file in the *tests* directory is a separate crate, so we need to bring our library into each test crate’s scope. For that reason we add `use -adder::add_two` at the top of the code, which we didn’t need in the unit -tests. +adder::add_two;` at the top of the code, which we didn’t need in the unit tests. We don’t need to annotate any code in *tests/integration_test.rs* with -`#[cfg(test)]`. Cargo treats the `tests` directory specially and compiles files +`#[cfg(test)]`. Cargo treats the *tests* directory specially and compiles files in this directory only when we run `cargo test`. Run `cargo test` now: ```console @@ -193,11 +192,9 @@ did we call the `setup` function from anywhere: Having `common` appear in the test results with `running 0 tests` displayed for it is not what we wanted. We just wanted to share some code with the other -integration test files. - -To avoid having `common` appear in the test output, instead of creating -*tests/common.rs*, we’ll create *tests/common/mod.rs*. The project directory -now looks like this: +integration test files. To avoid having `common` appear in the test output, +instead of creating *tests/common.rs*, we’ll create *tests/common/mod.rs*. The +project directory now looks like this: ```text ├── Cargo.lock @@ -230,7 +227,7 @@ function from the `it_adds_two` test in *tests/integration_test.rs*: ``` Note that the `mod common;` declaration is the same as the module declaration -we demonstrated in Listing 7-21. Then in the test function, we can call the +we demonstrated in Listing 7-21. Then, in the test function, we can call the `common::setup()` function. #### Integration Tests for Binary Crates @@ -244,10 +241,9 @@ crates can use; binary crates are meant to be run on their own. This is one of the reasons Rust projects that provide a binary have a straightforward *src/main.rs* file that calls logic that lives in the *src/lib.rs* file. Using that structure, integration tests *can* test the -library crate with `use` to make the important functionality available. -If the important functionality works, the small amount of code in the -*src/main.rs* file will work as well, and that small amount of code doesn’t -need to be tested. +library crate with `use` to make the important functionality available. If the +important functionality works, the small amount of code in the *src/main.rs* +file will work as well, and that small amount of code doesn’t need to be tested. ## Summary From d9303e300ce53db39e6af6a9ae8a591419c61c9f Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 5 Jul 2024 14:30:34 -0400 Subject: [PATCH 349/720] Don't just discard output without examining it when doing manual update here --- src/ch11-01-writing-tests.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index 12baf6f49b..2b904b3468 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -50,8 +50,9 @@ cd listings/ch11-writing-automated-tests rm -rf listing-11-01 cargo new listing-11-01 --lib --name adder cd listing-11-01 -cargo test -git co output.txt +echo "$ cargo test" > output.txt +RUSTFLAGS="-A unused_variables -A dead_code" RUST_TEST_THREADS=1 cargo test >> output.txt 2>&1 +git diff output.txt # commit any relevant changes; discard irrelevant ones cd ../../.. --> From d5670bf97afb67de32e697fdb1c7163c8ad911e1 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 5 Jul 2024 14:38:15 -0400 Subject: [PATCH 350/720] Remove anchors around entire listings --- .../ch11-writing-automated-tests/listing-11-03/src/lib.rs | 2 -- .../ch11-writing-automated-tests/listing-11-05/src/lib.rs | 2 -- src/ch11-01-writing-tests.md | 4 ++-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs index 0db269085f..866f0238ba 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs @@ -1,4 +1,3 @@ -// ANCHOR: here pub fn add(left: usize, right: usize) -> usize { left + right } @@ -18,4 +17,3 @@ mod tests { panic!("Make this test fail"); } } -// ANCHOR_END: here diff --git a/listings/ch11-writing-automated-tests/listing-11-05/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-05/src/lib.rs index 0f1bc4e084..0a03a2b447 100644 --- a/listings/ch11-writing-automated-tests/listing-11-05/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-05/src/lib.rs @@ -1,4 +1,3 @@ -// ANCHOR: here #[derive(Debug)] struct Rectangle { width: u32, @@ -10,4 +9,3 @@ impl Rectangle { self.width > other.width && self.height > other.height } } -// ANCHOR_END: here diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index 2b904b3468..f539b41e0d 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -137,7 +137,7 @@ is to call the `panic!` macro. Enter the new test as a function named ```rust,panics,noplayground -{{#rustdoc_include ../listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs}} ``` @@ -186,7 +186,7 @@ method, which are repeated here in Listing 11-5. Let’s put this code in the ```rust,noplayground -{{#rustdoc_include ../listings/ch11-writing-automated-tests/listing-11-05/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch11-writing-automated-tests/listing-11-05/src/lib.rs}} ``` From 024ee9542d5dfa6c5fb85419033ffe7c52bdf05f Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 5 Jul 2024 14:23:29 -0400 Subject: [PATCH 351/720] Increase consistency with what cargo new --lib generates --- .../listing-11-07/src/lib.rs | 5 +- .../listing-11-10/output.txt | 4 +- .../listing-11-10/src/lib.rs | 4 +- .../listing-11-11/src/lib.rs | 11 ++-- .../listing-11-12/src/lib.rs | 9 +-- .../listing-11-13/src/lib.rs | 9 +-- .../listing-11-13/tests/integration_test.rs | 3 +- .../no-listing-04-bug-in-add-two/output.txt | 2 +- .../no-listing-04-bug-in-add-two/src/lib.rs | 5 +- .../src/lib.rs | 3 +- .../no-listing-10-result-in-tests/src/lib.rs | 12 +++- .../no-listing-11-ignore-a-test/output.txt | 4 +- .../no-listing-11-ignore-a-test/src/lib.rs | 26 ++++++--- .../src/lib.rs | 9 +-- .../tests/integration_test.rs | 5 +- .../src/lib.rs | 9 +-- .../tests/integration_test.rs | 6 +- .../src/lib.rs | 9 +-- .../tests/integration_test.rs | 5 +- src/ch11-01-writing-tests.md | 56 +++++++++++-------- src/ch11-02-running-tests.md | 2 +- src/ch11-03-test-organization.md | 15 +++-- 22 files changed, 128 insertions(+), 85 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-07/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-07/src/lib.rs index 3e5d66bfaf..682e8ae172 100644 --- a/listings/ch11-writing-automated-tests/listing-11-07/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-07/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { a + 2 } @@ -8,6 +8,7 @@ mod tests { #[test] fn it_adds_two() { - assert_eq!(4, add_two(2)); + let result = add_two(2); + assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/listing-11-10/output.txt b/listings/ch11-writing-automated-tests/listing-11-10/output.txt index 36fae57883..c67b607d8c 100644 --- a/listings/ch11-writing-automated-tests/listing-11-10/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-10/output.txt @@ -13,8 +13,8 @@ failures: I got the value 8 thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9: assertion `left == right` failed - left: 5 - right: 10 + left: 10 + right: 5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/listing-11-10/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-10/src/lib.rs index 99fc06b8d6..3fbde2a1ed 100644 --- a/listings/ch11-writing-automated-tests/listing-11-10/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-10/src/lib.rs @@ -10,12 +10,12 @@ mod tests { #[test] fn this_test_will_pass() { let value = prints_and_returns_10(4); - assert_eq!(10, value); + assert_eq!(value, 10); } #[test] fn this_test_will_fail() { let value = prints_and_returns_10(8); - assert_eq!(5, value); + assert_eq!(value, 5); } } diff --git a/listings/ch11-writing-automated-tests/listing-11-11/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-11/src/lib.rs index f56715263e..ccf1eb2a2f 100644 --- a/listings/ch11-writing-automated-tests/listing-11-11/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-11/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { a + 2 } @@ -8,16 +8,19 @@ mod tests { #[test] fn add_two_and_two() { - assert_eq!(4, add_two(2)); + let result = add_two(2); + assert_eq!(result, 4); } #[test] fn add_three_and_two() { - assert_eq!(5, add_two(3)); + let result = add_two(3); + assert_eq!(result, 5); } #[test] fn one_hundred() { - assert_eq!(102, add_two(100)); + let result = add_two(100); + assert_eq!(result, 102); } } diff --git a/listings/ch11-writing-automated-tests/listing-11-12/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-12/src/lib.rs index c3961b1f62..9ba15d8b22 100644 --- a/listings/ch11-writing-automated-tests/listing-11-12/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-12/src/lib.rs @@ -1,9 +1,9 @@ -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { internal_adder(a, 2) } -fn internal_adder(a: i32, b: i32) -> i32 { - a + b +fn internal_adder(left: usize, right: usize) -> usize { + left + right } #[cfg(test)] @@ -12,6 +12,7 @@ mod tests { #[test] fn internal() { - assert_eq!(4, internal_adder(2, 2)); + let result = internal_adder(2, 2); + assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/listing-11-13/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-13/src/lib.rs index c3961b1f62..9ba15d8b22 100644 --- a/listings/ch11-writing-automated-tests/listing-11-13/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-13/src/lib.rs @@ -1,9 +1,9 @@ -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { internal_adder(a, 2) } -fn internal_adder(a: i32, b: i32) -> i32 { - a + b +fn internal_adder(left: usize, right: usize) -> usize { + left + right } #[cfg(test)] @@ -12,6 +12,7 @@ mod tests { #[test] fn internal() { - assert_eq!(4, internal_adder(2, 2)); + let result = internal_adder(2, 2); + assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs index 3822d6b976..d6b88a7505 100644 --- a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs @@ -2,5 +2,6 @@ use adder::add_two; #[test] fn it_adds_two() { - assert_eq!(4, add_two(2)); + let result = add_two(2); + assert_eq!(result, 4); } diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt index eb925aa9b9..927f89144c 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt @@ -9,7 +9,7 @@ test tests::it_adds_two ... FAILED failures: ---- tests::it_adds_two stdout ---- -thread 'tests::it_adds_two' panicked at src/lib.rs:11:9: +thread 'tests::it_adds_two' panicked at src/lib.rs:12:9: assertion `left == right` failed left: 5 right: 4 diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs index d7b4e139b8..aed772b0ea 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs @@ -1,5 +1,5 @@ // ANCHOR: here -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { a + 3 } // ANCHOR_END: here @@ -10,6 +10,7 @@ mod tests { #[test] fn it_adds_two() { - assert_eq!(add_two(2), 4); + let result = add_two(2); + assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/src/lib.rs index 519c7a4c6f..8bbaca53fd 100644 --- a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/src/lib.rs @@ -12,8 +12,7 @@ mod tests { let result = greeting("Carol"); assert!( result.contains("Carol"), - "Greeting did not contain name, value was `{}`", - result + "Greeting did not contain name, value was `{result}`" ); } // ANCHOR_END: here diff --git a/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs index 6284f4f291..c31cdcae45 100644 --- a/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs @@ -1,11 +1,21 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + + // ANCHOR: here #[test] fn it_works() -> Result<(), String> { - if 2 + 2 == 4 { + let result = add(2, 2); + + if result == 4 { Ok(()) } else { Err(String::from("two plus two does not equal four")) } } + // ANCHOR_END: here } diff --git a/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt b/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt index 8d700c7cd9..bc40c96eb8 100644 --- a/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt @@ -4,8 +4,8 @@ $ cargo test Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 2 tests -test expensive_test ... ignored -test it_works ... ok +test tests::expensive_test ... ignored +test tests::it_works ... ok test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s diff --git a/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/src/lib.rs index d54a6095d7..0c8b38defd 100644 --- a/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/src/lib.rs @@ -1,10 +1,22 @@ -#[test] -fn it_works() { - assert_eq!(2 + 2, 4); +pub fn add(left: usize, right: usize) -> usize { + left + right } -#[test] -#[ignore] -fn expensive_test() { - // code that takes an hour to run +// ANCHOR: here +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } + + #[test] + #[ignore] + fn expensive_test() { + // code that takes an hour to run + } } +// ANCHOR_END: here diff --git a/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/src/lib.rs index c3961b1f62..9ba15d8b22 100644 --- a/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/src/lib.rs @@ -1,9 +1,9 @@ -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { internal_adder(a, 2) } -fn internal_adder(a: i32, b: i32) -> i32 { - a + b +fn internal_adder(left: usize, right: usize) -> usize { + left + right } #[cfg(test)] @@ -12,6 +12,7 @@ mod tests { #[test] fn internal() { - assert_eq!(4, internal_adder(2, 2)); + let result = internal_adder(2, 2); + assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/tests/integration_test.rs b/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/tests/integration_test.rs index e26fa71096..d6b88a7505 100644 --- a/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/no-listing-12-shared-test-code-problem/tests/integration_test.rs @@ -1,6 +1,7 @@ -use adder; +use adder::add_two; #[test] fn it_adds_two() { - assert_eq!(4, adder::add_two(2)); + let result = add_two(2); + assert_eq!(result, 4); } diff --git a/listings/ch11-writing-automated-tests/no-listing-13-fix-shared-test-code-problem/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-13-fix-shared-test-code-problem/src/lib.rs index c3961b1f62..9ba15d8b22 100644 --- a/listings/ch11-writing-automated-tests/no-listing-13-fix-shared-test-code-problem/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-13-fix-shared-test-code-problem/src/lib.rs @@ -1,9 +1,9 @@ -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { internal_adder(a, 2) } -fn internal_adder(a: i32, b: i32) -> i32 { - a + b +fn internal_adder(left: usize, right: usize) -> usize { + left + right } #[cfg(test)] @@ -12,6 +12,7 @@ mod tests { #[test] fn internal() { - assert_eq!(4, internal_adder(2, 2)); + let result = internal_adder(2, 2); + assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/no-listing-13-fix-shared-test-code-problem/tests/integration_test.rs b/listings/ch11-writing-automated-tests/no-listing-13-fix-shared-test-code-problem/tests/integration_test.rs index 58b8b7b89b..d18b5b689b 100644 --- a/listings/ch11-writing-automated-tests/no-listing-13-fix-shared-test-code-problem/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/no-listing-13-fix-shared-test-code-problem/tests/integration_test.rs @@ -1,9 +1,11 @@ -use adder; +use adder::add_two; mod common; #[test] fn it_adds_two() { common::setup(); - assert_eq!(4, adder::add_two(2)); + + let result = add_two(2); + assert_eq!(result, 4); } diff --git a/listings/ch11-writing-automated-tests/output-only-05-single-integration/src/lib.rs b/listings/ch11-writing-automated-tests/output-only-05-single-integration/src/lib.rs index c3961b1f62..9ba15d8b22 100644 --- a/listings/ch11-writing-automated-tests/output-only-05-single-integration/src/lib.rs +++ b/listings/ch11-writing-automated-tests/output-only-05-single-integration/src/lib.rs @@ -1,9 +1,9 @@ -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { internal_adder(a, 2) } -fn internal_adder(a: i32, b: i32) -> i32 { - a + b +fn internal_adder(left: usize, right: usize) -> usize { + left + right } #[cfg(test)] @@ -12,6 +12,7 @@ mod tests { #[test] fn internal() { - assert_eq!(4, internal_adder(2, 2)); + let result = internal_adder(2, 2); + assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/output-only-05-single-integration/tests/integration_test.rs b/listings/ch11-writing-automated-tests/output-only-05-single-integration/tests/integration_test.rs index e26fa71096..d6b88a7505 100644 --- a/listings/ch11-writing-automated-tests/output-only-05-single-integration/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/output-only-05-single-integration/tests/integration_test.rs @@ -1,6 +1,7 @@ -use adder; +use adder::add_two; #[test] fn it_adds_two() { - assert_eq!(4, adder::add_two(2)); + let result = add_two(2); + assert_eq!(result, 4); } diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index f539b41e0d..5c6452a7bd 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -43,7 +43,7 @@ $ cd adder The contents of the *src/lib.rs* file in your `adder` library should look like Listing 11-1. -+ section later in this chapter. Because we -haven’t done that here, the summary shows `0 ignored`. We can also pass an -argument to the `cargo test` command to run only tests whose name matches a -string; this is called *filtering* and we’ll cover that in the [“Running a -Subset of Tests by Name”][subset] section. Here we haven’t -filtered the tests being run, so the end of the summary shows `0 filtered out`. +haven’t done that here, the summary shows `0 ignored`. The `0 measured` statistic is for benchmark tests that measure performance. Benchmark tests are, as of this writing, only available in nightly Rust. See [the documentation about benchmark tests][bench] to learn more. +We can pass an argument to the `cargo test` command to run only tests whose +name matches a string; this is called *filtering* and we’ll cover that in the +[“Running a Subset of Tests by Name”][subset] section. Here we +haven’t filtered the tests being run, so the end of the summary shows `0 +filtered out`. + The next part of the test output starting at `Doc-tests adder` is for the results of any documentation tests. We don’t have any documentation tests yet, but Rust can compile any code examples that appear in our API documentation. @@ -153,11 +155,16 @@ Run the tests again using `cargo test`. The output should look like Listing + + Instead of `ok`, the line `test tests::another` shows `FAILED`. Two new sections appear between the individual results and the summary: the first displays the detailed reason for each test failure. In this case, we get the details that `another` failed because it `panicked at 'Make this test fail'` on -line 10 in the *src/lib.rs* file. The next section lists just the names of all +line 17 in the *src/lib.rs* file. The next section lists just the names of all the failing tests, which is useful when there are lots of tests and lots of detailed failing test output. We can use the name of a failing test to run just that test to more easily debug it; we’ll talk more about ways to run tests in @@ -205,9 +212,9 @@ has a width of 5 and a height of 1. -Note that we’ve added a new line inside the `tests` module: `use super::*;`. -The `tests` module is a regular module that follows the usual visibility rules -we covered in Chapter 7 in the [“Paths for Referring to an Item in the Module +Note the `use super::*;` line inside the `tests` module. The `tests` module is +a regular module that follows the usual visibility rules we covered in Chapter +7 in the [“Paths for Referring to an Item in the Module Tree”][paths-for-referring-to-an-item-in-the-module-tree] section. Because the `tests` module is an inner module, we need to bring the code under test in the outer module into the scope of the inner module. We use @@ -289,9 +296,10 @@ Let’s check that it passes! {{#include ../listings/ch11-writing-automated-tests/listing-11-07/output.txt}} ``` -We pass `4` as the argument to `assert_eq!`, which is equal to the result of -calling `add_two(2)`. The line for this test is `test tests::it_adds_two ... -ok`, and the `ok` text indicates that our test passed! +We create a variable named `result` that holds the result of calling +`add_two(2)`. Then we pass `result` and `4` as the arguments to `assert_eq!`. +The output line for this test is `test tests::it_adds_two ... ok`, and the `ok` +text indicates that our test passed! Let’s introduce a bug into our code to see what `assert_eq!` looks like when it fails. Change the implementation of the `add_two` function to instead add `3`: @@ -307,18 +315,18 @@ Run the tests again: ``` Our test caught the bug! The `it_adds_two` test failed, and the message tells -us that the assertion that fails was ``assertion `left == right` failed`` -and what the `left` and `right` values are. This message helps us start -debugging: the `left` argument was `4` but the `right` argument, where we had -`add_two(2)`, was `5`. You can imagine that this would be especially helpful -when we have a lot of tests going on. +us ``assertion `left == right` failed`` and what the `left` and `right` values +are. This message helps us start debugging: the `left` argument, where we had +the result of calling `add_two(2)`, was `5` but the `right` argument was `4`. +You can imagine that this would be especially helpful when we have a lot of +tests going on. Note that in some languages and test frameworks, the parameters to equality assertion functions are called `expected` and `actual`, and the order in which we specify the arguments matters. However, in Rust, they’re called `left` and `right`, and the order in which we specify the value we expect and the value the code produces doesn’t matter. We could write the assertion in this test as -`assert_eq!(4, add_two(2))`, which would result in the same failure message +`assert_eq!(4, result)`, which would produce the same failure message that displays `` assertion failed: `(left == right)` ``. The `assert_ne!` macro will pass if the two values we give it are not equal and @@ -504,7 +512,7 @@ Our tests so far all panic when they fail. We can also write tests that use E>` and return an `Err` instead of panicking: ```rust,noplayground -{{#rustdoc_include ../listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs}} +{{#rustdoc_include ../listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs:here}} ``` The `it_works` function now has the `Result<(), String>` return type. In the diff --git a/src/ch11-02-running-tests.md b/src/ch11-02-running-tests.md index 053c1a88ec..406b06e681 100644 --- a/src/ch11-02-running-tests.md +++ b/src/ch11-02-running-tests.md @@ -157,7 +157,7 @@ here: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/src/lib.rs}} +{{#rustdoc_include ../listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/src/lib.rs:here}} ``` After `#[test]`, we add the `#[ignore]` line to the test we want to exclude. diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index 48f37c4395..323f01a74a 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -41,14 +41,13 @@ this chapter, Cargo generated this code for us: {{#rustdoc_include ../listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs}} ``` -This code is the automatically generated `tests` module. The attribute `cfg` -stands for *configuration* and tells Rust that the following item should only -be included given a certain configuration option. In this case, the -configuration option is `test`, which is provided by Rust for compiling and -running tests. By using the `cfg` attribute, Cargo compiles our test code only -if we actively run the tests with `cargo test`. This includes any helper -functions that might be within this module, in addition to the functions -annotated with `#[test]`. +On the automatically generated `tests` module, the attribute `cfg` stands for +*configuration* and tells Rust that the following item should only be included +given a certain configuration option. In this case, the configuration option is +`test`, which is provided by Rust for compiling and running tests. By using the +`cfg` attribute, Cargo compiles our test code only if we actively run the tests +with `cargo test`. This includes any helper functions that might be within this +module, in addition to the functions annotated with `#[test]`. #### Testing Private Functions From 1f7ac863532413df628df4fd0008d0d78476972a Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 5 Jul 2024 16:56:08 -0400 Subject: [PATCH 352/720] Handle more non-links in code and handle them a better way That is, don't remove the square brackets in these cases. I don't know how I lived like this. --- packages/tools/src/bin/link2print.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/tools/src/bin/link2print.rs b/packages/tools/src/bin/link2print.rs index 09edd84bdb..7d11278876 100644 --- a/packages/tools/src/bin/link2print.rs +++ b/packages/tools/src/bin/link2print.rs @@ -60,8 +60,12 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String { name.starts_with("profile") || name.starts_with("test") || name.starts_with("no_mangle") || + name.starts_with("cfg") || + name.starts_with("unoptimized") || + name.starts_with("ignore") || + name.starts_with("should_panic") || error_code.is_match(name) { - return name.to_string() + return format!("[{name}]") } let val = match caps.name("val") { From 010f769361f49d2792860c2fb32491702374f129 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 5 Jul 2024 17:11:50 -0400 Subject: [PATCH 353/720] Snapshot changes to generated ch11 that SHOULDN'T be sent to nostarch --- nostarch/chapter11.md | 515 +++++++++++++++++++++++++++--------------- 1 file changed, 332 insertions(+), 183 deletions(-) diff --git a/nostarch/chapter11.md b/nostarch/chapter11.md index cf909d70c5..ccaf39817c 100644 --- a/nostarch/chapter11.md +++ b/nostarch/chapter11.md @@ -85,8 +85,20 @@ $ cd adder The contents of the *src/lib.rs* file in your `adder` library should look like Listing 11-1. + Filename: src/lib.rs + + ``` #[cfg(test)] mod tests { @@ -108,14 +120,15 @@ non-test functions in the `tests` module to help set up common scenarios or perform common operations, so we always need to indicate which functions are tests. -The example function body uses the `assert_eq!` macro [2] to assert that -`result`, which contains the result of adding 2 and 2, equals 4. This assertion -serves as an example of the format for a typical test. Let’s run it to see that -this test passes. +The example function body uses the `assert_eq!` macro to assert that `result`, +which contains the result of adding 2 and 2, equals 4. This assertion serves as +an example of the format for a typical test. Let’s run it to see that this test +passes. The `cargo test` command runs all tests in our project, as shown in Listing 11-2. + ``` $ cargo test Compiling adder v0.1.0 (file:///projects/adder) @@ -123,18 +136,17 @@ $ cargo test Running unittests src/lib.rs (target/debug/deps/adder- 92948b65e88960b4) -1 running 1 test -2 test tests::it_works ... ok +running 1 test +test tests::it_works ... ok -3 test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - 4 Doc-tests adder + Doc-tests adder running 0 tests -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` Listing 11-2: The output from running the automatically generated test @@ -155,16 +167,16 @@ the tests being run, so the end of the summary shows `0 filtered out`. The `0 measured` statistic is for benchmark tests that measure performance. Benchmark tests are, as of this writing, only available in nightly Rust. See -the documentation about benchmark tests at -*https://doc.rust-lang.org/unstable-book/library-features/test.html* to learn -more. +the documentation about benchmark tests at *../unstable-book/library-features/test.html* to learn more. -The next part of the test output starting at `Doc-tests adder` [4] is for the + +The next part of the test output starting at `Doc-tests adder` is for the results of any documentation tests. We don’t have any documentation tests yet, but Rust can compile any code examples that appear in our API documentation. This feature helps keep your docs and your code in sync! We’ll discuss how to -write documentation tests in “Documentation Comments as Tests” on page XX. For -now, we’ll ignore the `Doc-tests` output. +write documentation tests in the “Documentation Comments as +Tests” section of Chapter 14. For now, we’ll +ignore the `Doc-tests` output. Let’s start to customize the test to our own needs. First, change the name of the `it_works` function to a different name, such as `exploration`, like so: @@ -186,11 +198,22 @@ Then run `cargo test` again. The output now shows `exploration` instead of `it_works`: ``` +$ cargo test + Compiling adder v0.1.0 (file:///projects/adder) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.59s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) + running 1 test test tests::exploration ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests adder + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` Now we’ll add another test, but this time we’ll make a test that fails! Tests @@ -200,6 +223,7 @@ marked as failed. In Chapter 9, we talked about how the simplest way to panic is to call the `panic!` macro. Enter the new test as a function named `another`, so your *src/lib.rs* file looks like Listing 11-3. + Filename: src/lib.rs ``` @@ -217,52 +241,62 @@ mod tests { } ``` -Listing 11-3: Adding a second test that will fail because we call the `panic!` -macro +Listing 11-3: Adding a second test that will fail because we call the panic! macro Run the tests again using `cargo test`. The output should look like Listing 11-4, which shows that our `exploration` test passed and `another` failed. + ``` +$ cargo test + Compiling adder v0.1.0 (file:///projects/adder) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.72s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) + running 2 tests +test tests::another ... FAILED test tests::exploration ... ok -1 test tests::another ... FAILED -2 failures: +failures: ---- tests::another stdout ---- thread 'main' panicked at 'Make this test fail', src/lib.rs:10:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -3 failures: + +failures: tests::another -4 test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s error: test failed, to rerun pass '--lib' ``` Listing 11-4: Test results when one test passes and one test fails -Instead of `ok`, the line `test tests::another` shows `FAILED` [1]. Two new -sections appear between the individual results and the summary: the first [2] + + +Instead of `ok`, the line `test tests::another` shows `FAILED`. Two new +sections appear between the individual results and the summary: the first displays the detailed reason for each test failure. In this case, we get the details that `another` failed because it `panicked at 'Make this test fail'` on line 10 in the *src/lib.rs* file. The next section [3] lists just the names of all the failing tests, which is useful when there are lots of tests and lots of detailed failing test output. We can use the name of a failing test to run just that test to more easily debug it; we’ll talk more about ways to run tests in -“Controlling How Tests Are Run” on page XX. +the “Controlling How Tests Are Run” section. -The summary line displays at the end [4]: overall, our test result is `FAILED`. -We had one test pass and one test fail. +The summary line displays at the end: overall, our test result is `FAILED`. We +had one test pass and one test fail. Now that you’ve seen what the test results look like in different scenarios, let’s look at some macros other than `panic!` that are useful in tests. -### Checking Results with the assert! Macro +### Checking Results with the `assert!` Macro The `assert!` macro, provided by the standard library, is useful when you want to ensure that some condition in a test evaluates to `true`. We give the @@ -271,9 +305,10 @@ to ensure that some condition in a test evaluates to `true`. We give the `assert!` macro calls `panic!` to cause the test to fail. Using the `assert!` macro helps us check that our code is functioning in the way we intend. -In Listing 5-15, we used a `Rectangle` struct and a `can_hold` method, which -are repeated here in Listing 11-5. Let’s put this code in the *src/lib.rs* -file, then write some tests for it using the `assert!` macro. +In Chapter 5, Listing 5-15, we used a `Rectangle` struct and a `can_hold` +method, which are repeated here in Listing 11-5. Let’s put this code in the +*src/lib.rs* file, then write some tests for it using the `assert!` macro. + Filename: src/lib.rs @@ -291,8 +326,7 @@ impl Rectangle { } ``` -Listing 11-5: Using the `Rectangle` struct and its `can_hold` method from -Chapter 5 +Listing 11-5: The Rectangle struct and its can_hold method from Chapter 5 The `can_hold` method returns a Boolean, which means it’s a perfect use case for the `assert!` macro. In Listing 11-6, we write a test that exercises the @@ -300,16 +334,17 @@ for the `assert!` macro. In Listing 11-6, we write a test that exercises the a height of 7 and asserting that it can hold another `Rectangle` instance that has a width of 5 and a height of 1. + Filename: src/lib.rs ``` #[cfg(test)] mod tests { - 1 use super::*; + use super::*; #[test] - 2 fn larger_can_hold_smaller() { - 3 let larger = Rectangle { + fn larger_can_hold_smaller() { + let larger = Rectangle { width: 8, height: 7, }; @@ -318,13 +353,12 @@ mod tests { height: 1, }; - 4 assert!(larger.can_hold(&smaller)); + assert!(larger.can_hold(&smaller)); } } ``` -Listing 11-6: A test for `can_hold` that checks whether a larger rectangle can -indeed hold a smaller rectangle +Listing 11-6: A test for can_hold that checks whether a larger rectangle can indeed hold a smaller rectangle Note that we’ve added a new line inside the `tests` module: `use super::*;` [1]. The `tests` module is a regular module that follows the usual visibility @@ -334,18 +368,28 @@ under test in the outer module into the scope of the inner module. We use a glob here, so anything we define in the outer module is available to this `tests` module. -We’ve named our test `larger_can_hold_smaller` [2], and we’ve created the two -`Rectangle` instances that we need [3]. Then we called the `assert!` macro and -passed it the result of calling `larger.can_hold(&smaller)` [4]. This -expression is supposed to return `true`, so our test should pass. Let’s find -out! +We’ve named our test `larger_can_hold_smaller`, and we’ve created the two +`Rectangle` instances that we need. Then we called the `assert!` macro and +passed it the result of calling `larger.can_hold(&smaller)`. This expression is +supposed to return `true`, so our test should pass. Let’s find out! ``` +$ cargo test + Compiling rectangle v0.1.0 (file:///projects/rectangle) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s + Running unittests src/lib.rs (target/debug/deps/rectangle-6584c4561e48942e) + running 1 test test tests::larger_can_hold_smaller ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests rectangle + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` It does pass! Let’s add another test, this time asserting that a smaller @@ -360,7 +404,7 @@ mod tests { #[test] fn larger_can_hold_smaller() { - --snip-- + // --snip-- } #[test] @@ -384,12 +428,23 @@ we need to negate that result before we pass it to the `assert!` macro. As a result, our test will pass if `can_hold` returns `false`: ``` +$ cargo test + Compiling rectangle v0.1.0 (file:///projects/rectangle) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s + Running unittests src/lib.rs (target/debug/deps/rectangle-6584c4561e48942e) + running 2 tests test tests::larger_can_hold_smaller ... ok test tests::smaller_cannot_hold_larger ... ok -test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests rectangle + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` Two tests that pass! Now let’s see what happens to our test results when we @@ -398,8 +453,7 @@ method by replacing the greater-than sign with a less-than sign when it compares the widths: ``` ---snip-- - +// --snip-- impl Rectangle { fn can_hold(&self, other: &Rectangle) -> bool { self.width < other.width && self.height > other.height @@ -410,9 +464,14 @@ impl Rectangle { Running the tests now produces the following: ``` +$ cargo test + Compiling rectangle v0.1.0 (file:///projects/rectangle) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s + Running unittests src/lib.rs (target/debug/deps/rectangle-6584c4561e48942e) + running 2 tests -test tests::smaller_cannot_hold_larger ... ok test tests::larger_can_hold_smaller ... FAILED +test tests::smaller_cannot_hold_larger ... ok failures: @@ -426,15 +485,16 @@ a backtrace failures: tests::larger_can_hold_smaller -test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +error: test failed, to rerun pass `--lib` ``` Our tests caught the bug! Because `larger.width` is `8` and `smaller.width` is `5`, the comparison of the widths in `can_hold` now returns `false`: 8 is not less than 5. -### Testing Equality with the assert_eq! and assert_ne! Macros +### Testing Equality with the `assert_eq!` and `assert_ne!` Macros A common way to verify functionality is to test for equality between the result of the code under test and the value you expect the code to return. You could @@ -450,6 +510,7 @@ expression, without printing the values that led to the `false` value. In Listing 11-7, we write a function named `add_two` that adds `2` to its parameter, then we test this function using the `assert_eq!` macro. + Filename: src/lib.rs ``` @@ -468,16 +529,27 @@ mod tests { } ``` -Listing 11-7: Testing the function `add_two` using the `assert_eq!` macro +Listing 11-7: Testing the function add_two using the assert_eq! macro Let’s check that it passes! ``` +$ cargo test + Compiling adder v0.1.0 (file:///projects/adder) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.58s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) + running 1 test test tests::it_adds_two ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests adder + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` We pass `4` as the argument to `assert_eq!`, which is equal to the result of @@ -496,6 +568,11 @@ pub fn add_two(a: i32) -> i32 { Run the tests again: ``` +$ cargo test + Compiling adder v0.1.0 (file:///projects/adder) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.61s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) + running 1 test test tests::it_adds_two ... FAILED @@ -546,20 +623,23 @@ the standard library types implement these traits. For structs and enums that you define yourself, you’ll need to implement `PartialEq` to assert equality of those types. You’ll also need to implement `Debug` to print the values when the assertion fails. Because both traits are derivable traits, as mentioned in -Listing 5-12, this is usually as straightforward as adding the +Listing 5-12 in Chapter 5, this is usually as straightforward as adding the `#[derive(PartialEq, Debug)]` annotation to your struct or enum definition. See -Appendix C for more details about these and other derivable traits. +Appendix C, “Derivable Traits,” for more +details about these and other derivable traits. ### Adding Custom Failure Messages You can also add a custom message to be printed with the failure message as optional arguments to the `assert!`, `assert_eq!`, and `assert_ne!` macros. Any arguments specified after the required arguments are passed along to the -`format!` macro (discussed in “Concatenation with the + Operator or the format! -Macro” on page XX), so you can pass a format string that contains `{}` -placeholders and values to go in those placeholders. Custom messages are useful -for documenting what an assertion means; when a test fails, you’ll have a -better idea of what the problem is with the code. +`format!` macro (discussed in Chapter 8 in the “Concatenation with the `+` +Operator or the `format!` +Macro” +section), so you can pass a format string that contains `{}` placeholders and +values to go in those placeholders. Custom messages are useful for documenting +what an assertion means; when a test fails, you’ll have a better idea of what +the problem is with the code. For example, let’s say we have a function that greets people by name and we want to test that the name we pass into the function appears in the output: @@ -602,6 +682,11 @@ pub fn greeting(name: &str) -> String { Running this test produces the following: ``` +$ cargo test + Compiling greeter v0.1.0 (file:///projects/greeter) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.91s + Running unittests src/lib.rs (target/debug/deps/greeter-170b942eb5bf5e3a) + running 1 test test tests::greeting_contains_name ... FAILED @@ -616,6 +701,10 @@ a backtrace failures: tests::greeting_contains_name + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +error: test failed, to rerun pass `--lib` ``` This result just indicates that the assertion failed and which line the @@ -625,19 +714,29 @@ string with a placeholder filled in with the actual value we got from the `greeting` function: ``` -#[test] -fn greeting_contains_name() { - let result = greeting("Carol"); - assert!( - result.contains("Carol"), - "Greeting did not contain name, value was `{result}`" - ); -} + #[test] + fn greeting_contains_name() { + let result = greeting("Carol"); + assert!( + result.contains("Carol"), + "Greeting did not contain name, value was `{result}`" + ); + } ``` Now when we run the test, we’ll get a more informative error message: ``` +$ cargo test + Compiling greeter v0.1.0 (file:///projects/greeter) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.93s + Running unittests src/lib.rs (target/debug/deps/greeter-170b942eb5bf5e3a) + +running 1 test +test tests::greeting_contains_name ... FAILED + +failures: + ---- tests::greeting_contains_name stdout ---- thread 'main' panicked at 'Greeting did not contain name, value was `Hello!`', src/lib.rs:12:9 @@ -648,14 +747,14 @@ a backtrace We can see the value we actually got in the test output, which would help us debug what happened instead of what we were expecting to happen. -### Checking for Panics with should_panic +### Checking for Panics with `should_panic` In addition to checking return values, it’s important to check that our code handles error conditions as we expect. For example, consider the `Guess` type -that we created in Listing 9-13. Other code that uses `Guess` depends on the -guarantee that `Guess` instances will contain only values between 1 and 100. We -can write a test that ensures that attempting to create a `Guess` instance with -a value outside that range panics. +that we created in Chapter 9, Listing 9-13. Other code that uses `Guess` +depends on the guarantee that `Guess` instances will contain only values +between 1 and 100. We can write a test that ensures that attempting to create a +`Guess` instance with a value outside that range panics. We do this by adding the attribute `should_panic` to our test function. The test passes if the code inside the function panics; the test fails if the code @@ -664,8 +763,10 @@ inside the function doesn’t panic. Listing 11-8 shows a test that checks that the error conditions of `Guess::new` happen when we expect them to. + +Filename: src/lib.rs + ``` -// src/lib.rs pub struct Guess { value: i32, } @@ -695,27 +796,36 @@ mod tests { } ``` -Listing 11-8: Testing that a condition will cause a panic! +Listing 11-8: Testing that a condition will cause a panic! We place the `#[should_panic]` attribute after the `#[test]` attribute and before the test function it applies to. Let’s look at the result when this test passes: ``` +$ cargo test + Compiling guessing_game v0.1.0 (file:///projects/guessing_game) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.58s + Running unittests src/lib.rs (target/debug/deps/guessing_game-57d70c3acb738f4d) + running 1 test test tests::greater_than_100 - should panic ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests guessing_game + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` Looks good! Now let’s introduce a bug in our code by removing the condition that the `new` function will panic if the value is greater than 100: ``` -// src/lib.rs ---snip-- - +// --snip-- impl Guess { pub fn new(value: i32) -> Guess { if value < 1 { @@ -733,6 +843,11 @@ impl Guess { When we run the test in Listing 11-8, it will fail: ``` +$ cargo test + Compiling guessing_game v0.1.0 (file:///projects/guessing_game) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.62s + Running unittests src/lib.rs (target/debug/deps/guessing_game-57d70c3acb738f4d) + running 1 test test tests::greater_than_100 - should panic ... FAILED @@ -744,8 +859,9 @@ note: test did not panic as expected failures: tests::greater_than_100 -test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +error: test failed, to rerun pass `--lib` ``` We don’t get a very helpful message in this case, but when we look at the test @@ -761,9 +877,11 @@ consider the modified code for `Guess` in Listing 11-9 where the `new` function panics with different messages depending on whether the value is too small or too large. + +Filename: src/lib.rs + ``` -// src/lib.rs ---snip-- +// --snip-- impl Guess { pub fn new(value: i32) -> Guess { @@ -795,14 +913,12 @@ mod tests { } ``` -Listing 11-9: Testing for a `panic!` with a panic message containing a -specified substring +Listing 11-9: Testing for a panic! with a panic message containing a specified substring This test will pass because the value we put in the `should_panic` attribute’s `expected` parameter is a substring of the message that the `Guess::new` function panics with. We could have specified the entire panic message that we -expect, which in this case would be `Guess value must be less than or equal to -100, got 200`. What you choose to specify depends on how much of the panic +expect, which in this case would be `Guess value must be less than or equal to 100, got 200`. What you choose to specify depends on how much of the panic message is unique or dynamic and how precise you want your test to be. In this case, a substring of the panic message is enough to ensure that the code in the test function executes the `else if value > 100` case. @@ -831,6 +947,11 @@ if value < 1 { This time when we run the `should_panic` test, it will fail: ``` +$ cargo test + Compiling guessing_game v0.1.0 (file:///projects/guessing_game) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.66s + Running unittests src/lib.rs (target/debug/deps/guessing_game-57d70c3acb738f4d) + running 1 test test tests::greater_than_100 - should panic ... FAILED @@ -841,15 +962,15 @@ thread 'main' panicked at 'Guess value must be greater than or equal to 1, got 200.', src/lib.rs:13:13 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace note: panic did not contain expected string - panic message: `"Guess value must be greater than or equal to 1, got -200."`, + panic message: `"Guess value must be greater than or equal to 1, got 200."`, expected substring: `"less than or equal to 100"` failures: tests::greater_than_100 -test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; -finished in 0.00s +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +error: test failed, to rerun pass `--lib` ``` The failure message indicates that this test did indeed panic as we expected, @@ -858,13 +979,10 @@ less than or equal to 100'`. The panic message that we did get in this case was `Guess value must be greater than or equal to 1, got 200`. Now we can start figuring out where our bug is! -### Using Result in Tests +### Using `Result` in Tests Our tests so far all panic when they fail. We can also write tests that use -`Result`! Here’s the test from Listing 11-1, rewritten to use `Result` and return an `Err` instead of panicking: - -Filename: src/lib.rs +`Result`! Here’s the test from Listing 11-1, rewritten to use `Result` and return an `Err` instead of panicking: ``` #[cfg(test)] @@ -889,14 +1007,12 @@ Writing tests so they return a `Result` enables you to use the question mark operator in the body of tests, which can be a convenient way to write tests that should fail if any operation within them returns an `Err` variant. -You can’t use the `#[should_panic]` annotation on tests that use `Result`. To assert that an operation returns an `Err` variant, *don’t* use the +You can’t use the `#[should_panic]` annotation on tests that use `Result`. To assert that an operation returns an `Err` variant, *don’t* use the question mark operator on the `Result` value. Instead, use `assert!(value.is_err())`. Now that you know several ways to write tests, let’s look at what is happening -when we run our tests and explore the different options we can use with `cargo -test`. +when we run our tests and explore the different options we can use with `cargo test`. ## Controlling How Tests Are Run @@ -958,6 +1074,7 @@ printed to standard output with the rest of the failure message. As an example, Listing 11-10 has a silly function that prints the value of its parameter and returns 10, as well as a test that passes and a test that fails. + Filename: src/lib.rs ``` @@ -984,14 +1101,19 @@ mod tests { } ``` -Listing 11-10: Tests for a function that calls `println!` +Listing 11-10: Tests for a function that calls println! When we run these tests with `cargo test`, we’ll see the following output: ``` +$ cargo test + Compiling silly-function v0.1.0 (file:///projects/silly-function) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.58s + Running unittests src/lib.rs (target/debug/deps/silly_function-160869f38cff9166) + running 2 tests -test tests::this_test_will_pass ... ok test tests::this_test_will_fail ... FAILED +test tests::this_test_will_pass ... ok failures: @@ -1006,15 +1128,15 @@ a backtrace failures: tests::this_test_will_fail -test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +error: test failed, to rerun pass `--lib` ``` Note that nowhere in this output do we see `I got the value 4`, which is printed when the test that passes runs. That output has been captured. The -output from the test that failed, `I got the value 8` [1], appears in the -section of the test summary output, which also shows the cause of the test -failure. +output from the test that failed, `I got the value 8`, appears in the section +of the test summary output, which also shows the cause of the test failure. If we want to see printed values for passing tests as well, we can tell Rust to also show the output of successful tests with `--show-output`: @@ -1027,9 +1149,14 @@ When we run the tests in Listing 11-10 again with the `--show-output` flag, we see the following output: ``` +$ cargo test -- --show-output + Compiling silly-function v0.1.0 (file:///projects/silly-function) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.60s + Running unittests src/lib.rs (target/debug/deps/silly_function-160869f38cff9166) + running 2 tests -test tests::this_test_will_pass ... ok test tests::this_test_will_fail ... FAILED +test tests::this_test_will_pass ... ok successes: @@ -1053,8 +1180,9 @@ a backtrace failures: tests::this_test_will_fail -test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +error: test failed, to rerun pass `--lib` ``` ### Running a Subset of Tests by Name @@ -1067,6 +1195,7 @@ or names of the test(s) you want to run as an argument. To demonstrate how to run a subset of tests, we’ll first create three tests for our `add_two` function, as shown in Listing 11-11, and choose which ones to run. + Filename: src/lib.rs ``` @@ -1101,13 +1230,24 @@ If we run the tests without passing any arguments, as we saw earlier, all the tests will run in parallel: ``` +$ cargo test + Compiling adder v0.1.0 (file:///projects/adder) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.62s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) + running 3 tests test tests::add_three_and_two ... ok test tests::add_two_and_two ... ok test tests::one_hundred ... ok -test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests adder + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` #### Running Single Tests @@ -1124,8 +1264,8 @@ $ cargo test one_hundred running 1 test test tests::one_hundred ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.00s + ``` Only the test with the name `one_hundred` ran; the other two tests didn’t match @@ -1152,8 +1292,8 @@ running 2 tests test tests::add_three_and_two ... ok test tests::add_two_and_two ... ok -test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1 -filtered out; finished in 0.00s +test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s + ``` This command ran all tests with `add` in the name and filtered out the test @@ -1196,11 +1336,17 @@ $ cargo test 92948b65e88960b4) running 2 tests -test expensive_test ... ignored -test it_works ... ok +test tests::expensive_test ... ignored +test tests::it_works ... ok + +test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests adder + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s -test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 -filtered out; finished in 0.00s ``` The `expensive_test` function is listed as `ignored`. If we want to run only @@ -1215,8 +1361,14 @@ $ cargo test -- --ignored running 1 test test expensive_test ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s + + Doc-tests adder + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` By controlling which tests run, you can make sure your `cargo test` results @@ -1248,11 +1400,10 @@ code that they’re testing. The convention is to create a module named `tests` in each file to contain the test functions and to annotate the module with `cfg(test)`. -#### The Tests Module and #[cfg(test)] +#### The Tests Module and `#[cfg(test)]` The `#[cfg(test)]` annotation on the `tests` module tells Rust to compile and -run the test code only when you run `cargo test`, not when you run `cargo -build`. This saves compile time when you only want to build the library and +run the test code only when you run `cargo test`, not when you run `cargo build`. This saves compile time when you only want to build the library and saves space in the resultant compiled artifact because the tests are not included. You’ll see that because integration tests go in a different directory, they don’t need the `#[cfg(test)]` annotation. However, because unit @@ -1292,6 +1443,7 @@ impossible to test private functions. Regardless of which testing ideology you adhere to, Rust’s privacy rules do allow you to test private functions. Consider the code in Listing 11-12 with the private function `internal_adder`. + Filename: src/lib.rs ``` @@ -1334,7 +1486,7 @@ work correctly on their own could have problems when integrated, so test coverage of the integrated code is important as well. To create integration tests, you first need a *tests* directory. -#### The tests Directory +#### The *tests* Directory We create a *tests* directory at the top level of our project directory, next to *src*. Cargo knows to look for integration test files in this directory. We @@ -1350,13 +1502,14 @@ adder ├── Cargo.lock ├── Cargo.toml ├── src -│ └── lib.rs +│   └── lib.rs └── tests └── integration_test.rs ``` Enter the code in Listing 11-13 into the *tests/integration_test.rs* file. + Filename: tests/integration_test.rs ``` @@ -1368,7 +1521,7 @@ fn it_adds_two() { } ``` -Listing 11-13: An integration test of a function in the `adder` crate +Listing 11-13: An integration test of a function in the adder crate Each file in the *tests* directory is a separate crate, so we need to bring our library into each test crate’s scope. For that reason we add `use adder;` at @@ -1385,27 +1538,24 @@ $ cargo test Running unittests src/lib.rs (target/debug/deps/adder- 1082c4b063a8fbe6) -1 running 1 test +running 1 test test tests::internal ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - 2 Running tests/integration_test.rs -(target/debug/deps/integration_test-1082c4b063a8fbe6) + Running tests/integration_test.rs (target/debug/deps/integration_test-1082c4b063a8fbe6) running 1 test -3 test it_adds_two ... ok +test it_adds_two ... ok -4 test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s Doc-tests adder running 0 tests -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` The three sections of output include the unit tests, the integration test, and @@ -1414,14 +1564,13 @@ will not be run. For example, if a unit test fails, there won’t be any output for integration and doc tests because those tests will only be run if all unit tests are passing. -The first section for the unit tests [1] is the same as we’ve been seeing: one -line for each unit test (one named `internal` that we added in Listing 11-12) -and then a summary line for the unit tests. +The first section for the unit tests is the same as we’ve been seeing: one line +for each unit test (one named `internal` that we added in Listing 11-12) and +then a summary line for the unit tests. -The integration tests section starts with the line `Running -tests/integration_test.rs` [2]. Next, there is a line for each test function in -that integration test [3] and a summary line for the results of the integration -test [4] just before the `Doc-tests adder` section starts. +The integration tests section starts with the line `Running tests/integration_test.rs`. Next, there is a line for each test function in +that integration test and a summary line for the results of the integration +test just before the `Doc-tests adder` section starts. Each integration test file has its own section, so if we add more files in the *tests* directory, there will be more integration test sections. @@ -1440,8 +1589,8 @@ $ cargo test --test integration_test running 1 test test it_adds_two ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` This command runs only the tests in the *tests/integration_test.rs* file. @@ -1459,11 +1608,11 @@ regarding how to separate code into modules and files. The different behavior of *tests* directory files is most noticeable when you have a set of helper functions to use in multiple integration test files and -you try to follow the steps in “Separating Modules into Different Files” on -page XX to extract them into a common module. For example, if we create -*tests/common.rs* and place a function named `setup` in it, we can add some -code to `setup` that we want to call from multiple test functions in multiple -test files: +you try to follow the steps in the “Separating Modules into Different +Files” section of Chapter 7 to +extract them into a common module. For example, if we create *tests/common.rs* +and place a function named `setup` in it, we can add some code to `setup` that +we want to call from multiple test functions in multiple test files: Filename: tests/common.rs @@ -1478,35 +1627,35 @@ When we run the tests again, we’ll see a new section in the test output for th did we call the `setup` function from anywhere: ``` +$ cargo test + Compiling adder v0.1.0 (file:///projects/adder) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.89s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) + running 1 test test tests::internal ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - Running tests/common.rs (target/debug/deps/common- -92948b65e88960b4) + Running tests/common.rs (target/debug/deps/common-92948b65e88960b4) running 0 tests -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - Running tests/integration_test.rs -(target/debug/deps/integration_test-92948b65e88960b4) + Running tests/integration_test.rs (target/debug/deps/integration_test-92948b65e88960b4) running 1 test test it_adds_two ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s Doc-tests adder running 0 tests -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` Having `common` appear in the test results with `running 0 tests` displayed for @@ -1519,20 +1668,21 @@ project directory now looks like this: ├── Cargo.lock ├── Cargo.toml ├── src -│ └── lib.rs +│   └── lib.rs └── tests ├── common - │ └── mod.rs + │   └── mod.rs └── integration_test.rs ``` This is the older naming convention that Rust also understands that we -mentioned in “Alternate File Paths” on page XX. Naming the file this way tells -Rust not to treat the `common` module as an integration test file. When we move -the `setup` function code into *tests/common/mod.rs* and delete the -*tests/common.rs* file, the section in the test output will no longer appear. -Files in subdirectories of the *tests* directory don’t get compiled as separate -crates or have sections in the test output. +mentioned in the “Alternate File Paths” section of +Chapter 7. Naming the file this way tells Rust not to treat the `common` module +as an integration test file. When we move the `setup` function code into +*tests/common/mod.rs* and delete the *tests/common.rs* file, the section in the +test output will no longer appear. Files in subdirectories of the *tests* +directory don’t get compiled as separate crates or have sections in the test +output. After we’ve created *tests/common/mod.rs*, we can use it from any of the integration test files as a module. Here’s an example of calling the `setup` @@ -1584,4 +1734,3 @@ reduce logic bugs having to do with how your code is expected to behave. Let’s combine the knowledge you learned in this chapter and in previous chapters to work on a project! - From 6a1bf5dede17bb0c7c3d5e15fadac109044a9039 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 5 Jul 2024 17:12:24 -0400 Subject: [PATCH 354/720] Snapshot changes to ch11 to consider sending to nostarch --- nostarch/chapter11.md | 374 ++++++++++++++++++++++-------------------- 1 file changed, 199 insertions(+), 175 deletions(-) diff --git a/nostarch/chapter11.md b/nostarch/chapter11.md index ccaf39817c..d44a501497 100644 --- a/nostarch/chapter11.md +++ b/nostarch/chapter11.md @@ -100,25 +100,29 @@ cd ../../.. --> ``` +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { - 1 #[test] + use super::*; + + #[test] fn it_works() { - let result = 2 + 2; - 2 assert_eq!(result, 4); + let result = add(2, 2); + assert_eq!(result, 4); } } ``` -Listing 11-1: The test module and function generated automatically by `cargo -new` +Listing 11-1: The code generated automatically by cargo new -For now, let’s ignore the top two lines and focus on the function. Note the -`#[test]` annotation [1]: this attribute indicates this is a test function, so -the test runner knows to treat this function as a test. We might also have -non-test functions in the `tests` module to help set up common scenarios or -perform common operations, so we always need to indicate which functions are -tests. +For now, let’s focus solely on the `it_works` function. Note the `#[test]` +annotation: this attribute indicates this is a test function, so the test +runner knows to treat this function as a test. We might also have non-test +functions in the `tests` module to help set up common scenarios or perform +common operations, so we always need to indicate which functions are tests. The example function body uses the `assert_eq!` macro to assert that `result`, which contains the result of adding 2 and 2, equals 4. This assertion serves as @@ -132,9 +136,8 @@ The `cargo test` command runs all tests in our project, as shown in Listing ``` $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.57s - Running unittests src/lib.rs (target/debug/deps/adder- -92948b65e88960b4) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.57s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test test tests::it_works ... ok @@ -151,24 +154,23 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini Listing 11-2: The output from running the automatically generated test -Cargo compiled and ran the test. We see the line `running 1 test` [1]. The next -line shows the name of the generated test function, called `it_works`, and that -the result of running that test is `ok` [2]. The overall summary `test result: -ok.` [3] means that all the tests passed, and the portion that reads `1 passed; -0 failed` totals the number of tests that passed or failed. +Cargo compiled and ran the test. We see the line `running 1 test`. The next +line shows the name of the generated test function, called `tests::it_works`, +and that the result of running that test is `ok`. The overall summary `test result: ok.` means that all the tests passed, and the portion that reads `1 passed; 0 failed` totals the number of tests that passed or failed. It’s possible to mark a test as ignored so it doesn’t run in a particular -instance; we’ll cover that in “Ignoring Some Tests Unless Specifically -Requested” on page XX. Because we haven’t done that here, the summary shows `0 -ignored`. We can also pass an argument to the `cargo test` command to run only -tests whose name matches a string; this is called *filtering* and we’ll cover -it in “Running a Subset of Tests by Name” on page XX. Here we haven’t filtered -the tests being run, so the end of the summary shows `0 filtered out`. +instance; we’ll cover that in the “Ignoring Some Tests Unless Specifically +Requested” section later in this chapter. Because we +haven’t done that here, the summary shows `0 ignored`. The `0 measured` statistic is for benchmark tests that measure performance. Benchmark tests are, as of this writing, only available in nightly Rust. See the documentation about benchmark tests at *../unstable-book/library-features/test.html* to learn more. +We can pass an argument to the `cargo test` command to run only tests whose +name matches a string; this is called *filtering* and we’ll cover that in the +“Running a Subset of Tests by Name” section. Here we +haven’t filtered the tests being run, so the end of the summary shows `0 filtered out`. The next part of the test output starting at `Doc-tests adder` is for the results of any documentation tests. We don’t have any documentation tests yet, @@ -184,11 +186,17 @@ the `it_works` function to a different name, such as `exploration`, like so: Filename: src/lib.rs ``` +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn exploration() { - let result = 2 + 2; + let result = add(2, 2); assert_eq!(result, 4); } } @@ -227,11 +235,18 @@ is to call the `panic!` macro. Enter the new test as a function named Filename: src/lib.rs ``` +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn exploration() { - assert_eq!(2 + 2, 4); + let result = add(2, 2); + assert_eq!(result, 4); } #[test] @@ -260,9 +275,9 @@ test tests::exploration ... ok failures: ---- tests::another stdout ---- -thread 'main' panicked at 'Make this test fail', src/lib.rs:10:9 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +thread 'tests::another' panicked at src/lib.rs:17:9: +Make this test fail +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: @@ -270,7 +285,7 @@ failures: test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s -error: test failed, to rerun pass '--lib' +error: test failed, to rerun pass `--lib` ``` Listing 11-4: Test results when one test passes and one test fails @@ -284,8 +299,8 @@ Instead of `ok`, the line `test tests::another` shows `FAILED`. Two new sections appear between the individual results and the summary: the first displays the detailed reason for each test failure. In this case, we get the details that `another` failed because it `panicked at 'Make this test fail'` on -line 10 in the *src/lib.rs* file. The next section [3] lists just the names of -all the failing tests, which is useful when there are lots of tests and lots of +line 17 in the *src/lib.rs* file. The next section lists just the names of all +the failing tests, which is useful when there are lots of tests and lots of detailed failing test output. We can use the name of a failing test to run just that test to more easily debug it; we’ll talk more about ways to run tests in the “Controlling How Tests Are Run” section. @@ -360,12 +375,13 @@ mod tests { Listing 11-6: A test for can_hold that checks whether a larger rectangle can indeed hold a smaller rectangle -Note that we’ve added a new line inside the `tests` module: `use super::*;` -[1]. The `tests` module is a regular module that follows the usual visibility -rules we covered in “Paths for Referring to an Item in the Module Tree” on page -XX. Because the `tests` module is an inner module, we need to bring the code -under test in the outer module into the scope of the inner module. We use a -glob here, so anything we define in the outer module is available to this +Note the `use super::*;` line inside the `tests` module. The `tests` module is +a regular module that follows the usual visibility rules we covered in Chapter +7 in the “Paths for Referring to an Item in the Module +Tree” +section. Because the `tests` module is an inner module, we need to bring the +code under test in the outer module into the scope of the inner module. We use +a glob here, so anything we define in the outer module is available to this `tests` module. We’ve named our test `larger_can_hold_smaller`, and we’ve created the two @@ -476,10 +492,9 @@ test tests::smaller_cannot_hold_larger ... ok failures: ---- tests::larger_can_hold_smaller stdout ---- -thread 'main' panicked at 'assertion failed: -larger.can_hold(&smaller)', src/lib.rs:28:9 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +thread 'tests::larger_can_hold_smaller' panicked at src/lib.rs:28:9: +assertion failed: larger.can_hold(&smaller) +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: @@ -514,7 +529,7 @@ parameter, then we test this function using the `assert_eq!` macro. Filename: src/lib.rs ``` -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { a + 2 } @@ -524,7 +539,8 @@ mod tests { #[test] fn it_adds_two() { - assert_eq!(4, add_two(2)); + let result = add_two(2); + assert_eq!(result, 4); } } ``` @@ -552,15 +568,16 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini ``` -We pass `4` as the argument to `assert_eq!`, which is equal to the result of -calling `add_two(2)`. The line for this test is `test tests::it_adds_two ... -ok`, and the `ok` text indicates that our test passed! +We create a variable named `result` that holds the result of calling +`add_two(2)`. Then we pass `result` and `4` as the arguments to `assert_eq!`. +The output line for this test is `test tests::it_adds_two ... ok`, and the `ok` +text indicates that our test passed! Let’s introduce a bug into our code to see what `assert_eq!` looks like when it fails. Change the implementation of the `add_two` function to instead add `3`: ``` -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { a + 3 } ``` @@ -579,33 +596,35 @@ test tests::it_adds_two ... FAILED failures: ---- tests::it_adds_two stdout ---- -1 thread 'main' panicked at 'assertion failed: `(left == right)` -2 left: `4`, -3 right: `5`', src/lib.rs:11:9 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +thread 'tests::it_adds_two' panicked at src/lib.rs:12:9: +assertion `left == right` failed + left: 5 + right: 4 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace + failures: tests::it_adds_two -test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +error: test failed, to rerun pass `--lib` ``` Our test caught the bug! The `it_adds_two` test failed, and the message tells -us that the assertion that failed was `assertion failed: `(left == right)`` [1] -and what the `left` [2] and `right` [3] values are. This message helps us start -debugging: the `left` argument was `4` but the `right` argument, where we had -`add_two(2)`, was `5`. You can imagine that this would be especially helpful -when we have a lot of tests going on. +us ``assertion `left == right` failed`` and what the `left` and `right` values +are. This message helps us start debugging: the `left` argument, where we had +the result of calling `add_two(2)`, was `5` but the `right` argument was `4`. +You can imagine that this would be especially helpful when we have a lot of +tests going on. Note that in some languages and test frameworks, the parameters to equality assertion functions are called `expected` and `actual`, and the order in which we specify the arguments matters. However, in Rust, they’re called `left` and `right`, and the order in which we specify the value we expect and the value the code produces doesn’t matter. We could write the assertion in this test as -`assert_eq!(add_two(2), 4)`, which would result in the same failure message -that displays `assertion failed: `(left == right)``. +`assert_eq!(4, result)`, which would produce the same failure message +that displays `` assertion failed: `(left == right)` ``. The `assert_ne!` macro will pass if the two values we give it are not equal and fail if they’re equal. This macro is most useful for cases when we’re not sure @@ -693,10 +712,9 @@ test tests::greeting_contains_name ... FAILED failures: ---- tests::greeting_contains_name stdout ---- -thread 'main' panicked at 'assertion failed: -result.contains(\"Carol\")', src/lib.rs:12:9 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +thread 'tests::greeting_contains_name' panicked at src/lib.rs:12:9: +assertion failed: result.contains("Carol") +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: @@ -738,10 +756,17 @@ test tests::greeting_contains_name ... FAILED failures: ---- tests::greeting_contains_name stdout ---- -thread 'main' panicked at 'Greeting did not contain name, value -was `Hello!`', src/lib.rs:12:9 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +thread 'tests::greeting_contains_name' panicked at src/lib.rs:12:9: +Greeting did not contain name, value was `Hello!` +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace + + +failures: + tests::greeting_contains_name + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +error: test failed, to rerun pass `--lib` ``` We can see the value we actually got in the test output, which would help us @@ -774,10 +799,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 } @@ -829,10 +851,7 @@ that the `new` function will panic if the value is greater than 100: 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 } @@ -887,13 +906,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}." ); } @@ -928,20 +945,15 @@ fails, let’s again introduce a bug into our code by swapping the bodies of the `if value < 1` and the `else if value > 100` blocks: ``` -// src/lib.rs ---snip-- -if value < 1 { - panic!( - "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 - ); -} ---snip-- + if value < 1 { + panic!( + "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}." + ); + } ``` This time when we run the `should_panic` test, it will fail: @@ -958,8 +970,8 @@ test tests::greater_than_100 - should panic ... FAILED failures: ---- tests::greater_than_100 stdout ---- -thread 'main' panicked at 'Guess value must be greater than or equal to 1, got -200.', src/lib.rs:13:13 +thread 'tests::greater_than_100' panicked at src/lib.rs:12:13: +Guess value must be greater than or equal to 1, got 200. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace note: panic did not contain expected string panic message: `"Guess value must be greater than or equal to 1, got 200."`, @@ -974,10 +986,8 @@ error: test failed, to rerun pass `--lib` ``` The failure message indicates that this test did indeed panic as we expected, -but the panic message did not include the expected string `'Guess value must be -less than or equal to 100'`. The panic message that we did get in this case was -`Guess value must be greater than or equal to 1, got 200`. Now we can start -figuring out where our bug is! +but the panic message did not include the expected string `less than or equal to 100`. The panic message that we did get in this case was `Guess value must be greater than or equal to 1, got 200.` Now we can start figuring out where +our bug is! ### Using `Result` in Tests @@ -985,17 +995,16 @@ Our tests so far all panic when they fail. We can also write tests that use `Result`! Here’s the test from Listing 11-1, rewritten to use `Result` and return an `Err` instead of panicking: ``` -#[cfg(test)] -mod tests { #[test] fn it_works() -> Result<(), String> { - if 2 + 2 == 4 { + let result = add(2, 2); + + if result == 4 { Ok(()) } else { Err(String::from("two plus two does not equal four")) } } -} ``` The `it_works` function now has the `Result<(), String>` return type. In the @@ -1090,13 +1099,13 @@ mod tests { #[test] fn this_test_will_pass() { let value = prints_and_returns_10(4); - assert_eq!(10, value); + assert_eq!(value, 10); } #[test] fn this_test_will_fail() { let value = prints_and_returns_10(8); - assert_eq!(5, value); + assert_eq!(value, 5); } } ``` @@ -1118,12 +1127,13 @@ test tests::this_test_will_pass ... ok failures: ---- tests::this_test_will_fail stdout ---- -1 I got the value 8 -thread 'main' panicked at 'assertion failed: `(left == right)` - left: `5`, - right: `10`', src/lib.rs:19:9 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +I got the value 8 +thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9: +assertion `left == right` failed + left: 10 + right: 5 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace + failures: tests::this_test_will_fail @@ -1171,11 +1181,12 @@ failures: ---- tests::this_test_will_fail stdout ---- I got the value 8 -thread 'main' panicked at 'assertion failed: `(left == right)` - left: `5`, - right: `10`', src/lib.rs:19:9 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9: +assertion `left == right` failed + left: 5 + right: 10 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace + failures: tests::this_test_will_fail @@ -1199,7 +1210,7 @@ our `add_two` function, as shown in Listing 11-11, and choose which ones to run. Filename: src/lib.rs ``` -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { a + 2 } @@ -1209,17 +1220,20 @@ mod tests { #[test] fn add_two_and_two() { - assert_eq!(4, add_two(2)); + let result = add_two(2); + assert_eq!(result, 4); } #[test] fn add_three_and_two() { - assert_eq!(5, add_two(3)); + let result = add_two(3); + assert_eq!(result, 5); } #[test] fn one_hundred() { - assert_eq!(102, add_two(100)); + let result = add_two(100); + assert_eq!(result, 102); } } ``` @@ -1257,9 +1271,8 @@ We can pass the name of any test function to `cargo test` to run only that test: ``` $ cargo test one_hundred Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.69s - Running unittests src/lib.rs (target/debug/deps/adder- -92948b65e88960b4) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.69s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test test tests::one_hundred ... ok @@ -1284,9 +1297,8 @@ run those two by running `cargo test add`: ``` $ cargo test add Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.61s - Running unittests src/lib.rs (target/debug/deps/adder- -92948b65e88960b4) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.61s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 2 tests test tests::add_three_and_two ... ok @@ -1312,16 +1324,21 @@ here: Filename: src/lib.rs ``` -#[test] -fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); -} +#[cfg(test)] +mod tests { + use super::*; -#[test] -#[ignore] -fn expensive_test() { - // code that takes an hour to run + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } + + #[test] + #[ignore] + fn expensive_test() { + // code that takes an hour to run + } } ``` @@ -1331,9 +1348,8 @@ Now when we run our tests, `it_works` runs, but `expensive_test` doesn’t: ``` $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 0.60s - Running unittests src/lib.rs (target/debug/deps/adder- -92948b65e88960b4) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.60s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 2 tests test tests::expensive_test ... ignored @@ -1354,9 +1370,9 @@ the ignored tests, we can use `cargo test -- --ignored`: ``` $ cargo test -- --ignored - Finished test [unoptimized + debuginfo] target(s) in 0.61s - Running unittests src/lib.rs (target/debug/deps/adder- -92948b65e88960b4) + Compiling adder v0.1.0 (file:///projects/adder) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.61s + Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) running 1 test test expensive_test ... ok @@ -1416,24 +1432,29 @@ this chapter, Cargo generated this code for us: Filename: src/lib.rs ``` +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn it_works() { - let result = 2 + 2; + let result = add(2, 2); assert_eq!(result, 4); } } ``` -This code is the automatically generated `tests` module. The attribute `cfg` -stands for *configuration* and tells Rust that the following item should only -be included given a certain configuration option. In this case, the -configuration option is `test`, which is provided by Rust for compiling and -running tests. By using the `cfg` attribute, Cargo compiles our test code only -if we actively run the tests with `cargo test`. This includes any helper -functions that might be within this module, in addition to the functions -annotated with `#[test]`. +On the automatically generated `tests` module, the attribute `cfg` stands for +*configuration* and tells Rust that the following item should only be included +given a certain configuration option. In this case, the configuration option is +`test`, which is provided by Rust for compiling and running tests. By using the +`cfg` attribute, Cargo compiles our test code only if we actively run the tests +with `cargo test`. This includes any helper functions that might be within this +module, in addition to the functions annotated with `#[test]`. #### Testing Private Functions @@ -1447,12 +1468,12 @@ Consider the code in Listing 11-12 with the private function `internal_adder`. Filename: src/lib.rs ``` -pub fn add_two(a: i32) -> i32 { +pub fn add_two(a: usize) -> usize { internal_adder(a, 2) } -fn internal_adder(a: i32, b: i32) -> i32 { - a + b +fn internal_adder(left: usize, right: usize) -> usize { + left + right } #[cfg(test)] @@ -1461,7 +1482,8 @@ mod tests { #[test] fn internal() { - assert_eq!(4, internal_adder(2, 2)); + let result = internal_adder(2, 2); + assert_eq!(result, 4); } } ``` @@ -1470,11 +1492,12 @@ Listing 11-12: Testing a private function Note that the `internal_adder` function is not marked as `pub`. Tests are just Rust code, and the `tests` module is just another module. As we discussed in -“Paths for Referring to an Item in the Module Tree” on page XX, items in child -modules can use the items in their ancestor modules. In this test, we bring all -of the `test` module’s parent’s items into scope with `use super::*`, and then -the test can call `internal_adder`. If you don’t think private functions should -be tested, there’s nothing in Rust that will compel you to do so. +the “Paths for Referring to an Item in the Module Tree” +section, items in child modules can use the items in their ancestor modules. In +this test, we bring all of the `tests` module’s parent’s items into scope with +`use super::*`, and then the test can call `internal_adder`. If you don’t think +private functions should be tested, there’s nothing in Rust that will compel +you to do so. ### Integration Tests @@ -1513,19 +1536,19 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file. Filename: tests/integration_test.rs ``` -use adder; +use adder::add_two; #[test] fn it_adds_two() { - assert_eq!(4, adder::add_two(2)); + let result = add_two(2); + assert_eq!(result, 4); } ``` Listing 11-13: An integration test of a function in the adder crate Each file in the *tests* directory is a separate crate, so we need to bring our -library into each test crate’s scope. For that reason we add `use adder;` at -the top of the code, which we didn’t need in the unit tests. +library into each test crate’s scope. For that reason we add `use adder::add_two;` at the top of the code, which we didn’t need in the unit tests. We don’t need to annotate any code in *tests/integration_test.rs* with `#[cfg(test)]`. Cargo treats the *tests* directory specially and compiles files @@ -1534,9 +1557,8 @@ in this directory only when we run `cargo test`. Run `cargo test` now: ``` $ cargo test Compiling adder v0.1.0 (file:///projects/adder) - Finished test [unoptimized + debuginfo] target(s) in 1.31s - Running unittests src/lib.rs (target/debug/deps/adder- -1082c4b063a8fbe6) + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.31s + Running unittests src/lib.rs (target/debug/deps/adder-1082c4b063a8fbe6) running 1 test test tests::internal ... ok @@ -1582,9 +1604,9 @@ followed by the name of the file: ``` $ cargo test --test integration_test - Finished test [unoptimized + debuginfo] target(s) in 0.64s - Running tests/integration_test.rs -(target/debug/deps/integration_test-82e7799c1bc62298) + Compiling adder v0.1.0 (file:///projects/adder) + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.64s + Running tests/integration_test.rs (target/debug/deps/integration_test-82e7799c1bc62298) running 1 test test it_adds_two ... ok @@ -1691,14 +1713,16 @@ function from the `it_adds_two` test in *tests/integration_test.rs*: Filename: tests/integration_test.rs ``` -use adder; +use adder::add_two; mod common; #[test] fn it_adds_two() { common::setup(); - assert_eq!(4, adder::add_two(2)); + + let result = add_two(2); + assert_eq!(result, 4); } ``` From ee5c7ec70496cc625b467012c44caa167eb60309 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 5 Jul 2024 17:30:00 -0400 Subject: [PATCH 355/720] Yes, RUSTFLAGS is a word --- ci/dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index e54b164f19..6329ed1238 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -429,6 +429,7 @@ Rustaceans rUsT rustc rustdoc +RUSTFLAGS Rustonomicon rustfix rustfmt From 451f77bc65952032f1946c80525e9792ef1e2da3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 3 Jul 2024 13:50:07 -0600 Subject: [PATCH 356/720] =?UTF-8?q?Ch.=2017=C2=A703=20initial=20edits=20on?= =?UTF-8?q?=20pinning=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Made a bunch of structural changes, including removing an entire unhelpful aside with an example that actually just confused things, and I *think* it is much more technically accurate *and* much easier to follow. - Updated the listings referenced within it for their new numberings, including deleting one per the above. --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../output.txt | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../ch17-async-await/listing-17-22/Cargo.lock | 280 ---------------- .../listing-17-22/src/main.rs | 18 -- .../listing-17-22/test-data/hello.txt | 1 - .../listing-17-22/test-data/punct.txt | 1 - .../listing-17-22/test-data/world.txt | 1 - .../ch17-async-await/listing-17-25/Cargo.toml | 9 - src/ch17-01-futures-and-syntax.md | 20 +- src/ch17-03-more-futures.md | 306 ++++++++---------- 18 files changed, 143 insertions(+), 493 deletions(-) rename listings/ch17-async-await/{listing-17-23 => listing-17-17}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-14 => listing-17-17}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-23 => listing-17-17}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-14 => listing-17-18}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-22 => listing-17-18}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-14 => listing-17-18}/output.txt (100%) rename listings/ch17-async-await/{listing-17-14 => listing-17-18}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-25 => listing-17-19}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-23 => listing-17-19}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-25 => listing-17-19}/src/main.rs (100%) delete mode 100644 listings/ch17-async-await/listing-17-22/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-22/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-22/test-data/hello.txt delete mode 100644 listings/ch17-async-await/listing-17-22/test-data/punct.txt delete mode 100644 listings/ch17-async-await/listing-17-22/test-data/world.txt delete mode 100644 listings/ch17-async-await/listing-17-25/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-23/Cargo.lock b/listings/ch17-async-await/listing-17-17/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-23/Cargo.lock rename to listings/ch17-async-await/listing-17-17/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-14/Cargo.toml b/listings/ch17-async-await/listing-17-17/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-14/Cargo.toml rename to listings/ch17-async-await/listing-17-17/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-23/src/main.rs b/listings/ch17-async-await/listing-17-17/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-23/src/main.rs rename to listings/ch17-async-await/listing-17-17/src/main.rs diff --git a/listings/ch17-async-await/listing-17-14/Cargo.lock b/listings/ch17-async-await/listing-17-18/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-14/Cargo.lock rename to listings/ch17-async-await/listing-17-18/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-22/Cargo.toml b/listings/ch17-async-await/listing-17-18/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-22/Cargo.toml rename to listings/ch17-async-await/listing-17-18/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-14/output.txt b/listings/ch17-async-await/listing-17-18/output.txt similarity index 100% rename from listings/ch17-async-await/listing-17-14/output.txt rename to listings/ch17-async-await/listing-17-18/output.txt diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-18/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-14/src/main.rs rename to listings/ch17-async-await/listing-17-18/src/main.rs diff --git a/listings/ch17-async-await/listing-17-25/Cargo.lock b/listings/ch17-async-await/listing-17-19/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-25/Cargo.lock rename to listings/ch17-async-await/listing-17-19/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-23/Cargo.toml b/listings/ch17-async-await/listing-17-19/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-23/Cargo.toml rename to listings/ch17-async-await/listing-17-19/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-25/src/main.rs b/listings/ch17-async-await/listing-17-19/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-25/src/main.rs rename to listings/ch17-async-await/listing-17-19/src/main.rs diff --git a/listings/ch17-async-await/listing-17-22/Cargo.lock b/listings/ch17-async-await/listing-17-22/Cargo.lock deleted file mode 100644 index 9eeeffaff4..0000000000 --- a/listings/ch17-async-await/listing-17-22/Cargo.lock +++ /dev/null @@ -1,280 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "memchr" -version = "2.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d0d8b92cd8358e8d229c11df9358decae64d137c5be540952c5ca7b25aea768" - -[[package]] -name = "miniz_oxide" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-22/src/main.rs b/listings/ch17-async-await/listing-17-22/src/main.rs deleted file mode 100644 index fbba735c3f..0000000000 --- a/listings/ch17-async-await/listing-17-22/src/main.rs +++ /dev/null @@ -1,18 +0,0 @@ -fn main() { - trpl::block_on({ - // ANCHOR: here - async { - let mut strings = vec![]; - - let a = trpl::read_to_string("test-data/hello.txt").await.unwrap(); - strings.push(a.trim()); - - let b = trpl::read_to_string("test-data/world.txt").await.unwrap(); - strings.push(b.trim()); - - let combined = strings.join(" "); - println!("{combined}"); - } - // ANCHOR_END: here - }); -} diff --git a/listings/ch17-async-await/listing-17-22/test-data/hello.txt b/listings/ch17-async-await/listing-17-22/test-data/hello.txt deleted file mode 100644 index e965047ad7..0000000000 --- a/listings/ch17-async-await/listing-17-22/test-data/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello diff --git a/listings/ch17-async-await/listing-17-22/test-data/punct.txt b/listings/ch17-async-await/listing-17-22/test-data/punct.txt deleted file mode 100644 index cdf4cb4feb..0000000000 --- a/listings/ch17-async-await/listing-17-22/test-data/punct.txt +++ /dev/null @@ -1 +0,0 @@ -! diff --git a/listings/ch17-async-await/listing-17-22/test-data/world.txt b/listings/ch17-async-await/listing-17-22/test-data/world.txt deleted file mode 100644 index 216e97ce08..0000000000 --- a/listings/ch17-async-await/listing-17-22/test-data/world.txt +++ /dev/null @@ -1 +0,0 @@ -World diff --git a/listings/ch17-async-await/listing-17-25/Cargo.toml b/listings/ch17-async-await/listing-17-25/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-25/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index d3e08bc01b..f5e912ba79 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -282,18 +282,24 @@ state machine, as if you wrote something like this: ```rust enum MyAsyncStateMachine { - FirstAwaitPoint(/* the state used after the first await point */), - SecondAwaitPoint(/* the state used after the second await point */), + FirstAwaitPoint { + // the state used up to the first await point... + }, + SecondAwaitPoint { + // the state used up to the second await point... + }, // etc. for each `.await` point... } ``` Writing that out by hand would be tedious and error-prone, especially when -making changes to code later. Instead, async Rust creates and manages the state -machine data structures for us. (If you’re wondering: yep, the normal borrowing -and ownership rules around data structures all apply. Happily, the compiler also -handles checking those for us, and has good error messages. We will work through -a few of those later in the chapter!) +making changes to code later. Instead, the Rust compiler creates and manages the +state machine data structures for async code automatically. + +If you’re wondering: yep, the normal borrowing and ownership rules around data +structures all apply. Happily, the compiler also handles checking those for us, +and has good error messages. We will work through a few of those later in the +chapter! Now we can understand why the compiler stopped us from making `main` itself an async function in Listing 17-3. If `main` were an async function, something else diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 7057e02cb2..4f15c6b861 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -234,9 +234,10 @@ the idea of *pinning*. ### Pinning and the Pin and Unpin Traits -When we introduced the `Future` trait in the previous chapter, we saw that the -definition of its `poll` method has an unusual way of specifying the `self` -parameter. To review, here is the full definition of `Future`: + + +Let’s look again at the definition of `Future`, focusing now on its `poll` +method’s `self` type: ```rust pub trait Future { @@ -247,95 +248,15 @@ pub trait Future { } ``` -We have not seen a method definition like this before, where `self` has a type -annotation rather than simply being named like `self`, `mut self`, `&self`, or -`&mut self`. This syntax means that the method can only be called when the -instance of the type which implements `Future` is behind a `Pin` pointer type. -This syntax is not specific to `Pin`; it also works with `Box` and other smart -pointer types, and we will see it again in Chapter 18. - -Here, the signature tells us that if we want to poll a future to check whether -it is `Pending` or `Ready(Output)`, the type which implements `Future` has to be -behind a `Pin` smart pointer type. Recalling that `.await` is implemented in -terms of calls to `poll()`, this starts to explain the error message we saw -above—but that was in terms of `Unpin`, not `Pin`. So what exactly are `Pin` and -`Unpin`, how do they relate, and why does `Future` need `self` to be in a `Pin` -type to call `poll`? - -In [“Futures and Syntax: What Are Futures”][what-are-futures], we described how -a series of await points in a future get compiled into a state machine—and noted -how the compiler helps make sure that state machine follows all of Rust’s normal -rules around safety, including borrowing and ownership. Consider code which has -a mutable `Vec` of strings, which asynchronously reads strings from files and -pushes those strings into the `Vec`: - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:here}} -``` - - - -If we think about the state machine that would get compiled to, it might be -something kind of like this: - -```rust,ignore -enum AsyncStateMachine<'a> { - AfterFirstAwait(&'a mut Vec), - AfterSecondAwait(&'a mut Vec), -} -``` - -That is, at each `.await` in the source code, Rust would look at what state is -needed between that await point and the point another `.await` appears or the -async block ends, and create a corresponding variant in the `AsyncStateMachine`. -Each variant has the appropriate kind of reference to the data that will be -referenced in that section. The real implementation is not *exactly* like this, -but it is close enough to give the right mental model. - -And this could actually be fine, on its own—Rust would keep track of those -mutable references, and if we got something wrong, the borrow checker would tell -us. It gets a bit tricky, though, if we want to move around the future that -corresponds to that block. Remember, we could always do something like this: - -```rust,ignore -let file_reads_future = async { - // snip... -}; - -let some_other_future = async { - // snip... -}; - -trpl::join(file_reads_future, some_other_future).await; -``` - - - -If we pass those futures into `join`, or return them from a function, or put -them in a data structure to keep track of for some reason, that moves the state -machine as well. That means the reference to `Vec` for the values we -read in with `trpl::read_to_string` moves along with it. Since references point -to the actual memory address of the `Vec`, Rust needs some way to either update -them so they are still valid after the `Vec` moves, or it needs some way to keep -`Vec` from getting moved around so that the references do not need to be -updated. Updating all the references to an object every time it moves could be -quite a lot of work for the compiler to add, especially since there can be a -whole web of references that need updating. On the other hand, making sure the -underlying item *does not move in memory* can be “free” at runtime in exchange -for keeping some promises at compile time. That is where `Pin` and `Unpin` come -in. - -> Note: The specific mechanics for how `Pin` and `Unpin` work under the hood are -> covered extensively in the API documentation for `std::pin`, so if you would -> like to understand them more fundamentally, that is a great place to start. -> Those details are not at all necessary for working with async Rust day to day, -> though. Here, we will stick to the parts you *do* need to understand to work -> with them in everyday Rust! +This is the first time we have seen a method where `self` has a type annotation +like this. When we specify the type of `self` like this, we are telling Rust +what type `self` must be to call this method. These kinds of type annotations +for `self` are similar to those for other function parameters, but with the +restriction that the type annotation has to be the type on which the method is +implemented, or a reference or smart pointer to that type. We will see more on +this syntax in Chapter 18. For now, it is enough to know that if we want to poll +a future (to check whether it is `Pending` or `Ready(Output)`), we need a +mutable reference to the type, which is wrapped in a `Pin`. `Pin` is a smart pointer, much like `Box`, `Rc`, and the others we saw in Chapter 15. Unlike those, however, `Pin` only works with *other pointer types* @@ -343,65 +264,103 @@ like reference (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` works with types which implement the `Deref` or `DerefMut` traits, which we covered in Chapter 15. You can think of this restriction as equivalent to only working with pointers, though, since implementing `Deref` or -`DerefMut` means your type behaves like a pointer type. including references, -other smart pointers, and so on. - -Wrapping a pointer type in `Pin` enforces the exact guarantee we need: the value -*behind* the pointer we wrap in `Pin` cannot move. It is “pinned” in its current -spot by the `Pin` wrapper. Thus, if you have `Pin>`, you actually -pin the `SomeType` value, *not* the `Box` pointer. In fact, the pinned box -pointer can move around freely. Remember: we care about making sure the data -ultimately being referenced stays in its place. If a pointer moves around, but -the data it points to is in the same place, there is no problem. +`DerefMut` means your type behaves like a pointer type. + +Recalling that `.await` is implemented in terms of calls to `poll()`, this +starts to explain the error message we saw above—but that was in terms of +`Unpin`, not `Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, +and why does `Future` need `self` to be in a `Pin` type to call `poll`? + +In [“What Are Futures”][what-are-futures], we described how a series of await +points in a future get compiled into a state machine—and noted how the compiler +helps make sure that state machine follows all of Rust’s normal rules around +safety, including borrowing and ownership. To make that work, Rust looks at what +data is needed between each await point and the next await point or the end of +the async block. It then creates a corresponding variant in the state machine it +creates. Each variant gets the access it needs to the data that will be used in +that section of the source code, whether by taking ownership of that data or by +getting a mutable or immutable reference to it. + +So far so good: if we get anything wrong about the ownership or references in a +given async block, the borrow checker will tell us. When we want to move around +the future that corresponds to that block—like moving it into a `Vec` to pass to +`join_all`—things get trickier. + +When we move a future—whether by pushing into a data structure to use as an +iterator with `join_all`, or returning them from a function—that actually means +moving the state machine Rust creates for us. And unlike most other types in +Rust, the futures Rust creates for async blocks can end up with references to +themselves in the fields of any given variant. Any object which has a reference +to itself is unsafe to move, though, because references always point to the +actual memory address of the thing they refer to. If you move the data structure +itself, you *have* to update any references to it, or they will be left pointing +to the old location. + +In principle, you could make the Rust compiler try to update every reference to +an object every time it gets moved. That would potentially be a lot of +performance overhead, especially given there can be a whole web of references +that need updating. On the other hand, if we could make sure the data structure +in question *does not move in memory*, we do not have to update any references. +And this is exactly what Rust’s borrow checker already guarantees: you cannot +move an item which has any active references to it using safe code. + +`Pin` builds on that to give us the exact guarantee we need. When we *pin* a +value by wrapping a pointer to it in `Pin`, it can no longer move. Thus, if you +have `Pin>`, you actually pin the `SomeType` value, *not* the +`Box` pointer. In fact, the pinned box pointer can move around freely. Remember: +we care about making sure the data ultimately being referenced stays in its +place. If a pointer moves around, but the data it points to is in the same +place, there is no problem. However, most types are perfectly safe to move around, even if they happen to be -behind a `Pin` pointer. Remember: the problem `Pin` addresses is when data -structures have internal references which need to maintained when the structure -moves around, as happens with internal references in futures. Primitive values -like numbers and booleans do not have any internal structure like that, so they -are obviously safe. Neither do most types you normally work with in Rust. A -`Vec`, for example, does not have any internal references it needs to keep up to -date this way, so you can move it around without worrying. But what happens if -you have a `Pin` or a `Pin>`? - -We need a way to tell the compiler that it is actually just fine to move items -around in cases like these where there is nothing to worry about. For that, we -have `Unpin`. `Unpin` is a marker trait, like `Send` and `Sync`, which we saw in -Chapter 16. Recall that marker traits have no functionality of their own. They -exist only to tell the compiler that it is safe to use the type which implements -a given trait in a particular context. `Unpin` informs the compiler that a given -type does *not* need to uphold any particular guarantees about whether the value -in question can be moved. +behind a `Pin` pointer. We only need to think about pinning when items have +internal references. Primitive values like numbers and booleans do not have any +internal structure like that, so they are obviously safe. Neither do most types +you normally work with in Rust. A `Vec`, for example, does not have any internal +references it needs to keep up to date this way, so you can move it around +without worrying. If you have a `Pin>`, you would have to do +everything via Pin’s safe but restrictive APIs, even though a `Vec` is +always safe to move if there are no other references to it. We need a way to +tell the compiler that it is actually just fine to move items around in cases +like these. For that, we have `Unpin`. + +`Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. +Recall that marker traits have no functionality of their own. They exist only to +tell the compiler that it is safe to use the type which implements a given trait +in a particular context. `Unpin` informs the compiler that a given type does +*not* need to uphold any particular guarantees about whether the value in +question can be moved. Just like `Send` and `Sync`, the compiler implements `Unpin` automatically for -most types, and implementing it manually is unsafe. That is because you have to -make sure that the type for which you are implementing `Unsafe` *never* moves -data out from a reference that *needs* to be stable. +all types where it can prove it is safe. Implementing `Unpin` manually is unsafe +because it requires *you* to uphold all the guarantees which make `Pin` and +`Unpin` safe yourself for a type with internal references. In practice, this is +a very rare thing to implement yourself! > Note: This combination of `Pin` and `Unpin` allows a whole class of complex > types to be safe in Rust which are otherwise difficult to implement because -> they are *self-referential*. That is, they are data structures where one part -> of the structure refers to another internally. As we have seen, futures can -> match that description, so self-referential types which require `Pin` show up -> *most* commonly in async Rust today, but you might—very rarely!—see it in -> other contexts, too. - -Now we know enough to understand the error message from above. The problem is -that the futures produced by an async block are *not* pinned by default. -Strictly: they implement `!Unpin` to opt out of being copyable by default the -way most types are. We need to pin them explicitly. - -Now that we have an idea what that error message was telling us, we can finally -get our `join_all` call to compile! First, we need to explicitly annotate -`futures` as referring to a pinned `Box` of futures. Second, we actually need to -pin the futures, which we can do using the handy `Box::pin` API, which exists -for exactly this. Putting that together, we end up with the code in Listing -17-23. - -+> they are self-referential. Types which require `Pin` show up *most* commonly +> in async Rust today, but you might—very rarely!—see it in other contexts, too. +> +> The specific mechanics for how `Pin` and `Unpin` work under the hood are +> covered extensively in the API documentation for `std::pin`, so if you would +> like to understand them more deeply, that is a great place to start. + +Now we know enough to fix the last errors with `join_all`. We tried to move the +futures produced by an async blocks into a `Vec>>`, +but as we have seen, those futures may have internal references, so they do not +implement `Unpin`. They need to be pinned, and then we can pass the `Pin` type +into the `Vec`, confident that the underlying data in the futures will *not* be +moved. + +Listing 17-17 shows how we put this all into practice. First, we update the type +annotation for `futures`, with a `Pin` wrapping each `Box`. Second, we use +`Box::pin` to pin the futures themselves. + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-17/src/main.rs:here}} ``` @@ -432,60 +391,55 @@ actually *need* the heap allocation, after all: these futures are local to this particular function. As noted above, `Pin` is itself a smart pointer, so we can get the benefit of having a single type in the `Vec`—the original reason we reached for `Box`—without doing a heap allocation. We can use `Pin` directly -instead. +with each future, using the `std::pin::pin` macro. -The `std::pin::pin` macro exists to do just that for values. However, we must -still be explicit about the type of the pinned reference; otherwise Rust will -still not know to interpret these as dynamic trait objects, which is what we -need them to be in the `Vec`. We therefore `pin!` each future when we define it, -and define `futures` as a `Vec` containing pinned mutable references to the -dynamic `Future` type, as in Listing 17-24. +However, we must still be explicit about the type of the pinned reference; +otherwise Rust will still not know to interpret these as dynamic trait objects, +which is what we need them to be in the `Vec`. We therefore `pin!` each future +when we define it, and define `futures` as a `Vec` containing pinned mutable +references to the dynamic `Future` type, as in Listing 17-18. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-18/src/main.rs:here}} ``` -This keeps everything on the stack, which is a nice little performance win, but -it is still a lot of explicit types, which is quite unusual for Rust! - There is another, more serious, issue as well. We got this far by ignoring the -fact that we might have different `Output` types. For example, in Listing 17-25, -the anonymous future type for `a` implements `Future`, the -anonymous future type for `b` implements `Future`, and the -anonymous future type for `c` implements `Future`. We can use -`trpl::join!` to await them together, since it accepts futures of different -types. +fact that we might have different `Output` types. For example, in Listing 17-19, +the anonymous future for `a` implements `Future`, the anonymous +future for `b` implements `Future`, and the anonymous future for +`c` implements `Future`. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} ``` -We cannot use `trpl::join_all` with these futures, though, because -we will never be able to make them have the same type. (Remember, that error is -what got us started on this adventure with `Pin`!) +We can use `trpl::join!` to await them, because it allows you to pass in +multiple future types and produces a tuple of those htypes. We *cannot* use +`trpl::join_all`, because it requires the futures passed in all to have the same +type. (Remember, that error is what got us started on this adventure with +`Pin`!) -We have a basic tradeoff here: we can either deal with a dynamic number of +This is a fundamental tradeoff: we can either deal with a dynamic number of futures with `join_all`, as long as they all have the same type, or we can deal with a set number of futures with the `join` functions or the `join!` macro, even if they have different types. This is the same as working with any other -type in Rust, though: futures are not special, even though we have some nice -syntax for working with them, and that is a good thing! - -In practice, you will usually work directly with `async` and `.await`, and only -as a secondary tool reach for the functions like `join` or `join_all`, or their -corresponding macro equivalents. Likewise, you will only need to reach for `pin` -now and again to use them *with* those APIs. These kinds of tools are mostly -handy for building frameworks, or especially when you are building a runtime -itself, rather than for day to day Rust code. When you see them, though, now you -will know what to do! +types in Rust, though. Futures are not special, even though we have some nice +syntax for working with them, and that is a good thing. + +In practice, you will usually work directly with `async` and `.await`, and +secondarily with functions and macros like `join` or `join_all`. You will only +need to reach for `pin` now and again to use them with those APIs. `Pin` and +`Unpin` are mostly important for building lower-level libraries, or when you are +building a runtime itself, rather than for day to day Rust code. When you see +them, though, now you will know what to do! [collections]: ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: ch12-03-improving-error-handling-and-modularity.html From 1cc4dbedd9d739afcd900841725d4562b88ff442 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 5 Jul 2024 17:25:22 -0600 Subject: [PATCH 357/720] =?UTF-8?q?Ch.=2017=C2=A703:=20Rename=20the=20sect?= =?UTF-8?q?ion=20for=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SUMMARY.md | 2 +- src/ch17-03-more-futures.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 5a6dbfc377..2645cfcedf 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -104,7 +104,7 @@ - [Async and Await](ch17-00-async-await.md) - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) - [Concurrency With Async](ch17-02-concurrency-with-async.md) - - [Working With More Futures](ch17-03-more-futures.md) + - [Working With More Than Two Futures](ch17-03-more-futures.md) - [More Ways of Combining Futures](ch17-04-more-ways-of-combining-futures.md) - [Streams](ch17-05-streams.md) - [Futures, Tasks, and Threads](ch17-06-futures-tasks-threads.md) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 4f15c6b861..6475a268fa 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -1,4 +1,4 @@ -## Working With More Futures +## Working With More Than Two Futures When we switched from using two futures to three in the previous section, we also had to switch from using `join` to using `join3`. It would be annoying to From cc0f913a74402ad25e43547116428ceb3755db78 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 5 Jul 2024 17:25:22 -0600 Subject: [PATCH 358/720] Ch. 17: remove now unused Listing 17-24 --- .../ch17-async-await/listing-17-24/Cargo.lock | 280 ------------------ .../ch17-async-await/listing-17-24/Cargo.toml | 9 - .../listing-17-24/src/main.rs | 62 ---- 3 files changed, 351 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-24/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-24/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-24/src/main.rs diff --git a/listings/ch17-async-await/listing-17-24/Cargo.lock b/listings/ch17-async-await/listing-17-24/Cargo.lock deleted file mode 100644 index c0e8bb2b3f..0000000000 --- a/listings/ch17-async-await/listing-17-24/Cargo.lock +++ /dev/null @@ -1,280 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-24/Cargo.toml b/listings/ch17-async-await/listing-17-24/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-24/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-24/src/main.rs b/listings/ch17-async-await/listing-17-24/src/main.rs deleted file mode 100644 index 7e33ab3cc8..0000000000 --- a/listings/ch17-async-await/listing-17-24/src/main.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::{ - future::Future, - pin::{pin, Pin}, - time::Duration, -}; - -fn main() { - trpl::block_on(async { - let (tx, mut rx) = trpl::channel(); - - let tx1 = tx.clone(); - // ANCHOR: here - let tx1_fut = pin!(async move { - // snip... - // ANCHOR_END: here - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - // ANCHOR: here - }); - - let rx_fut = pin!(async { - // snip... - // ANCHOR_END: here - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR: here - }); - - let tx_fut = pin!(async move { - // snip... - // ANCHOR_END: here - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; - } - // ANCHOR: here - }); - - let futures: Vec>> = - vec![tx1_fut, rx_fut, tx_fut]; - // ANCHOR_END: here - - trpl::join_all(futures).await; - }); -} From 1030015d0b34bc72e304f0b8e0c5cb1503faf895 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 5 Jul 2024 17:25:22 -0600 Subject: [PATCH 359/720] =?UTF-8?q?Ch.=2017=C2=A704=20initial=20edits=20on?= =?UTF-8?q?=20intro=20and=20=E2=80=9CYielding=E2=80=9D=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 12 + .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 12 + .../Cargo.toml | 0 .../src/main.rs | 14 +- .../Cargo.lock | 12 + .../Cargo.toml | 0 .../src/main.rs | 18 +- .../ch17-async-await/listing-17-24/Cargo.lock | 292 ++++++++++ .../Cargo.toml | 0 .../src/main.rs | 22 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../ch17-async-await/listing-17-28/output.txt | 38 -- .../ch17-async-await/listing-17-31/Cargo.lock | 540 ------------------ src/ch17-04-more-ways-of-combining-futures.md | 195 +++---- 21 files changed, 448 insertions(+), 707 deletions(-) rename listings/ch17-async-await/{listing-17-26 => listing-17-20}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-26 => listing-17-20}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-26 => listing-17-20}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-27 => listing-17-21}/Cargo.lock (96%) rename listings/ch17-async-await/{listing-17-27 => listing-17-21}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-27 => listing-17-21}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-28 => listing-17-22}/Cargo.lock (96%) rename listings/ch17-async-await/{listing-17-28 => listing-17-22}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-28 => listing-17-22}/src/main.rs (75%) rename listings/ch17-async-await/{listing-17-29 => listing-17-23}/Cargo.lock (96%) rename listings/ch17-async-await/{listing-17-29 => listing-17-23}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-29 => listing-17-23}/src/main.rs (71%) create mode 100644 listings/ch17-async-await/listing-17-24/Cargo.lock rename listings/ch17-async-await/{listing-17-30 => listing-17-24}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-30 => listing-17-24}/src/main.rs (65%) rename listings/ch17-async-await/{listing-17-30 => listing-17-25}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-31 => listing-17-25}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-31 => listing-17-25}/src/main.rs (100%) delete mode 100644 listings/ch17-async-await/listing-17-28/output.txt delete mode 100644 listings/ch17-async-await/listing-17-31/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-26/Cargo.lock b/listings/ch17-async-await/listing-17-20/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-26/Cargo.lock rename to listings/ch17-async-await/listing-17-20/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-26/Cargo.toml b/listings/ch17-async-await/listing-17-20/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-26/Cargo.toml rename to listings/ch17-async-await/listing-17-20/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-26/src/main.rs b/listings/ch17-async-await/listing-17-20/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-26/src/main.rs rename to listings/ch17-async-await/listing-17-20/src/main.rs diff --git a/listings/ch17-async-await/listing-17-27/Cargo.lock b/listings/ch17-async-await/listing-17-21/Cargo.lock similarity index 96% rename from listings/ch17-async-await/listing-17-27/Cargo.lock rename to listings/ch17-async-await/listing-17-21/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-27/Cargo.lock +++ b/listings/ch17-async-await/listing-17-21/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-27/Cargo.toml b/listings/ch17-async-await/listing-17-21/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-27/Cargo.toml rename to listings/ch17-async-await/listing-17-21/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-27/src/main.rs b/listings/ch17-async-await/listing-17-21/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-27/src/main.rs rename to listings/ch17-async-await/listing-17-21/src/main.rs diff --git a/listings/ch17-async-await/listing-17-28/Cargo.lock b/listings/ch17-async-await/listing-17-22/Cargo.lock similarity index 96% rename from listings/ch17-async-await/listing-17-28/Cargo.lock rename to listings/ch17-async-await/listing-17-22/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-28/Cargo.lock +++ b/listings/ch17-async-await/listing-17-22/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-28/Cargo.toml b/listings/ch17-async-await/listing-17-22/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-28/Cargo.toml rename to listings/ch17-async-await/listing-17-22/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-28/src/main.rs b/listings/ch17-async-await/listing-17-22/src/main.rs similarity index 75% rename from listings/ch17-async-await/listing-17-28/src/main.rs rename to listings/ch17-async-await/listing-17-22/src/main.rs index 9948c79e57..e9474873c9 100644 --- a/listings/ch17-async-await/listing-17-28/src/main.rs +++ b/listings/ch17-async-await/listing-17-22/src/main.rs @@ -5,21 +5,19 @@ fn main() { // ANCHOR: slow-futures let a = async { println!("'a' started."); - slow("a", 300); - slow("a", 100); - slow("a", 200); - slow("a", 900); + slow("a", 30); + slow("a", 10); + slow("a", 20); trpl::sleep(Duration::from_millis(50)).await; println!("'a' finished."); }; let b = async { println!("'b' started."); - slow("b", 750); - slow("b", 100); - slow("b", 150); + slow("b", 75); + slow("b", 10); + slow("b", 15); slow("b", 350); - slow("b", 150); trpl::sleep(Duration::from_millis(50)).await; println!("'b' finished."); }; diff --git a/listings/ch17-async-await/listing-17-29/Cargo.lock b/listings/ch17-async-await/listing-17-23/Cargo.lock similarity index 96% rename from listings/ch17-async-await/listing-17-29/Cargo.lock rename to listings/ch17-async-await/listing-17-23/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-29/Cargo.lock +++ b/listings/ch17-async-await/listing-17-23/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-29/Cargo.toml b/listings/ch17-async-await/listing-17-23/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-29/Cargo.toml rename to listings/ch17-async-await/listing-17-23/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-29/src/main.rs b/listings/ch17-async-await/listing-17-23/src/main.rs similarity index 71% rename from listings/ch17-async-await/listing-17-29/src/main.rs rename to listings/ch17-async-await/listing-17-23/src/main.rs index d5c90e0226..ae9536c5bd 100644 --- a/listings/ch17-async-await/listing-17-29/src/main.rs +++ b/listings/ch17-async-await/listing-17-23/src/main.rs @@ -7,28 +7,24 @@ fn main() { let a = async { println!("'a' started."); - slow("a", 300); + slow("a", 30); trpl::sleep(one_ms).await; - slow("a", 100); + slow("a", 10); trpl::sleep(one_ms).await; - slow("a", 200); - trpl::sleep(one_ms).await; - slow("a", 900); + slow("a", 20); trpl::sleep(one_ms).await; println!("'a' finished."); }; let b = async { println!("'b' started."); - slow("b", 750); - trpl::sleep(one_ms).await; - slow("b", 100); + slow("b", 75); trpl::sleep(one_ms).await; - slow("b", 150); + slow("b", 10); trpl::sleep(one_ms).await; - slow("b", 350); + slow("b", 15); trpl::sleep(one_ms).await; - slow("b", 150); + slow("b", 35); trpl::sleep(one_ms).await; println!("'b' finished."); }; diff --git a/listings/ch17-async-await/listing-17-24/Cargo.lock b/listings/ch17-async-await/listing-17-24/Cargo.lock new file mode 100644 index 0000000000..2e0f3ebedb --- /dev/null +++ b/listings/ch17-async-await/listing-17-24/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-30/Cargo.toml b/listings/ch17-async-await/listing-17-24/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-30/Cargo.toml rename to listings/ch17-async-await/listing-17-24/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-30/src/main.rs b/listings/ch17-async-await/listing-17-24/src/main.rs similarity index 65% rename from listings/ch17-async-await/listing-17-30/src/main.rs rename to listings/ch17-async-await/listing-17-24/src/main.rs index d4552dace7..7efd8fff9a 100644 --- a/listings/ch17-async-await/listing-17-30/src/main.rs +++ b/listings/ch17-async-await/listing-17-24/src/main.rs @@ -2,35 +2,31 @@ use std::{thread, time::Duration}; fn main() { trpl::block_on(async { - // ANCHOR: here + // ANCHOR: yields let a = async { println!("'a' started."); - slow("a", 300); + slow("a", 30); trpl::yield_now().await; - slow("a", 100); + slow("a", 10); trpl::yield_now().await; - slow("a", 200); - trpl::yield_now().await; - slow("a", 900); + slow("a", 20); trpl::yield_now().await; println!("'a' finished."); }; let b = async { println!("'b' started."); - slow("b", 750); - trpl::yield_now().await; - slow("b", 100); + slow("b", 75); trpl::yield_now().await; - slow("b", 150); + slow("b", 10); trpl::yield_now().await; - slow("b", 350); + slow("b", 15); trpl::yield_now().await; - slow("b", 150); + slow("b", 35); trpl::yield_now().await; println!("'b' finished."); }; - // ANCHOR_end: here + // ANCHOR_END: yields trpl::race(a, b).await; }); diff --git a/listings/ch17-async-await/listing-17-30/Cargo.lock b/listings/ch17-async-await/listing-17-25/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-30/Cargo.lock rename to listings/ch17-async-await/listing-17-25/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-31/Cargo.toml b/listings/ch17-async-await/listing-17-25/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-31/Cargo.toml rename to listings/ch17-async-await/listing-17-25/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-31/src/main.rs b/listings/ch17-async-await/listing-17-25/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-31/src/main.rs rename to listings/ch17-async-await/listing-17-25/src/main.rs diff --git a/listings/ch17-async-await/listing-17-28/output.txt b/listings/ch17-async-await/listing-17-28/output.txt deleted file mode 100644 index 22cbc4fad4..0000000000 --- a/listings/ch17-async-await/listing-17-28/output.txt +++ /dev/null @@ -1,38 +0,0 @@ -$ cargo run - Compiling proc-macro2 v1.0.82 - Compiling unicode-ident v1.0.12 - Compiling autocfg v1.3.0 - Compiling futures-sink v0.3.30 - Compiling futures-core v0.3.30 - Compiling libc v0.2.154 - Compiling pin-project-lite v0.2.14 - Compiling futures-io v0.3.30 - Compiling memchr v2.7.2 - Compiling futures-task v0.3.30 - Compiling futures-channel v0.3.30 - Compiling pin-utils v0.1.0 - Compiling slab v0.4.9 - Compiling num_cpus v1.16.0 - Compiling tokio v1.37.0 - Compiling quote v1.0.36 - Compiling syn v2.0.63 - Compiling futures-macro v0.3.30 - Compiling futures-util v0.3.30 - Compiling futures-executor v0.3.30 - Compiling futures v0.3.30 - Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-26) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.32s - Running `target/debug/async_await` -'a' started. -'a' ran for 300ms -'a' ran for 100ms -'a' ran for 200ms -'a' ran for 900ms -'b' started. -'b' ran for 750ms -'b' ran for 100ms -'b' ran for 150ms -'b' ran for 350ms -'b' ran for 150ms -'a' finished. diff --git a/listings/ch17-async-await/listing-17-31/Cargo.lock b/listings/ch17-async-await/listing-17-31/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-31/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index fb0cb56c3c..49e3190237 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -1,113 +1,118 @@ ## More Ways of Combining Futures -Thus far, we have only used the `join` family of functions and macros. When we -“join” on some collection of futures, we require *all* of them to finish before -we move on. Sometimes, though, we only need *some* future from a set to finish -before we move on—kind of like racing one future against another. This operation -is often named `race` for exactly that reason. +When we “join” futures with the `join` family of functions and macros, we +require *all* of them to finish before we move on. Sometimes, though, we only +need *some* future from a set to finish before we move on—kind of like racing +one future against another. This operation is often named `race` for exactly +that reason. -In Listing 17-26, we use `race` to run two futures, `slow` and `fast`, against +In Listing 17-20, we use `race` to run two futures, `slow` and `fast`, against each other. Each one prints a message when it starts running, pauses for some amount of time by calling and awaiting `sleep`, and then prints another message when it finishes. Then we pass both to `trpl::race` and wait for one of them to finish. (The outcome here won’t be too surprising: `fast` wins!) -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} ``` -One other thing to notice: if you flip the order of the arguments to `race`, the -order of the start messages changes, even though the `fast` future always -completes first. That is because the implementation of this particular `race` -function is not *fair*. It always runs the futures passed as arguments in the -order they are passed. Other implementations *are* fair, and will randomly -choose which future to start first. - -Regardless of whether the implementation of race we are using is fair, though, -*one* of the futures will run up to the first `.await` in its body before -another task can start. - -To see why, recall from our discussion in [“What Are Futures?”][futures] that -Rust compiles async blocks in a way that hands control back to the async runtime -at each await point. That has an important corollary: async runtimes can only -switch which future they are executing at await points. Everything in between -await points is just normal synchronous Rust code. That means if you do a bunch -of really expensive work in an async function without an `.await`, that future -will block any other futures from making progress. - -> Note: You may sometimes hear this referred to as one future *starving* other -> futures. The same thing applies to threads, too! - -That has another important consequence for using `race`, `join`, and other such -helpers. *Some* future is going to run first, and everything up to the first -await point in that future will run before any part of any other future gets a -chance to run. For simple code, that may not be a big deal. However, if you are -doing some kind of expensive setup or long-running work, or if you have a future -which will keep doing some particular task indefinitely, you will need to think -about when and where to hand control back to the runtime. +Notice that if you flip the order of the arguments to `race`, the order of the +“started” messages changes, even though the `fast` future always completes +first. That is because the implementation of this particular `race` function is +not fair. It always runs the futures passed as arguments in the order they are +passed. Other implementations *are* fair, and will randomly choose which future +to poll first. Regardless of whether the implementation of race we are using is +fair, though, *one* of the futures will run up to the first `.await` in its body +before another task can start. + +Recall from [“What Are Futures?”][futures] that at each await point, Rust pauses +the async block and hands control back to a runtime. The inverse is also true: +Rust *only* pauses async blocks and hands control back to a runtime at an await +point. Everything between await points is synchronous. + +That means if you do a bunch of work in an async block without an await point, +that future will block any other futures from making progress. (You may +sometimes hear this referred to as one future *starving* other futures. And this +applies to threads, too!) In many cases, that may not be a big deal. However, if +you are doing some kind of expensive setup or long-running work, or if you have +a future which will keep doing some particular task indefinitely, you will need +to think about when and where to hand control back to the runtime. + +But *how* would you hand control back to the runtime in those cases? ### Yielding -Let’s consider a long-running operation. Here, we will simulate it using `sleep` -inside the function, but in the real world it could be any of operations which -might take a while, and which, critically, are *blocking*. Our `slow` helper -function “slow” will just take a number of milliseconds to run, and sleep the -thread for that long. This is intentionally not an async function, because the -idea is to represent work that is *not* async. +Let’s simulate a long-running operation. Listing 17-21 introduces a `slow` +function which uses `std::thread::sleep` to block the current thread for some +number of milliseconds. We can use `slow` to stand in for real-world operations +which are both long-running and blocking. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:slow}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:slow}} ``` -In Listing 17-28, we use `slow` to emulate doing this kind of CPU-bound work in +In Listing 17-22, we use `slow` to emulate doing this kind of CPU-bound work in a pair of futures. To begin, each future only hands control back to the runtime *after* carrying out a bunch of slow operations. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:slow-futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:slow-futures}} ``` If you run this, you will see this output: -```console -{{#include ../listings/ch17-async-await/listing-17-28/output.txt}} + + +```text +'a' started. +'a' ran for 30ms +'a' ran for 10ms +'a' ran for 20ms +'b' started. +'b' ran for 75ms +'b' ran for 10ms +'b' ran for 15ms +'b' ran for 350ms +'a' finished. ``` -As with our earlier example, `race` still finishes when `a` finishes. There is -no interleaving between the two futures, though. The `a` future does all of its -work until the `trpl::sleep` call is awaited, then the `b` future does all of -its work until its own `trpl::sleep` call is awaited, and then the `a` future -completes. It would be better if both futures could make progress between their -slow tasks. We need some way to hand control back to the runtime there—and we -know that await points are the way to do that. However, that means we need +As with our earlier example, `race` still finishes as soon as `a` is done. There +is no interleaving between the two futures, though. The `a` future does all of +its work until the `trpl::sleep` call is awaited, then the `b` future does all +of its work until its own `trpl::sleep` call is awaited, and then the `a` future +completes. To allow both futures to make progress between their slow tasks, we +need await points so we can hand control back to the runtime. That means we need something we can await! -However, we can also see the handoff happening in this very example: if we +We can already see this kind of handoff happening in Listing 17-22: if we removed the `trpl::sleep` at the end of the `a` future, it would complete -without the `b` future running *at all*. Given that, maybe we could use the -`sleep` function as a starting point, as in Listing 17-29. +without the `b` future running *at all*. Maybe we could use the `sleep` function +as a starting point? -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:here}} ``` -Now the two futures’ work is interleaved, as we can see if we run it. +In Listing 17-23, we add `trpl::sleep` calls with await points between each call +to `slow`. Now the two futures’ work is interleaved: ```text 'a' started. -'a' ran for 300ms +'a' ran for 30ms 'b' started. -'b' ran for 750ms -'a' ran for 100ms -'b' ran for 100ms -'a' ran for 200ms -'b' ran for 150ms -'a' ran for 900ms -'b' ran for 350ms +'b' ran for 75ms +'a' ran for 10ms +'b' ran for 10ms +'a' ran for 20ms +'b' ran for 15ms 'a' finished. ``` - The `a` future still runs for a bit before handing off control to `b`, because -it has some expensive work to do up front, but after that they just swap back -and forth every time one of them hits an await point. In this case, we have done -that after every call to `slow`, but we could break up the work however makes -the most sense to us. +it calls `slow` before ever calling `trpl::sleep`, but after that the futures +swap back and forth eaach time one of them hits an await point. In this case, we +have done that after every call to `slow`, but we could break up the work +however makes the most sense to us. -However, we do not actually need to sleep to accomplish this. We just need to -hand back control to the runtime. We can actually *yield* control back to the -runtime, using a function named `yield_now`. It does just what it says: hands -control back to the runtime, so that the runtime can check whether any other -tasks are ready to make progress. +We do not really want to *sleep* here, though: we want to make progress as fast +as we can. We just need to hand back control to the runtime. We can do that +directly, using the `yield_now` function. In Listing 17-24, we replace all those +`sleep` calls with `yield_now`. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-30/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:yields}} ``` @@ -156,34 +157,34 @@ example, will always sleep for at least a millisecond, even if we pass it a lot in one millisecond! You can see this for yourself by setting up a little benchmark, like the one in -Listing 17-31. (This is not an especially rigorous way to do performance +Listing 17-25. (This is not an especially rigorous way to do performance testing, but it suffices to show the difference here.) Here, we skip all the status printing, pass a one-nanosecond `Duration` to `sleep`, let each future run by itself so that they do not interfere with each other, and get rid of all the status printing that we did to see the back-and-forth between tasks in -Listings 17-29 and 17-30. Then we run for 1,000 iterations and see how long +Listings 17-23 and 17-24. Then we run for 1,000 iterations and see how long `sleep` takes vs. `yield_now`. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:here}} ``` The version with `yield_now` is *way* faster! -> Note: This also means that async can be a useful tool even for CPU-bound -> tasks, depending on what else your program is doing, because it provides a -> useful tool for structuring the relationships between different parts of the -> program. This is a form of *cooperative multitasking*, where each future has -> both the power to determine when it hands over control via await points and -> therefore also the *responsibility* to avoid blocking for too long. This is -> how some Rust-based embedded operating systems work! +> Note: This means that async can be a useful tool even for CPU-bound tasks, +> depending on what else your program is doing, because it provides a useful +> tool for structuring the relationships between different parts of the program. +> This is a form of *cooperative multitasking*, where each future has both the +> power to determine when it hands over control via await points and therefore +> also the *responsibility* to avoid blocking for too long. This is how some +> Rust-based embedded operating systems work! -In real-world code, you will not usually be alternative regular function calls -with await points on every single line, of course. The underlying dynamic is an +In real-world code, you will not usually be alternating function calls with +await points on every single line, of course. The underlying dynamic is an important one to keep in mind, though! ### Building Our Own Async Abstractions @@ -228,7 +229,7 @@ We can write the same signature ourselves, as in Listing 17-33. Then, in the body of the function, we can `race` whatever future the caller passes with a `sleep` future. -When we saw `race` earlier in Listing 17-26, we ignored its return type, +When we saw `race` earlier in Listing 17-20, we ignored its return type, because we were just interested in seeing the behavior of `fast` and `slow` when we ran the program. Here, though, its return value tells us whether the future or the sleep finished first. With `race`, both futures passed as arguments can From ef1ed96053cc07759f6573a5b5d189f38232fcc3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 8 Jul 2024 08:28:46 -0600 Subject: [PATCH 360/720] =?UTF-8?q?Ch.=2017=C2=A704=20initial=20edits=20on?= =?UTF-8?q?=20Building=20Our=20Own=20Async=20Abstractions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eliminate `trpl::timeout` entirely. Instead, just build the `timeout` directly (as the rest of the section already did). Restructure the listings as well, eliminating duplication and extraneous bits. --- .../Cargo.lock | 12 + .../Cargo.toml | 0 .../src/main.rs | 4 +- .../Cargo.lock | 12 + .../Cargo.toml | 0 .../src/main.rs | 13 +- .../Cargo.lock | 12 + .../Cargo.toml | 0 .../src/main.rs | 4 +- .../ch17-async-await/listing-17-32/Cargo.lock | 540 ------------------ .../listing-17-34/src/main.rs | 31 - .../ch17-async-await/listing-17-35/Cargo.toml | 9 - packages/trpl/src/lib.rs | 26 +- packages/trpl/tests/integration/main.rs | 27 +- src/ch17-04-more-ways-of-combining-futures.md | 155 +++-- 15 files changed, 132 insertions(+), 713 deletions(-) rename listings/ch17-async-await/{listing-17-34 => listing-17-26}/Cargo.lock (96%) rename listings/ch17-async-await/{listing-17-32 => listing-17-26}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-32 => listing-17-26}/src/main.rs (75%) rename listings/ch17-async-await/{listing-17-33 => listing-17-27}/Cargo.lock (96%) rename listings/ch17-async-await/{listing-17-33 => listing-17-27}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-33 => listing-17-27}/src/main.rs (51%) rename listings/ch17-async-await/{listing-17-35 => listing-17-28}/Cargo.lock (96%) rename listings/ch17-async-await/{listing-17-34 => listing-17-28}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-35 => listing-17-28}/src/main.rs (92%) delete mode 100644 listings/ch17-async-await/listing-17-32/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-34/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-35/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-34/Cargo.lock b/listings/ch17-async-await/listing-17-26/Cargo.lock similarity index 96% rename from listings/ch17-async-await/listing-17-34/Cargo.lock rename to listings/ch17-async-await/listing-17-26/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-34/Cargo.lock +++ b/listings/ch17-async-await/listing-17-26/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-32/Cargo.toml b/listings/ch17-async-await/listing-17-26/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-32/Cargo.toml rename to listings/ch17-async-await/listing-17-26/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-32/src/main.rs b/listings/ch17-async-await/listing-17-26/src/main.rs similarity index 75% rename from listings/ch17-async-await/listing-17-32/src/main.rs rename to listings/ch17-async-await/listing-17-26/src/main.rs index 5e702a2edc..4727e58c48 100644 --- a/listings/ch17-async-await/listing-17-32/src/main.rs +++ b/listings/ch17-async-await/listing-17-26/src/main.rs @@ -4,11 +4,11 @@ fn main() { trpl::block_on(async { // ANCHOR: here let slow = async { - trpl::sleep(Duration::from_secs(5)).await; + trpl::sleep(Duration::from_millis(100)).await; "I finished!" }; - match trpl::timeout(Duration::from_secs(2), slow).await { + match timeout(slow, Duration::from_millis(10)).await { Ok(message) => println!("Succeeded with '{message}'"), Err(duration) => { println!("Failed after {} seconds", duration.as_secs()) diff --git a/listings/ch17-async-await/listing-17-33/Cargo.lock b/listings/ch17-async-await/listing-17-27/Cargo.lock similarity index 96% rename from listings/ch17-async-await/listing-17-33/Cargo.lock rename to listings/ch17-async-await/listing-17-27/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-33/Cargo.lock +++ b/listings/ch17-async-await/listing-17-27/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-33/Cargo.toml b/listings/ch17-async-await/listing-17-27/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-33/Cargo.toml rename to listings/ch17-async-await/listing-17-27/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-33/src/main.rs b/listings/ch17-async-await/listing-17-27/src/main.rs similarity index 51% rename from listings/ch17-async-await/listing-17-33/src/main.rs rename to listings/ch17-async-await/listing-17-27/src/main.rs index 17d2f985f1..a53169bfb2 100644 --- a/listings/ch17-async-await/listing-17-33/src/main.rs +++ b/listings/ch17-async-await/listing-17-27/src/main.rs @@ -7,15 +7,20 @@ fn main() { "Finally finished" }; - // Here we will actually use the new `timeout` with `slow`. + match timeout(slow, Duration::from_millis(10)).await { + Ok(message) => println!("Succeeded with '{message}'"), + Err(duration) => { + println!("Failed after {} seconds", duration.as_secs()) + } + } }); } // ANCHOR: declaration async fn timeout( - max_time: Duration, future: F, + max_time: Duration, ) -> Result { - // ANCHOR_END: declaration - unimplemented!() + // Here is where our implementation will go! } +// ANCHOR_END: declaration diff --git a/listings/ch17-async-await/listing-17-35/Cargo.lock b/listings/ch17-async-await/listing-17-28/Cargo.lock similarity index 96% rename from listings/ch17-async-await/listing-17-35/Cargo.lock rename to listings/ch17-async-await/listing-17-28/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-35/Cargo.lock +++ b/listings/ch17-async-await/listing-17-28/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-34/Cargo.toml b/listings/ch17-async-await/listing-17-28/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-34/Cargo.toml rename to listings/ch17-async-await/listing-17-28/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-35/src/main.rs b/listings/ch17-async-await/listing-17-28/src/main.rs similarity index 92% rename from listings/ch17-async-await/listing-17-35/src/main.rs rename to listings/ch17-async-await/listing-17-28/src/main.rs index 2e389a6509..639d9c8978 100644 --- a/listings/ch17-async-await/listing-17-35/src/main.rs +++ b/listings/ch17-async-await/listing-17-28/src/main.rs @@ -9,9 +9,7 @@ fn main() { "Finally finished" }; - // ANCHOR: main match timeout(Duration::from_secs(2), slow).await { - // ANCHOR_END: main Ok(message) => println!("Succeeded with '{message}'"), Err(duration) => { println!("Failed after {} seconds", duration.as_secs()) @@ -24,8 +22,10 @@ async fn timeout( max_time: Duration, future: F, ) -> Result { + // ANCHOR: implementation match trpl::race(future, trpl::sleep(max_time)).await { Either::Left(output) => Ok(output), Either::Right(_) => Err(max_time), } + // ANCHOR_END: implementation } diff --git a/listings/ch17-async-await/listing-17-32/Cargo.lock b/listings/ch17-async-await/listing-17-32/Cargo.lock deleted file mode 100644 index 3be4eaaa53..0000000000 --- a/listings/ch17-async-await/listing-17-32/Cargo.lock +++ /dev/null @@ -1,540 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.154" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "syn" -version = "2.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-34/src/main.rs b/listings/ch17-async-await/listing-17-34/src/main.rs deleted file mode 100644 index 7ff4a59390..0000000000 --- a/listings/ch17-async-await/listing-17-34/src/main.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::{future::Future, time::Duration}; - -// ANCHOR: timeout -use trpl::Either; -// ANCHOR_END: timeout - -fn main() { - trpl::block_on(async { - let slow = async { - trpl::sleep(Duration::from_secs(5)).await; - "Finally finished" - }; - - // Here we will actually use the new `timeout` with `slow`. - }); -} - -// Note for maintainers: the extra space after the `ANCHOR` is intentional: it -// makes this render more nicely! -// ANCHOR: timeout - -async fn timeout( - max_time: Duration, - future: F, -) -> Result { - match trpl::race(future, trpl::sleep(max_time)).await { - Either::Left(output) => Ok(output), - Either::Right(_) => Err(max_time), - } -} -// ANCHOR_END: timeout diff --git a/listings/ch17-async-await/listing-17-35/Cargo.toml b/listings/ch17-async-await/listing-17-35/Cargo.toml deleted file mode 100644 index 349041d3eb..0000000000 --- a/listings/ch17-async-await/listing-17-35/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index c661ffd459..e95cce16d1 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -13,8 +13,7 @@ //! release at some point. // For direct use within the `trpl` crate, *not* re-exported. -use std::{future::Future, pin::pin, time::Duration}; -use tokio::time; +use std::{future::Future, pin::pin}; // Re-exports, to be used like `trpl::join`. pub use futures::{ @@ -65,22 +64,6 @@ pub fn block_on(future: F) -> F::Output { rt.block_on(future) } -/// Race a future against a specified timeout duration. -/// -/// Under the hood, this uses `tokio::time::timeout`, but instead of returning -/// Tokio's internal error type in the case of a failure, this simply returns -/// the duration which had elapsed. (It actually provides strictly *more* info -/// than Tokio's error does, though it does not `impl Error`.) -pub async fn timeout( - duration: Duration, - future: F, -) -> Result -where - F: Future, -{ - time::timeout(duration, future).await.map_err(|_| duration) -} - /// Run two futures, taking whichever finishes first and canceling the other. /// /// Notice that this is built on [`futures::future::select`], which has the @@ -91,6 +74,13 @@ where /// We use the `race` semantics, where the slower future is simply dropped, for /// the sake of simplicity in the examples: no need to deal with the tuple and /// intentionally ignore the second future this way! +/// +/// Note that this only works as “simply” as it does because: +/// +/// - It takes ownership of the futures. +/// - It internally *pins* the futures. +/// - It throws away (rather than returning) the unused future (which is why it +/// can get away with pinning them). pub async fn race(f1: F1, f2: F2) -> Either where F1: Future, diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index a46533534a..639c460eb6 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -94,10 +94,10 @@ mod re_exported_join_apis_work { let result = trpl::block_on(async { let a = async { format!("{}", 1) }; - let b = async { format!("Hello") }; + let b = async { "Hello".to_string() }; let outer = String::from("World"); - let c = async move { format!("{outer}") }; + let c = async move { outer.to_string() }; let futures: Vec>>> = vec![Box::pin(a), Box::pin(b), Box::pin(c)]; @@ -131,29 +131,6 @@ mod re_exported_join_apis_work { } } -#[test] -fn re_exported_timeout_works() { - let val = trpl::block_on(async { - let winner = async { - trpl::sleep(Duration::from_millis(1)).await; - String::from("Hello") - }; - trpl::timeout(Duration::from_millis(2), winner).await - }); - - assert_eq!(val, Ok(String::from("Hello"))); - - let val = trpl::block_on(async { - let loser = async { - trpl::sleep(Duration::from_millis(2)).await; - String::from("Hello") - }; - trpl::timeout(Duration::from_millis(1), loser).await - }); - - assert!(val.is_err()); -} - #[test] fn race() { #[derive(Debug, PartialEq)] diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index 49e3190237..060cd569f5 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -73,9 +73,11 @@ a pair of futures. To begin, each future only hands control back to the runtime If you run this, you will see this output: - + ```text 'a' started. @@ -114,9 +116,11 @@ as a starting point? In Listing 17-23, we add `trpl::sleep` calls with await points between each call to `slow`. Now the two futures’ work is interleaved: - + ```text 'a' started. @@ -175,13 +179,13 @@ Listings 17-23 and 17-24. Then we run for 1,000 iterations and see how long The version with `yield_now` is *way* faster! -> Note: This means that async can be a useful tool even for CPU-bound tasks, -> depending on what else your program is doing, because it provides a useful -> tool for structuring the relationships between different parts of the program. -> This is a form of *cooperative multitasking*, where each future has both the -> power to determine when it hands over control via await points and therefore -> also the *responsibility* to avoid blocking for too long. This is how some -> Rust-based embedded operating systems work! +This means that async can be useful even for CPU-bound tasks, depending on what +else your program is doing, because it provides a useful tool for structuring +the relationships between different parts of the program. This is a form of +*cooperative multitasking*, where each future has both the power to determine +when it hands over control via await points. Each future therefore also has the +*responsibility* to avoid blocking for too long. In some Rust-based embedded +operating systems, this is the *only* kind of multitasking! In real-world code, you will not usually be alternating function calls with await points on every single line, of course. The underlying dynamic is an @@ -189,55 +193,57 @@ important one to keep in mind, though! ### Building Our Own Async Abstractions -Many of these patterns are common enough to warrant abstracting over. For -example, the `trpl::timeout` function takes a `Duration` for the maximum time to -run, but also takes a future to run, and produces a new future you can await, -whose `Output` type is a `Result`. Listing 17-32 shows how we can use it. If -the passed-in future finishes first, the output result will be `Ok`, with the -result of that passed-in future. If the duration elapses before the passed-in -future finishes, the result will be `Err` with the duration that elapsed. +We can also compose futures together to create new patterns. For example, we can +build a `timeout` function with async building blocks we already have. When we +are done, the result will be another building block we could use to build up yet +further async abstractions. -+Listing 17-26 shows how we would expect this `timeout` to work with a slow +future. -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs:here}} ++ +```rust,ignore +{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:here}} ``` -Here we were using the `timeout` supplied by `trpl`, but we do not have to. We -can implement it ourselves using `race` and `sleep`! To begin, let’s think about -the API of `timeout`: +Let’s implement this! To begin, let’s think about the API for `timeout`: -- Its first parameter is a `std::time::Duration` which specifies the maximum - time to wait. -- Its second parameter is the future to run. -- It returns a `Result`. If the future completes successfully, the `Result` will - be `Ok` with the value produced by the future. If the timeout happens, the - `Result` will be `Err` with the duration that the timeout waited for. +- It needs to be an async function itself so we can await it. +- Its first parameter should be a future to run. We can make it generic to allow + it to work with any future. +- Its second parameter will be the maximum time to wait. If we use a `Duration`, + that will make it easy to pass along to `trpl::sleep`. +- It should return a `Result`. If the future completes successfully, the + `Result` will be `Ok` with the value produced by the future. If the timeout + elapses first, the `Result` will be `Err` with the duration that the timeout + waited for. -We can write the same signature ourselves, as in Listing 17-33. +Listing 17-27 shows this declaration. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-33/src/main.rs:declaration}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:declaration}} ``` -Then, in the body of the function, we can `race` whatever future the caller -passes with a `sleep` future. +The types line up now, so let’s think about the *behavior* we need. We want to +race the future passed in against the duration. We can use `trpl::sleep` to make +a timer future from the duration, and use `trpl::race` to run the future and the +timer against each other. -When we saw `race` earlier in Listing 17-20, we ignored its return type, -because we were just interested in seeing the behavior of `fast` and `slow` when -we ran the program. Here, though, its return value tells us whether the future -or the sleep finished first. With `race`, both futures passed as arguments can +When we saw `race` earlier in Listing 17-20, we ignored its return type, because +we were just interested in seeing the behavior of `fast` and `slow` when we ran +the program. Here, though, its return value tells us whether the future or the +sleep finished first. With `race`, both futures passed as arguments can legitimately “win,” so it does not make sense to use a `Result` to represent the -return type. Instead, it returns a similar type called `Either`. Like `Result`, -`Either` can be one of two types, but unlike `Result`, there is no notion of -success or failure baked into the type. Instead, it uses `Left` and `Right` to -indicate “one or the other”. Its implementation looks like this: +return type. Instead, it returns a similar type called `Either`. Unlike +`Result`, there is no notion of success or failure baked into `Either`. Instead, +it uses `Left` and `Right` to indicate “one or the other”: ```rust enum Either { @@ -246,54 +252,39 @@ enum Either { } ``` -In the case of `race` specifically, it returns `Left` if the first argument -finishes first, with that future’s output, and `Right` with the second future -argument’s output if *that* one finishes first. - -```rust,ignore -match trpl::race(future_a, future_b).await { - Either::Left(output_from_future_a) => /* ... */, - Either::Right(output_from_future_b) => /* ... */, -} -``` +The `race` function returns `Left` if the first argument finishes first, with +that future’s output, and `Right` with the second future argument’s output if +*that* one finishes first. We also know that `race` is not fair, and polls +arguments in the order they are passed. For `timeout`, we pass the future to +`race` first so it gets a chance to complete even if `max_time` is a very short +duration. If `future` finishes first, `race` will return `Left` with the output +from `future`. If `timer` finishes first, `race` will return `Right` with the +timer’s output of `()`. -That gives us enough to be able to implement `timeout` ourselves using `race` -and `sleep`. +In Listing 17-28, we match on the result of awaiting `trpl::race`. If the +future succeeded and we get a `Left(output)`, we return `Ok(output)`. If the +sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` with +`_` and return `Err(duration)` instead. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-34/src/main.rs:timeout}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:implementation}} ``` -Let’s walk through the details. Since we know from earlier that `race` is not -fair, and will prefer the first argument to the second, we pass it the future -first so it gets a chance to complete even if the caller passes in a very short -value for `max_time`. Then we match on the result of awaiting the `race`. If the -future passed in by the caller finished first, we will have `Left(output)`, -which we can return as a success with `Ok`. If the sleep finished first, we will -have `Right(())` instead, since `timeout` returns the unit type `()` if it -succeeds. We can ignore that `()` by using `_` and return `Err` with the -duration the user passed in instead. And that’s it! +With that, we have a working `timeout`, built out of two other async helpers. If +we run our code, it will print the failure mode after the timeout: -Back in `main`, we can call this new `timeout` function exactly like we called -`trpl::timeout` before, but without the `trpl::` namespace: - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-35/src/main.rs:main}} +```text +Failed after 2 seconds ``` - - -This pattern is quite common and useful. Futures compose with other futures, so -you can build really powerful tools using smaller async building blocks. For -example, you can use this same approach to combine timeouts with retries, and -in turn use those with things like network calls—the exact example we started -out with at the beginning of the chapter! +Because futures compose with other futures, you can build really powerful tools +using smaller async building blocks. For example, you can use this same approach +to combine timeouts with retries, and in turn use those with things like network +calls—one of the examples from the beginning of the chapter! Over the last two sections, we have seen how to work with multiple futures at the same time. Up next, let’s look at how we can work with multiple futures in a From 995e932711b43da7ba445e609feaacf68572d5fd Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 10 Jul 2024 18:14:59 -0600 Subject: [PATCH 361/720] Use Rust 2021 Edition for mdBook A number of examples *already* do not work correctly, and the inbound async chapter requires Rust 2021. --- book.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/book.toml b/book.toml index b73ff03b7a..800adcf0f5 100644 --- a/book.toml +++ b/book.toml @@ -15,3 +15,6 @@ git-repository-url = "https://github.com/rust-lang/book" [preprocessor.trpl-listing] output-mode = "default" + +[rust] +edition = "2021" From 074c44267fbf09261e0e0b7d797009830d698424 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 9 Jul 2024 09:03:43 -0600 Subject: [PATCH 362/720] =?UTF-8?q?Ch.=2017=C2=A705=20initial=20edits=20on?= =?UTF-8?q?=20first=20two=20sections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Flip the order, so that the semi-practical introduction comes first. - Merge several of the listings together. - The usual polishing and iterating on the text. --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 8 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 6 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 3 - .../listing-17-36/src/main.rs | 8 - .../listing-17-37/src/main.rs | 9 - .../ch17-async-await/listing-17-38/output.txt | 51 --- .../ch17-async-await/listing-17-39/Cargo.lock | 292 ------------------ .../ch17-async-await/listing-17-39/Cargo.toml | 8 - .../ch17-async-await/listing-17-40/Cargo.lock | 292 ------------------ .../ch17-async-await/listing-17-40/Cargo.toml | 8 - src/ch17-05-streams.md | 268 ++++++++-------- 17 files changed, 146 insertions(+), 807 deletions(-) rename listings/ch17-async-await/{listing-17-36 => listing-17-29}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-36 => listing-17-29}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-38 => listing-17-29}/src/main.rs (57%) rename listings/ch17-async-await/{listing-17-37 => listing-17-30}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-37 => listing-17-30}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-39 => listing-17-30}/src/main.rs (69%) rename listings/ch17-async-await/{listing-17-38 => listing-17-31}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-38 => listing-17-31}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-40 => listing-17-31}/src/main.rs (84%) delete mode 100644 listings/ch17-async-await/listing-17-36/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-37/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-38/output.txt delete mode 100644 listings/ch17-async-await/listing-17-39/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-39/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-40/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-40/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-36/Cargo.lock b/listings/ch17-async-await/listing-17-29/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-36/Cargo.lock rename to listings/ch17-async-await/listing-17-29/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-36/Cargo.toml b/listings/ch17-async-await/listing-17-29/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-36/Cargo.toml rename to listings/ch17-async-await/listing-17-29/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-38/src/main.rs b/listings/ch17-async-await/listing-17-29/src/main.rs similarity index 57% rename from listings/ch17-async-await/listing-17-38/src/main.rs rename to listings/ch17-async-await/listing-17-29/src/main.rs index 08bd4b0b72..db9c724d4f 100644 --- a/listings/ch17-async-await/listing-17-38/src/main.rs +++ b/listings/ch17-async-await/listing-17-29/src/main.rs @@ -1,13 +1,13 @@ fn main() { trpl::block_on(async { - let values = 1..101; - let iter = values.map(|n| n * 2); + // ANCHOR: stream + let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let iter = values.iter().map(|n| n * 2); let mut stream = trpl::stream_from_iter(iter); - // ANCHOR: next while let Some(value) = stream.next().await { println!("The value was: {value}"); } - // ANCHOR_END: next + // ANCHOR_END: stream }); } diff --git a/listings/ch17-async-await/listing-17-37/Cargo.lock b/listings/ch17-async-await/listing-17-30/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-37/Cargo.lock rename to listings/ch17-async-await/listing-17-30/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-37/Cargo.toml b/listings/ch17-async-await/listing-17-30/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-37/Cargo.toml rename to listings/ch17-async-await/listing-17-30/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-39/src/main.rs b/listings/ch17-async-await/listing-17-30/src/main.rs similarity index 69% rename from listings/ch17-async-await/listing-17-39/src/main.rs rename to listings/ch17-async-await/listing-17-30/src/main.rs index 317677eba1..ad546a68fc 100644 --- a/listings/ch17-async-await/listing-17-39/src/main.rs +++ b/listings/ch17-async-await/listing-17-30/src/main.rs @@ -1,10 +1,9 @@ -// ANCHOR: all use trpl::StreamExt; fn main() { trpl::block_on(async { - let values = 1..101; - let iter = values.map(|n| n * 2); + let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let iter = values.iter().map(|n| n * 2); let mut stream = trpl::stream_from_iter(iter); while let Some(value) = stream.next().await { @@ -12,4 +11,3 @@ fn main() { } }); } -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-38/Cargo.lock b/listings/ch17-async-await/listing-17-31/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-38/Cargo.lock rename to listings/ch17-async-await/listing-17-31/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-38/Cargo.toml b/listings/ch17-async-await/listing-17-31/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-38/Cargo.toml rename to listings/ch17-async-await/listing-17-31/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-40/src/main.rs b/listings/ch17-async-await/listing-17-31/src/main.rs similarity index 84% rename from listings/ch17-async-await/listing-17-40/src/main.rs rename to listings/ch17-async-await/listing-17-31/src/main.rs index 8c98a66dfe..5cda39eb4c 100644 --- a/listings/ch17-async-await/listing-17-40/src/main.rs +++ b/listings/ch17-async-await/listing-17-31/src/main.rs @@ -6,14 +6,11 @@ fn main() { let iter = values.map(|n| n * 2); let stream = trpl::stream_from_iter(iter); - // ANCHOR: filter let mut filtered = stream.filter(|value| value % 3 == 0 || value % 5 == 0); while let Some(value) = filtered.next().await { println!("The value was: {value}"); } - // ANCHOR_END: filter }); } -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-36/src/main.rs b/listings/ch17-async-await/listing-17-36/src/main.rs deleted file mode 100644 index afe325e6d6..0000000000 --- a/listings/ch17-async-await/listing-17-36/src/main.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - trpl::block_on(async { - // ANCHOR: range - let values = 1..101; - let iter = values.map(|n| n * 2); - // ANCHOR_END: range - }); -} diff --git a/listings/ch17-async-await/listing-17-37/src/main.rs b/listings/ch17-async-await/listing-17-37/src/main.rs deleted file mode 100644 index 5bc9e01ac5..0000000000 --- a/listings/ch17-async-await/listing-17-37/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - trpl::block_on(async { - let values = 1..101; - let iter = values.map(|n| n * 2); - // ANCHOR: stream - let mut stream = trpl::stream_from_iter(iter); - // ANCHOR_END: stream - }); -} diff --git a/listings/ch17-async-await/listing-17-38/output.txt b/listings/ch17-async-await/listing-17-38/output.txt deleted file mode 100644 index 6e6886fb5c..0000000000 --- a/listings/ch17-async-await/listing-17-38/output.txt +++ /dev/null @@ -1,51 +0,0 @@ -$ cargo run - Compiling proc-macro2 v1.0.85 - Compiling unicode-ident v1.0.12 - Compiling autocfg v1.3.0 - Compiling pin-project-lite v0.2.14 - Compiling futures-core v0.3.30 - Compiling libc v0.2.155 - Compiling futures-sink v0.3.30 - Compiling futures-task v0.3.30 - Compiling pin-utils v0.1.0 - Compiling futures-io v0.3.30 - Compiling memchr v2.7.4 - Compiling futures-channel v0.3.30 - Compiling slab v0.4.9 - Compiling num_cpus v1.16.0 - Compiling quote v1.0.36 - Compiling tokio v1.38.0 - Compiling syn v2.0.66 - Compiling tokio-stream v0.1.15 - Compiling futures-macro v0.3.30 - Compiling futures-util v0.3.30 - Compiling futures-executor v0.3.30 - Compiling futures v0.3.30 - Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-38) -error[E0599]: no method named `next` found for struct `Iter` in the current scope - --> src/main.rs:8:40 - | -8 | while let Some(value) = stream.next().await { - | ^^^^ - | - = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-38/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-17453505919820464996.txt' - = note: consider using `--verbose` to print the full type name to the console - = help: items from traits can only be used if the trait is in scope -help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them - | -1 + use futures_util::stream::stream::StreamExt; - | -1 + use std::iter::Iterator; - | -1 + use std::str::pattern::Searcher; - | -1 + use trpl::StreamExt; - | -help: there is a method `try_next` with a similar name - | -8 | while let Some(value) = stream.try_next().await { - | ~~~~~~~~ - -For more information about this error, try `rustc --explain E0599`. -error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-39/Cargo.lock b/listings/ch17-async-await/listing-17-39/Cargo.lock deleted file mode 100644 index 36905af42a..0000000000 --- a/listings/ch17-async-await/listing-17-39/Cargo.lock +++ /dev/null @@ -1,292 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "tokio-stream" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", - "tokio-stream", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-39/Cargo.toml b/listings/ch17-async-await/listing-17-39/Cargo.toml deleted file mode 100644 index e094f067f1..0000000000 --- a/listings/ch17-async-await/listing-17-39/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-40/Cargo.lock b/listings/ch17-async-await/listing-17-40/Cargo.lock deleted file mode 100644 index 36905af42a..0000000000 --- a/listings/ch17-async-await/listing-17-40/Cargo.lock +++ /dev/null @@ -1,292 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "tokio-stream" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", - "tokio-stream", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-40/Cargo.toml b/listings/ch17-async-await/listing-17-40/Cargo.toml deleted file mode 100644 index e094f067f1..0000000000 --- a/listings/ch17-async-await/listing-17-40/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index d52334ce02..988ea383f9 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -1,23 +1,116 @@ ## Streams -In Chapter 13, we looked at the `Iterator` trait, and we saw how we could work -with a sequence of items in turn. So far in this chapter, we have mostly stuck -with individual futures. The one big exception was the async channel we used. -Recall how we used the receiver for our async channel in the [“Message -Passing”][17-02-messages] earlier in the chapter: +So far in this chapter, we have mostly stuck with individual futures. The one +big exception was the async channel we used. Recall how we used the receiver for +our async channel in the [“Message Passing”][17-02-messages] earlier in the +chapter, which waits on a sequence of items produced over time—a *stream*. + +A sequence of items is something we have seen before, when we looked at the +`Iterator` trait in Chapter 13, but there are two differences between iterators +and the async channel receiver. The first difference is the element of time: +iterators are synchronous, while the channel receiver is asynchronous. The +second difference is the API. With iterators, if we worked with them directly +rather than using `iter` or `.into_iter` (including implicitly with a `for` +loop), we called `next`, whereas with the channel we call `recv`. Otherwise, +these APIs feel very similar. + +That is not a coincidence. A stream—of messages or of anything else—is like an +an asynchronous form of iteration. In fact, we can create a stream from any +iterator. Like an iterator, we can work with a stream by calling its `next` +method, and then awaiting the output, as in Listing 17-29. + ++ +```rust,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:stream}} +``` + + + +We start with an array of numbers, which we convert to an iterator and then call +`map` on to double all the values. Then we convert the iterator into a stream +using the `trpl::stream_from_iter` function. Then we loop over the items in the +stream as they arrive with the `while let` loop + +Unfortunately, this does not yet work. When we try to run the code, it does not +compile. Instead, as we can see in the output, it reports that there is no +`next` method available. + + + + +```console +error[E0599]: no method named `next` found for struct `Iter` in the current scope + --> src/main.rs:8:40 + | +8 | while let Some(value) = stream.next().await { + | ^^^^ + | + = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-29/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' + = note: consider using `--verbose` to print the full type name to the console + = help: items from traits can only be used if the trait is in scope +help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them + | +1 + use futures_util::stream::stream::StreamExt; + | +1 + use std::iter::Iterator; + | +1 + use std::str::pattern::Searcher; + | +1 + use trpl::StreamExt; + | +help: there is a method `try_next` with a similar name + | +8 | while let Some(value) = stream.try_next().await { + | ~~~~~~~~ + +For more information about this error, try `rustc --explain E0599`. +``` + +As the output suggests, the problem is that we need the right trait in scope to +be able to use the `next` method. In this case, that trait is `StreamExt`. The +`Ext` there is for “extension”: this is a common pattern in the Rust community +for extending one trait with another. We will discuss `StreamExt` more shortly! +All we need to do here is add a `use` statement for `trpl::StreamExt`, as in +Listing 17-30. + ++ +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-30/src/main.rs}} +``` + + + +With all those pieces put together, things work the way we want! From here, we +can do the same kinds of things we can with iterators. For example, we can +filter out everything but multiples of three and five by using the `filter` +method, which conveniently also comes from `StreamExt`, as in Listing 17-31. + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:loop}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs}} ``` -This is because the `rx` receiver actually represents a *stream* of messages: a -sequence over time. + -Unlike `Iterator` and `Future`, there is no definition of a `Stream` type in the -standard library yet but there *is* a -very common definition used throughout the ecosystem. If we start with the -definition of the `Iterator` and `Trait` types, we can figure out what a trait -that merges them together might look like. +Of course, these examples are not very interesting. We could do these things +with normal iterators and without any async at all. There are more interesting +things we can do with streams, of course! First, though, let’s take a step back +and dig into the `Stream` and `StreamExt` traits themselves. + +### The Stream API + +Unlike `Iterator` and `Future`, there is no definition of a `Stream` trait in +the standard library yet as of the time of writing, but there *is* a very common definition used throughout the +ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, +so we can build up to how a `Stream` trait that merges them together might look. The `Iterator` trait defines an associated type `Item` and a function `next`, which produces `Some(Item)` until the underlying iterator is empty, and then @@ -33,9 +126,9 @@ trait Iterator { } ``` -As we saw earlier in this chapter, the `Future` trait defines an associated item -`Output` and a function `poll`, which produces `Poll::Pending` while waiting and -then `Poll::Ready(Output)` once the future is ready. +The `Future` trait defines an associated item `Output` and a function `poll`, +which produces `Poll::Pending` while waiting and then `Poll::Ready(Output)` once +the future is ready. ```rust trait Future { @@ -45,27 +138,11 @@ trait Future { } ``` -From `Iterator`, we have the idea of a sequence; its `next` method provides an -`Option`. From `Future`, we have the idea of readiness; its `poll` -method provides a `Poll`. To get a stream, a sequence of items -which become ready over time, we can define a `Stream` as a trait which has all -of those features put together: - -* An associated type `Item` for the type of the items, just like in `Iterator`. - Unlike in `Future`, where there was a single `Output`, we use `Item` here to - indicate that it is more like `Iterator`: there may be zero to many of these. - -* A method to get those items. We can call it `poll_next`, to make it clear that - it is polling like a future and producing a sequence of items one after - another, just like an iterator. - -* A return type from `poll_next` which uses both `Poll` and `Option`. The outer - type is `Poll`, since it has to be checked for readiness as a kind of future. - The inner type is `Option`, since it needs to signal whether there are more - messages, just like an iterator. - -When we put those all together, we end up with the same definition for a -`Stream` trait as the one used by the Rust ecosystem: +From `Iterator`, we have the idea of a sequence: its `next` method provides an +`Option`. From `Future`, we have the idea of readiness over time: +its `poll` method provides a `Poll`. To represent a sequence of +items which become ready over time, we define a `Stream` trait which has all of +those features put together: ```rust trait Stream { @@ -78,21 +155,30 @@ trait Stream { } ``` -Something very similar to this will likely end up standardized as part of Rust’s -standard library, just the way `Future` was. In the meantime, it is part of the -toolkit of most runtimes, so you can rely on it, and everything we cover below -should generally apply! +The `Stream` trait defines an associated type `Item` for the type of the items +produced by the stream. This is like `Iterator`: there may be zero to many of +these, and unlike `Future`, where there was a single `Output`. -### Working With Streams +`Stream` also defines a method to get those items. We call it `poll_next`, to +make it clear that it polls like `Future::poll` and produces a sequence of items +like `Iterator::next`. Its return type uses both `Poll` and `Option`. The outer +type is `Poll`, since it has to be checked for readiness, just like a future. +The inner type is `Option`, since it needs to signal whether there are more +messages, just like an iterator. + +Something very similar to this will likely end up standardized as part of Rust’s +standard library. In the meantime, it is part of the toolkit of most runtimes, +so you can rely on it, and everything we cover below should generally apply! -We *could* work directly in terms of the `poll_next` API by hand-writing our own -`Stream` state machines. However, just as we do not generally work with futures -directly via their `poll` method, we generally also do not work directly with -the `poll_next` method for streams. Instead, we usually use a `next` method, -which is defined roughly like this: +In the example we saw above, though, we did not use `poll_next` *or* `Stream`, +but instead `next` and `StreamExt`. We *could* work directly in terms of the +`poll_next` API by hand-writing our own `Stream` state machines, of course, just +as we *could* work with futures directly via their `poll` method. Using `await` +is much nicer, though, so the `StreamExt` trait supplies the `next` method so +we can do just that. ```rust -trait Stream { +trait StreamExt { async fn next(&mut self) -> Option; } ``` @@ -113,88 +199,14 @@ since the lack thereof is the reason they do not yet have this. > That `Next` type is just a simple `struct` which implements `Future`, so that > `.await` can work with this! -Working with this API will be kind of like working with iterators without the -convenience of a `for` loop. In fact, it will look a lot like the way we used -`rx.recv` back in the [“Message Passing”][17-02-messages] section, using `while -let` loops. - -Let’s start with a very simple example: using an iterator *as* a stream. Let’s -start by creating a range of numbers, including every integer from 1 to 100, -using the `..` range operator. Then we can double all of those values with the -`map` method, as Listing 17-36 shows: - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-36/src/main.rs:range}} -``` - - - -We can convert this iterator to a stream using the `trpl::stream_from_iter` -function. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-37/src/main.rs:stream}} -``` - - - -This gives us the stream. Now, to work with it, we want to use the `next` method -with a `while let` loop as described above, as in Listing 17-38: - -- -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-38/src/main.rs:next}} -``` - - - -Unfortunately, this does not yet work. When we try to run the code, it does not -compile. Instead, as we can see in the output, it reports that there is no -`next` method available. - -```console -{{#include ../listings/ch17-async-await/listing-17-38/output.txt}} -``` - -As the output suggests, the problem is that we need the right trait in scope to -be able to use it. In this case, that trait is `StreamExt`. (The `Ext` there is -for “extension”: this is a common pattern in the Rust community for extending -one trait with another.) `StreamExt` is automatically implemented for every type +The `StreamExt` trait is also the home of all the interesting methods available +to use with streams. `StreamExt` is automatically implemented for every type which implements `Stream`, but they are separated out so that the community can -iterate on the foundational trait distinctly from the convenience APIs. All we -need to do, then, is add a `use` statement for `trpl::StreamExt`, as in Listing -17-39. - -- -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-39/src/main.rs:all}} -``` - - - - With all those pieces put together, things work the way we want! There is a lot - of output, though, since we told it to print all of the 100 numbers in the - iterator. We can filter that down, to, say, multiples of three and five by using - the `filter` method, which conveniently also comes from `StreamExt`. - - - - ```rust,ignore,does_not_compile - {{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:filter}} - ``` - - +iterate on the foundational trait distinctly from the convenience APIs. -Of course, in the real world, the only time we would be directly converting an -iterator to a stream like this is to help break up longer chunks of work, like -we discussed in the previous section. There are more interesting things we can -do with streams, though! +Now that we have a handle on the core traits that make streams work, let’s see +how we can use some of those interesting `StreamExt` methods to combine +streams in interesting ways. ### Composing Streams From fbcdb24fd74219627d47c61a04303e05b2090b27 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 10 Jul 2024 20:03:05 -0600 Subject: [PATCH 363/720] =?UTF-8?q?Ch.=2017=C2=A705=20initial=20edits=20on?= =?UTF-8?q?=20'Composing=20Streams'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 4 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 8 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 4 +- .../listing-17-41/src/main.rs | 17 - .../listing-17-43/src/main.rs | 32 -- .../ch17-async-await/listing-17-44/Cargo.lock | 292 ------------------ .../ch17-async-await/listing-17-44/Cargo.toml | 8 - .../ch17-async-await/listing-17-45/Cargo.lock | 292 ------------------ .../ch17-async-await/listing-17-45/Cargo.toml | 8 - src/ch17-05-streams.md | 161 ++++------ 16 files changed, 73 insertions(+), 753 deletions(-) rename listings/ch17-async-await/{listing-17-41 => listing-17-32}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-41 => listing-17-32}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-42 => listing-17-32}/src/main.rs (91%) rename listings/ch17-async-await/{listing-17-42 => listing-17-33}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-42 => listing-17-33}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-44 => listing-17-33}/src/main.rs (88%) rename listings/ch17-async-await/{listing-17-43 => listing-17-34}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-43 => listing-17-34}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-45 => listing-17-34}/src/main.rs (94%) delete mode 100644 listings/ch17-async-await/listing-17-41/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-43/src/main.rs delete mode 100644 listings/ch17-async-await/listing-17-44/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-44/Cargo.toml delete mode 100644 listings/ch17-async-await/listing-17-45/Cargo.lock delete mode 100644 listings/ch17-async-await/listing-17-45/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-41/Cargo.lock b/listings/ch17-async-await/listing-17-32/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-41/Cargo.lock rename to listings/ch17-async-await/listing-17-32/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-41/Cargo.toml b/listings/ch17-async-await/listing-17-32/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-41/Cargo.toml rename to listings/ch17-async-await/listing-17-32/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-42/src/main.rs b/listings/ch17-async-await/listing-17-32/src/main.rs similarity index 91% rename from listings/ch17-async-await/listing-17-42/src/main.rs rename to listings/ch17-async-await/listing-17-32/src/main.rs index d503a4c77d..5f818ae9f6 100644 --- a/listings/ch17-async-await/listing-17-42/src/main.rs +++ b/listings/ch17-async-await/listing-17-32/src/main.rs @@ -7,18 +7,16 @@ fn main() { while let Some(message) = messages.next().await { println!("{message}"); } - }) + }); } fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); - // ANCHOR: send let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; for message in messages { tx.send(format!("Message: '{message}'")).unwrap(); } - // ANCHOR_END: send ReceiverStream::new(rx) } diff --git a/listings/ch17-async-await/listing-17-42/Cargo.lock b/listings/ch17-async-await/listing-17-33/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-42/Cargo.lock rename to listings/ch17-async-await/listing-17-33/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-42/Cargo.toml b/listings/ch17-async-await/listing-17-33/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-42/Cargo.toml rename to listings/ch17-async-await/listing-17-33/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-44/src/main.rs b/listings/ch17-async-await/listing-17-33/src/main.rs similarity index 88% rename from listings/ch17-async-await/listing-17-44/src/main.rs rename to listings/ch17-async-await/listing-17-33/src/main.rs index 986d0419e9..c99c1f3636 100644 --- a/listings/ch17-async-await/listing-17-44/src/main.rs +++ b/listings/ch17-async-await/listing-17-33/src/main.rs @@ -1,16 +1,11 @@ -// ANCHOR: pin +// ANCHOR: timeout use std::{pin::pin, time::Duration}; -// --snip-- - -// ANCHOR_END: pin use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { trpl::block_on(async { - // ANCHOR: pin let mut messages = pin!(get_messages().timeout(Duration::from_millis(200))); - // ANCHOR_END: pin while let Some(result) = messages.next().await { match result { @@ -20,6 +15,7 @@ fn main() { } }) } +// ANCHOR_END: timeout fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); diff --git a/listings/ch17-async-await/listing-17-43/Cargo.lock b/listings/ch17-async-await/listing-17-34/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-43/Cargo.lock rename to listings/ch17-async-await/listing-17-34/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-43/Cargo.toml b/listings/ch17-async-await/listing-17-34/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-43/Cargo.toml rename to listings/ch17-async-await/listing-17-34/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-45/src/main.rs b/listings/ch17-async-await/listing-17-34/src/main.rs similarity index 94% rename from listings/ch17-async-await/listing-17-45/src/main.rs rename to listings/ch17-async-await/listing-17-34/src/main.rs index f044684113..4dc6ed1fdb 100644 --- a/listings/ch17-async-await/listing-17-45/src/main.rs +++ b/listings/ch17-async-await/listing-17-34/src/main.rs @@ -16,10 +16,10 @@ fn main() { }) } +// ANCHOR: messages fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); - // ANCHOR: messages trpl::spawn_task(async move { let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; for (index, message) in messages.into_iter().enumerate() { @@ -29,7 +29,7 @@ fn get_messages() -> impl Stream { tx.send(format!("Message: '{message}'")).unwrap(); } }); - // ANCHOR_END: messages ReceiverStream::new(rx) } +// ANCHOR_END: messages diff --git a/listings/ch17-async-await/listing-17-41/src/main.rs b/listings/ch17-async-await/listing-17-41/src/main.rs deleted file mode 100644 index 4ca575988a..0000000000 --- a/listings/ch17-async-await/listing-17-41/src/main.rs +++ /dev/null @@ -1,17 +0,0 @@ -use trpl::{ReceiverStream, Stream, StreamExt}; - -fn main() { - trpl::block_on(async { - let mut messages = get_messages(); - - while let Some(message) = messages.next().await { - println!("{message}"); - } - }) -} - -fn get_messages() -> impl Stream { - let (tx, rx) = trpl::channel(); - - ReceiverStream::new(rx) -} diff --git a/listings/ch17-async-await/listing-17-43/src/main.rs b/listings/ch17-async-await/listing-17-43/src/main.rs deleted file mode 100644 index 2ec150b9ac..0000000000 --- a/listings/ch17-async-await/listing-17-43/src/main.rs +++ /dev/null @@ -1,32 +0,0 @@ -// ANCHOR: timeout -use std::time::Duration; -// --snip-- -// ANCHOR_END: timeout -use trpl::{ReceiverStream, Stream, StreamExt}; - -fn main() { - trpl::block_on(async { - // ANCHOR: timeout - - let mut messages = get_messages().timeout(Duration::from_millis(200)); - - while let Some(result) = messages.next().await { - match result { - Ok(message) => println!("{message}"), - Err(reason) => eprintln!("Problem: {reason:?}"), - } - } - // ANCHOR_END: timeout - }) -} - -fn get_messages() -> impl Stream { - let (tx, rx) = trpl::channel(); - - let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; - for message in messages { - tx.send(format!("Message: '{message}'")).unwrap(); - } - - ReceiverStream::new(rx) -} diff --git a/listings/ch17-async-await/listing-17-44/Cargo.lock b/listings/ch17-async-await/listing-17-44/Cargo.lock deleted file mode 100644 index 36905af42a..0000000000 --- a/listings/ch17-async-await/listing-17-44/Cargo.lock +++ /dev/null @@ -1,292 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "tokio-stream" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", - "tokio-stream", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-44/Cargo.toml b/listings/ch17-async-await/listing-17-44/Cargo.toml deleted file mode 100644 index e094f067f1..0000000000 --- a/listings/ch17-async-await/listing-17-44/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-45/Cargo.lock b/listings/ch17-async-await/listing-17-45/Cargo.lock deleted file mode 100644 index 36905af42a..0000000000 --- a/listings/ch17-async-await/listing-17-45/Cargo.lock +++ /dev/null @@ -1,292 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "async_await" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "cc" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "syn" -version = "2.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", -] - -[[package]] -name = "tokio-stream" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "trpl" -version = "0.1.0" -dependencies = [ - "futures", - "tokio", - "tokio-stream", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-45/Cargo.toml b/listings/ch17-async-await/listing-17-45/Cargo.toml deleted file mode 100644 index e094f067f1..0000000000 --- a/listings/ch17-async-await/listing-17-45/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "async_await" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] -trpl = { path = "../../../packages/trpl" } diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index 988ea383f9..173ee4f0fe 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -210,49 +210,34 @@ streams in interesting ways. ### Composing Streams -For one thing, lots of things are naturally represented as streams—items -becoming available in a queue over time, for example, or working with more data -than can fit in a computer’s memory by only pulling chunks of it from the file -system at a time, or data arriving over the network over time. For another -thing, since streams are futures, we can use them with any other kind of -future, and we can combine them in interesting ways. - -In the real world, we can use this to do things like debounce events to avoid -triggering too many network calls, set timeouts on sequences of long-running -operations, or throttle user interface events to avoid doing needless work. -Let’s start by building a little stream of messages. This is similar to what we -might see from a WebSocket or some other real-time communication protocol. To -begin, we will create a function, `get_messages()`, which returns `impl -Stream`, and use a `while let` loop to print all the messages -from the stream. - -+Lots of things are naturally represented as streams: items becoming available in +a queue over time, or working with more data than can fit in a computer’s memory +by only pulling chunks of it from the file system at a time, or data arriving +over the network over time. And because streams are futures, we can use them +with any other kind of future, and we can combine them in interesting ways. For +example, we can debounce events to avoid triggering too many network calls, set +timeouts on sequences of long-running operations, or throttle user interface +events to avoid doing needless work. + +Let’s start by building a little stream of messages, similar to what we might +see from a WebSocket or other real-time communication protocols. In Listing +17-32, we create a function `get_messages()` which returns `impl Stream`. For its implementation, we create an async channel, loop over the +first ten letters of the English alphabet, and send them across the channel. + +We also use a new type: `ReceiverStream`. This converts the `rx` receiver from +the `trpl::channel` into a stream. Back in `main`, we use a `while let` loop to +print all the messages from the stream. + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-41/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs}} ``` -In Listing 17-41, we also use a new type: `ReceiverStream`. This converts the -`rx` receiver from the `trpl::channel` into a stream. This is pretty easy, since -the API for a receiver like this already has the same basic shape as a `Stream`. - -So far this will compile just fine, but we are not sending any messages, so -nothing will happen when we run the program. We can change that by looping over -the first ten letters of the English alphabet, and sending those across the -channel. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-42/src/main.rs:send}} -``` - - - -When we run the code in Listing 17-42, we get exactly the results we would -expect: +When we run this code, we get exactly the results we would expect: +To sleep between messages in the `get_messages` function without blocking, we +need to use async. However, we cannot make `get_messages` itself into an async +function, because then we would return a `Future>` instead of just a `Stream>`. The caller would have to +await `get_messages` itself to get access to the stream. But remember: +everything in a given future happens linearly; concurrency happens *between* +futures. Awaiting `get_messages` would require it to send all the messages, and +sleeping between sending them, before returning the receiver stream. As a +result, The timeout would end up useless, because there would be no delays in +the stream itself: the delays all happen before the stream is even available. Instead, we leave `get_messages` as a regular function which returns a stream, and spawn a task to handle the async `sleep` calls. @@ -345,17 +317,14 @@ and spawn a task to handle the async `sleep` calls. > spawn tasks without reference to a runtime. You should make sure you know what > tradeoff your runtime has chosen and write your code accordingly! -Now our code has a much more interesting result! Between the messages, we see an -error reported: `Problem: Elapsed(())`. Notice that it does not prevent the -messages from arriving in the end—we still get all of the original messages. -This is because our channel is unbounded: it can hold as many messages as we can -fit in memory. If the message does not arrive before the timeout, our stream -handler will account for that, but when it polls the stream again, the message -may now have arrived. +Now our code has a much more interesting result! Between every other pair of +messages, we see an error reported: `Problem: Elapsed(())`. - + ```text Message: 'a' @@ -375,6 +344,12 @@ Problem: Elapsed(()) Message: 'j' ``` +The timeout does not prevent the messages from arriving in the end—we still get +all of the original messages. This is because our channel is unbounded: it can +hold as many messages as we can fit in memory. If the message does not arrive +before the timeout, our stream handler will account for that, but when it polls +the stream again, the message may now have arrived. + You can get different behavior if needed by using other kinds of channels, or other kinds of streams more generally. Let’s see one of those in practice in our final example for this section, by combining a stream of time intervals with From 2797d950ab36f26c11b473461383df16986471f0 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 11 Jul 2024 17:14:08 -0600 Subject: [PATCH 364/720] =?UTF-8?q?Ch.=2017=C2=A705=20initial=20edits=20on?= =?UTF-8?q?=20'Merging=20Streams'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 1 - .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 8 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 8 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 25 +-- src/ch17-05-streams.md | 182 ++++++++++-------- 16 files changed, 120 insertions(+), 104 deletions(-) rename listings/ch17-async-await/{listing-17-46 => listing-17-35}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-46 => listing-17-35}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-46 => listing-17-35}/src/main.rs (100%) rename listings/ch17-async-await/{listing-17-47 => listing-17-36}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-47 => listing-17-36}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-47 => listing-17-36}/src/main.rs (99%) rename listings/ch17-async-await/{listing-17-48 => listing-17-37}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-48 => listing-17-37}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-48 => listing-17-37}/src/main.rs (87%) rename listings/ch17-async-await/{listing-17-49 => listing-17-38}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-49 => listing-17-38}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-49 => listing-17-38}/src/main.rs (90%) rename listings/ch17-async-await/{listing-17-50 => listing-17-39}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-50 => listing-17-39}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-50 => listing-17-39}/src/main.rs (78%) diff --git a/listings/ch17-async-await/listing-17-46/Cargo.lock b/listings/ch17-async-await/listing-17-35/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-46/Cargo.lock rename to listings/ch17-async-await/listing-17-35/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-46/Cargo.toml b/listings/ch17-async-await/listing-17-35/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-46/Cargo.toml rename to listings/ch17-async-await/listing-17-35/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-46/src/main.rs b/listings/ch17-async-await/listing-17-35/src/main.rs similarity index 100% rename from listings/ch17-async-await/listing-17-46/src/main.rs rename to listings/ch17-async-await/listing-17-35/src/main.rs diff --git a/listings/ch17-async-await/listing-17-47/Cargo.lock b/listings/ch17-async-await/listing-17-36/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-47/Cargo.lock rename to listings/ch17-async-await/listing-17-36/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-47/Cargo.toml b/listings/ch17-async-await/listing-17-36/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-47/Cargo.toml rename to listings/ch17-async-await/listing-17-36/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-47/src/main.rs b/listings/ch17-async-await/listing-17-36/src/main.rs similarity index 99% rename from listings/ch17-async-await/listing-17-47/src/main.rs rename to listings/ch17-async-await/listing-17-36/src/main.rs index 62a93fc0f6..dde9b34c6f 100644 --- a/listings/ch17-async-await/listing-17-47/src/main.rs +++ b/listings/ch17-async-await/listing-17-36/src/main.rs @@ -7,7 +7,6 @@ fn main() { // ANCHOR: main let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals(); - let merged = messages.merge(intervals); // ANCHOR_END: main diff --git a/listings/ch17-async-await/listing-17-48/Cargo.lock b/listings/ch17-async-await/listing-17-37/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-48/Cargo.lock rename to listings/ch17-async-await/listing-17-37/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-48/Cargo.toml b/listings/ch17-async-await/listing-17-37/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-48/Cargo.toml rename to listings/ch17-async-await/listing-17-37/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-48/src/main.rs b/listings/ch17-async-await/listing-17-37/src/main.rs similarity index 87% rename from listings/ch17-async-await/listing-17-48/src/main.rs rename to listings/ch17-async-await/listing-17-37/src/main.rs index 30d0928ea9..4d2c747cc7 100644 --- a/listings/ch17-async-await/listing-17-48/src/main.rs +++ b/listings/ch17-async-await/listing-17-37/src/main.rs @@ -7,13 +7,13 @@ fn main() { // ANCHOR: main let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() - .map(|count| format!("Interval #{count}")) + .map(|count| format!("Interval: {count}")) .timeout(Duration::from_secs(10)); - - let mut merged = pin!(messages.merge(intervals)); + let merged = messages.merge(intervals); + let mut stream = pin!(merged); // ANCHOR_END: main - while let Some(result) = merged.next().await { + while let Some(result) = stream.next().await { match result { Ok(message) => println!("{message}"), Err(reason) => eprintln!("Problem: {reason:?}"), diff --git a/listings/ch17-async-await/listing-17-49/Cargo.lock b/listings/ch17-async-await/listing-17-38/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-49/Cargo.lock rename to listings/ch17-async-await/listing-17-38/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-49/Cargo.toml b/listings/ch17-async-await/listing-17-38/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-49/Cargo.toml rename to listings/ch17-async-await/listing-17-38/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-49/src/main.rs b/listings/ch17-async-await/listing-17-38/src/main.rs similarity index 90% rename from listings/ch17-async-await/listing-17-49/src/main.rs rename to listings/ch17-async-await/listing-17-38/src/main.rs index 48e4ceea43..5103787668 100644 --- a/listings/ch17-async-await/listing-17-49/src/main.rs +++ b/listings/ch17-async-await/listing-17-38/src/main.rs @@ -4,17 +4,17 @@ use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { trpl::block_on(async { - let messages = get_messages().timeout(Duration::from_millis(200)); // ANCHOR: throttle + let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() .map(|count| format!("Interval #{count}")) .throttle(Duration::from_millis(100)) .timeout(Duration::from_secs(10)); - - let mut merged = pin!(messages.merge(intervals).take(20)); + let merged = messages.merge(intervals).take(20); + let mut stream = pin!(merged); // ANCHOR_END: throttle - while let Some(result) = merged.next().await { + while let Some(result) = stream.next().await { match result { Ok(message) => println!("{message}"), Err(reason) => eprintln!("Problem: {reason:?}"), diff --git a/listings/ch17-async-await/listing-17-50/Cargo.lock b/listings/ch17-async-await/listing-17-39/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-50/Cargo.lock rename to listings/ch17-async-await/listing-17-39/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-50/Cargo.toml b/listings/ch17-async-await/listing-17-39/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-50/Cargo.toml rename to listings/ch17-async-await/listing-17-39/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-50/src/main.rs b/listings/ch17-async-await/listing-17-39/src/main.rs similarity index 78% rename from listings/ch17-async-await/listing-17-50/src/main.rs rename to listings/ch17-async-await/listing-17-39/src/main.rs index e8ee79e4a4..597e6f0298 100644 --- a/listings/ch17-async-await/listing-17-50/src/main.rs +++ b/listings/ch17-async-await/listing-17-39/src/main.rs @@ -23,9 +23,6 @@ fn main() { // ANCHOR: errors fn get_messages() -> impl Stream { - // --snip-- - - // ANCHOR_END: errors let (tx, rx) = trpl::channel(); trpl::spawn_task(async move { @@ -35,27 +32,18 @@ fn get_messages() -> impl Stream { let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; trpl::sleep(Duration::from_millis(time_to_sleep)).await; - // ANCHOR: errors - if let Err(send_error) = - tx.send(format!("Message: '{message}' after {time_to_sleep}ms")) - { + let result = tx.send(format!("Message: '{message}'")); + if let Err(send_error) = result { eprintln!("Cannot send message '{message}': {send_error}"); break; } - // ANCHOR_END: errors } }); ReceiverStream::new(rx) - // ANCHOR: errors - - // --snip-- } fn get_intervals() -> impl Stream { - // --snip-- - - // ANCHOR_END: errors let (tx, rx) = trpl::channel(); trpl::spawn_task(async move { @@ -63,18 +51,15 @@ fn get_intervals() -> impl Stream { loop { trpl::sleep(Duration::from_millis(1)).await; count += 1; - // ANCHOR: errors - if let Err(send_error) = tx.send(count) { + + let result = tx.send(count); + if let Err(send_error) = result { eprintln!("Could not send interval {count}: {send_error}"); break; }; - // ANCHOR_END: errors } }); ReceiverStream::new(rx) - // ANCHOR: errors - - // --snip-- } // ANCHOR_END: errors diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index 173ee4f0fe..49b69f6246 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -359,14 +359,12 @@ this stream of messages. First, let’s create another stream, called `get_intervals`, which will emit an item every millisecond if we let it run directly. For simplicity, we can use the -`sleep` function to send a message on that delay, and combine it with the same -approach of creating a stream from a channel that we used for `get_messages`. -(There are, of course, many other ways to build streams, including some -dedicated to working with intervals!) The difference is that this time, we are -going to send back the count of intervals, rather than a string, so the -resulting stream will have the type `Stream`. - -In Listing 17-46, we start by defining a `count` in the task. (We could define +`sleep` function to send a message on a delay, and combine it with the same +approach of creating a stream from a channel we used in `get_messages`. The +difference is that this time, we are going to send back the count of intervals +which has elapsed, so the return type will be `impl Stream`. + +In Listing 17-35, we start by defining a `count` in the task. (We could define it outside the task, too, but it is clearer to limit the scope of any given variable.) Then we create a an infinite loop. Each iteration of the loop asynchronously sleeps for one millisecond, increments the count, and then sends @@ -374,63 +372,65 @@ it over the channel. Since this is all wrapped in the task created by `spawn_task`, all of it will get cleaned up along with the runtime, including the infinite loop. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-46/src/main.rs:intervals}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-35/src/main.rs:intervals}} ``` This kind of infinite loop, which only ends when the whole runtime gets torn -down, is a fairly common pattern when dealing with many different kinds of async -operations in Rust. That is because there are many kinds of programs which need -to keep running until something actually ends the program. +down, is fairly common in async Rust: many programs need to keep running +indefinitely. With async, this does not block anything else! -Now we need to use these intervals! Back in our main function’s async block, we -start by getting the intervals. Then we can try to create a merged stream using -`messages` and `intervals`, and loop over that combined stream instead of over -`messages` (Listing 17-47). At this point, neither `messages` nor `intervals` -needs to be pinned or mutable, because both will be combined into the single -`merged` stream. However, this call to `merge` does not type check! (Neither -does the `next` call in the `while let` loop, but we will come back to that -after fixing this first.) +Back in our main function’s async block, we start by calling `get_intervals`. +Then we merge the `messages` and `intervals` streams with the `merge` method. +Finally, we loop over that combined stream instead of over `messages` (Listing +17-36). -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-47/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-36/src/main.rs:main}} ``` -The problem is that our two streams have different types. The `messages` stream -has the type `Timeout>`. The `Timeout` is the type -which implements `Stream` for a `timeout` call! Meanwhile, the `intervals` stream has -the type `impl Stream`. To merge these two streams, we need to transform one of -them to match the other. Let’s work with the `intervals`, since `messages` is -already in the basic format we want and has to handle timeout errors. - -Listing 17-48 shows the transformations we need. First, we can use the `map` -helper method to transform the `intervals` into a string. Second, we need to -match the `Timeout` from `messages`. Since we do not actually *want* a timeout -for `intervals`, though, we can just create a timeout which is longer than the -other durations we are using. Here, we create a 10-second time out with -`Duration::from_secs(10)`. Finally, we need to make `merged` both mutable, so -that the `while let` loop’s `next` calls can iterate through the stream, and -pinned, so that it is safe to do so. - -+At this point, neither `messages` nor `intervals` needs to be pinned or mutable, +because both will be combined into the single `merged` stream. However, this +call to `merge` does not type check! (Neither does the `next` call in the `while +let` loop, but we will come back to that after fixing this.) The two streams +have different types. The `messages` stream has the type `Timeout>`, where `Timeout` is the type which implements `Stream` +for a `timeout` call. Meanwhile, the `intervals` stream has the type `impl +Stream`. To merge these two streams, we need to transform one of +them to match the other. + +In Listing 17-37, we rework with the `intervals` stream, since `messages` is +already in the basic format we want and has to handle timeout errors. First, we +can use the `map` helper method to transform the `intervals` into a string. +Second, we need to match the `Timeout` from `messages`. Since we do not actually +*want* a timeout for `intervals`, though, we can just create a timeout which is +longer than the other durations we are using. Here, we create a 10-second time +out with `Duration::from_secs(10)`. Finally, we need to make `merged` both +mutable, so that the `while let` loop’s `next` calls can iterate through the +stream, and pinned, so that it is safe to do so. + + ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-48/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-37/src/main.rs:main}} ``` -That gets us *almost* to where we need to be. Everything type checks! If you run -this, though, the messages from the English alphabet will be buried in the midst -of all the interval counter messages: + +That gets us *almost* to where we need to be. Everything type checks. If you run +this, though, there will be two problems. First, it will never stop! You will +need to stop it with ctrl-c. Second, the +messages from the English alphabet will be buried in the midst of all the +interval counter messages: ```text --snip-- -Interval #38 -Interval #39 -Interval #40 +Interval: 38 +Interval: 39 +Interval: 40 Message: 'a' -Interval #41 -Interval #42 -Interval #43 +Interval: 41 +Interval: 42 +Interval: 43 --snip-- ``` -This is no good; we need to only take *some* of those intervals—say, once every -hundred milliseconds. For that, we can use the `throttle` method. Throttling is -a way of limiting the rate at which a function will be called—or, in this case, -how often the stream will be polled. We also don’t want to keep going -indefinitely! We can use the `take` method to limit how many items we pull from -a stream. In Listing 17-49, we apply `throttle` to the `intervals` stream, -because we want to avoid overwhelming the stream of messages, but we apply the -`take` method to the *merged* messages, because we want to limit the final +Listing 17-38 shows one way to solve these last two problems. First, we use the +`throttle` method on the `intervals` stream, so that it does not overwhelm the +`messages` stream. Throttling is a way of limiting the rate at which a function +will be called—or, in this case, how often the stream will be polled. Once every +hundred milliseconds should do, since that is in the same ballpark as how often +our messages arrive. + +To limit the number of items we will accept from a stream, we can use the `take` +method. We apply it to the *merged* stream, because we want to limit the final output, not just one stream or the other. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-49/src/main.rs:throttle}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-38/src/main.rs:throttle}} ``` +Now when we run the program, it stop after pulling twenty items from the stream, +and the intervals do not overwhelm the messages. We also do not get `Interval: +100` or `Interval: 200` or so on, but instead simply get `Interval: 1`, +`Interval: 2`, and so on—even though we have a source stream which *can* produce +an event every millisecond. That is because the `throttle` call produces a new +stream, wrapping the original stream, so that the original stream only gets +polled at the throttle rate, not its own “native” rate. We do not have a bunch +of unhandled interval messages we are simply choosing to ignore. Instead, we +never produce those interval messages in the first place! This is the inherent +“laziness” of Rust’s futures at work again, allowing us to choose our +performance characteristics. + + + +```text +Interval #1 +Message: 'a' +Interval #2 +Interval #3 +Problem: Elapsed(()) +Interval #4 +Message: 'b' +Interval #5 +Message: 'c' +Interval #6 +Interval #7 +Problem: Elapsed(()) +Interval #8 +Message: 'd' +Interval #9 +Message: 'e' +Interval #10 +Interval #11 +Problem: Elapsed(()) +Interval #12 +``` + There is one last thing we need to handle: errors! With both of these channel-based streams, the `send` calls could fail when the other side of the channel closes—and that is just a matter of how the runtime executes the futures which make up the stream. Up till now we have ignored this by calling `unwrap`, but in a well-behaved app, we should explicitly handle the error, at minimum by -ending the loop so we do not try to send any more messages! Listing 17-50 shows +ending the loop so we do not try to send any more messages! Listing 17-39 shows a simple error strategy: print the issue and then `break` from the loops. As -usual, the correct behavior on a message send error will vary—just make sure you -do in fact have a strategy. +usual, the correct way to handle a message send error will vary—just make sure +you have a strategy. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-50/src/main.rs:errors}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-39/src/main.rs:errors}} ``` -Notice that we do not get `Interval #100` or `Interval #200` or so on, but -instead simply get `Interval #1`, `Interval #2`, and so on—even though we have a -source stream which *can* produce an event every millisecond. That is because -the `throttle` call produces a new stream, wrapping the original stream, so that -the original stream only gets polled at the throttle rate, not its own “native” -rate. We do not have a bunch of unhandled interval messages we are simply -choosing to ignore. Instead, we never produce those interval messages in the -first place! This is the inherent “laziness” of Rust’s futures at work again, -allowing us to choose our performance characteristics. - That is a good note to turn to our final section and wrap up this walk through async in Rust, by discussing how futures (including streams), tasks, and threads relate to each other, and how you can use them together. From 92c19ce9cf9b6b711de9b4d22e43bc8a987c14ed Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 11 Jul 2024 19:30:27 -0600 Subject: [PATCH 365/720] =?UTF-8?q?Ch.=2017=C2=A706=20initial=20edits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listing-17-39/src/main.rs | 14 ++-- .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 19 +++-- packages/trpl/src/lib.rs | 6 +- src/ch17-06-futures-tasks-threads.md | 80 +++++++++++-------- 6 files changed, 65 insertions(+), 54 deletions(-) rename listings/ch17-async-await/{listing-17-51 => listing-17-40}/Cargo.lock (100%) rename listings/ch17-async-await/{listing-17-51 => listing-17-40}/Cargo.toml (100%) rename listings/ch17-async-await/{listing-17-51 => listing-17-40}/src/main.rs (79%) diff --git a/listings/ch17-async-await/listing-17-39/src/main.rs b/listings/ch17-async-await/listing-17-39/src/main.rs index 597e6f0298..15a3fddd30 100644 --- a/listings/ch17-async-await/listing-17-39/src/main.rs +++ b/listings/ch17-async-await/listing-17-39/src/main.rs @@ -9,16 +9,16 @@ fn main() { .map(|count| format!("Interval #{count}")) .throttle(Duration::from_millis(500)) .timeout(Duration::from_secs(10)); + let merged = messages.merge(intervals).take(20); + let mut stream = pin!(merged); - let mut merged = pin!(messages.merge(intervals).take(20)); - - while let Some(result) = merged.next().await { + while let Some(result) = stream.next().await { match result { Ok(item) => println!("{item}"), Err(reason) => eprintln!("Problem: {reason:?}"), } } - }) + }); } // ANCHOR: errors @@ -32,8 +32,7 @@ fn get_messages() -> impl Stream { let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; trpl::sleep(Duration::from_millis(time_to_sleep)).await; - let result = tx.send(format!("Message: '{message}'")); - if let Err(send_error) = result { + if let Err(send_error) = tx.send(format!("Message: '{message}'")) { eprintln!("Cannot send message '{message}': {send_error}"); break; } @@ -52,8 +51,7 @@ fn get_intervals() -> impl Stream { trpl::sleep(Duration::from_millis(1)).await; count += 1; - let result = tx.send(count); - if let Err(send_error) = result { + if let Err(send_error) = tx.send(count) { eprintln!("Could not send interval {count}: {send_error}"); break; }; diff --git a/listings/ch17-async-await/listing-17-51/Cargo.lock b/listings/ch17-async-await/listing-17-40/Cargo.lock similarity index 100% rename from listings/ch17-async-await/listing-17-51/Cargo.lock rename to listings/ch17-async-await/listing-17-40/Cargo.lock diff --git a/listings/ch17-async-await/listing-17-51/Cargo.toml b/listings/ch17-async-await/listing-17-40/Cargo.toml similarity index 100% rename from listings/ch17-async-await/listing-17-51/Cargo.toml rename to listings/ch17-async-await/listing-17-40/Cargo.toml diff --git a/listings/ch17-async-await/listing-17-51/src/main.rs b/listings/ch17-async-await/listing-17-40/src/main.rs similarity index 79% rename from listings/ch17-async-await/listing-17-51/src/main.rs rename to listings/ch17-async-await/listing-17-40/src/main.rs index 4b44ab723e..d25f8492ce 100644 --- a/listings/ch17-async-await/listing-17-51/src/main.rs +++ b/listings/ch17-async-await/listing-17-40/src/main.rs @@ -1,4 +1,4 @@ -use std::{pin::pin, time::Duration}; +use std::{pin::pin, thread, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; @@ -9,16 +9,16 @@ fn main() { .map(|count| format!("Interval #{count}")) .throttle(Duration::from_millis(500)) .timeout(Duration::from_secs(10)); + let merged = messages.merge(intervals).take(20); + let mut stream = pin!(merged); - let mut merged = pin!(messages.merge(intervals).take(20)); - - while let Some(result) = merged.next().await { + while let Some(result) = stream.next().await { match result { Ok(item) => println!("{item}"), Err(reason) => eprintln!("Problem: {reason:?}"), } } - }) + }); } fn get_messages() -> impl Stream { @@ -31,9 +31,7 @@ fn get_messages() -> impl Stream { let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; trpl::sleep(Duration::from_millis(time_to_sleep)).await; - if let Err(send_error) = - tx.send(format!("Message: '{message}' after {time_to_sleep}ms")) - { + if let Err(send_error) = tx.send(format!("Message: '{message}'")) { eprintln!("Cannot send message '{message}': {send_error}"); break; } @@ -47,11 +45,12 @@ fn get_messages() -> impl Stream { fn get_intervals() -> impl Stream { let (tx, rx) = trpl::channel(); - trpl::spawn_task(async move { + thread::spawn(move || { let mut count = 0; loop { - trpl::sleep(Duration::from_millis(1)).await; + thread::sleep(Duration::from_millis(1)); count += 1; + if let Err(send_error) = tx.send(count) { eprintln!("Could not send interval {count}: {send_error}"); break; diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index e95cce16d1..9336a69a19 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -15,9 +15,11 @@ // For direct use within the `trpl` crate, *not* re-exported. use std::{future::Future, pin::pin}; +use futures::future; + // Re-exports, to be used like `trpl::join`. pub use futures::{ - future::{self, join, join3, join_all, Either}, + future::{join, join3, join_all, Either}, join, }; pub use tokio::{ @@ -38,7 +40,7 @@ pub use tokio::{ unbounded_channel as channel, UnboundedReceiver as Receiver, UnboundedSender as Sender, }, - task::{spawn as spawn_task, yield_now}, + task::{spawn as spawn_task, yield_now, JoinHandle}, time::{interval, sleep}, }; diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index a723a022e9..5a65ab66af 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -3,18 +3,17 @@ As we saw in the previous chapter, threads provide one approach to concurrency. We have seen another approach to concurrency in this chapter, using async with futures and streams. You might be wondering why you would choose one or the -other. The answer is: it depends! And in many cases, it is not threads *vs.* +other. The answer is: it depends! And in many cases, it is not threads *or* async but rather threads *and* async. -Threads are an older and more common tool for concurrency. Many operating -systems have supplied threading-based concurrency models for decades now, and -many programming languages have support for them as a result. However, they are -not without their tradeoffs. On many operating systems, they use a fair bit of -memory for each thread, and they come with some overhead for starting up and -shutting down. Threads are also only an option when your operating system and -hardware support them! Unlike mainstream desktop and mobile operating systems, -many embedded operating systems, like those used on some microcontrollers, do -not have OS-level threads at all. +Many operating systems have supplied threading-based concurrency models for +decades now, and many programming languages have support for them as a result. +However, they are not without their tradeoffs. On many operating systems, they +use a fair bit of memory for each thread, and they come with some overhead for +starting up and shutting down. Threads are also only an option when your +operating system and hardware support them! Unlike mainstream desktop and mobile +operating systems, many embedded operating systems, like those used on some +microcontrollers, do not have OS-level threads at all. The async model provides a different—and ultimately complementary—set of tradeoffs. In the async model, concurrent operations do not require their own @@ -23,18 +22,17 @@ kick off work from a synchronous function throughout the streams section. A task is a lot like a thread—but instead of being managed by the operating system, it is managed by library-level code: the runtime. -In the previous section, we saw that we could build a `Stream` by using a +In the previous section, we saw that we could build a `Stream` by using an async channel and spawning an async task which we could call from synchronous code. We -could do the exact same thing with a thread! We’ll use a simpler version of the -streams example so we can focus on the differences. In Listing 17-50, we used -`trpl::spawn_task` and `trpl::sleep`. In Listing 17-51, we replace those with -the `thread::spawn` and `thread::sleep` APIs from the standard library, in just -the `get_intervals` function. +could do the exact same thing with a thread! In Listing 17-39, we used +`trpl::spawn_task` and `trpl::sleep`. In Listing 17-40, we replace those with +the `thread::spawn` and `thread::sleep` APIs from the standard library in the +`get_intervals` function. -+ ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-51/src/main.rs:threads}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:threads}} ``` @@ -42,21 +40,23 @@ the `get_intervals` function. If you run this, the output is identical. And notice how little changes here from the perspective of the calling code! What is more, even though one of our functions spawned an async task on the runtime and the other spawned an -operating system thread, they worked exactly the same way as far as processing -the stream was concerned. +OS thread, the resulting streams were unaffected by the differences. -However, there is a meaningful difference in the way this system -behaves, although we might have a hard time measuring it in this very simple -example. We could spawn hundreds of thousands or even millions of async tasks on -any modern personal computer. If we tried to do that with threads, we would -literally run out of memory! +However, there is a significant difference between these two approaches behave, +although we might have a hard time measuring it in this very simple example. We +could spawn hundreds of thousands or even millions of async tasks on any modern +personal computer. If we tried to do that with threads, we would literally run +out of memory! However, there is a reason these APIs are so similar. Threads act as a boundary for sets of synchronous operations; concurrency is possible *between* threads. Tasks act as a boundary for sets of *asynchronous* operations; concurrency is possible both *between* and *within* tasks. In that regard, tasks are kind of like lightweight, runtime-managed threads with added capabilities that come from -being managed by a runtime instead of by the operating system. +being managed by a runtime instead of by the operating system. Futures are an +even more granular unit of concurrency, where each future may represent a tree +of other futures. However, this does not mean that async tasks are always better than threads, any more than that threads are always better than tasks. @@ -71,12 +71,12 @@ cancellation—a subject we have not covered in depth in this chapter, but which is implicit in the fact that whenever we ended a future, its state got cleaned up correctly. -These limitations make threads harder to compose than futures. It -is much more difficult, for example, to build something like the `timeout` we -built in [“Building Our Own Async Abstractions”][combining-futures], or the -`throttle` method we used with streams in [“Working With Streams”][streams]. The fact -that futures are richer data structures means they *can* be composed together -more naturally, as we have seen. +These limitations make threads harder to compose than futures. It is much more +difficult, for example, to build something like the `timeout` we built in +[“Building Our Own Async Abstractions”][combining-futures], or the `throttle` +method we used with streams in [“Working With Streams”][streams]. The fact that +futures are richer data structures means they *can* be composed together more +naturally, as we have seen. Tasks then give *additional* control over futures, allowing you to choose where and how to group them. And it turns out that threads and tasks often work very @@ -88,6 +88,18 @@ tasks around between threads based on the current utilization of the threads, to hopefully improve the overall performance of the system. To build that actually requires threads *and* tasks, and therefore futures. +As a default way of thinking about which to use when: + +- If the task is *very parallelizable*, like processing a bunch of data where + each part can be processed separately, threads are a better choice. +- If the task is *very concurrent*, like handling messages from a bunch of + different sources which may come in a different intervals or different rates, + async is a better choice. + +And if you need some mix of parallelism and concurrency, you do not have to +choose between threads and async. You can use them together freely, letting each +one serve the part it is best at. + ## Summary This isn’t the last you’ll see of concurrency in this book: the project in @@ -95,8 +107,8 @@ Chapter 21 will use the concepts in this chapter in a more realistic situation than the smaller examples discussed here—and compare more directly what it looks like to solve these kinds of problems with threading vs. with tasks and futures. -Whether with threads or with futures and tasks, or combining them for greatest -performance, Rust gives you the tools you need to write safe, fast, concurrent +Whether with threads, with futures and tasks, or with the combination of them +all, Rust gives you the tools you need to write safe, fast, concurrent code—whether for a high-throughput web server or an embedded operating system. Next, we’ll talk about idiomatic ways to model problems and structure solutions From 28230e6cb448444a5705596dbb2e9b48e2505ca6 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 12 Jul 2024 15:41:11 -0600 Subject: [PATCH 366/720] infra: extract listing tests to separate files - `tests` -> `src/tests/mod.rs` - `tests::config` -> `src/tests/config.rs` This is just profoundly easier to work with. --- packages/mdbook-trpl-listing/src/lib.rs | 385 +----------------- .../mdbook-trpl-listing/src/tests/config.rs | 242 +++++++++++ packages/mdbook-trpl-listing/src/tests/mod.rs | 135 ++++++ 3 files changed, 378 insertions(+), 384 deletions(-) create mode 100644 packages/mdbook-trpl-listing/src/tests/config.rs create mode 100644 packages/mdbook-trpl-listing/src/tests/mod.rs diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index 59d338fe56..8f203645bc 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -361,387 +361,4 @@ impl<'a> ListingBuilder<'a> { } #[cfg(test)] -mod tests { - use super::*; - - /// Note: This inserts an additional backtick around the re-emitted code. - /// It is not clear *why*, but that seems to be an artifact of the rendering - /// done by the `pulldown_cmark_to_cmark` crate. - #[test] - fn default_mode_works() { - let result = rewrite_listing( - r#"- -```rust -fn main() {} -``` - -"#, - Mode::Default, - ); - - assert_eq!( - &result.unwrap(), - r#"
-Filename: src/main.rs - -````rust -fn main() {} -```` - -
Listing 1-2: A write-up which might include inline Markdown like code etc.
-
"# - ); - } - - #[test] - fn simple_mode_works() { - let result = rewrite_listing( - r#"- -```rust -fn main() {} -``` - -"#, - Mode::Simple, - ); - - assert_eq!( - &result.unwrap(), - r#" -Filename: src/main.rs - -````rust -fn main() {} -```` - -Listing 1-2: A write-up which might include inline Markdown like code etc."# - ); - } - - #[test] - fn actual_listing() { - let result = rewrite_listing( - r#"Now open the *main.rs* file you just created and enter the code in Listing 1-1. - -- -```rust -fn main() { - println!("Hello, world!"); -} -``` - - - -Save the file and go back to your terminal window"#, - Mode::Default, - ); - - assert!(result.is_ok()); - assert_eq!( - result.unwrap(), - r#"Now open the *main.rs* file you just created and enter the code in Listing 1-1. - -
-Filename: main.rs - -````rust -fn main() { - println!("Hello, world!"); -} -```` - -
Listing 1-1: A program that prints Hello, world!
-
- -Save the file and go back to your terminal window"# - ); - } - - #[test] - fn no_filename() { - let result = rewrite_listing( - r#"This is the opening. - -- -```rust -fn main() {} -``` - - - -This is the closing."#, - Mode::Default, - ); - - assert!(result.is_ok()); - assert_eq!( - result.unwrap(), - r#"This is the opening. - -
- -````rust -fn main() {} -```` - -
Listing 1-1: This is the caption
-
- -This is the closing."# - ); - } - - /// Check that the config options are correctly handled. - /// - /// Note: none of these tests particularly exercise the *wiring*. They just - /// assume that the config itself is done correctly. This is a small enough - /// chunk of code that it easy to verify by hand at present. If it becomes - /// more complex in the future, it would be good to revisit and integrate - /// the same kinds of tests as the unit tests above here. - #[cfg(test)] - mod config { - use super::*; - - // TODO: what *should* the behavior here be? I *think* it should error, - // in that there is a problem if it is invoked without that info. - #[test] - fn no_config() { - let input_json = r##"[ - { - "root": "/path/to/book", - "config": { - "book": { - "authors": ["AUTHOR"], - "language": "en", - "multilingual": false, - "src": "src", - "title": "TITLE" - }, - "preprocessor": {} - }, - "renderer": "html", - "mdbook_version": "0.4.21" - }, - { - "sections": [ - { - "Chapter": { - "name": "Chapter 1", - "content": "# Chapter 1\n", - "number": [1], - "sub_items": [], - "path": "chapter_1.md", - "source_path": "chapter_1.md", - "parent_names": [] - } - } - ], - "__non_exhaustive": null - } - ]"##; - let input_json = input_json.as_bytes(); - let (ctx, book) = - mdbook::preprocess::CmdPreprocessor::parse_input(input_json) - .unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_err()); - let err = result.unwrap_err(); - assert_eq!(format!("{err}"), "No config for trpl-listing"); - } - - #[test] - fn empty_config() { - let input_json = r##"[ - { - "root": "/path/to/book", - "config": { - "book": { - "authors": ["AUTHOR"], - "language": "en", - "multilingual": false, - "src": "src", - "title": "TITLE" - }, - "preprocessor": { - "trpl-listing": {} - } - }, - "renderer": "html", - "mdbook_version": "0.4.21" - }, - { - "sections": [ - { - "Chapter": { - "name": "Chapter 1", - "content": "# Chapter 1\n", - "number": [1], - "sub_items": [], - "path": "chapter_1.md", - "source_path": "chapter_1.md", - "parent_names": [] - } - } - ], - "__non_exhaustive": null - } - ]"##; - let input_json = input_json.as_bytes(); - let (ctx, book) = - mdbook::preprocess::CmdPreprocessor::parse_input(input_json) - .unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_ok()); - } - - #[test] - fn specify_default() { - let input_json = r##"[ - { - "root": "/path/to/book", - "config": { - "book": { - "authors": ["AUTHOR"], - "language": "en", - "multilingual": false, - "src": "src", - "title": "TITLE" - }, - "preprocessor": { - "trpl-listing": { - "output-mode": "default" - } - } - }, - "renderer": "html", - "mdbook_version": "0.4.21" - }, - { - "sections": [ - { - "Chapter": { - "name": "Chapter 1", - "content": "# Chapter 1\n", - "number": [1], - "sub_items": [], - "path": "chapter_1.md", - "source_path": "chapter_1.md", - "parent_names": [] - } - } - ], - "__non_exhaustive": null - } - ]"##; - let input_json = input_json.as_bytes(); - let (ctx, book) = - mdbook::preprocess::CmdPreprocessor::parse_input(input_json) - .unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_ok()); - } - - #[test] - fn specify_simple() { - let input_json = r##"[ - { - "root": "/path/to/book", - "config": { - "book": { - "authors": ["AUTHOR"], - "language": "en", - "multilingual": false, - "src": "src", - "title": "TITLE" - }, - "preprocessor": { - "trpl-listing": { - "output-mode": "simple" - } - } - }, - "renderer": "html", - "mdbook_version": "0.4.21" - }, - { - "sections": [ - { - "Chapter": { - "name": "Chapter 1", - "content": "# Chapter 1\n", - "number": [1], - "sub_items": [], - "path": "chapter_1.md", - "source_path": "chapter_1.md", - "parent_names": [] - } - } - ], - "__non_exhaustive": null - } - ]"##; - let input_json = input_json.as_bytes(); - let (ctx, book) = - mdbook::preprocess::CmdPreprocessor::parse_input(input_json) - .unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_ok()); - } - - #[test] - fn specify_invalid() { - let input_json = r##"[ - { - "root": "/path/to/book", - "config": { - "book": { - "authors": ["AUTHOR"], - "language": "en", - "multilingual": false, - "src": "src", - "title": "TITLE" - }, - "preprocessor": { - "trpl-listing": { - "output-mode": "nonsense" - } - } - }, - "renderer": "html", - "mdbook_version": "0.4.21" - }, - { - "sections": [ - { - "Chapter": { - "name": "Chapter 1", - "content": "# Chapter 1\n", - "number": [1], - "sub_items": [], - "path": "chapter_1.md", - "source_path": "chapter_1.md", - "parent_names": [] - } - } - ], - "__non_exhaustive": null - } - ]"##; - let input_json = input_json.as_bytes(); - let (ctx, book) = - mdbook::preprocess::CmdPreprocessor::parse_input(input_json) - .unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_err()); - let err = result.unwrap_err(); - assert_eq!( - format!("{err}"), - "Bad config value '\"nonsense\"' for key 'output-mode'" - ); - } - } -} +mod tests; diff --git a/packages/mdbook-trpl-listing/src/tests/config.rs b/packages/mdbook-trpl-listing/src/tests/config.rs new file mode 100644 index 0000000000..d44004b3e2 --- /dev/null +++ b/packages/mdbook-trpl-listing/src/tests/config.rs @@ -0,0 +1,242 @@ +//! Check that the config options are correctly handled. +//! +//! Note: none of these tests particularly exercise the *wiring*. They just +//! assume that the config itself is done correctly. This is a small enough +//! chunk of code that it easy to verify by hand at present. If it becomes +//! more complex in the future, it would be good to revisit and integrate +//! the same kinds of tests as the unit tests above here. + +use super::*; + +// TODO: what *should* the behavior here be? I *think* it should error, +// in that there is a problem if it is invoked without that info. +#[test] +fn no_config() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": {} + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_err()); + let err = result.unwrap_err(); + assert_eq!(format!("{err}"), "No config for trpl-listing"); +} + +#[test] +fn empty_config() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": { + "trpl-listing": {} + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_ok()); +} + +#[test] +fn specify_default() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": { + "trpl-listing": { + "output-mode": "default" + } + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_ok()); +} + +#[test] +fn specify_simple() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": { + "trpl-listing": { + "output-mode": "simple" + } + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_ok()); +} + +#[test] +fn specify_invalid() { + let input_json = r##"[ + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" + }, + "preprocessor": { + "trpl-listing": { + "output-mode": "nonsense" + } + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ + { + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } + } + ], + "__non_exhaustive": null + } + ]"##; + let input_json = input_json.as_bytes(); + let (ctx, book) = + mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); + let result = TrplListing.run(&ctx, book); + assert!(result.is_err()); + let err = result.unwrap_err(); + assert_eq!( + format!("{err}"), + "Bad config value '\"nonsense\"' for key 'output-mode'" + ); +} diff --git a/packages/mdbook-trpl-listing/src/tests/mod.rs b/packages/mdbook-trpl-listing/src/tests/mod.rs new file mode 100644 index 0000000000..1e1240e855 --- /dev/null +++ b/packages/mdbook-trpl-listing/src/tests/mod.rs @@ -0,0 +1,135 @@ +use super::*; + +/// Note: This inserts an additional backtick around the re-emitted code. +/// It is not clear *why*, but that seems to be an artifact of the rendering +/// done by the `pulldown_cmark_to_cmark` crate. +#[test] +fn default_mode_works() { + let result = rewrite_listing( + r#"+ +```rust +fn main() {} +``` + +"#, + Mode::Default, + ); + + assert_eq!( + &result.unwrap(), + r#"
+Filename: src/main.rs + +````rust +fn main() {} +```` + +
Listing 1-2: A write-up which might include inline Markdown like code etc.
+
"# + ); +} + +#[test] +fn simple_mode_works() { + let result = rewrite_listing( + r#"+ +```rust +fn main() {} +``` + +"#, + Mode::Simple, + ); + + assert_eq!( + &result.unwrap(), + r#" +Filename: src/main.rs + +````rust +fn main() {} +```` + +Listing 1-2: A write-up which might include inline Markdown like code etc."# + ); +} + +#[test] +fn actual_listing() { + let result = rewrite_listing( + r#"Now open the *main.rs* file you just created and enter the code in Listing 1-1. + ++ +```rust +fn main() { + println!("Hello, world!"); +} +``` + + + +Save the file and go back to your terminal window"#, + Mode::Default, + ); + + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + r#"Now open the *main.rs* file you just created and enter the code in Listing 1-1. + +
+Filename: main.rs + +````rust +fn main() { + println!("Hello, world!"); +} +```` + +
Listing 1-1: A program that prints Hello, world!
+
+ +Save the file and go back to your terminal window"# + ); +} + +#[test] +fn no_filename() { + let result = rewrite_listing( + r#"This is the opening. + ++ +```rust +fn main() {} +``` + + + +This is the closing."#, + Mode::Default, + ); + + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + r#"This is the opening. + +
+ +````rust +fn main() {} +```` + +
Listing 1-1: This is the caption
+
+ +This is the closing."# + ); +} + +#[cfg(test)] +mod config; From 4d357442af2f4e05d5d0afbe6b1e8003c0638e04 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 12 Jul 2024 15:41:11 -0600 Subject: [PATCH 367/720] infra: support non-numbered and no-caption listings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When I originally built this, I thought *all* “listings” had numbers and captions, but it turns out that there are a number of places in the book where having the overall `figure`-driven output, i.e. with a file name, is desirable even though there is no number or caption. A potential enhancement later would be to require a caption if a number is present, since that seems to be what the book actually does. --- packages/mdbook-trpl-listing/src/lib.rs | 108 +++++++++--------- packages/mdbook-trpl-listing/src/tests/mod.rs | 27 +++++ 2 files changed, 79 insertions(+), 56 deletions(-) diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index 8f203645bc..3d8eabcf49 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -155,7 +155,7 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { match ev { Event::Html(tag) => { if tag.starts_with(" Result { }) .build(); - match listing_result { - Ok(listing) => { - let opening_event = match mode { - Mode::Default => { - let opening_html = - listing.opening_html(); - Event::Html(opening_html.into()) - } - Mode::Simple => { - let opening_text = - listing.opening_text(); - Event::Text(opening_text.into()) - } - }; - - state.current_listing = Some(listing); - state.events.push(Ok(opening_event)); + let opening_event = match mode { + Mode::Default => { + let opening_html = listing.opening_html(); + Event::Html(opening_html.into()) } - Err(reason) => state.events.push(Err(reason)), - } + Mode::Simple => { + let opening_text = listing.opening_text(); + Event::Text(opening_text.into()) + } + }; + + state.current_listing = Some(listing); + state.events.push(Ok(opening_event)); } else if tag.starts_with("
") { let trailing = if !tag.ends_with('>') { tag.replace("
", "") @@ -259,8 +252,8 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { #[derive(Debug)] struct Listing { - number: String, - caption: String, + number: Option, + caption: Option, file_name: Option, } @@ -277,12 +270,21 @@ impl Listing { } fn closing_html(&self, trailing: &str) -> String { - format!( - r#"
Listing {number}: {caption}
-
{trailing}"#, - number = self.number, - caption = self.caption - ) + match (&self.number, &self.caption) { + (Some(number), Some(caption)) => format!( + r#"
Listing {number}: {caption}
+
{trailing}"# + ), + (None, Some(caption)) => format!( + r#"
{caption}
+{trailing}"# + ), + (Some(number), None) => format!( + r#"
Listing {number}
+{trailing}"# + ), + (None, None) => format!("{trailing}"), + } } fn opening_text(&self) -> String { @@ -293,11 +295,14 @@ impl Listing { } fn closing_text(&self, trailing: &str) -> String { - format!( - "Listing {number}: {caption}{trailing}", - number = self.number, - caption = self.caption, - ) + match (&self.number, &self.caption) { + (Some(number), Some(caption)) => { + format!("Listing {number}: {caption}{trailing}") + } + (None, Some(caption)) => format!("{caption}{trailing}"), + (Some(number), None) => format!("Listing {number}{trailing}"), + (None, None) => trailing.into(), + } } } @@ -331,32 +336,23 @@ impl<'a> ListingBuilder<'a> { self } - fn build(self) -> Result { - let number = self - .number - .ok_or_else(|| String::from("Missing number"))? - .to_owned(); - - let caption = self - .caption - .map(|caption_source| { - let events = new_cmark_parser(caption_source, true); - let mut buf = String::with_capacity(caption_source.len() * 2); - html::push_html(&mut buf, events); - - // This is not particularly principled, but since the only - // place it is used is here, for caption source handling, it - // is “fine”. - buf.replace("

", "").replace("

", "").replace('\n', "") - }) - .ok_or_else(|| String::from("Missing caption"))? - .to_owned(); + fn build(self) -> Listing { + let caption = self.caption.map(|caption_source| { + let events = new_cmark_parser(caption_source, true); + let mut buf = String::with_capacity(caption_source.len() * 2); + html::push_html(&mut buf, events); - Ok(Listing { - number, + // This is not particularly principled, but since the only + // place it is used is here, for caption source handling, it + // is “fine”. + buf.replace("

", "").replace("

", "").replace('\n', "") + }); + + Listing { + number: self.number.map(String::from), caption, file_name: self.file_name.map(String::from), - }) + } } } diff --git a/packages/mdbook-trpl-listing/src/tests/mod.rs b/packages/mdbook-trpl-listing/src/tests/mod.rs index 1e1240e855..71407581b7 100644 --- a/packages/mdbook-trpl-listing/src/tests/mod.rs +++ b/packages/mdbook-trpl-listing/src/tests/mod.rs @@ -131,5 +131,32 @@ This is the closing."# ); } +#[test] +fn without_number() { + let result = rewrite_listing( + r#"+ +```rust +fn main() {} +``` + +"#, + Mode::Default, + ); + + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + r#"
+Filename: src/main.rs + +````rust +fn main() {} +```` + +
"# + ); +} + #[cfg(test)] mod config; From 7bd97c9688e3fa8c8f82334d7536c0f8f4215c5a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 15 Jul 2024 09:42:53 -0600 Subject: [PATCH 368/720] infra: support HTML in listing caption body XML does not allow more XML to appear in the body of an attribute, but this is not XML! It is *HTML*, since Markdown allows embedding HTML, and HTML *does* allow embedding further `<` and `>` characters within the attributes on the element. Accordingly, switch to `html_parser`, add a test covering this behavior, and update `ListingBuilder` to take the number, caption, and file name types as owned rather than as references, since that is what `html_parser` supplies. Additionally, refactor the guts a bit so it is easy to see the overall logic of `rewrite_listing`, with the gnarly bits around opening and closing the rewritten listings pushed into a method on the `State` struct, itself renamed to `ListingState` and its `current_listing` field renamed to `current`. This also clarifies the semantics of each part of the rewrite operation, e.g. `ListingState::open_listing` is fallible; `ListingState::close_listing` is not. --- packages/mdbook-trpl-listing/Cargo.lock | 23 +- packages/mdbook-trpl-listing/Cargo.toml | 2 +- packages/mdbook-trpl-listing/src/lib.rs | 203 ++++++++++-------- packages/mdbook-trpl-listing/src/tests/mod.rs | 30 +++ 4 files changed, 163 insertions(+), 95 deletions(-) diff --git a/packages/mdbook-trpl-listing/Cargo.lock b/packages/mdbook-trpl-listing/Cargo.lock index dba6f20985..c61da8a7f4 100644 --- a/packages/mdbook-trpl-listing/Cargo.lock +++ b/packages/mdbook-trpl-listing/Cargo.lock @@ -362,6 +362,21 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "html_parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f56db07b6612644f6f7719f8ef944f75fff9d6378fdf3d316fd32194184abd" +dependencies = [ + "doc-comment", + "pest", + "pest_derive", + "serde", + "serde_derive", + "serde_json", + "thiserror", +] + [[package]] name = "humantime" version = "2.1.0" @@ -482,13 +497,13 @@ version = "0.1.0" dependencies = [ "assert_cmd", "clap", + "html_parser", "mdbook", "pulldown-cmark", "pulldown-cmark-to-cmark", "serde_json", "thiserror", "toml 0.8.13", - "xmlparser", ] [[package]] @@ -1162,9 +1177,3 @@ checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" dependencies = [ "memchr", ] - -[[package]] -name = "xmlparser" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" diff --git a/packages/mdbook-trpl-listing/Cargo.toml b/packages/mdbook-trpl-listing/Cargo.toml index 4cf009b3f2..20bfe347db 100644 --- a/packages/mdbook-trpl-listing/Cargo.toml +++ b/packages/mdbook-trpl-listing/Cargo.toml @@ -7,13 +7,13 @@ edition = "2021" [dependencies] clap = { version = "4", features = ["derive"] } +html_parser = "0.7.0" mdbook = { version = "0.4", default-features = false } # only need the library pulldown-cmark = { version = "0.10", features = ["simd"] } pulldown-cmark-to-cmark = "13" serde_json = "1" thiserror = "1.0.60" toml = "0.8.12" -xmlparser = "0.13.6" [dev-dependencies] assert_cmd = "2" diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index 3d8eabcf49..a1fbfb597e 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -1,3 +1,4 @@ +use html_parser::Dom; use mdbook::{ book::Book, errors::Result, @@ -7,7 +8,6 @@ use mdbook::{ }; use pulldown_cmark::{html, Event}; use pulldown_cmark_to_cmark::cmark; -use xmlparser::{Token, Tokenizer}; /// A preprocessor for rendering listings more elegantly. /// @@ -139,97 +139,29 @@ impl TryFrom<&str> for Mode { } fn rewrite_listing(src: &str, mode: Mode) -> Result { - let parser = new_cmark_parser(src, true); - - struct State<'e> { - current_listing: Option, - events: Vec, String>>, - } - - let final_state = parser.fold( - State { - current_listing: None, + let final_state = new_cmark_parser(src, true).try_fold( + ListingState { + current: None, events: vec![], }, |mut state, ev| { match ev { Event::Html(tag) => { if tag.starts_with(" { - match local.as_str() { - "number" => builder - .with_number(value.as_str()), - "caption" => builder - .with_caption(value.as_str()), - "file-name" => builder - .with_file_name(value.as_str()), - _ => builder, // TODO: error on extra attrs? - } - } - _ => builder, - } - }) - .build(); - - let opening_event = match mode { - Mode::Default => { - let opening_html = listing.opening_html(); - Event::Html(opening_html.into()) - } - Mode::Simple => { - let opening_text = listing.opening_text(); - Event::Text(opening_text.into()) - } - }; - - state.current_listing = Some(listing); - state.events.push(Ok(opening_event)); + state.open_listing(tag, mode)?; } else if tag.starts_with("") { - let trailing = if !tag.ends_with('>') { - tag.replace("
", "") - } else { - String::from("") - }; - - match state.current_listing { - Some(listing) => { - let closing_event = match mode { - Mode::Default => { - let closing_html = - listing.closing_html(&trailing); - Event::Html(closing_html.into()) - } - Mode::Simple => { - let closing_text = - listing.closing_text(&trailing); - Event::Text(closing_text.into()) - } - }; - - state.current_listing = None; - state.events.push(Ok(closing_event)); - } - None => state.events.push(Err(String::from( - "Closing `
` without opening tag.", - ))), - } + state.close_listing(tag, mode); } else { state.events.push(Ok(Event::Html(tag))); } } ev => state.events.push(Ok(ev)), }; - state + Ok::(state) }, - ); + )?; - if final_state.current_listing.is_some() { + if final_state.current.is_some() { return Err("Unclosed listing".into()); } @@ -250,6 +182,103 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { Ok(buf) } +struct ListingState<'e> { + current: Option, + events: Vec, String>>, +} + +impl<'e> ListingState<'e> { + fn open_listing( + &mut self, + tag: pulldown_cmark::CowStr, + mode: Mode, + ) -> Result<(), String> { + // We do not *keep* the version constructed here, just temporarily + // construct it so the HTML parser, which expects properly closed tags + // to parse it as a *tag* rather than a *weird text node*, which accept + // it and provide a useful view of it. + let to_parse = tag.to_owned().to_string() + ""; + let listing = Dom::parse(&to_parse) + .map_err(|e| e.to_string())? + .children + .into_iter() + .filter_map(|node| match node { + html_parser::Node::Element(element) => Some(element.attributes), + html_parser::Node::Text(_) | html_parser::Node::Comment(_) => { + None + } + }) + .flatten() + .try_fold(ListingBuilder::new(), |builder, (key, maybe_value)| { + match (key.as_str(), maybe_value) { + ("number", Some(value)) => Ok(builder.with_number(value)), + ("number", None) => { + Err(String::from("number attribute without value")) + } + ("caption", Some(value)) => Ok(builder.with_caption(value)), + ("caption", None) => { + Err(String::from("caption attribute without value")) + } + ("file-name", Some(value)) => { + Ok(builder.with_file_name(value)) + } + ("file-name", None) => { + Err(String::from("file-name attribute without value")) + } + + _ => Ok(builder), // TODO: error on extra attrs? + } + })? + .build(); + + let opening_event = match mode { + Mode::Default => { + let opening_html = listing.opening_html(); + Event::Html(opening_html.into()) + } + Mode::Simple => { + let opening_text = listing.opening_text(); + Event::Text(opening_text.into()) + } + }; + + self.current = Some(listing); + self.events.push(Ok(opening_event)); + Ok(()) + } + + fn close_listing(&mut self, tag: pulldown_cmark::CowStr, mode: Mode) { + let trailing = if !tag.ends_with('>') { + tag.replace("", "") + } else { + String::from("") + }; + + match &self.current { + Some(listing) => { + let closing_event = match mode { + Mode::Default => { + let closing_html = listing.closing_html(&trailing); + Event::Html(closing_html.into()) + } + Mode::Simple => { + let closing_text = listing.closing_text(&trailing); + Event::Text(closing_text.into()) + } + }; + + self.current = None; + self.events.push(Ok(closing_event)); + } + None => { + self.events.push(Err(String::from( + "Closing `` without opening tag.", + ))); + } + } + } +} + #[derive(Debug)] struct Listing { number: Option, @@ -306,14 +335,14 @@ impl Listing { } } -struct ListingBuilder<'a> { - number: Option<&'a str>, - caption: Option<&'a str>, - file_name: Option<&'a str>, +struct ListingBuilder { + number: Option, + caption: Option, + file_name: Option, } -impl<'a> ListingBuilder<'a> { - fn new() -> ListingBuilder<'a> { +impl ListingBuilder { + fn new() -> ListingBuilder { ListingBuilder { number: None, caption: None, @@ -321,24 +350,24 @@ impl<'a> ListingBuilder<'a> { } } - fn with_number(mut self, value: &'a str) -> Self { + fn with_number(mut self, value: String) -> Self { self.number = Some(value); self } - fn with_caption(mut self, value: &'a str) -> Self { + fn with_caption(mut self, value: String) -> Self { self.caption = Some(value); self } - fn with_file_name(mut self, value: &'a str) -> Self { + fn with_file_name(mut self, value: String) -> Self { self.file_name = Some(value); self } fn build(self) -> Listing { let caption = self.caption.map(|caption_source| { - let events = new_cmark_parser(caption_source, true); + let events = new_cmark_parser(&caption_source, true); let mut buf = String::with_capacity(caption_source.len() * 2); html::push_html(&mut buf, events); diff --git a/packages/mdbook-trpl-listing/src/tests/mod.rs b/packages/mdbook-trpl-listing/src/tests/mod.rs index 71407581b7..5ae5c8e964 100644 --- a/packages/mdbook-trpl-listing/src/tests/mod.rs +++ b/packages/mdbook-trpl-listing/src/tests/mod.rs @@ -56,6 +56,36 @@ Listing 1-2: A write-up which might include inline Markdown like ); } +#[test] +fn listing_with_embedded_angle_brackets() { + let result = rewrite_listing( + r#"+ +```rust +fn get_a_box_of(t: T) -> Box { + Box::new(T) +} +``` + +"#, + Mode::Default, + ); + + assert_eq!( + &result.unwrap(), + r#"
+ +````rust +fn get_a_box_of(t: T) -> Box { + Box::new(T) +} +```` + +
Listing 34-5: This has a Box<T> in it.
+
"# + ); +} + #[test] fn actual_listing() { let result = rewrite_listing( From c3c88e4b4f8e17ca5233535dd32b466a9c50c7a7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 15 Jul 2024 17:28:58 -0600 Subject: [PATCH 369/720] =?UTF-8?q?Ch.=2017=20=C2=A703:=20restore=20accide?= =?UTF-8?q?ntally-removed=20Listing=2017-14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ch17-async-await/listing-17-14/Cargo.lock | 292 ++++++++++++++++++ .../ch17-async-await/listing-17-14/Cargo.toml | 9 + .../listing-17-14/src/main.rs | 48 +++ src/ch17-03-more-futures.md | 3 +- 4 files changed, 350 insertions(+), 2 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-14/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-14/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-14/src/main.rs diff --git a/listings/ch17-async-await/listing-17-14/Cargo.lock b/listings/ch17-async-await/listing-17-14/Cargo.lock new file mode 100644 index 0000000000..2e0f3ebedb --- /dev/null +++ b/listings/ch17-async-await/listing-17-14/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-14/Cargo.toml b/listings/ch17-async-await/listing-17-14/Cargo.toml new file mode 100644 index 0000000000..349041d3eb --- /dev/null +++ b/listings/ch17-async-await/listing-17-14/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs new file mode 100644 index 0000000000..097114bb73 --- /dev/null +++ b/listings/ch17-async-await/listing-17-14/src/main.rs @@ -0,0 +1,48 @@ +use std::time::Duration; + +fn main() { + trpl::block_on(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + }; + + // ANCHOR: here + let futures = vec![tx1_fut, rx_fut, tx_fut]; + + trpl::join_all(futures).await; + // ANCHOR_END: here + }); +} diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 6475a268fa..3ae03f25ef 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -25,7 +25,7 @@ To check all the futures in some collection, we will need to iterate over and join on *all* of them. The `trpl::join_all` function accepts any type which implements the `Iterator` trait, which we learned about back in Chapter 13, so it seems like just the ticket. Let’s try putting our futures in a vector, and -replace `join3` with `join_all`. +replace `join!` with `join_all`. @@ -39,7 +39,6 @@ Unfortunately, this does not compile. Instead, we get this error: -This crate currently requires at least Rust 1.77. +This crate currently requires at least Rust 1.79. diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 9336a69a19..e096d9d2cd 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -1,4 +1,6 @@ -//! A support crate for _The Rust Programming Language_. +//! A support crate for [_The Rust Programming Language_][trpl]. +//! +//! [trpl]: https://doc.rust-lang.org/book //! //! This crate mostly just re-exports items from *other* crates. It exists for //! two main reasons: From 58fff3cc4864aaa50b24726ae2f5c7b23505aadb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 16 Jul 2024 16:57:45 -0600 Subject: [PATCH 371/720] =?UTF-8?q?Ch.=2017=C2=A703:=20fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit htypes! What are htypes? No one will ever know. Co-authored-by: James Munns --- src/ch17-03-more-futures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 3ae03f25ef..afc00eb3e8 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -421,7 +421,7 @@ future for `b` implements `Future`, and the anonymous future for We can use `trpl::join!` to await them, because it allows you to pass in -multiple future types and produces a tuple of those htypes. We *cannot* use +multiple future types and produces a tuple of those types. We *cannot* use `trpl::join_all`, because it requires the futures passed in all to have the same type. (Remember, that error is what got us started on this adventure with `Pin`!) From 130e6d09a41d6c112348fd7a3df9f78b078c13c6 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 16 Jul 2024 08:12:22 -0600 Subject: [PATCH 372/720] Ch. 17: correct wrapping for a `Note` --- src/ch17-00-async-await.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index bc1a301a6c..52fe3f8468 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -72,10 +72,10 @@ time. Many operating system APIs for interacting with network sockets are program when they are called until they return. > Note: This is how *most* function calls work, if you think about it! However, -we normally reserve the term “blocking” for function calls which interact with -files, network sockets, or other resources on the computer, because those are -the places where an individual program would benefit from the operation being -*non*-blocking. +> we normally reserve the term “blocking” for function calls which interact with +> files, network sockets, or other resources on the computer, because those are +> the places where an individual program would benefit from the operation being +> *non*-blocking. We could use threads to avoid blocking while downloading files, by using a dedicated thread. But it would be nicer if the call were not blocking in the From 8d8d8f4be24d0f389990cc38bd260398b4d3dd2b Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 12:44:56 +0200 Subject: [PATCH 373/720] Converted Listing 6-1 to `` --- src/ch06-01-defining-an-enum.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch06-01-defining-an-enum.md b/src/ch06-01-defining-an-enum.md index eacd091bd4..30c62b7120 100644 --- a/src/ch06-01-defining-an-enum.md +++ b/src/ch06-01-defining-an-enum.md @@ -59,12 +59,13 @@ only know what *kind* it is. Given that you just learned about structs in Chapter 5, you might be tempted to tackle this problem with structs as shown in Listing 6-1. ++ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs:here}} ``` -Listing 6-1: Storing the data and `IpAddrKind` variant of -an IP address using a `struct` + Here, we’ve defined a struct `IpAddr` that has two fields: a `kind` field that is of type `IpAddrKind` (the enum we defined previously) and an `address` field From e7f864d64e58f86722fa1feda8d4ef351967e049 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 12:45:45 +0200 Subject: [PATCH 374/720] Converted listing 6-2 to `` --- src/ch06-01-defining-an-enum.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch06-01-defining-an-enum.md b/src/ch06-01-defining-an-enum.md index 30c62b7120..567832f6da 100644 --- a/src/ch06-01-defining-an-enum.md +++ b/src/ch06-01-defining-an-enum.md @@ -141,12 +141,13 @@ more about bringing types into scope in Chapter 7. Let’s look at another example of an enum in Listing 6-2: this one has a wide variety of types embedded in its variants. ++ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs:here}} ``` -Listing 6-2: A `Message` enum whose variants each store -different amounts and types of values + This enum has four variants with different types: From 2bb1771b35028b52ce664cfba3521d874592d0da Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 12:50:05 +0200 Subject: [PATCH 375/720] Converted Listing 6-3 to `` --- src/ch06-02-match.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index 6a510df402..07b9025a05 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -22,12 +22,13 @@ function that takes an unknown US coin and, in a similar way as the counting machine, determines which coin it is and returns its value in cents, as shown in Listing 6-3. ++ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs:here}} ``` -Listing 6-3: An enum and a `match` expression that has -the variants of the enum as its patterns + Let’s break down the `match` in the `value_in_cents` function. First we list the `match` keyword followed by an expression, which in this case is the value From d52fca9300eeb0340e269c379cb8a250b2e7ad2b Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 12:54:20 +0200 Subject: [PATCH 376/720] Converted Listing 6-4 to `` --- src/ch06-02-match.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index 07b9025a05..80d60460c1 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -76,12 +76,13 @@ designs, so only quarters have this extra value. We can add this information to our `enum` by changing the `Quarter` variant to include a `UsState` value stored inside it, which we’ve done in Listing 6-4. ++ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs:here}} ``` -Listing 6-4: A `Coin` enum in which the `Quarter` variant -also holds a `UsState` value + Let’s imagine that a friend is trying to collect all 50 state quarters. While we sort our loose change by coin type, we’ll also call out the name of the From 4c461f6fb99538311ea7c52e5606cacc9c70f515 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 12:57:41 +0200 Subject: [PATCH 377/720] Fixed issue with chapter 6 ``s My bad, when I copy and pasted the captions from the `` into the ``, I failed to realize that my text editor copied over the line numbers into the strings. Removed them, should be all good now. --- src/ch06-01-defining-an-enum.md | 4 ++-- src/ch06-02-match.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch06-01-defining-an-enum.md b/src/ch06-01-defining-an-enum.md index 567832f6da..3462f38917 100644 --- a/src/ch06-01-defining-an-enum.md +++ b/src/ch06-01-defining-an-enum.md @@ -59,7 +59,7 @@ only know what *kind* it is. Given that you just learned about structs in Chapter 5, you might be tempted to tackle this problem with structs as shown in Listing 6-1. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs:here}} @@ -141,7 +141,7 @@ more about bringing types into scope in Chapter 7. Let’s look at another example of an enum in Listing 6-2: this one has a wide variety of types embedded in its variants. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs:here}} diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index 80d60460c1..e53c830730 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -22,7 +22,7 @@ function that takes an unknown US coin and, in a similar way as the counting machine, determines which coin it is and returns its value in cents, as shown in Listing 6-3. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs:here}} From 256be8e4f125c7e4c6b98a03483eac4043b5efa7 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:01:59 +0200 Subject: [PATCH 378/720] Converted Listing 6-5 into `` --- src/ch06-02-match.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index e53c830730..2bb8929798 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -121,12 +121,13 @@ operations. This function is very easy to write, thanks to `match`, and will look like Listing 6-5. ++ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-05/src/main.rs:here}} ``` -Listing 6-5: A function that uses a `match` expression on -an `Option` + Let’s examine the first execution of `plus_one` in more detail. When we call `plus_one(five)`, the variable `x` in the body of `plus_one` will have the From 0b339ad8387770af853a5ec28263900e2bcc5e9f Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:04:34 +0200 Subject: [PATCH 379/720] Converted Listing 6-6 to `` --- src/ch06-03-if-let.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch06-03-if-let.md b/src/ch06-03-if-let.md index c9bfbf3c7f..fee6b2caf3 100644 --- a/src/ch06-03-if-let.md +++ b/src/ch06-03-if-let.md @@ -6,12 +6,13 @@ program in Listing 6-6 that matches on an `Option` value in the `config_max` variable but only wants to execute code if the value is the `Some` variant. ++ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs:here}} ``` -Listing 6-6: A `match` that only cares about executing -code when the value is `Some` + If the value is `Some`, we print out the value in the `Some` variant by binding the value to the variable `max` in the pattern. We don’t want to do anything From b1bb69fe5d822f637b4a357d49e92affd6ef1002 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 10:15:56 +0200 Subject: [PATCH 380/720] Chapter 6 - Wrap all ``s to comply with the virtual 80 character limit (READ DESC.) I'm unsure whether wrapping the text may cause the listing text to be wrapped too as the newlines are found within quotation marks. If it causes issues, feel free to revert this commit. Another odd thing is that my editor uncolored the closing `` tag when I split the lines. Maybe the newline characters need to be escaped with a backslash? --- src/ch06-01-defining-an-enum.md | 6 ++++-- src/ch06-02-match.md | 9 ++++++--- src/ch06-03-if-let.md | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ch06-01-defining-an-enum.md b/src/ch06-01-defining-an-enum.md index 3462f38917..04fb327164 100644 --- a/src/ch06-01-defining-an-enum.md +++ b/src/ch06-01-defining-an-enum.md @@ -59,7 +59,8 @@ only know what *kind* it is. Given that you just learned about structs in Chapter 5, you might be tempted to tackle this problem with structs as shown in Listing 6-1. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs:here}} @@ -141,7 +142,8 @@ more about bringing types into scope in Chapter 7. Let’s look at another example of an enum in Listing 6-2: this one has a wide variety of types embedded in its variants. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs:here}} diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index 2bb8929798..9b5ec3a03b 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -22,7 +22,8 @@ function that takes an unknown US coin and, in a similar way as the counting machine, determines which coin it is and returns its value in cents, as shown in Listing 6-3. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs:here}} @@ -76,7 +77,8 @@ designs, so only quarters have this extra value. We can add this information to our `enum` by changing the `Quarter` variant to include a `UsState` value stored inside it, which we’ve done in Listing 6-4. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs:here}} @@ -121,7 +123,8 @@ operations. This function is very easy to write, thanks to `match`, and will look like Listing 6-5. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-05/src/main.rs:here}} diff --git a/src/ch06-03-if-let.md b/src/ch06-03-if-let.md index fee6b2caf3..37bed8cf2d 100644 --- a/src/ch06-03-if-let.md +++ b/src/ch06-03-if-let.md @@ -6,7 +6,8 @@ program in Listing 6-6 that matches on an `Option` value in the `config_max` variable but only wants to execute code if the value is the `Some` variant. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs:here}} From 7cd0748d8d3771e2f1701d5130cd45642fd516ef Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:09:46 +0200 Subject: [PATCH 381/720] Converted Listing 7-1 into `` --- src/ch07-02-defining-modules-to-control-scope-and-privacy.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index 4a25c161be..02fb887591 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -114,14 +114,13 @@ restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to define some modules and function signatures; this code is the front of house section. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-01/src/lib.rs}} ``` -Listing 7-1: A `front_of_house` module containing other -modules that then contain functions + We define a module with the `mod` keyword followed by the name of the module (in this case, `front_of_house`). The body of the module then goes inside curly From 3d32026903940dda2096109f885cb446bcc2e390 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:11:50 +0200 Subject: [PATCH 382/720] Converted Listing 7-2 into `` --- src/ch07-02-defining-modules-to-control-scope-and-privacy.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index 02fb887591..0a711f9e6e 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -142,6 +142,8 @@ known as the *module tree*. Listing 7-2 shows the module tree for the structure in Listing 7-1. ++ ```text crate └── front_of_house @@ -154,8 +156,7 @@ crate └── take_payment ``` -Listing 7-2: The module tree for the code in Listing -7-1 + This tree shows how some of the modules nest inside other modules; for example, `hosting` nests inside `front_of_house`. The tree also shows that some modules From 12c4a764834d0169e8492e5ddd959acd03242985 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:15:03 +0200 Subject: [PATCH 383/720] Converted Listing 7-3 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 4201ea3db2..39bd541ce1 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -29,14 +29,13 @@ The `eat_at_restaurant` function is part of our library crate’s public API, so we mark it with the `pub` keyword. In the [“Exposing Paths with the `pub` Keyword”][pub] section, we’ll go into more detail about `pub`. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-03/src/lib.rs}} ``` -Listing 7-3: Calling the `add_to_waitlist` function using -absolute and relative paths + The first time we call the `add_to_waitlist` function in `eat_at_restaurant`, we use an absolute path. The `add_to_waitlist` function is defined in the same From 4513d38611fa24420ec853ceea98b94bcfaf5236 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:17:18 +0200 Subject: [PATCH 384/720] Converted Listing 7-4 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 39bd541ce1..bdb9911db5 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -69,12 +69,13 @@ each other. Let’s try to compile Listing 7-3 and find out why it won’t compile yet! The errors we get are shown in Listing 7-4. ++ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-03/output.txt}} ``` -Listing 7-4: Compiler errors from building the code in -Listing 7-3 + The error messages say that module `hosting` is private. In other words, we have the correct paths for the `hosting` module and the `add_to_waitlist` From f79de2535d494dbb068c05e8f9b5465ddcccee3f Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:23:06 +0200 Subject: [PATCH 385/720] Converted Listing 7-5 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index bdb9911db5..7e3faeda8e 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -105,14 +105,13 @@ private. We want the `eat_at_restaurant` function in the parent module to have access to the `add_to_waitlist` function in the child module, so we mark the `hosting` module with the `pub` keyword, as shown in Listing 7-5. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-05/src/lib.rs}} ``` -Listing 7-5: Declaring the `hosting` module as `pub` to -use it from `eat_at_restaurant` + Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. From 1cd2240da1142f6bb25d9e32743303ecf0c60d02 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:28:46 +0200 Subject: [PATCH 386/720] Converted Listing 7-6 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 7e3faeda8e..9b92dfae31 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -116,12 +116,13 @@ access to the `add_to_waitlist` function in the child module, so we mark the Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. ++ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-05/output.txt}} ``` -Listing 7-6: Compiler errors from building the code in -Listing 7-5 + What happened? Adding the `pub` keyword in front of `mod hosting` makes the module public. With this change, if we can access `front_of_house`, we can From e29723539925a93563347c93cf2093142905849e Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:31:47 +0200 Subject: [PATCH 387/720] Converted Listing 7-7 to `` --- ...-03-paths-for-referring-to-an-item-in-the-module-tree.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 9b92dfae31..1e791d22d6 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -140,15 +140,13 @@ modules. Let’s also make the `add_to_waitlist` function public by adding the `pub` keyword before its definition, as in Listing 7-7. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs}} ``` -Listing 7-7: Adding the `pub` keyword to `mod hosting` -and `fn add_to_waitlist` lets us call the function from -`eat_at_restaurant` + Now the code will compile! To see why adding the `pub` keyword lets us use these paths in `eat_at_restaurant` with respect to the privacy rules, let’s look From 8f5e623c99395312b766148f9e74e2691d1c09fd Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:33:53 +0200 Subject: [PATCH 388/720] Converted Listing 7-8 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 1e791d22d6..47fd9a0d11 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -214,14 +214,13 @@ function `fix_incorrect_order` defined in the `back_of_house` module calls the function `deliver_order` defined in the parent module by specifying the path to `deliver_order`, starting with `super`. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-08/src/lib.rs}} ``` -Listing 7-8: Calling a function using a relative path -starting with `super` + The `fix_incorrect_order` function is in the `back_of_house` module, so we can use `super` to go to the parent module of `back_of_house`, which in this case From 2a52d9c7a7442d1881ce7b32fed3479e0a7da2c0 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:36:11 +0200 Subject: [PATCH 389/720] Convert Listing 7-9 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 47fd9a0d11..723372386c 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -244,14 +244,13 @@ comes with a meal, but the chef decides which fruit accompanies the meal based on what’s in season and in stock. The available fruit changes quickly, so customers can’t choose the fruit or even see which fruit they’ll get. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs}} ``` -Listing 7-9: A struct with some public fields and some -private fields + Because the `toast` field in the `back_of_house::Breakfast` struct is public, in `eat_at_restaurant` we can write and read to the `toast` field using dot From cc71c024eee1a7f0a93f723c88f9fda4d9e43f03 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:39:17 +0200 Subject: [PATCH 390/720] Converted Listing 7-10 to `` --- ...7-03-paths-for-referring-to-an-item-in-the-module-tree.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 723372386c..da07d9fd83 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -268,14 +268,13 @@ have such a function, we couldn’t create an instance of `Breakfast` in In contrast, if we make an enum public, all of its variants are then public. We only need the `pub` before the `enum` keyword, as shown in Listing 7-10. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-10/src/lib.rs}} ``` -Listing 7-10: Designating an enum as public makes all its -variants public + Because we made the `Appetizer` enum public, we can use the `Soup` and `Salad` variants in `eat_at_restaurant`. From db0262caaa29e23fed71acad17beaf6f0f788aab Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 13:41:25 +0200 Subject: [PATCH 391/720] Converted Listing 7-11 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index defa950c6b..0a77bb480d 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -12,14 +12,13 @@ scope of the `eat_at_restaurant` function so we only have to specify `hosting::add_to_waitlist` to call the `add_to_waitlist` function in `eat_at_restaurant`. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-11/src/lib.rs}} ``` -Listing 7-11: Bringing a module into scope with -`use` + Adding `use` and a path in a scope is similar to creating a symbolic link in the filesystem. By adding `use crate::front_of_house::hosting` in the crate From c1ba6757732182f93e4a454430dcb5a813003200 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:03:53 +0200 Subject: [PATCH 392/720] Converted Listing 7-12 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 0a77bb480d..77940dcf77 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -31,14 +31,13 @@ Note that `use` only creates the shortcut for the particular scope in which the child module named `customer`, which is then a different scope than the `use` statement, so the function body won’t compile. -Filename: src/lib.rs + ```rust,noplayground,test_harness,does_not_compile,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-12/src/lib.rs}} ``` -Listing 7-12: A `use` statement only applies in the scope -it’s in + The compiler error shows that the shortcut no longer applies within the `customer` module: From 6178940e1881023f82099dde9e83b968c1b12d1c Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:10:09 +0200 Subject: [PATCH 393/720] Convert Listing 7-13 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 77940dcf77..8951835035 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -58,14 +58,13 @@ crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in `eat_at_restaurant`, rather than specifying the `use` path all the way out to the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-13/src/lib.rs}} ``` -Listing 7-13: Bringing the `add_to_waitlist` function -into scope with `use`, which is unidiomatic + Although both Listing 7-11 and Listing 7-13 accomplish the same task, Listing 7-11 is the idiomatic way to bring a function into scope with `use`. Bringing From 9996cae5f591244c65f726a5aa15e73dc991cbc1 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:12:34 +0200 Subject: [PATCH 394/720] Convert Listing 7-14 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 8951835035..5b1b05cf91 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -79,14 +79,13 @@ it’s idiomatic to specify the full path. Listing 7-14 shows the idiomatic way to bring the standard library’s `HashMap` struct into the scope of a binary crate. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-14/src/main.rs}} ``` -Listing 7-14: Bringing `HashMap` into scope in an -idiomatic way + There’s no strong reason behind this idiom: it’s just the convention that has emerged, and folks have gotten used to reading and writing Rust code this way. From 4f860403624a14a912b6846a8baa2515c3107397 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:16:20 +0200 Subject: [PATCH 395/720] Convert Listing 7-15 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 5b1b05cf91..a32ee60f90 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -95,14 +95,13 @@ into scope with `use` statements, because Rust doesn’t allow that. Listing 7-1 shows how to bring two `Result` types into scope that have the same name but different parent modules, and how to refer to them. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-15/src/lib.rs:here}} ``` -Listing 7-15: Bringing two types with the same name into -the same scope requires using their parent modules. + As you can see, using the parent modules distinguishes the two `Result` types. If instead we specified `use std::fmt::Result` and `use std::io::Result`, we’d From 744d4df1bf8323faebe3743076ae3dad53a8ec9a Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:27:23 +0200 Subject: [PATCH 396/720] Convert Listing 7-16 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index a32ee60f90..01a8019d47 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -115,14 +115,13 @@ into the same scope with `use`: after the path, we can specify `as` and a new local name, or *alias*, for the type. Listing 7-16 shows another way to write the code in Listing 7-15 by renaming one of the two `Result` types using `as`. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-16/src/lib.rs:here}} ``` -Listing 7-16: Renaming a type when it’s brought into -scope with the `as` keyword + In the second `use` statement, we chose the new name `IoResult` for the `std::io::Result` type, which won’t conflict with the `Result` from `std::fmt` From cd5a840e50e243e70b9d7033cbeb0514986945c7 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:29:24 +0200 Subject: [PATCH 397/720] Convert Listing 7-17 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 01a8019d47..e0122e2b80 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -140,14 +140,13 @@ their scope. Listing 7-17 shows the code in Listing 7-11 with `use` in the root module changed to `pub use`. -Filename: src/lib.rs + ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-17/src/lib.rs}} ``` -Listing 7-17: Making a name available for any code to use -from a new scope with `pub use` + Before this change, external code would have to call the `add_to_waitlist` function by using the path From be0f5f9e0197906bc55ceea01c3eb9e6c907f2bd Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:32:35 +0200 Subject: [PATCH 398/720] Convert unnamed listing to `` I am unsure whether this `` will work properly due to no number being associated with it. @chriskrycho , since you implemented the pre-processor, could you please comment? (Sorry if there is a way that I could have checked this myself, I am unsure how to build the book. I'm just editing in plain-text and crossing my fingers, hope the whole thing doesn't come crumbling down when it's built.) --- src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index e0122e2b80..011ea5bbec 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -179,12 +179,14 @@ added this line to *Cargo.toml*: * ch14-03-cargo-workspaces.md --> -Filename: Cargo.toml + ```toml {{#include ../listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml:9:}} ``` + + Adding `rand` as a dependency in *Cargo.toml* tells Cargo to download the `rand` package and any dependencies from [crates.io](https://crates.io/) and make `rand` available to our project. From fbaee3d031c4d6e49a29fbd27e49f2a391591934 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:38:34 +0200 Subject: [PATCH 399/720] Converted another unnamed listing to `` (chapter 7.4) --- src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 011ea5bbec..bc0fa91880 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -226,12 +226,14 @@ each item on its own line can take up a lot of vertical space in our files. For example, these two `use` statements we had in the guessing game in Listing 2-4 bring items from `std` into scope: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/src/main.rs:here}} ``` + + Instead, we can use nested paths to bring the same items into scope in one line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that From de599ba6e143c06d72311b4bf72bf19982b709d6 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:41:32 +0200 Subject: [PATCH 400/720] Convert Listing 7-18 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index bc0fa91880..867ba0e332 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -239,14 +239,13 @@ line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that differ, as shown in Listing 7-18. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-18/src/main.rs:here}} ``` -Listing 7-18: Specifying a nested path to bring multiple -items with the same prefix into scope + In bigger programs, bringing many items into scope from the same crate or module using nested paths can reduce the number of separate `use` statements From 68a4499c5e3adfc7799cb51185bff5b5b7017676 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:44:27 +0200 Subject: [PATCH 401/720] Convert Listing 7-19 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 867ba0e332..cd0d3b9615 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -256,14 +256,13 @@ two `use` statements that share a subpath. For example, Listing 7-19 shows two `use` statements: one that brings `std::io` into scope and one that brings `std::io::Write` into scope. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-19/src/lib.rs}} ``` -Listing 7-19: Two `use` statements where one is a subpath -of the other + The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in From 3ae0b411494388144a1e5e557d5a6fed9fbefa46 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:46:22 +0200 Subject: [PATCH 402/720] Convert Listing 7-20 to `` --- ...ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index cd0d3b9615..aaf7713e95 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -268,14 +268,13 @@ The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in the nested path, as shown in Listing 7-20. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-20/src/lib.rs}} ``` -Listing 7-20: Combining the paths in Listing 7-19 into -one `use` statement + This line brings `std::io` and `std::io::Write` into scope. From 2c1ebb142eca8346cefe999c6da76bee9feb529d Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:49:13 +0200 Subject: [PATCH 403/720] Convert Listing 7-21 to `` --- src/ch07-05-separating-modules-into-different-files.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index b4cbcdbeda..c4a7805b97 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -16,14 +16,13 @@ the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code shown in Listing 7-21. Note that this won’t compile until we create the *src/front_of_house.rs* file in Listing 7-22. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/lib.rs}} ``` -Listing 7-21: Declaring the `front_of_house` module whose -body will be in *src/front_of_house.rs* + Next, place the code that was in the curly brackets into a new file named *src/front_of_house.rs*, as shown in Listing 7-22. The compiler knows to look From f294ad722ef975bac6d2eb1be836c59882f6f03a Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:51:53 +0200 Subject: [PATCH 404/720] Convert Listing 7-22 to `` --- src/ch07-05-separating-modules-into-different-files.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index c4a7805b97..26ab046fd6 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -29,14 +29,13 @@ Next, place the code that was in the curly brackets into a new file named in this file because it came across the module declaration in the crate root with the name `front_of_house`. -Filename: src/front_of_house.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/front_of_house.rs}} ``` -Listing 7-22: Definitions inside the `front_of_house` -module in *src/front_of_house.rs* + Note that you only need to load a file using a `mod` declaration *once* in your module tree. Once the compiler knows the file is part of the project (and knows From 50ad3cff2a248bbb043a55c9f586b4dc1e536283 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:55:00 +0200 Subject: [PATCH 405/720] Converted unnamed listing to `` (Chapter 7.5, 1/2) --- src/ch07-05-separating-modules-into-different-files.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index 26ab046fd6..f3788598ab 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -54,12 +54,14 @@ named for its ancestors in the module tree, in this case *src/front_of_house*. To start moving `hosting`, we change *src/front_of_house.rs* to contain only the declaration of the `hosting` module: -Filename: src/front_of_house.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/no-listing-02-extracting-hosting/src/front_of_house.rs}} ``` + + Then we create a *src/front_of_house* directory and a *hosting.rs* file to contain the definitions made in the `hosting` module: From 1d1b40c1157fb24ad0a721da44ce3320579e5952 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 16:57:22 +0200 Subject: [PATCH 406/720] Converted unnamed listing to `` (Chapter 7.5, 2/2) --- src/ch07-05-separating-modules-into-different-files.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index f3788598ab..2952e4b156 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -65,12 +65,14 @@ the declaration of the `hosting` module: Then we create a *src/front_of_house* directory and a *hosting.rs* file to contain the definitions made in the `hosting` module: -Filename: src/front_of_house/hosting.rs + ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/no-listing-02-extracting-hosting/src/front_of_house/hosting.rs}} ``` + + If we instead put *hosting.rs* in the *src* directory, the compiler would expect the *hosting.rs* code to be in a `hosting` module declared in the crate root, and not declared as a child of the `front_of_house` module. The From c521d2d4e498ae89174db8349774fe36d8042a1e Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 10:21:11 +0200 Subject: [PATCH 407/720] Chapter 7 - Wrap all ``s to comply with the virtual 80 character limit More infos and concerns can be found in the equivalent commit, in the chapter 6 PR. --- ...ng-modules-to-control-scope-and-privacy.md | 3 +- ...referring-to-an-item-in-the-module-tree.md | 25 +++++++++++----- ...g-paths-into-scope-with-the-use-keyword.md | 30 ++++++++++++------- ...separating-modules-into-different-files.md | 6 ++-- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index 0a711f9e6e..87ed1ee9e9 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -114,7 +114,8 @@ restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to define some modules and function signatures; this code is the front of house section. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-01/src/lib.rs}} diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index da07d9fd83..6931dd314d 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -29,7 +29,8 @@ The `eat_at_restaurant` function is part of our library crate’s public API, so we mark it with the `pub` keyword. In the [“Exposing Paths with the `pub` Keyword”][pub] section, we’ll go into more detail about `pub`. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-03/src/lib.rs}} @@ -69,7 +70,8 @@ each other. Let’s try to compile Listing 7-3 and find out why it won’t compile yet! The errors we get are shown in Listing 7-4. -+ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-03/output.txt}} @@ -105,7 +107,8 @@ private. We want the `eat_at_restaurant` function in the parent module to have access to the `add_to_waitlist` function in the child module, so we mark the `hosting` module with the `pub` keyword, as shown in Listing 7-5. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-05/src/lib.rs}} @@ -116,7 +119,8 @@ access to the `add_to_waitlist` function in the child module, so we mark the Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. -+ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-05/output.txt}} @@ -140,7 +144,9 @@ modules. Let’s also make the `add_to_waitlist` function public by adding the `pub` keyword before its definition, as in Listing 7-7. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs}} @@ -214,7 +220,8 @@ function `fix_incorrect_order` defined in the `back_of_house` module calls the function `deliver_order` defined in the parent module by specifying the path to `deliver_order`, starting with `super`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-08/src/lib.rs}} @@ -244,7 +251,8 @@ comes with a meal, but the chef decides which fruit accompanies the meal based on what’s in season and in stock. The available fruit changes quickly, so customers can’t choose the fruit or even see which fruit they’ll get. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs}} @@ -268,7 +276,8 @@ have such a function, we couldn’t create an instance of `Breakfast` in In contrast, if we make an enum public, all of its variants are then public. We only need the `pub` before the `enum` keyword, as shown in Listing 7-10. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-10/src/lib.rs}} diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index aaf7713e95..3de3ec1ad2 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -12,7 +12,8 @@ scope of the `eat_at_restaurant` function so we only have to specify `hosting::add_to_waitlist` to call the `add_to_waitlist` function in `eat_at_restaurant`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-11/src/lib.rs}} @@ -31,7 +32,8 @@ Note that `use` only creates the shortcut for the particular scope in which the child module named `customer`, which is then a different scope than the `use` statement, so the function body won’t compile. -+ ```rust,noplayground,test_harness,does_not_compile,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-12/src/lib.rs}} @@ -58,7 +60,8 @@ crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in `eat_at_restaurant`, rather than specifying the `use` path all the way out to the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-13/src/lib.rs}} @@ -79,7 +82,8 @@ it’s idiomatic to specify the full path. Listing 7-14 shows the idiomatic way to bring the standard library’s `HashMap` struct into the scope of a binary crate. -+ ```rust {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-14/src/main.rs}} @@ -95,7 +99,8 @@ into scope with `use` statements, because Rust doesn’t allow that. Listing 7-1 shows how to bring two `Result` types into scope that have the same name but different parent modules, and how to refer to them. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-15/src/lib.rs:here}} @@ -115,7 +120,8 @@ into the same scope with `use`: after the path, we can specify `as` and a new local name, or *alias*, for the type. Listing 7-16 shows another way to write the code in Listing 7-15 by renaming one of the two `Result` types using `as`. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-16/src/lib.rs:here}} @@ -140,7 +146,8 @@ their scope. Listing 7-17 shows the code in Listing 7-11 with `use` in the root module changed to `pub use`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-17/src/lib.rs}} @@ -239,7 +246,8 @@ line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that differ, as shown in Listing 7-18. -+ ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-18/src/main.rs:here}} @@ -256,7 +264,8 @@ two `use` statements that share a subpath. For example, Listing 7-19 shows two `use` statements: one that brings `std::io` into scope and one that brings `std::io::Write` into scope. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-19/src/lib.rs}} @@ -268,7 +277,8 @@ The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in the nested path, as shown in Listing 7-20. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-20/src/lib.rs}} diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index 2952e4b156..d0881a5767 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -16,7 +16,8 @@ the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code shown in Listing 7-21. Note that this won’t compile until we create the *src/front_of_house.rs* file in Listing 7-22. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/lib.rs}} @@ -29,7 +30,8 @@ Next, place the code that was in the curly brackets into a new file named in this file because it came across the module declaration in the crate root with the name `front_of_house`. -+ ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/front_of_house.rs}} From 68c60cb01498345bed2a01ff7609fa0aa9ffd871 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:00:52 +0200 Subject: [PATCH 408/720] Convert Listing 8-1 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index ece5d59dce..40793ad352 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -11,12 +11,13 @@ lines of text in a file or the prices of items in a shopping cart. To create a new empty vector, we call the `Vec::new` function, as shown in Listing 8-1. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-01/src/main.rs:here}} ``` -Listing 8-1: Creating a new, empty vector to hold values -of type `i32` + Note that we added a type annotation here. Because we aren’t inserting any values into this vector, Rust doesn’t know what kind of elements we intend to From 7e0d98d2998453d64dbefb80c0a7293dfadccc6b Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:02:55 +0200 Subject: [PATCH 409/720] Convert Listing 8-2 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index 40793ad352..30595d2277 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -36,12 +36,13 @@ new vector that holds the values you give it. Listing 8-2 creates a new because that’s the default integer type, as we discussed in the [“Data Types”][data-types] section of Chapter 3. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-02/src/main.rs:here}} ``` -Listing 8-2: Creating a new vector containing -values + Because we’ve given initial `i32` values, Rust can infer that the type of `v` is `Vec`, and the type annotation isn’t necessary. Next, we’ll look at how From 62b29107212e14f367fb7f0ac2a52cc634e33043 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:04:36 +0200 Subject: [PATCH 410/720] Convert Listing 8-3 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index 30595d2277..cf2c2e7bb7 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -53,12 +53,13 @@ to modify a vector. To create a vector and then add elements to it, we can use the `push` method, as shown in Listing 8-3. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-03/src/main.rs:here}} ``` -Listing 8-3: Using the `push` method to add values to a -vector + As with any variable, if we want to be able to change its value, we need to make it mutable using the `mut` keyword, as discussed in Chapter 3. The numbers From d09b84c273f060ed68cb109d6df4d6881c95c26f Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:06:52 +0200 Subject: [PATCH 411/720] Convert Listing 8-4 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index cf2c2e7bb7..a583374f4c 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -75,12 +75,13 @@ the values that are returned from these functions for extra clarity. Listing 8-4 shows both methods of accessing a value in a vector, with indexing syntax and the `get` method. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-04/src/main.rs:here}} ``` -Listing 8-4: Using indexing syntax and using the `get` -method to access an item in a vector + Note a few details here. We use the index value of `2` to get the third element because vectors are indexed by number, starting at zero. Using `&` and `[]` From d3e2527a77cb7859776bc8ea5e1dd419c472154d Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:08:40 +0200 Subject: [PATCH 412/720] Convert Listing 8-5 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index a583374f4c..5541b637f4 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -95,12 +95,13 @@ existing elements. As an example, let’s see what happens when we have a vector of five elements and then we try to access an element at index 100 with each technique, as shown in Listing 8-5. ++ ```rust,should_panic,panics {{#rustdoc_include ../listings/ch08-common-collections/listing-08-05/src/main.rs:here}} ``` -Listing 8-5: Attempting to access the element at index -100 in a vector containing five elements + When we run this code, the first `[]` method will cause the program to panic because it references a nonexistent element. This method is best used when you From 86f647af198ddab147dfde9ee53e21d384752552 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:10:54 +0200 Subject: [PATCH 413/720] Convert Listing 8-6 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index 5541b637f4..8189afb9f2 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -128,12 +128,13 @@ to the first element in a vector and try to add an element to the end. This program won’t work if we also try to refer to that element later in the function. ++ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch08-common-collections/listing-08-06/src/main.rs:here}} ``` -Listing 8-6: Attempting to add an element to a vector -while holding a reference to an item + Compiling this code will result in this error: From 51597b62ddb4ac094e38b0f0fbd92b51f7debdd1 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:13:42 +0200 Subject: [PATCH 414/720] Convert Listing 8-7 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index 8189afb9f2..aa32ff6147 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -162,12 +162,13 @@ elements rather than use indices to access one at a time. Listing 8-7 shows how to use a `for` loop to get immutable references to each element in a vector of `i32` values and print them. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-07/src/main.rs:here}} ``` -Listing 8-7: Printing each element in a vector by -iterating over the elements using a `for` loop + We can also iterate over mutable references to each element in a mutable vector in order to make changes to all the elements. The `for` loop in Listing 8-8 From 3029bd0d65e2353c25d12c9bfce79cc5c16315b3 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:16:06 +0200 Subject: [PATCH 415/720] Convert Listing 8-8 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index aa32ff6147..64142ab3a4 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -174,12 +174,13 @@ We can also iterate over mutable references to each element in a mutable vector in order to make changes to all the elements. The `for` loop in Listing 8-8 will add `50` to each element. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-08/src/main.rs:here}} ``` -Listing 8-8: Iterating over mutable references to -elements in a vector + To change the value that the mutable reference refers to, we have to use the `*` dereference operator to get to the value in `i` before we can use the `+=` From a179f406c4ea8ee255d1c3740941196ce0070f8b Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:18:52 +0200 Subject: [PATCH 416/720] Convert Listing 8-9 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index 64142ab3a4..df4717aafc 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -210,12 +210,13 @@ value types, and all the enum variants will be considered the same type: that of the enum. Then we can create a vector to hold that enum and so, ultimately, hold different types. We’ve demonstrated this in Listing 8-9. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-09/src/main.rs:here}} ``` -Listing 8-9: Defining an `enum` to store values of -different types in one vector + Rust needs to know what types will be in the vector at compile time so it knows exactly how much memory on the heap will be needed to store each element. We From fbf4c5075db7f8b102735a29149d01f224799a6a Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:21:52 +0200 Subject: [PATCH 417/720] Convert Listing 8-10 to `` --- src/ch08-01-vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index df4717aafc..718cd597a3 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -240,12 +240,13 @@ addition to `push`, a `pop` method removes and returns the last element. Like any other `struct`, a vector is freed when it goes out of scope, as annotated in Listing 8-10. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-10/src/main.rs:here}} ``` -Listing 8-10: Showing where the vector and its elements -are dropped + When the vector gets dropped, all of its contents are also dropped, meaning the integers it holds will be cleaned up. The borrow checker ensures that any From c4b601068faa972c49b272a82e5cc830e337e18b Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:27:21 +0200 Subject: [PATCH 418/720] Convert Listing 8-11 to `` --- src/ch08-02-strings.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index be0c874748..aec81de9fa 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -41,11 +41,13 @@ of bytes with some extra guarantees, restrictions, and capabilities. An example of a function that works the same way with `Vec` and `String` is the `new` function to create an instance, shown in Listing 8-11. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-11/src/main.rs:here}} ``` -Listing 8-11: Creating a new, empty `String` + This line creates a new, empty string called `s`, into which we can then load data. Often, we’ll have some initial data with which we want to start the From a66cccee27ee733262d0fd64746e872dd2a7e546 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:28:44 +0200 Subject: [PATCH 419/720] Convert Listing 8-12 to `` --- src/ch08-02-strings.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index aec81de9fa..c951cf51f6 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -55,12 +55,13 @@ string. For that, we use the `to_string` method, which is available on any type that implements the `Display` trait, as string literals do. Listing 8-12 shows two examples. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-12/src/main.rs:here}} ``` -Listing 8-12: Using the `to_string` method to create a -`String` from a string literal + This code creates a string containing `initial contents`. From ec6737b32d95aa43ed8ae983c969288319f85b8c Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:30:26 +0200 Subject: [PATCH 420/720] Convert Listing 8-13 to `` --- src/ch08-02-strings.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index c951cf51f6..65f006b4be 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -69,12 +69,13 @@ We can also use the function `String::from` to create a `String` from a string literal. The code in Listing 8-13 is equivalent to the code in Listing 8-12 that uses `to_string`. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-13/src/main.rs:here}} ``` -Listing 8-13: Using the `String::from` function to create -a `String` from a string literal + Because strings are used for so many things, we can use many different generic APIs for strings, providing us with a lot of options. Some of them can seem From ed4e0a9ed725027e39a6715e81c425eaf8ba1ce2 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:32:09 +0200 Subject: [PATCH 421/720] Convert Listing 8-14 to `` --- src/ch08-02-strings.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index 65f006b4be..2af543468b 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -86,12 +86,13 @@ readability. Remember that strings are UTF-8 encoded, so we can include any properly encoded data in them, as shown in Listing 8-14. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-14/src/main.rs:here}} ``` -Listing 8-14: Storing greetings in different languages in -strings + All of these are valid `String` values. From 211dd0ad81fc5c3753b55473b101fea120b9faff Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:34:20 +0200 Subject: [PATCH 422/720] Convert Listing 8-15 to `` --- src/ch08-02-strings.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index 2af543468b..cc1df979a7 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -107,12 +107,14 @@ use the `+` operator or the `format!` macro to concatenate `String` values. We can grow a `String` by using the `push_str` method to append a string slice, as shown in Listing 8-15. ++ + ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-15/src/main.rs:here}} ``` -Listing 8-15: Appending a string slice to a `String` -using the `push_str` method + After these two lines, `s` will contain `foobar`. The `push_str` method takes a string slice because we don’t necessarily want to take ownership of the From d593065169549eaa636fb1e8dde537c98a75afbc Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Sun, 26 May 2024 17:50:23 +0200 Subject: [PATCH 423/720] Convert Listing 8-16 to `` --- src/ch08-02-strings.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index cc1df979a7..b838ef6d13 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -109,7 +109,6 @@ as shown in Listing 8-15. - ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-15/src/main.rs:here}} ``` @@ -121,12 +120,13 @@ string slice because we don’t necessarily want to take ownership of the parameter. For example, in the code in Listing 8-16, we want to be able to use `s2` after appending its contents to `s1`. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-16/src/main.rs:here}} ``` -Listing 8-16: Using a string slice after appending its -contents to a `String` + If the `push_str` method took ownership of `s2`, we wouldn’t be able to print its value on the last line. However, this code works as we’d expect! From 2778c4fdcb59a30556d8740c45cf96529169c3b9 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 18:56:05 +0200 Subject: [PATCH 424/720] Convert Listing 8-17 to `` I understand why "Any estimates that you make at the coffee machine will come back to haunt you". I shouldn't've claimed 5 chapters. --- src/ch08-02-strings.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index b838ef6d13..00919a79d9 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -135,12 +135,13 @@ The `push` method takes a single character as a parameter and adds it to the `String`. Listing 8-17 adds the letter *l* to a `String` using the `push` method. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-17/src/main.rs:here}} ``` -Listing 8-17: Adding one character to a `String` value -using `push` + As a result, `s` will contain `lol`. From e1af4c12811edb3cdf5624f72727c0c56a6de444 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 18:59:11 +0200 Subject: [PATCH 425/720] Convert Listing 8-18 to `` --- src/ch08-02-strings.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index 00919a79d9..cce644b295 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -150,12 +150,13 @@ As a result, `s` will contain `lol`. Often, you’ll want to combine two existing strings. One way to do so is to use the `+` operator, as shown in Listing 8-18. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-18/src/main.rs:here}} ``` -Listing 8-18: Using the `+` operator to combine two -`String` values into a new `String` value + The string `s3` will contain `Hello, world!`. The reason `s1` is no longer valid after the addition, and the reason we used a reference to `s2`, has to do From c2632f73cd85ea7900a83b8fb72dfe66879aab42 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:01:30 +0200 Subject: [PATCH 426/720] Convert Listing 8-19 to `` --- src/ch08-02-strings.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index cce644b295..9494fd94cb 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -224,12 +224,13 @@ string by referencing them by index is a valid and common operation. However, if you try to access parts of a `String` using indexing syntax in Rust, you’ll get an error. Consider the invalid code in Listing 8-19. ++ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch08-common-collections/listing-08-19/src/main.rs:here}} ``` -Listing 8-19: Attempting to use indexing syntax with a -String + This code will result in the following error: From f4105cbb35d9f93a772a72e7afd768942ebeb74f Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:04:04 +0200 Subject: [PATCH 427/720] Convert Listing 8-20 to `` --- src/ch08-03-hash-maps.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index 72331e5b91..f41ce8b73f 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -24,12 +24,13 @@ One way to create an empty hash map is to use `new` and to add elements with names are *Blue* and *Yellow*. The Blue team starts with 10 points, and the Yellow team starts with 50. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-20/src/main.rs:here}} ``` -Listing 8-20: Creating a new hash map and inserting some -keys and values + Note that we need to first `use` the `HashMap` from the collections portion of the standard library. Of our three common collections, this one is the least From f9756188debb9e76eef570cfadee262a3629db00 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:05:43 +0200 Subject: [PATCH 428/720] Convert Listing 8-21 to `` --- src/ch08-03-hash-maps.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index f41ce8b73f..008f64f136 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -48,12 +48,13 @@ must have the same type. We can get a value out of the hash map by providing its key to the `get` method, as shown in Listing 8-21. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-21/src/main.rs:here}} ``` -Listing 8-21: Accessing the score for the Blue team -stored in the hash map + Here, `score` will have the value that’s associated with the Blue team, and the result will be `10`. The `get` method returns an `Option<&V>`; if there’s no From 4cb8ab0ada146946e09a152bba812420d683fd11 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:16:16 +0200 Subject: [PATCH 429/720] Convert Listing 8-22 to `` --- src/ch08-03-hash-maps.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index 008f64f136..d3842ddc19 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -83,12 +83,13 @@ For types that implement the `Copy` trait, like `i32`, the values are copied into the hash map. For owned values like `String`, the values will be moved and the hash map will be the owner of those values, as demonstrated in Listing 8-22. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-22/src/main.rs:here}} ``` -Listing 8-22: Showing that keys and values are owned by -the hash map once they’re inserted + We aren’t able to use the variables `field_name` and `field_value` after they’ve been moved into the hash map with the call to `insert`. From d306a72aff3633556ed36d09a1db3dc865282417 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:17:57 +0200 Subject: [PATCH 430/720] Convert Listing 8-23 to `` --- src/ch08-03-hash-maps.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index d3842ddc19..53a62adfcc 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -123,12 +123,13 @@ Even though the code in Listing 8-23 calls `insert` twice, the hash map will only contain one key–value pair because we’re inserting the value for the Blue team’s key both times. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-23/src/main.rs:here}} ``` -Listing 8-23: Replacing a value stored with a particular -key + This code will print `{"Blue": 25}`. The original value of `10` has been overwritten. From 36d7d209659a4a7761fbfcd07c0ef1d1d674f87f Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:20:08 +0200 Subject: [PATCH 431/720] Convert Listing 8-24 to `` --- src/ch08-03-hash-maps.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index 53a62adfcc..49bfd48386 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -151,12 +151,13 @@ we want to check whether the key for the Yellow team has a value associated with it. If it doesn’t, we want to insert the value `50`, and the same for the Blue team. Using the `entry` API, the code looks like Listing 8-24. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-24/src/main.rs:here}} ``` -Listing 8-24: Using the `entry` method to only insert if -the key does not already have a value + The `or_insert` method on `Entry` is defined to return a mutable reference to the value for the corresponding `Entry` key if that key exists, and if not, it From 3678c0f238264812099f392387fd1240bc02ae8a Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:21:38 +0200 Subject: [PATCH 432/720] Convert Listing 8-25 to `` --- src/ch08-03-hash-maps.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index 49bfd48386..057501415a 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -180,12 +180,13 @@ the words as keys and increment the value to keep track of how many times we’v seen that word. If it’s the first time we’ve seen a word, we’ll first insert the value `0`. ++ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-25/src/main.rs:here}} ``` -Listing 8-25: Counting occurrences of words using a hash -map that stores words and counts + This code will print `{"world": 2, "hello": 1, "wonderful": 1}`. You might see the same key–value pairs printed in a different order: recall from the From 2b3b9f537034e95408a50bcf24c62bc30f5a3463 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 10:24:30 +0200 Subject: [PATCH 433/720] Chapter 8 - Wrap all ``s to comply with the virtual 80 character limit More infos and concerns can be found in the equivalent commit, in the chapter 6 PR. --- src/ch08-01-vectors.md | 21 ++++++++++++++------- src/ch08-02-strings.md | 24 ++++++++++++++++-------- src/ch08-03-hash-maps.md | 18 ++++++++++++------ 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index 718cd597a3..fcec18f17f 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -11,7 +11,8 @@ lines of text in a file or the prices of items in a shopping cart. To create a new empty vector, we call the `Vec::new` function, as shown in Listing 8-1. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-01/src/main.rs:here}} @@ -53,7 +54,8 @@ to modify a vector. To create a vector and then add elements to it, we can use the `push` method, as shown in Listing 8-3. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-03/src/main.rs:here}} @@ -75,7 +77,8 @@ the values that are returned from these functions for extra clarity. Listing 8-4 shows both methods of accessing a value in a vector, with indexing syntax and the `get` method. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-04/src/main.rs:here}} @@ -95,7 +98,8 @@ existing elements. As an example, let’s see what happens when we have a vector of five elements and then we try to access an element at index 100 with each technique, as shown in Listing 8-5. -+ ```rust,should_panic,panics {{#rustdoc_include ../listings/ch08-common-collections/listing-08-05/src/main.rs:here}} @@ -128,7 +132,8 @@ to the first element in a vector and try to add an element to the end. This program won’t work if we also try to refer to that element later in the function. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch08-common-collections/listing-08-06/src/main.rs:here}} @@ -162,7 +167,8 @@ elements rather than use indices to access one at a time. Listing 8-7 shows how to use a `for` loop to get immutable references to each element in a vector of `i32` values and print them. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-07/src/main.rs:here}} @@ -174,7 +180,8 @@ We can also iterate over mutable references to each element in a mutable vector in order to make changes to all the elements. The `for` loop in Listing 8-8 will add `50` to each element. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-08/src/main.rs:here}} diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index 9494fd94cb..8f8464cc77 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -55,7 +55,8 @@ string. For that, we use the `to_string` method, which is available on any type that implements the `Display` trait, as string literals do. Listing 8-12 shows two examples. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-12/src/main.rs:here}} @@ -69,7 +70,8 @@ We can also use the function `String::from` to create a `String` from a string literal. The code in Listing 8-13 is equivalent to the code in Listing 8-12 that uses `to_string`. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-13/src/main.rs:here}} @@ -86,7 +88,8 @@ readability. Remember that strings are UTF-8 encoded, so we can include any properly encoded data in them, as shown in Listing 8-14. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-14/src/main.rs:here}} @@ -107,7 +110,8 @@ use the `+` operator or the `format!` macro to concatenate `String` values. We can grow a `String` by using the `push_str` method to append a string slice, as shown in Listing 8-15. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-15/src/main.rs:here}} @@ -120,7 +124,8 @@ string slice because we don’t necessarily want to take ownership of the parameter. For example, in the code in Listing 8-16, we want to be able to use `s2` after appending its contents to `s1`. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-16/src/main.rs:here}} @@ -135,7 +140,8 @@ The `push` method takes a single character as a parameter and adds it to the `String`. Listing 8-17 adds the letter *l* to a `String` using the `push` method. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-17/src/main.rs:here}} @@ -150,7 +156,8 @@ As a result, `s` will contain `lol`. Often, you’ll want to combine two existing strings. One way to do so is to use the `+` operator, as shown in Listing 8-18. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-18/src/main.rs:here}} @@ -224,7 +231,8 @@ string by referencing them by index is a valid and common operation. However, if you try to access parts of a `String` using indexing syntax in Rust, you’ll get an error. Consider the invalid code in Listing 8-19. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch08-common-collections/listing-08-19/src/main.rs:here}} diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index 057501415a..c4327a019e 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -24,7 +24,8 @@ One way to create an empty hash map is to use `new` and to add elements with names are *Blue* and *Yellow*. The Blue team starts with 10 points, and the Yellow team starts with 50. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-20/src/main.rs:here}} @@ -48,7 +49,8 @@ must have the same type. We can get a value out of the hash map by providing its key to the `get` method, as shown in Listing 8-21. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-21/src/main.rs:here}} @@ -83,7 +85,8 @@ For types that implement the `Copy` trait, like `i32`, the values are copied into the hash map. For owned values like `String`, the values will be moved and the hash map will be the owner of those values, as demonstrated in Listing 8-22. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-22/src/main.rs:here}} @@ -123,7 +126,8 @@ Even though the code in Listing 8-23 calls `insert` twice, the hash map will only contain one key–value pair because we’re inserting the value for the Blue team’s key both times. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-23/src/main.rs:here}} @@ -151,7 +155,8 @@ we want to check whether the key for the Yellow team has a value associated with it. If it doesn’t, we want to insert the value `50`, and the same for the Blue team. Using the `entry` API, the code looks like Listing 8-24. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-24/src/main.rs:here}} @@ -180,7 +185,8 @@ the words as keys and increment the value to keep track of how many times we’v seen that word. If it’s the first time we’ve seen a word, we’ll first insert the value `0`. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-25/src/main.rs:here}} From cf5076ffc13954e103378cec11d8a2d60633ce12 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:46:14 +0200 Subject: [PATCH 434/720] Convert Listing 9-1 to `` --- src/ch09-01-unrecoverable-errors-with-panic.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch09-01-unrecoverable-errors-with-panic.md b/src/ch09-01-unrecoverable-errors-with-panic.md index 5c27c8f07f..8cb531f08c 100644 --- a/src/ch09-01-unrecoverable-errors-with-panic.md +++ b/src/ch09-01-unrecoverable-errors-with-panic.md @@ -64,14 +64,13 @@ a `panic!` call comes from a library because of a bug in our code instead of from our code calling the macro directly. Listing 9-1 has some code that attempts to access an index in a vector beyond the range of valid indexes. -Filename: src/main.rs + ```rust,should_panic,panics {{#rustdoc_include ../listings/ch09-error-handling/listing-09-01/src/main.rs}} ``` -Listing 9-1: Attempting to access an element beyond the -end of a vector, which will cause a call to `panic!` + Here, we’re attempting to access the 100th element of our vector (which is at index 99 because indexing starts at zero), but the vector has only three From 654915a08c17d3a522eac77d9128c38b7ec2aac0 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:49:22 +0200 Subject: [PATCH 435/720] Convert Listing 9-2 to `` --- src/ch09-01-unrecoverable-errors-with-panic.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch09-01-unrecoverable-errors-with-panic.md b/src/ch09-01-unrecoverable-errors-with-panic.md index 8cb531f08c..8218774de4 100644 --- a/src/ch09-01-unrecoverable-errors-with-panic.md +++ b/src/ch09-01-unrecoverable-errors-with-panic.md @@ -116,6 +116,8 @@ copy the backtrace output below check the backtrace number mentioned in the text below the listing --> ++ ```console $ RUST_BACKTRACE=1 cargo run thread 'main' panicked at src/main.rs:4:6: @@ -140,8 +142,7 @@ stack backtrace: note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ``` -Listing 9-2: The backtrace generated by a call to -`panic!` displayed when the environment variable `RUST_BACKTRACE` is set + That’s a lot of output! The exact output you see might be different depending on your operating system and Rust version. In order to get backtraces with this From e17acd8419a74d0f66ef6d66b3e17c19d7793ed5 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:51:37 +0200 Subject: [PATCH 436/720] Convert Listing 9-3 to `` --- src/ch09-02-recoverable-errors-with-result.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 35bcd11474..f3ad56d7df 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -29,13 +29,13 @@ return may differ. Let’s call a function that returns a `Result` value because the function could fail. In Listing 9-3 we try to open a file. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch09-error-handling/listing-09-03/src/main.rs}} ``` -Listing 9-3: Opening a file + The return type of `File::open` is a `Result`. The generic parameter `T` has been filled in by the implementation of `File::open` with the type of the From 2181c3b12c68582822686e1c57c2e77536c42e1d Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 19:53:32 +0200 Subject: [PATCH 437/720] Convert Listing 9-4 to `` --- src/ch09-02-recoverable-errors-with-result.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index f3ad56d7df..0ddf5bbc65 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -59,14 +59,13 @@ on the value `File::open` returns. Listing 9-4 shows one way to handle the `Result` using a basic tool, the `match` expression that we discussed in Chapter 6. -Filename: src/main.rs + ```rust,should_panic {{#rustdoc_include ../listings/ch09-error-handling/listing-09-04/src/main.rs}} ``` -Listing 9-4: Using a `match` expression to handle the -`Result` variants that might be returned + Note that, like the `Option` enum, the `Result` enum and its variants have been brought into scope by the prelude, so we don’t need to specify `Result::` From 01fd90a182da2d66f6ff85202ea977aadafbe215 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:00:21 +0200 Subject: [PATCH 438/720] Convert Listing 9-5 to `` --- src/ch09-02-recoverable-errors-with-result.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 0ddf5bbc65..060cd1c351 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -97,7 +97,7 @@ reason—for example, because we didn’t have permission to open the file—we want the code to `panic!` in the same way it did in Listing 9-4. For this, we add an inner `match` expression, shown in Listing 9-5. -Filename: src/main.rs + @@ -106,8 +106,7 @@ tests to fail lol --> {{#rustdoc_include ../listings/ch09-error-handling/listing-09-05/src/main.rs}} ``` -Listing 9-5: Handling different kinds of errors in -different ways + The type of the value that `File::open` returns inside the `Err` variant is `io::Error`, which is a struct provided by the standard library. This struct From ec9bb0acbff4b566b3ba02cc2f916e66bf214533 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:02:40 +0200 Subject: [PATCH 439/720] Convert Listing 9-6 to `` --- src/ch09-02-recoverable-errors-with-result.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 060cd1c351..f0917ad427 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -235,7 +235,7 @@ For example, Listing 9-6 shows a function that reads a username from a file. If the file doesn’t exist or can’t be read, this function will return those errors to the code that called the function. -Filename: src/main.rs + {{#include ../listings/ch09-error-handling/listing-09-06/src/main.rs:here}} ``` -Listing 9-6: A function that returns errors to the -calling code using `match` + This function can be written in a much shorter way, but we’re going to start by doing a lot of it manually in order to explore error handling; at the end, From 7b7378d2b24a6187c029984cc1efad41cf05b7b6 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:04:43 +0200 Subject: [PATCH 440/720] Convert Listing 9-7 to `` --- src/ch09-02-recoverable-errors-with-result.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index f0917ad427..5784703c55 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -304,7 +304,7 @@ Listing 9-7 shows an implementation of `read_username_from_file` that has the same functionality as in Listing 9-6, but this implementation uses the `?` operator. -Filename: src/main.rs + {{#include ../listings/ch09-error-handling/listing-09-07/src/main.rs:here}} ``` -Listing 9-7: A function that returns errors to the -calling code using the `?` operator + The `?` placed after a `Result` value is defined to work in almost the same way as the `match` expressions we defined to handle the `Result` values in Listing From e237ed52dd62ff20cd6456c361d0a59c8f77b7a7 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:10:18 +0200 Subject: [PATCH 441/720] Convert Listing 8-9 to `` --- src/ch09-02-recoverable-errors-with-result.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 5784703c55..a5e05522e8 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -351,7 +351,7 @@ The `?` operator eliminates a lot of boilerplate and makes this function’s implementation simpler. We could even shorten this code further by chaining method calls immediately after the `?`, as shown in Listing 9-8. -Filename: src/main.rs + {{#include ../listings/ch09-error-handling/listing-09-08/src/main.rs:here}} ``` -Listing 9-8: Chaining method calls after the `?` -operator + We’ve moved the creation of the new `String` in `username` to the beginning of the function; that part hasn’t changed. Instead of creating a variable From 3b2fa9b1b48840b8ec77f015766a51c94615034e Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:10:44 +0200 Subject: [PATCH 442/720] Convert Listing 9-9 to `` --- src/ch09-02-recoverable-errors-with-result.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index a5e05522e8..921afa4352 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -374,7 +374,7 @@ this is just a different, more ergonomic way to write it. Listing 9-9 shows a way to make this even shorter using `fs::read_to_string`. -Filename: src/main.rs + {{#include ../listings/ch09-error-handling/listing-09-09/src/main.rs:here}} ``` -Listing 9-9: Using `fs::read_to_string` instead of -opening and then reading the file + Reading a file into a string is a fairly common operation, so the standard library provides the convenient `fs::read_to_string` function that opens the From 0c0bbee010b6512d47ae3177e3d0d6b1e620794a Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:14:16 +0200 Subject: [PATCH 443/720] Convert Listing 9-10 to `` (had to fix a merge conflict here) --- src/ch09-02-recoverable-errors-with-result.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 921afa4352..99b9d749af 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -407,14 +407,13 @@ In Listing 9-10, let’s look at the error we’ll get if we use the `?` operato in a `main` function with a return type that is incompatible with the type of the value we use `?` on. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch09-error-handling/listing-09-10/src/main.rs}} ``` -Listing 9-10: Attempting to use the `?` in the `main` -function that returns `()` won’t compile. + This code opens a file, which might fail. The `?` operator follows the `Result` value returned by `File::open`, but this `main` function has the return type of From 7295612d173f334f8688c4935e97e2da5e433568 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:17:17 +0200 Subject: [PATCH 444/720] Convert Listing 9-11 to `` --- src/ch09-02-recoverable-errors-with-result.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 99b9d749af..a4656c9e9b 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -444,12 +444,13 @@ resultant value of the expression, and the function continues. Listing 9-11 has an example of a function that finds the last character of the first line in the given text. ++ ```rust {{#rustdoc_include ../listings/ch09-error-handling/listing-09-11/src/main.rs:here}} ``` -Listing 9-11: Using the `?` operator on an `Option` -value + This function returns `Option` because it’s possible that there is a character there, but it’s also possible that there isn’t. This code takes the From c35dc8adca566826af0ce1bb4eb5bc3a42b60eba Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:19:41 +0200 Subject: [PATCH 445/720] Convert Listing 9-12 to `` (had to fix a conflect here) --- src/ch09-02-recoverable-errors-with-result.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index a4656c9e9b..25885546ba 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -492,12 +492,13 @@ code will now compile. Filename: src/main.rs ++ ```rust,ignore {{#rustdoc_include ../listings/ch09-error-handling/listing-09-12/src/main.rs}} ``` -Listing 9-12: Changing `main` to return `Result<(), E>` -allows the use of the `?` operator on `Result` values. + The `Box` type is a *trait object*, which we’ll talk about in the [“Using Trait Objects that Allow for Values of Different From 899d625372447938bc62dfefc064c6ca38bc5a33 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Mon, 27 May 2024 20:24:49 +0200 Subject: [PATCH 446/720] Converted Listing 9-13 to `` (& more) I removed the line break in Listing 9-12, which I apparently forgot in the previous commit. I did realize that I will evetually have to re-add these to comply with the 80 character width limit, but for now I want to stay consistent with my current implementation. (Had to fix a conflict here) --- src/ch09-02-recoverable-errors-with-result.md | 4 +--- src/ch09-03-to-panic-or-not-to-panic.md | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 25885546ba..d9badb7469 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -490,9 +490,7 @@ from Listing 9-10, but we’ve changed the return type of `main` to be `Result<(), Box>` and added a return value `Ok(())` to the end. This code will now compile. -Filename: src/main.rs - -+ ```rust,ignore {{#rustdoc_include ../listings/ch09-error-handling/listing-09-12/src/main.rs}} diff --git a/src/ch09-03-to-panic-or-not-to-panic.md b/src/ch09-03-to-panic-or-not-to-panic.md index 40f93d67ce..ef5803a965 100644 --- a/src/ch09-03-to-panic-or-not-to-panic.md +++ b/src/ch09-03-to-panic-or-not-to-panic.md @@ -166,12 +166,13 @@ receives a value between 1 and 100. Filename: src/lib.rs ++ ```rust {{#rustdoc_include ../listings/ch09-error-handling/listing-09-13/src/lib.rs}} ``` -Listing 9-13: A `Guess` type that will only continue with -values between 1 and 100 + First we define a struct named `Guess` that has a field named `value` that holds an `i32`. This is where the number will be stored. From adaa6c2f4adafadbaff22cf7fb6aa56049a4b127 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 11:27:52 +0200 Subject: [PATCH 447/720] Convert unnamed `` (Chapter 9.2) --- src/ch09-02-recoverable-errors-with-result.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index d9badb7469..44d97e12c0 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -170,12 +170,14 @@ Listing 9-4. If the `Result` value is the `Ok` variant, `unwrap` will return the value inside the `Ok`. If the `Result` is the `Err` variant, `unwrap` will call the `panic!` macro for us. Here is an example of `unwrap` in action: -Filename: src/main.rs + ```rust,should_panic {{#rustdoc_include ../listings/ch09-error-handling/no-listing-04-unwrap/src/main.rs}} ``` + + If we run this code without a *hello.txt* file, we’ll see an error message from the `panic!` call that the `unwrap` method makes: From bc1d651d50d387dcc4dead40c5f8de32f5508741 Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 11:30:48 +0200 Subject: [PATCH 448/720] Convert unnamed `` (Chapter 9.2) --- src/ch09-02-recoverable-errors-with-result.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 44d97e12c0..9f3387c292 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -197,12 +197,14 @@ Using `expect` instead of `unwrap` and providing good error messages can convey your intent and make tracking down the source of a panic easier. The syntax of `expect` looks like this: -Filename: src/main.rs + ```rust,should_panic {{#rustdoc_include ../listings/ch09-error-handling/no-listing-05-expect/src/main.rs}} ``` + + We use `expect` in the same way as `unwrap`: to return the file handle or call the `panic!` macro. The error message used by `expect` in its call to `panic!` will be the parameter that we pass to `expect`, rather than the default From dd72f8fbc33fae0a3aaa4294e6b5947a1512932f Mon Sep 17 00:00:00 2001 From: SpectralPixel Date: Wed, 17 Jul 2024 10:26:00 +0200 Subject: [PATCH 449/720] Chapter 9 - Wrap all ``s to comply with the virtual 80 character limit More infos and concerns can be found in the equivalent commit in the chapter 6 PR. (Had to fix a conflict here) --- ...ch09-01-unrecoverable-errors-with-panic.md | 6 +++-- src/ch09-02-recoverable-errors-with-result.md | 27 ++++++++++++------- src/ch09-03-to-panic-or-not-to-panic.md | 3 ++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/ch09-01-unrecoverable-errors-with-panic.md b/src/ch09-01-unrecoverable-errors-with-panic.md index 8218774de4..0aa514769e 100644 --- a/src/ch09-01-unrecoverable-errors-with-panic.md +++ b/src/ch09-01-unrecoverable-errors-with-panic.md @@ -64,7 +64,8 @@ a `panic!` call comes from a library because of a bug in our code instead of from our code calling the macro directly. Listing 9-1 has some code that attempts to access an index in a vector beyond the range of valid indexes. -+ ```rust,should_panic,panics {{#rustdoc_include ../listings/ch09-error-handling/listing-09-01/src/main.rs}} @@ -116,7 +117,8 @@ copy the backtrace output below check the backtrace number mentioned in the text below the listing --> -+ ```console $ RUST_BACKTRACE=1 cargo run diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 9f3387c292..e04ea0da62 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -59,7 +59,8 @@ on the value `File::open` returns. Listing 9-4 shows one way to handle the `Result` using a basic tool, the `match` expression that we discussed in Chapter 6. -+ ```rust,should_panic {{#rustdoc_include ../listings/ch09-error-handling/listing-09-04/src/main.rs}} @@ -97,7 +98,8 @@ reason—for example, because we didn’t have permission to open the file—we want the code to `panic!` in the same way it did in Listing 9-4. For this, we add an inner `match` expression, shown in Listing 9-5. -+ @@ -239,7 +241,8 @@ For example, Listing 9-6 shows a function that reads a username from a file. If the file doesn’t exist or can’t be read, this function will return those errors to the code that called the function. -+ + -```rust +```rust,ignore {{#rustdoc_include ../listings/ch17-async-await/listing-17-09/src/main.rs:many-messages}} ``` @@ -260,9 +262,11 @@ each message, we need to put the `tx` and `rx` operations in their own async blocks. Then the runtime can execute each of them separately using `trpl::join`, just like in the counting example. + + -```rust +```rust,ignore {{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:futures}} ``` From 6a0d07280a99adbf88889ffecc68e9d5c016db9a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Jul 2024 15:12:54 -0600 Subject: [PATCH 488/720] =?UTF-8?q?Ch.=2017=C2=A703:=20Make=20code/listing?= =?UTF-8?q?s=20pass=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update all the listings in the chapter to use `extern crate` since `mdbook test` does not understand Rust 2018. Alas. - Fix one listing which had gotten out of sync somewhere along the way. (This also fixes a comment flagged up by a reviewer!) --- .../ch17-async-await/listing-17-13/Cargo.lock | 12 +++++++++ .../listing-17-13/src/main.rs | 2 ++ .../listing-17-14/src/main.rs | 2 ++ .../listing-17-15/src/main.rs | 2 ++ .../listing-17-16/src/main.rs | 2 ++ .../ch17-async-await/listing-17-17/Cargo.lock | 12 +++++++++ .../listing-17-17/src/main.rs | 2 ++ .../listing-17-18/src/main.rs | 26 ++++++++++++------- .../ch17-async-await/listing-17-19/Cargo.lock | 12 +++++++++ .../listing-17-19/src/main.rs | 2 ++ src/ch17-03-more-futures.md | 3 +++ 11 files changed, 68 insertions(+), 9 deletions(-) diff --git a/listings/ch17-async-await/listing-17-13/Cargo.lock b/listings/ch17-async-await/listing-17-13/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-13/Cargo.lock +++ b/listings/ch17-async-await/listing-17-13/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-13/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs index 945442dd8a..87b244daa8 100644 --- a/listings/ch17-async-await/listing-17-13/src/main.rs +++ b/listings/ch17-async-await/listing-17-13/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::time::Duration; fn main() { diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs index 097114bb73..684b174bdc 100644 --- a/listings/ch17-async-await/listing-17-14/src/main.rs +++ b/listings/ch17-async-await/listing-17-14/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::time::Duration; fn main() { diff --git a/listings/ch17-async-await/listing-17-15/src/main.rs b/listings/ch17-async-await/listing-17-15/src/main.rs index beff676dbe..5bc9c2c3bd 100644 --- a/listings/ch17-async-await/listing-17-15/src/main.rs +++ b/listings/ch17-async-await/listing-17-15/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::time::Duration; fn main() { diff --git a/listings/ch17-async-await/listing-17-16/src/main.rs b/listings/ch17-async-await/listing-17-16/src/main.rs index b712d344c0..020a4d37f3 100644 --- a/listings/ch17-async-await/listing-17-16/src/main.rs +++ b/listings/ch17-async-await/listing-17-16/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{future::Future, time::Duration}; fn main() { diff --git a/listings/ch17-async-await/listing-17-17/Cargo.lock b/listings/ch17-async-await/listing-17-17/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-17/Cargo.lock +++ b/listings/ch17-async-await/listing-17-17/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-17/src/main.rs b/listings/ch17-async-await/listing-17-17/src/main.rs index 5520a58ca5..b7fed9b427 100644 --- a/listings/ch17-async-await/listing-17-17/src/main.rs +++ b/listings/ch17-async-await/listing-17-17/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{ future::Future, pin::{pin, Pin}, diff --git a/listings/ch17-async-await/listing-17-18/src/main.rs b/listings/ch17-async-await/listing-17-18/src/main.rs index 78e17a3846..2c5748960d 100644 --- a/listings/ch17-async-await/listing-17-18/src/main.rs +++ b/listings/ch17-async-await/listing-17-18/src/main.rs @@ -1,11 +1,17 @@ -use std::time::Duration; +extern crate trpl; // required for mdbook test + +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; fn main() { trpl::block_on(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); - let tx1_fut = async move { + let tx1_fut = pin!(async move { let vals = vec![ String::from("hi"), String::from("from"), @@ -17,15 +23,15 @@ fn main() { tx1.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }; + }); - let rx_fut = async { + let rx_fut = pin!(async { while let Some(value) = rx.recv().await { println!("received '{value}'"); } - }; + }); - let tx_fut = async move { + let tx_fut = pin!(async move { let vals = vec![ String::from("more"), String::from("messages"), @@ -37,11 +43,13 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }; + }); // ANCHOR: here - let futures = vec![tx1_fut, rx_fut, tx_fut]; - trpl::join_all(futures).await; + let futures: Vec>> = + vec![tx1_fut, rx_fut, tx_fut]; // ANCHOR_END: here + + trpl::join_all(futures).await; }); } diff --git a/listings/ch17-async-await/listing-17-19/Cargo.lock b/listings/ch17-async-await/listing-17-19/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-19/Cargo.lock +++ b/listings/ch17-async-await/listing-17-19/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-19/src/main.rs b/listings/ch17-async-await/listing-17-19/src/main.rs index 6603223a5b..2088dbe21a 100644 --- a/listings/ch17-async-await/listing-17-19/src/main.rs +++ b/listings/ch17-async-await/listing-17-19/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + fn main() { trpl::block_on(async { // ANCHOR: here diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index afc00eb3e8..1b9c377f5c 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -239,6 +239,9 @@ Let’s look again at the definition of `Future`, focusing now on its `poll` method’s `self` type: ```rust +use std::pin::Pin; +use std::task::{Context, Poll}; + pub trait Future { type Output; From 0aacb80bf22e36640e07950ebbaaad8fef3a79aa Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Jul 2024 15:12:54 -0600 Subject: [PATCH 489/720] =?UTF-8?q?Ch.=2017=C2=A704:=20Make=20code/listing?= =?UTF-8?q?s=20pass=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update all the listings in the chapter to use `extern crate` since `mdbook test` does not understand Rust 2018. Alas. - Ignore a listing which has a missing body apurpose. --- listings/ch17-async-await/listing-17-20/src/main.rs | 2 ++ listings/ch17-async-await/listing-17-21/src/main.rs | 2 ++ listings/ch17-async-await/listing-17-22/src/main.rs | 2 ++ listings/ch17-async-await/listing-17-23/src/main.rs | 2 ++ listings/ch17-async-await/listing-17-24/src/main.rs | 2 ++ listings/ch17-async-await/listing-17-25/src/main.rs | 2 ++ listings/ch17-async-await/listing-17-26/src/main.rs | 2 ++ listings/ch17-async-await/listing-17-27/src/main.rs | 2 ++ listings/ch17-async-await/listing-17-28/src/main.rs | 2 ++ src/ch17-04-more-ways-of-combining-futures.md | 4 +++- 10 files changed, 21 insertions(+), 1 deletion(-) diff --git a/listings/ch17-async-await/listing-17-20/src/main.rs b/listings/ch17-async-await/listing-17-20/src/main.rs index eb86c1a486..0ac89fe6c1 100644 --- a/listings/ch17-async-await/listing-17-20/src/main.rs +++ b/listings/ch17-async-await/listing-17-20/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::time::Duration; fn main() { diff --git a/listings/ch17-async-await/listing-17-21/src/main.rs b/listings/ch17-async-await/listing-17-21/src/main.rs index 9d8dedfb3b..fa5cfe3c80 100644 --- a/listings/ch17-async-await/listing-17-21/src/main.rs +++ b/listings/ch17-async-await/listing-17-21/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{thread, time::Duration}; fn main() { diff --git a/listings/ch17-async-await/listing-17-22/src/main.rs b/listings/ch17-async-await/listing-17-22/src/main.rs index e9474873c9..55975462fa 100644 --- a/listings/ch17-async-await/listing-17-22/src/main.rs +++ b/listings/ch17-async-await/listing-17-22/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{thread, time::Duration}; fn main() { diff --git a/listings/ch17-async-await/listing-17-23/src/main.rs b/listings/ch17-async-await/listing-17-23/src/main.rs index ae9536c5bd..f9c795fc0c 100644 --- a/listings/ch17-async-await/listing-17-23/src/main.rs +++ b/listings/ch17-async-await/listing-17-23/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{thread, time::Duration}; fn main() { diff --git a/listings/ch17-async-await/listing-17-24/src/main.rs b/listings/ch17-async-await/listing-17-24/src/main.rs index 7efd8fff9a..e95e286a39 100644 --- a/listings/ch17-async-await/listing-17-24/src/main.rs +++ b/listings/ch17-async-await/listing-17-24/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{thread, time::Duration}; fn main() { diff --git a/listings/ch17-async-await/listing-17-25/src/main.rs b/listings/ch17-async-await/listing-17-25/src/main.rs index ef99235640..eaea8509c3 100644 --- a/listings/ch17-async-await/listing-17-25/src/main.rs +++ b/listings/ch17-async-await/listing-17-25/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::time::{Duration, Instant}; fn main() { diff --git a/listings/ch17-async-await/listing-17-26/src/main.rs b/listings/ch17-async-await/listing-17-26/src/main.rs index 4727e58c48..58c83229d4 100644 --- a/listings/ch17-async-await/listing-17-26/src/main.rs +++ b/listings/ch17-async-await/listing-17-26/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::time::Duration; fn main() { diff --git a/listings/ch17-async-await/listing-17-27/src/main.rs b/listings/ch17-async-await/listing-17-27/src/main.rs index a53169bfb2..d30da0d226 100644 --- a/listings/ch17-async-await/listing-17-27/src/main.rs +++ b/listings/ch17-async-await/listing-17-27/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{future::Future, time::Duration}; fn main() { diff --git a/listings/ch17-async-await/listing-17-28/src/main.rs b/listings/ch17-async-await/listing-17-28/src/main.rs index 639d9c8978..20e81e77c4 100644 --- a/listings/ch17-async-await/listing-17-28/src/main.rs +++ b/listings/ch17-async-await/listing-17-28/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{future::Future, time::Duration}; use trpl::Either; diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index 060cd569f5..6a307f7814 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -223,9 +223,11 @@ Let’s implement this! To begin, let’s think about the API for `timeout`: Listing 17-27 shows this declaration. + + -```rust +```rust,ignore {{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:declaration}} ``` From 40bdda77f8dae1a2142741c7dcabcf6235f95891 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Jul 2024 15:37:01 -0600 Subject: [PATCH 490/720] =?UTF-8?q?Ch.=2017=C2=A705:=20Make=20code/listing?= =?UTF-8?q?s=20pass=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rewrite the `StreamExt` definition to be more correct, and extract it to a standalone “no-listing listing” so we can make sure its definition at least type checks. - Update all the listings in the chapter to use `extern crate` since `mdbook test` does not understand Rust 2018. Alas. - Ignore the listings (inline or otherwise!) which are *intended* not to compile, so mdbook does not try to test them. - Clarify some of the text around the *actual* Tokio definition of the `StreamExt::next` method. --- .../listing-17-29/src/main.rs | 2 + .../listing-17-30/src/main.rs | 2 + .../listing-17-31/src/main.rs | 2 + .../listing-17-32/src/main.rs | 4 ++ .../listing-17-33/src/main.rs | 2 + .../listing-17-34/src/main.rs | 2 + .../listing-17-35/src/main.rs | 2 + .../listing-17-36/src/main.rs | 2 + .../listing-17-37/src/main.rs | 2 + .../listing-17-38/src/main.rs | 2 + .../listing-17-39/src/main.rs | 2 + .../no-listing-stream-ext/Cargo.lock | 7 +++ .../no-listing-stream-ext/Cargo.toml | 6 +++ .../no-listing-stream-ext/output.txt | 14 +++++ .../no-listing-stream-ext/src/lib.rs | 18 +++++++ src/ch17-05-streams.md | 52 ++++++------------- 16 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 listings/ch17-async-await/no-listing-stream-ext/Cargo.lock create mode 100644 listings/ch17-async-await/no-listing-stream-ext/Cargo.toml create mode 100644 listings/ch17-async-await/no-listing-stream-ext/output.txt create mode 100644 listings/ch17-async-await/no-listing-stream-ext/src/lib.rs diff --git a/listings/ch17-async-await/listing-17-29/src/main.rs b/listings/ch17-async-await/listing-17-29/src/main.rs index db9c724d4f..7900b39ce4 100644 --- a/listings/ch17-async-await/listing-17-29/src/main.rs +++ b/listings/ch17-async-await/listing-17-29/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + fn main() { trpl::block_on(async { // ANCHOR: stream diff --git a/listings/ch17-async-await/listing-17-30/src/main.rs b/listings/ch17-async-await/listing-17-30/src/main.rs index ad546a68fc..8f8dd7d93f 100644 --- a/listings/ch17-async-await/listing-17-30/src/main.rs +++ b/listings/ch17-async-await/listing-17-30/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use trpl::StreamExt; fn main() { diff --git a/listings/ch17-async-await/listing-17-31/src/main.rs b/listings/ch17-async-await/listing-17-31/src/main.rs index 5cda39eb4c..d312640b7f 100644 --- a/listings/ch17-async-await/listing-17-31/src/main.rs +++ b/listings/ch17-async-await/listing-17-31/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use trpl::StreamExt; fn main() { diff --git a/listings/ch17-async-await/listing-17-32/src/main.rs b/listings/ch17-async-await/listing-17-32/src/main.rs index 5f818ae9f6..dd1693790d 100644 --- a/listings/ch17-async-await/listing-17-32/src/main.rs +++ b/listings/ch17-async-await/listing-17-32/src/main.rs @@ -1,3 +1,6 @@ +extern crate trpl; // required for mdbook test + +// ANCHOR: all use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { @@ -20,3 +23,4 @@ fn get_messages() -> impl Stream { ReceiverStream::new(rx) } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-33/src/main.rs b/listings/ch17-async-await/listing-17-33/src/main.rs index c99c1f3636..6ad2bc72f9 100644 --- a/listings/ch17-async-await/listing-17-33/src/main.rs +++ b/listings/ch17-async-await/listing-17-33/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + // ANCHOR: timeout use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; diff --git a/listings/ch17-async-await/listing-17-34/src/main.rs b/listings/ch17-async-await/listing-17-34/src/main.rs index 4dc6ed1fdb..7446a2e795 100644 --- a/listings/ch17-async-await/listing-17-34/src/main.rs +++ b/listings/ch17-async-await/listing-17-34/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; diff --git a/listings/ch17-async-await/listing-17-35/src/main.rs b/listings/ch17-async-await/listing-17-35/src/main.rs index 5dbcb1d96e..a2b36ca487 100644 --- a/listings/ch17-async-await/listing-17-35/src/main.rs +++ b/listings/ch17-async-await/listing-17-35/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; diff --git a/listings/ch17-async-await/listing-17-36/src/main.rs b/listings/ch17-async-await/listing-17-36/src/main.rs index dde9b34c6f..b4cb9c094c 100644 --- a/listings/ch17-async-await/listing-17-36/src/main.rs +++ b/listings/ch17-async-await/listing-17-36/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; diff --git a/listings/ch17-async-await/listing-17-37/src/main.rs b/listings/ch17-async-await/listing-17-37/src/main.rs index 4d2c747cc7..4e28174860 100644 --- a/listings/ch17-async-await/listing-17-37/src/main.rs +++ b/listings/ch17-async-await/listing-17-37/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; diff --git a/listings/ch17-async-await/listing-17-38/src/main.rs b/listings/ch17-async-await/listing-17-38/src/main.rs index 5103787668..899d14fc23 100644 --- a/listings/ch17-async-await/listing-17-38/src/main.rs +++ b/listings/ch17-async-await/listing-17-38/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; diff --git a/listings/ch17-async-await/listing-17-39/src/main.rs b/listings/ch17-async-await/listing-17-39/src/main.rs index 15a3fddd30..1b4e686ea2 100644 --- a/listings/ch17-async-await/listing-17-39/src/main.rs +++ b/listings/ch17-async-await/listing-17-39/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; diff --git a/listings/ch17-async-await/no-listing-stream-ext/Cargo.lock b/listings/ch17-async-await/no-listing-stream-ext/Cargo.lock new file mode 100644 index 0000000000..d30b928a6c --- /dev/null +++ b/listings/ch17-async-await/no-listing-stream-ext/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "async_await" +version = "0.1.0" diff --git a/listings/ch17-async-await/no-listing-stream-ext/Cargo.toml b/listings/ch17-async-await/no-listing-stream-ext/Cargo.toml new file mode 100644 index 0000000000..67729afc80 --- /dev/null +++ b/listings/ch17-async-await/no-listing-stream-ext/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch17-async-await/no-listing-stream-ext/output.txt b/listings/ch17-async-await/no-listing-stream-ext/output.txt new file mode 100644 index 0000000000..46e6cd3111 --- /dev/null +++ b/listings/ch17-async-await/no-listing-stream-ext/output.txt @@ -0,0 +1,14 @@ +$ cargo run + Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-01) +warning: unused implementer of `Future` that must be used + --> src/main.rs:3:5 + | +3 | hello("async"); + | ^^^^^^^^^^^^^^ + | + = note: futures do nothing unless you `.await` or poll them + = note: `#[warn(unused_must_use)]` on by default + +warning: `async_await` (bin "async_await") generated 1 warning + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s + Running `target/debug/async_await` diff --git a/listings/ch17-async-await/no-listing-stream-ext/src/lib.rs b/listings/ch17-async-await/no-listing-stream-ext/src/lib.rs new file mode 100644 index 0000000000..e236c99260 --- /dev/null +++ b/listings/ch17-async-await/no-listing-stream-ext/src/lib.rs @@ -0,0 +1,18 @@ +use std::pin::Pin; +use std::task::{Context, Poll}; + +trait Stream { + type Item; + fn poll_next( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll>; +} + +// ANCHOR: here +trait StreamExt: Stream { + async fn next(&mut self) -> Option + where + Self: Unpin; +} +// ANCHOR_END: here diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index 49b69f6246..7824c391db 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -21,7 +21,7 @@ method, and then awaiting the output, as in Listing 17-29. -```rust,does_not_compile +```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:stream}} ``` @@ -112,32 +112,6 @@ press time! --> but there *is* a very common definition used throughout the ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, so we can build up to how a `Stream` trait that merges them together might look. -The `Iterator` trait defines an associated type `Item` and a function `next`, -which produces `Some(Item)` until the underlying iterator is empty, and then -produces `None`. - - - -```rust -trait Iterator { - type Item; - - fn next(&mut self) -> Option; -} -``` - -The `Future` trait defines an associated item `Output` and a function `poll`, -which produces `Poll::Pending` while waiting and then `Poll::Ready(Output)` once -the future is ready. - -```rust -trait Future { - type Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; -} -``` - From `Iterator`, we have the idea of a sequence: its `next` method provides an `Option`. From `Future`, we have the idea of readiness over time: its `poll` method provides a `Poll`. To represent a sequence of @@ -145,6 +119,9 @@ items which become ready over time, we define a `Stream` trait which has all of those features put together: ```rust +use std::pin::Pin; +use std::task::{Context, Poll}; + trait Stream { type Item; @@ -178,9 +155,7 @@ is much nicer, though, so the `StreamExt` trait supplies the `next` method so we can do just that. ```rust -trait StreamExt { - async fn next(&mut self) -> Option; -} +{{#rustdoc_include ../listings/ch17-async-await/no-listing-stream-ext/src/lib.rs:here}} ``` + -```rust +```rust,ignore {{#rustdoc_include ../listings/ch17-async-await/listing-17-37/src/main.rs:main}} ``` From 5099e5fb554103a093ded93c126526ea97b41728 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Jul 2024 15:43:14 -0600 Subject: [PATCH 491/720] =?UTF-8?q?Ch.=2017=C2=A706:=20Make=20code=20listi?= =?UTF-8?q?ng=20pass=20tests=20and=20add=20a=20caption?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- listings/ch17-async-await/listing-17-40/src/main.rs | 4 ++++ src/ch17-06-futures-tasks-threads.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/listings/ch17-async-await/listing-17-40/src/main.rs b/listings/ch17-async-await/listing-17-40/src/main.rs index d25f8492ce..7bd605d528 100644 --- a/listings/ch17-async-await/listing-17-40/src/main.rs +++ b/listings/ch17-async-await/listing-17-40/src/main.rs @@ -1,3 +1,5 @@ +extern crate trpl; // required for mdbook test + use std::{pin::pin, thread, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; @@ -45,9 +47,11 @@ fn get_messages() -> impl Stream { fn get_intervals() -> impl Stream { let (tx, rx) = trpl::channel(); + // This is *not* `trpl::spawn` but `std::thread::spawn`! thread::spawn(move || { let mut count = 0; loop { + // Likewise, this is *not* `trpl::sleep` but `std::thread::sleep`! thread::sleep(Duration::from_millis(1)); count += 1; diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 5a65ab66af..24c96d1c09 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -29,7 +29,7 @@ could do the exact same thing with a thread! In Listing 17-39, we used the `thread::spawn` and `thread::sleep` APIs from the standard library in the `get_intervals` function. -+ ```rust {{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:threads}} From d10039ff03a2a429ef0d385884236cd30d349721 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 17 Jul 2024 15:50:32 -0600 Subject: [PATCH 492/720] infra: support test renderer in mdbook preprocessors This does not change the actual behavior of `mdbook test`, but it does get rid of a warning about the test renderer being unsupported! --- packages/mdbook-trpl-listing/src/lib.rs | 2 +- packages/mdbook-trpl-note/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index a1fbfb597e..7be63e4ae4 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -98,7 +98,7 @@ impl Preprocessor for TrplListing { } fn supports_renderer(&self, renderer: &str) -> bool { - renderer == "html" || renderer == "markdown" + renderer == "html" || renderer == "markdown" || renderer == "test" } } diff --git a/packages/mdbook-trpl-note/src/lib.rs b/packages/mdbook-trpl-note/src/lib.rs index 1508a566ed..115641bac2 100644 --- a/packages/mdbook-trpl-note/src/lib.rs +++ b/packages/mdbook-trpl-note/src/lib.rs @@ -49,7 +49,7 @@ impl Preprocessor for TrplNote { } fn supports_renderer(&self, renderer: &str) -> bool { - renderer == "html" || renderer == "markdown" + renderer == "html" || renderer == "markdown" || renderer == "test" } } From 45f163588d17506e4536d84f7a57b6e24bfd9d17 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 22 Jul 2024 10:36:12 -0600 Subject: [PATCH 493/720] Ch. 17: fix spelling issues --- ci/dictionary.txt | 23 +++++++++++++++++++ src/ch17-03-more-futures.md | 2 +- src/ch17-04-more-ways-of-combining-futures.md | 2 +- src/ch17-05-streams.md | 4 ++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 6329ed1238..9fd8e33e41 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -55,6 +55,7 @@ bool boolean Boolean Booleans +booleans Bors BorrowMutError BoxMeUp @@ -109,6 +110,7 @@ deallocate deallocated deallocating deallocation +debounce debuginfo decl decrementing @@ -145,6 +147,7 @@ DisplayBacktrace DivAssign DraftPost DSTs +durations ebook ebooks Edsger @@ -179,6 +182,7 @@ filesystem's filesystems filmmaking Firefox +FirstAwaitPoint FnMut FnOnce formatter @@ -197,6 +201,7 @@ grapheme Grapheme growable gzip +handoff hardcode hardcoded hardcoding @@ -241,6 +246,7 @@ inline instantiation internet interoperate +IntoFuture IntoIterator InvalidDigit invariants @@ -256,6 +262,7 @@ isize iter iterator's JavaScript +JoinAll JoinHandle Kay's kinded @@ -294,6 +301,8 @@ Metadata metaprogramming mibbit Mibbit +microcontroller +microcontrollers millis minigrep mixup @@ -307,10 +316,12 @@ monomorphized MoveMessage Mozilla mpsc +MSRV msvc MulAssign multibyte multithreaded +multithreading mutex mutex's Mutex @@ -318,6 +329,7 @@ mutexes Mutexes MutexGuard mutext +MyAsyncStateMachine MyBox myprogram namespace @@ -359,6 +371,7 @@ OutlinePrint overloadable overread PanicPayload +parallelizable param parameterize ParseIntError @@ -371,6 +384,7 @@ PlaceholderType polymorphism PoolCreationError portia +postfix powershell PowerShell powi @@ -396,6 +410,8 @@ RangeTo RangeFull README READMEs +ReadFinished +ReceiverStream rect recurse recv @@ -438,6 +454,7 @@ sampleproject screenshot searchstring SecondaryColor +SecondAwaitPoint SelectBox semver SemVer @@ -455,6 +472,7 @@ SliceIndex Smalltalk snuck someproject +SomeType someusername SPDX spdx @@ -470,6 +488,7 @@ stdlib stdout steveklabnik's stringify +StreamExt Stroustrup Stroustrup's struct @@ -514,6 +533,8 @@ tlborm tlsv TODO TokenStream +Tokio +tokio toml TOML toolchain @@ -538,6 +559,7 @@ uncomment Uncomment uncommenting unevaluated +unhandled Uninstalling uninstall unittests @@ -556,6 +578,7 @@ username USERPROFILE usize UsState +util utils vals variable's diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 1b9c377f5c..b27e68ad73 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -154,7 +154,7 @@ That already made a big difference. Now when we run the compiler, we only have the errors mentioning `Unpin`. Although there are three of them, notice that each is very similar in its contents. - > Note: The actual definition we will use looks slightly different than this, From 463b819a750d4376eb36305187c67b0c56647cd3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 22 Jul 2024 12:04:09 -0600 Subject: [PATCH 494/720] Ch. 17: fix internal links with new ch. order Note: this does *not* include all fixes for the text, only for the links themselves. For the text, we will also need to search for references to chapters 17-20. This catches a few of those along the way, but there are no doubt others. --- 2018-edition/src/ch17-03-oo-design-patterns.md | 4 ++-- second-edition/src/ch17-03-oo-design-patterns.md | 4 ++-- second-edition/src/ch18-00-patterns.md | 4 ++-- src/appendix-03-derivable-traits.md | 2 +- src/ch05-03-method-syntax.md | 2 +- src/ch06-02-match.md | 5 +++-- src/ch09-02-recoverable-errors-with-result.md | 2 +- src/ch09-03-to-panic-or-not-to-panic.md | 2 +- src/ch10-02-traits.md | 2 +- src/ch12-00-an-io-project.md | 2 +- src/ch12-03-improving-error-handling-and-modularity.md | 2 +- src/ch15-01-box.md | 2 +- src/ch17-05-streams.md | 2 +- src/ch17-06-futures-tasks-threads.md | 6 +++--- src/ch18-02-trait-objects.md | 2 +- src/ch18-03-oo-design-patterns.md | 2 +- src/ch19-01-all-the-places-for-patterns.md | 2 +- src/ch20-03-advanced-traits.md | 2 +- src/ch20-04-advanced-types.md | 6 +++--- src/ch20-05-advanced-functions-and-closures.md | 6 +++--- src/ch21-02-multithreaded.md | 2 +- 21 files changed, 32 insertions(+), 31 deletions(-) diff --git a/2018-edition/src/ch17-03-oo-design-patterns.md b/2018-edition/src/ch17-03-oo-design-patterns.md index 1b74425fe2..9513538f57 100644 --- a/2018-edition/src/ch17-03-oo-design-patterns.md +++ b/2018-edition/src/ch17-03-oo-design-patterns.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-03-oo-design-patterns.html) instead. +version of the book](../ch18-03-oo-design-patterns.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-03-oo-design-patterns.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-03-oo-design-patterns.html). diff --git a/second-edition/src/ch17-03-oo-design-patterns.md b/second-edition/src/ch17-03-oo-design-patterns.md index 46bec2692f..b29dc2393c 100644 --- a/second-edition/src/ch17-03-oo-design-patterns.md +++ b/second-edition/src/ch17-03-oo-design-patterns.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-03-oo-design-patterns.html) instead. +version of the book](../ch18-03-oo-design-patterns.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch17-03-oo-design-patterns.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch17-03-oo-design-patterns.html). diff --git a/second-edition/src/ch18-00-patterns.md b/second-edition/src/ch18-00-patterns.md index 6bd221fa3c..e315b35274 100644 --- a/second-edition/src/ch18-00-patterns.md +++ b/second-edition/src/ch18-00-patterns.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-00-patterns.html) instead. +version of the book](../ch19-00-patterns.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch18-00-patterns.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch18-00-patterns.html). diff --git a/src/appendix-03-derivable-traits.md b/src/appendix-03-derivable-traits.md index 8b9b3d3584..d3951f9e5f 100644 --- a/src/appendix-03-derivable-traits.md +++ b/src/appendix-03-derivable-traits.md @@ -184,4 +184,4 @@ ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struc ch04-01-what-is-ownership.html#stack-only-data-copy [ways-variables-and-data-interact-clone]: ch04-01-what-is-ownership.html#ways-variables-and-data-interact-clone -[macros]: ch19-06-macros.html#macros +[macros]: ch20-06-macros.html#macros diff --git a/src/ch05-03-method-syntax.md b/src/ch05-03-method-syntax.md index d25e55b18c..f806021687 100644 --- a/src/ch05-03-method-syntax.md +++ b/src/ch05-03-method-syntax.md @@ -250,6 +250,6 @@ But structs aren’t the only way you can create custom types: let’s turn to Rust’s enum feature to add another tool to your toolbox. [enums]: ch06-00-enums.html -[trait-objects]: ch17-02-trait-objects.md +[trait-objects]: ch18-02-trait-objects.md [public]: ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#exposing-paths-with-the-pub-keyword [modules]: ch07-02-defining-modules-to-control-scope-and-privacy.html diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index 6a510df402..bdb5244100 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -246,9 +246,10 @@ that doesn’t match a pattern in an earlier arm, and we don’t want to run any code in this case. There’s more about patterns and matching that we’ll cover in [Chapter -18][ch18-00-patterns]. For now, we’re going to move on to the +19][ch19-00-patterns]. For now, we’re going to move on to the `if let` syntax, which can be useful in situations where the `match` expression is a bit wordy. [tuples]: ch03-02-data-types.html#the-tuple-type -[ch18-00-patterns]: ch18-00-patterns.html + +[ch19-00-patterns]: ch19-00-patterns.html diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 35bcd11474..78a87c7392 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -533,5 +533,5 @@ let’s return to the topic of how to decide which is appropriate to use in whic cases. [handle_failure]: ch02-00-guessing-game-tutorial.html#handling-potential-failure-with-result -[trait-objects]: ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types +[trait-objects]: ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types [termination]: ../std/process/trait.Termination.html diff --git a/src/ch09-03-to-panic-or-not-to-panic.md b/src/ch09-03-to-panic-or-not-to-panic.md index 40f93d67ce..138a783d00 100644 --- a/src/ch09-03-to-panic-or-not-to-panic.md +++ b/src/ch09-03-to-panic-or-not-to-panic.md @@ -219,4 +219,4 @@ Now that you’ve seen useful ways that the standard library uses generics with the `Option` and `Result` enums, we’ll talk about how generics work and how you can use them in your code. -[encoding]: ch17-03-oo-design-patterns.html#encoding-states-and-behavior-as-types +[encoding]: ch18-03-oo-design-patterns.html#encoding-states-and-behavior-as-types diff --git a/src/ch10-02-traits.md b/src/ch10-02-traits.md index 53e9b8115c..855ee1fc4b 100644 --- a/src/ch10-02-traits.md +++ b/src/ch10-02-traits.md @@ -385,5 +385,5 @@ that checks for behavior at runtime because we’ve already checked at compile time. Doing so improves performance without having to give up the flexibility of generics. -[using-trait-objects-that-allow-for-values-of-different-types]: ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types +[using-trait-objects-that-allow-for-values-of-different-types]: ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types [methods]: ch05-03-method-syntax.html#defining-methods diff --git a/src/ch12-00-an-io-project.md b/src/ch12-00-an-io-project.md index bae99c75f7..7780ac2738 100644 --- a/src/ch12-00-an-io-project.md +++ b/src/ch12-00-an-io-project.md @@ -47,4 +47,4 @@ detail. [ch10]: ch10-00-generics.html [ch11]: ch11-00-testing.html [ch13]: ch13-00-functional-features.html -[ch17]: ch17-00-oop.html +[ch17]: ch18-00-oop.html diff --git a/src/ch12-03-improving-error-handling-and-modularity.md b/src/ch12-03-improving-error-handling-and-modularity.md index 0de3ec2c22..bcff43a6d9 100644 --- a/src/ch12-03-improving-error-handling-and-modularity.md +++ b/src/ch12-03-improving-error-handling-and-modularity.md @@ -491,5 +491,5 @@ write some tests! [ch9-custom-types]: ch09-03-to-panic-or-not-to-panic.html#creating-custom-types-for-validation [ch9-error-guidelines]: ch09-03-to-panic-or-not-to-panic.html#guidelines-for-error-handling [ch9-result]: ch09-02-recoverable-errors-with-result.html -[ch17]: ch17-00-oop.html +[ch17]: ch18-00-oop.html [ch9-question-mark]: ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator diff --git a/src/ch15-01-box.md b/src/ch15-01-box.md index 53e829a4c3..1878f6f195 100644 --- a/src/ch15-01-box.md +++ b/src/ch15-01-box.md @@ -252,4 +252,4 @@ even more important to the functionality provided by the other smart pointer types we’ll discuss in the rest of this chapter. Let’s explore these two traits in more detail. -[trait-objects]: ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types +[trait-objects]: ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index 1a3a9b850f..8a44d37059 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -508,4 +508,4 @@ That is a good note to turn to our final section and wrap up this walk through async in Rust, by discussing how futures (including streams), tasks, and threads relate to each other, and how you can use them together. -[17-02-messages]: /ch17-02-concurrency-with-async.md#message-passing +[17-02-messages]: ch17-02-concurrency-with-async.md#message-passing diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 24c96d1c09..7ee933c4f7 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -74,7 +74,7 @@ up correctly. These limitations make threads harder to compose than futures. It is much more difficult, for example, to build something like the `timeout` we built in [“Building Our Own Async Abstractions”][combining-futures], or the `throttle` -method we used with streams in [“Working With Streams”][streams]. The fact that +method we used with streams in [“Composing Streams”][streams]. The fact that futures are richer data structures means they *can* be composed together more naturally, as we have seen. @@ -116,5 +116,5 @@ as your Rust programs get bigger. In addition, we’ll discuss how Rust’s idio relate to those you might be familiar with from object-oriented programming. -[combining-futures]: /ch17-04-more-ways-of-combining-futures.md#building-our-own-async-abstractions -[streams]: /ch17-05-streams.md#working-with-streams +[combining-futures]: ch17-04-more-ways-of-combining-futures.md#building-our-own-async-abstractions +[streams]: ch17-05-streams.md#composing-streams diff --git a/src/ch18-02-trait-objects.md b/src/ch18-02-trait-objects.md index 2d3fea24a1..c6a90ab2ff 100644 --- a/src/ch18-02-trait-objects.md +++ b/src/ch18-02-trait-objects.md @@ -253,4 +253,4 @@ support in Listing 17-9, so it’s a trade-off to consider. [performance-of-code-using-generics]: ch10-01-syntax.html#performance-of-code-using-generics -[dynamically-sized]: ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait +[dynamically-sized]: ch20-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait diff --git a/src/ch18-03-oo-design-patterns.md b/src/ch18-03-oo-design-patterns.md index 13503ef02b..6044841631 100644 --- a/src/ch18-03-oo-design-patterns.md +++ b/src/ch18-03-oo-design-patterns.md @@ -513,4 +513,4 @@ lots of flexibility. We’ve looked at them briefly throughout the book but haven’t seen their full capability yet. Let’s go! [more-info-than-rustc]: ch09-03-to-panic-or-not-to-panic.html#cases-in-which-you-have-more-information-than-the-compiler -[macros]: ch19-06-macros.html#macros +[macros]: ch20-06-macros.html#macros diff --git a/src/ch19-01-all-the-places-for-patterns.md b/src/ch19-01-all-the-places-for-patterns.md index 58f5af573b..e6f9ebd2cb 100644 --- a/src/ch19-01-all-the-places-for-patterns.md +++ b/src/ch19-01-all-the-places-for-patterns.md @@ -247,4 +247,4 @@ be irrefutable; in other circumstances, they can be refutable. We’ll discuss these two concepts next. [ignoring-values-in-a-pattern]: -ch18-03-pattern-syntax.html#ignoring-values-in-a-pattern +ch19-03-pattern-syntax.html#ignoring-values-in-a-pattern diff --git a/src/ch20-03-advanced-traits.md b/src/ch20-03-advanced-traits.md index 789591357b..a32b0e1da7 100644 --- a/src/ch20-03-advanced-traits.md +++ b/src/ch20-03-advanced-traits.md @@ -459,7 +459,7 @@ behavior—we would have to implement just the methods we do want manually. This newtype pattern is also useful even when traits are not involved. Let’s switch focus and look at some advanced ways to interact with Rust’s type system. -[newtype]: ch19-03-advanced-traits.html#using-the-newtype-pattern-to-implement-external-traits-on-external-types +[newtype]: ch20-03-advanced-traits.html#using-the-newtype-pattern-to-implement-external-traits-on-external-types [implementing-a-trait-on-a-type]: ch10-02-traits.html#implementing-a-trait-on-a-type [traits-defining-shared-behavior]: diff --git a/src/ch20-04-advanced-types.md b/src/ch20-04-advanced-types.md index 2dfed23cca..427c108aa4 100644 --- a/src/ch20-04-advanced-types.md +++ b/src/ch20-04-advanced-types.md @@ -288,10 +288,10 @@ pointer. In this case, we’ve chosen a reference. Next, we’ll talk about functions and closures! [encapsulation-that-hides-implementation-details]: -ch17-01-what-is-oo.html#encapsulation-that-hides-implementation-details +ch18-01-what-is-oo.html#encapsulation-that-hides-implementation-details [string-slices]: ch04-03-slices.html#string-slices [the-match-control-flow-operator]: ch06-02-match.html#the-match-control-flow-operator [using-trait-objects-that-allow-for-values-of-different-types]: -ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types -[using-the-newtype-pattern]: ch19-03-advanced-traits.html#using-the-newtype-pattern-to-implement-external-traits-on-external-types +ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types +[using-the-newtype-pattern]: ch20-03-advanced-traits.html#using-the-newtype-pattern-to-implement-external-traits-on-external-types diff --git a/src/ch20-05-advanced-functions-and-closures.md b/src/ch20-05-advanced-functions-and-closures.md index 88c46847d5..d0de1dfd0a 100644 --- a/src/ch20-05-advanced-functions-and-closures.md +++ b/src/ch20-05-advanced-functions-and-closures.md @@ -119,12 +119,12 @@ We can use a trait object: This code will compile just fine. For more about trait objects, refer to the section [“Using Trait Objects That Allow for Values of Different Types”][using-trait-objects-that-allow-for-values-of-different-types] in Chapter 17. +ignore --> in Chapter 18. Next, let’s look at macros! [advanced-traits]: -ch19-03-advanced-traits.html#advanced-traits +ch20-03-advanced-traits.html#advanced-traits [enum-values]: ch06-01-defining-an-enum.html#enum-values [using-trait-objects-that-allow-for-values-of-different-types]: -ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types +ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index cec2272db5..82d6fdf8f6 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -690,7 +690,7 @@ the associated block. In Listing 20-21, the lock remains held for the duration of the call to `job()`, meaning other workers cannot receive jobs. [creating-type-synonyms-with-type-aliases]: -ch19-04-advanced-types.html#creating-type-synonyms-with-type-aliases +ch20-04-advanced-types.html#creating-type-synonyms-with-type-aliases [integer-types]: ch03-02-data-types.html#integer-types [fn-traits]: ch13-01-closures.html#moving-captured-values-out-of-the-closure-and-the-fn-traits From 644dbab3d6d8f392905bdb609ea77f5d34d4fc02 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 22 Jul 2024 12:17:39 -0600 Subject: [PATCH 495/720] Ch. 17: fix an internal link reference --- src/ch06-02-match.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index bdb5244100..eec1ac4a89 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -6,7 +6,7 @@ Rust has an extremely powerful control flow construct called `match` that allows you to compare a value against a series of patterns and then execute code based on which pattern matches. Patterns can be made up of literal values, variable names, wildcards, and many other things; [Chapter -18][ch18-00-patterns] covers all the different kinds of patterns +18][ch19-00-patterns] covers all the different kinds of patterns and what they do. The power of `match` comes from the expressiveness of the patterns and the fact that the compiler confirms that all possible cases are handled. From 90994ca7abb02ffdbeccd19ab55df52a6c7f222c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 22 Jul 2024 12:37:38 -0600 Subject: [PATCH 496/720] infra: fix some shellcheck issues in CI config --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 77495c09aa..1737bce009 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: run: | mkdir bin curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.21/mdbook-v0.4.21-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin - echo "$(pwd)/bin" >> ${GITHUB_PATH} + echo "$(pwd)/bin" >> "${GITHUB_PATH}" - name: Report versions run: | rustup --version @@ -65,7 +65,7 @@ jobs: run: | mkdir bin curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.21/mdbook-v0.4.21-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin - echo "$(pwd)/bin" >> ${GITHUB_PATH} + echo "$(pwd)/bin" >> "${GITHUB_PATH}" - name: Install mdbook-trpl-note run: cargo install --path packages/mdbook-trpl-note - name: Install mdbook-trpl-listing @@ -82,7 +82,7 @@ jobs: aspell --version shellcheck --version - name: Shellcheck - run: find . -name '*.sh' | xargs shellcheck + run: find . -name '*.sh' -print0 | xargs -0 shellcheck - name: Spellcheck run: bash ci/spellcheck.sh list - name: Lint for local file paths From e2a5258f8324644c806cfdd661ac64093a65732d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 4 Mar 2024 12:22:37 -0700 Subject: [PATCH 497/720] Clarify function definitions vs. expressions Fixes #2980. --- src/ch03-03-how-functions-work.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch03-03-how-functions-work.md b/src/ch03-03-how-functions-work.md index b282cbb2ab..bb8c73a62f 100644 --- a/src/ch03-03-how-functions-work.md +++ b/src/ch03-03-how-functions-work.md @@ -125,7 +125,8 @@ assigning a value to it with the `let` keyword is a statement. In Listing 3-1, Function definitions are also statements; the entire preceding example is a -statement in itself. +statement in itself. (As we will see below, *calling* a function is not a +statement.) Statements do not return values. Therefore, you can’t assign a `let` statement to another variable, as the following code tries to do; you’ll get an error: From e6692504c64d56437d5395fd78fd39dfcca10cc1 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 23 Jul 2024 16:00:01 -0600 Subject: [PATCH 498/720] =?UTF-8?q?Ch.=2017=C2=A700:=20phrasing/wording-le?= =?UTF-8?q?vel=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tim McNamara Co-authored-by: James Munns --- src/ch17-00-async-await.md | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 52fe3f8468..3acc65b1c6 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -38,25 +38,25 @@ That would be a pretty frustrating experience, though. Instead, your computer can (and does!) invisibly interrupt the export often enough to let you get other work done along the way. -The file download is different. It does not take up very much CPU time. You are -mostly waiting on data to transfer across the network. You can start reading -from a network socket, but it might take a while for all the data to arrive and -be fed into the socket by the network controller. Even once the data has all -arrived, videos can be quite large, so it might take some time to load all the -data from the socket. Maybe it only takes a second or two—but that is a very -long time for a modern processor, which can do billions of operations every -second. It would be nice to be able to put the CPU to use for other work while -waiting for the network call to finish—so, again, your computer will once again -invisibly interrupt your program so other things can happen while the network -operation is still ongoing. +The file download is different. It does not take up very much CPU time. The CPU +needs to wait on data to arrive from the network. While you can start reading +the data once some of it arrives, it might take a while for the rest to arrive. +Even once the data has all arrived, videos can be quite large, so it might take +some time to load all the data from the socket. Maybe it only takes a second or +two—but that is a very long time for a modern processor, which can do billions +of operations every second. It would be nice to be able to put the CPU to use +for other work while waiting for the network call to finish—so, again, your +computer will once again invisibly interrupt your program so other things can +happen while the network operation is still ongoing. > Note: The video export is the kind of operation which is often described as -> “CPU-bound”. It is limited by the speed of the computer’s *CPU and GPU*, and -> how much of that speed it can use. The video download is the kind of operation -> which is often described as “IO-bound,” because it is limited by the speed of -> the computer’s *input and output*. It can only go as fast as the data can be -> sent across the network, which means that it can only go as fast as the data -> can be written to the socket by the network controller. +> “CPU-bound” or “compute-bound”. It is limited by the speed of the computer’s +> ability to process data within the *CPU* or *GPU*, and how much of that speed +> it can use. The video download is the kind of operation which is often +> described as “IO-bound,” because it is limited by the speed of the computer’s +> *input and output*. It can only go as fast as the data can be sent across the +> network, which means that it can only go as fast as the data can be written to +> the socket by the network controller. In both of these examples, the concurrency only happens at the level of a whole program. The operating system interrupts one program to let other @@ -68,8 +68,8 @@ For example, if we are building a tool to manage file downloads, we should be able to write our program in such a way that starting one download does not lock up the UI, and users should be able to start multiple downloads at the same time. Many operating system APIs for interacting with network sockets are -*blocking*, though. That is, the function calls block further progress in the -program when they are called until they return. +*blocking*, though. That is, these APIs block the program’s progress until the +data that they are processing is completely ready. > Note: This is how *most* function calls work, if you think about it! However, > we normally reserve the term “blocking” for function calls which interact with @@ -77,8 +77,8 @@ program when they are called until they return. > the places where an individual program would benefit from the operation being > *non*-blocking. -We could use threads to avoid blocking while downloading files, by using a -dedicated thread. But it would be nicer if the call were not blocking in the +We could avoid blocking our main thread, by spawning a dedicated thread to +download each file. But it would be nicer if the call were not blocking in the first place. One way to accomplish that would be to use an API built around callbacks. For From 133bb617d7c7c463e3894a25e96f8677fa8e925f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 23 Jul 2024 17:12:12 -0600 Subject: [PATCH 499/720] =?UTF-8?q?Ch.=2017=C2=A700:=20phrasing/wording-le?= =?UTF-8?q?vel=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Carol (Nichols || Goulding) Co-authored-by: Will Crichton Co-authored-by: Tim McNamara --- src/ch17-01-futures-and-syntax.md | 34 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 146697e919..272471247a 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -58,10 +58,13 @@ Let’s walk through each part of the transformed version: * The returned trait is a `Future`, with an associated type of `Output`. Notice that the `Output` type is `()`, which is the same as the the original return type from the `async fn` version of `hello`. -* The whole body of the function is wrapped in an `async move` block. Remember - that blocks are expressions. This whole block is the expression returned from - the function. It is an `async move` block -* It names the fact that +* All of the code called in the body of the original function is wrapped in an + `async move` block. Remember that blocks are expressions. This whole block is + the expression returned from the function. +* The new function body is an `async move` block because of how it uses the + `name` argument. +* The new version of the function makes the lifetime of the `name` parameter + explicit so that it can reference it in the output type. * The async block itself has the “unit” value `()`, since it ends with a `println!` statement. That value matches the `Output` type in the return type. @@ -73,10 +76,11 @@ return type of the original `async fn`. Thus, calling `hello` in Listing 17-1 returned a `Future`. Then Rust warned us that we did not do anything with the future. This is because -futures are *lazy*: they don’t do anything until you ask them to. This should -remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. -Iterators do nothing unless you call their `.next()` method—whether directly, or -using `for` loops or methods like `.map()` which use `.next()` under the hood. +futures are *lazy*: they don’t do anything until you ask them to with `await`. +This should remind you of our discussion of iterators [back in Chapter +13][iterators-lazy]. Iterators do nothing unless you call their `.next()` +method—whether directly, or using `for` loops or methods like `.map()` which use +`.next()` under the hood. With futures, the same basic idea applies: they do nothing unless you explicitly ask them to. This laziness allows Rust to avoid running async code until it is @@ -130,12 +134,12 @@ However, we get another compiler error here: The problem is that async code needs a *runtime*: a Rust crate which manages the details of executing asynchronous code. -Most languages which support async bundle a runtime with the language. At least -for now, Rust does not. Instead, there are many different async runtimes -available, each of which makes different tradeoffs suitable to the use case they -target. For example, a high-throughput web server with dozens of CPU cores and -terabytes of RAM has very different different needs than a microcontroller with -a single core, one gigabyte of RAM, and no ability to do heap allocations. +Most languages which support async bundle a runtime with the language. Rust does +not. Instead, there are many different async runtimes available, each of which +makes different tradeoffs suitable to the use case they target. For example, a +high-throughput web server with many CPU cores and a large amount of RAM has +very different different needs than a microcontroller with a single core, a +small amount of RAM, and no ability to do heap allocations. > ### The `trpl` Crate > @@ -151,7 +155,7 @@ a single core, one gigabyte of RAM, and no ability to do heap allocations. > - Tokio is the most widely used async runtime in Rust today, especially (but > not only!) for web applications. There are other great runtimes out there, > and they may be more suitable for your purposes. We use Tokio under the hood -> for `trpl` because it good and widely used. +> for `trpl` because it is good and widely used. > > In some cases, `trpl` also renames or wraps the original APIs to let us stay > focused on the details relevant to chapter. If you want to understand what the From 4044534e4fee16692661297aad17919a4d6f0f8c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Jul 2024 10:45:57 -0600 Subject: [PATCH 500/720] Ch. 16: avoid slightly-dismissive language in transition Use the original transitional paragraph and structure, adding to it instead of rewriting it entirely. HT @timClicks (Tim McNamara ) for pointing out how my rephrasing here made it worse! --- src/ch16-04-extensible-concurrency-sync-and-send.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ch16-04-extensible-concurrency-sync-and-send.md b/src/ch16-04-extensible-concurrency-sync-and-send.md index 1b74554341..ede5c66856 100644 --- a/src/ch16-04-extensible-concurrency-sync-and-send.md +++ b/src/ch16-04-extensible-concurrency-sync-and-send.md @@ -62,6 +62,11 @@ uphold them. ## Summary +This isn’t the last you’ll see of concurrency in this book: the whole next +chapter focuses on async programming, and the project in Chapter 20 will use the +concepts in this chapter in a more realistic situation than the smaller examples +discussed here. + As mentioned earlier, because very little of how Rust handles concurrency is part of the language, many concurrency solutions are implemented as crates. These evolve more quickly than the standard library, so be sure to search @@ -77,9 +82,6 @@ run on multiple threads without the kinds of hard-to-track-down bugs common in other languages. Concurrent programming is no longer a concept to be afraid of: go forth and make your programs concurrent, fearlessly! -This is just your first step into Rust’s concurrency story. In the next chapter, -we will explore a complementary approach, asynchronous programming. - [sharing-a-mutext-between-multiple-threads]: ch16-03-shared-state.html#sharing-a-mutext-between-multiple-threads [nomicon]: ../nomicon/index.html From eb41efb333f3c3873b98ee1eecd6395de89d618d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 24 Jul 2024 10:45:57 -0600 Subject: [PATCH 501/720] =?UTF-8?q?Ch.=2017=C2=A700:=20rework=20the=20intr?= =?UTF-8?q?oduction=20based=20on=20initial=20reviews?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Drop the history lesson and comparisons to other approaches. Focus on what async gives us instead. - Simplify and clarify the - Talk about “the network” instead of “network sockets” and simplify the example code to match. --- src/ch17-00-async-await.md | 182 ++++++++++--------------------------- 1 file changed, 46 insertions(+), 136 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 3acc65b1c6..22f200fa49 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -1,29 +1,5 @@ ## Async and Await -The threading-based concurrency model is one of the oldest concurrency models in -computing, and it was present and well-supported in Rust since 1.0. In the past -few decades, though, many programming languages have been experimenting with -other approaches to concurrency, especially asynchronous programming, or -*async*. - -It took a few years to work out the right design for async in Rust. After a -bunch of experimentation and design work in the library ecosystem, Rust added -language-level support for async in Rust 1.39, in 2019, and there is a thriving -ecosystem of crates supporting all sorts of interesting capabilities offered by -those language primitives. - -In the rest of this chapter, we will: - -* see how to use Rust’s `async` and `.await` syntax -* explore how to use the async model to solve some of the same challenges we - looked at in Chapter 16 -* look at how multithreading and async provide complementary solutions, which - you can even use together in many cases - -First, though, let’s explore what async gives us. - -### Why Async? - Many operations we ask the computer to do can take a while to finish. For example, if you used a video editor to create a video of a family celebration, exporting it could take anywhere from minutes to hours. Similarly, downloading a @@ -42,7 +18,7 @@ The file download is different. It does not take up very much CPU time. The CPU needs to wait on data to arrive from the network. While you can start reading the data once some of it arrives, it might take a while for the rest to arrive. Even once the data has all arrived, videos can be quite large, so it might take -some time to load all the data from the socket. Maybe it only takes a second or +some time to load all the data from the network. Maybe it only takes a second or two—but that is a very long time for a modern processor, which can do billions of operations every second. It would be nice to be able to put the CPU to use for other work while waiting for the network call to finish—so, again, your @@ -55,8 +31,7 @@ happen while the network operation is still ongoing. > it can use. The video download is the kind of operation which is often > described as “IO-bound,” because it is limited by the speed of the computer’s > *input and output*. It can only go as fast as the data can be sent across the -> network, which means that it can only go as fast as the data can be written to -> the socket by the network controller. +> network. In both of these examples, the concurrency only happens at the level of a whole program. The operating system interrupts one program to let other @@ -67,123 +42,48 @@ opportunities for concurrency that the operating system cannot see. For example, if we are building a tool to manage file downloads, we should be able to write our program in such a way that starting one download does not lock up the UI, and users should be able to start multiple downloads at the same -time. Many operating system APIs for interacting with network sockets are +time. Many operating system APIs for interacting with the network are *blocking*, though. That is, these APIs block the program’s progress until the data that they are processing is completely ready. > Note: This is how *most* function calls work, if you think about it! However, > we normally reserve the term “blocking” for function calls which interact with -> files, network sockets, or other resources on the computer, because those are -> the places where an individual program would benefit from the operation being +> files, the network, or other resources on the computer, because those are the +> places where an individual program would benefit from the operation being > *non*-blocking. -We could avoid blocking our main thread, by spawning a dedicated thread to +We could avoid blocking our main thread by spawning a dedicated thread to download each file. But it would be nicer if the call were not blocking in the -first place. - -One way to accomplish that would be to use an API built around callbacks. For -each blocking operation, we could pass in a function to call once the operation -completes: - -```rust,ignore -network_socket.read_non_blocking(|result| { - // ... -}); -``` - -Or we could register callbacks to run when events happen: - -```rust,ignore -network_socket.add_listener(Event::ReadFinished, |event| { - // ... -}); -``` - -Or we could have our functions return a type with `and_then` method, which in -turn accepts a callback which can do more work of the same sort (Historically, -this was the way that Rust did async): - -```rust,ignore -network_socket.read_non_blocking().and_then(|result| { - /* another non_blocking operation */ -}); -``` - -Each of these makes it harder to understand both the control flow and the flow -of data through the program. You can end up with event handler callbacks -scattered across the code base, or groups of deeply nested callbacks, or long -chains of `and_then` calls. - -There are also no particularly good ways to get data out of those callbacks. -With other common types in Rust, we often use pattern-matching in scenarios like -this. When we are using callbacks we do not yet have the data at the time we -call `read_non_blocking`—and we will not have it until the callback gets called. -That means that there is no way to match on the data it will return: it is not -here yet! - -As an alternative, we might try something like this, imagining a -`read_non_blocking` which has exactly the kind of `and_then` method described -above. If we were to try to do that, though, with code kind of like this, it -would not even compile: - -```rust,ignore,does_not_compile -let mut data = None; -network_socket.read_non_blocking().and_then(|result| { - data = Some(result); -}); -println!("{data:?}"); -``` - -In this very broken code, the callback passed to `and_then` needs a mutable -reference to `data`, but the `println` macro needs to borrow a reference to -`data` to be able to print it. Rust would helpfully tell us that we cannot -borrow `data` immutably to print it because it is still borrowed mutably for the -`and_then` callback. This is not just Rust being fussy, either: the result of -this would normally always just print the `None` value, but if the read -*happened* to go fast enough, it is possible it could sometimes print some -string data instead. That is *definitely* not what we want! - -We also could not cancel `read_non_blocking`: once it has started, it will run -till it finishes unless the whole program stops. - -What we really want to be able to write is something much more direct, like we -would write in blocking code, but with the benefits of getting the data when it -is available and *not* blocking the rest of the program while waiting for the -data to arrive—something like this: +first place. It would also be nice if we could write in the same direct style +we use in blocking code. Something like this: ```rust,ignore,does_not_compile -let data = network_socket.read(&path).await; +let data = fetch_data_from(url).await; println!("{data}"); ``` -That is exactly what Rust’s async abstraction gives us. It is designed to help -us solve all of these issues. Before we will see how this works in practice, -though, we need to dig a little deeper into the differences between parallelism -and concurrency. +That is exactly what Rust’s async abstraction gives us. Before we see how this +works in practice, though, we need to take a short detour into the differences +between parallelism and concurrency. ### Parallelism and Concurrency In the previous chapter we treated parallelism and concurrency as mostly interchangeable. Now we need to distinguish between them more precisely, because -the differences will show up as we start working: +the differences will show up as we start working. -* *Parallelism* is when operations can happen simultaneously. +Think about working on a software project as a team. -* *Concurrency* is when operations can make progress without having to wait for - all other operations to complete. +When an individual works on several different tasks before any of them is +complete, this is *concurrency*. Maybe you have two different projects checked +out on your computer, and when you get bored or stuck on one project, you switch +to the other. You are just one person, and you cannot make progress on both +tasks at the exact same time—but you can multi-task, making progress on multiple +tasks by switching between them. -Think about working on a software project as a team. When you agree to split up -a group of tasks between a group of people, with each person working on one task -and delivering them separately, this is *parallelism*. Each person on the team -can be making progress at the exact same time. On the other hand, when an -individual works on several different tasks before any of them is complete, this -is *concurrency*. Maybe you have two different projects checked out on your -computer, and when you get bored or stuck on one project, you switch to the -other. You are just one person, and you cannot make progress on both tasks at -the exact same time—but you can multi-task, making progress on multiple tasks by -switching between them. Work on one does not necessarily *block* working on the -other. +When you agree to split up a group of tasks between the people on the team, with +each person taking one task and working on it alone, this is *parallelism*. Each +person on the team can make progress at the exact same time. With both of these situations, you might have to coordinate between different tasks. Maybe you *thought* the task that one person was working on was totally @@ -195,20 +95,30 @@ working on needs the result from another of your tasks. Now your concurrent work has also become serial. Parallelism and concurrency can intersect with each other, too. For example, if -it turns out your coworker is waiting on one of your projects to finish, then -you might need to focus on that project and not give any time to your other task -until it is done, so your own work stops being concurrent. - -On a machine with a single CPU core, the CPU can only do one operation at a -time, but we can still have concurrency. Using tools like threads, processes, -and async, the computer can pause one activity and switch to others before -eventually cycling back to that first activity again. On a machine with multiple -CPU cores, we can actually do work in parallel. One core can be doing one thing -while another core does something completely unrelated, and those actually -happen at the same time. +it turns out your coworker is waiting on one of your projects to finish, you +might need to focus on that project and not give any time to your other task +until it is done. In that case, you and your coworker are no longer able to work +in parallel *and* you are no longer able to work concurrently. + +The same basic dynamics come into play with software and hardware. On a machine +with a single CPU core, the CPU can only do one operation at a time, but it can +still work concurrently. Using tools like threads, processes, and async, the +computer can pause one activity and switch to others before eventually cycling +back to that first activity again. On a machine with multiple CPU cores, it can +also do work in parallel. One core can be doing one thing while another core +does something completely unrelated, and those actually happen at the same +time. When working with async in Rust, we are always dealing with concurrency. Depending on the hardware, the operating system, and the async runtime we are using—more on async runtimes shortly!—that concurrency may or may not also use -parallelism under the hood. Now, let’s dive into how async programming in Rust -actually works! +parallelism under the hood. + +Now, let’s dive into how async programming in Rust actually works! In the rest +of this chapter, we will: + +* see how to use Rust’s `async` and `.await` syntax +* explore how to use the async model to solve some of the same challenges we + looked at in Chapter 16 +* look at how multithreading and async provide complementary solutions, which + you can even use together in many cases From cfaf187bbc3a1515f517498657d127fae247d8ff Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 25 Jul 2024 15:28:27 -0600 Subject: [PATCH 502/720] Ch. 17: diagrams for concurrent and parallel execution --- dot/trpl17-01.dot | 21 +++++++++++++++++++++ dot/trpl17-02.dot | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 dot/trpl17-01.dot create mode 100644 dot/trpl17-02.dot diff --git a/dot/trpl17-01.dot b/dot/trpl17-01.dot new file mode 100644 index 0000000000..d90c85b8ee --- /dev/null +++ b/dot/trpl17-01.dot @@ -0,0 +1,21 @@ +digraph { + dpi = 300.0; + + Parallel [label = "Parallel";shape = "plaintext";]; + rankdir = "TB"; + splines = false; + cluster = true; + + node [shape = diamond;]; + + subgraph cluster_ColleagueA { + newrank = true; + label = "Task 1"; + A1 -> A2 -> A3 -> A4; + } + + subgraph cluster_ColleagueB { + label = "Task 2"; + B1 -> B2 -> B3; + } +} \ No newline at end of file diff --git a/dot/trpl17-02.dot b/dot/trpl17-02.dot new file mode 100644 index 0000000000..3c8d2a18a3 --- /dev/null +++ b/dot/trpl17-02.dot @@ -0,0 +1,46 @@ +digraph { + dpi = 300.0; + + Concurrent [label = "Concurrent";shape = "plaintext";]; + rankdir = "TB"; + splines = false; + cluster = true; + + node [shape = diamond;]; + + subgraph cluster_task_a { + label = "Task A"; + + // makes ordering between subgraphs work + newrank = true; + + A1; + A2; + A3; + A4; + + // for vertical alignment purposes only + A0 [style = invis;]; + + edge [style = invis;]; + } + + subgraph cluster_task_b { + label = "Task B"; + cluster = true; + + // for vertical alignment purposes only + newrank = true; + + B0 [style = invis;]; + + B1; + B2; + B3; + } + + A1 -> B1 -> A2 -> B2 -> A3 -> A4 -> B3; + + // Makes the heights line up between the boxes. + A4 -> A0 [style = invis;]; +} \ No newline at end of file From 472f152eaec3d93a2ec0e73751eadead477f54d7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Jul 2024 08:12:41 -0600 Subject: [PATCH 503/720] Ch. 17: fix diagrams and embed them in the text - Swap the ordering to match the order in the text (concurrent is first, at least for now). - Make them go left-to-right instead of top-to-bottom for compactness in the text. - Fix rendering issues resulting from the VS Code extension doing things that normal `dot` does not, for who knows what reasons. --- dot/trpl17-01.dot | 45 +++++++++++---- dot/trpl17-02.dot | 40 +++----------- src/ch17-00-async-await.md | 16 ++++++ src/img/trp17-02.svg | 1 + src/img/trpl17-01.svg | 110 +++++++++++++++++++++++++++++++++++++ src/img/trpl17-02.svg | 94 +++++++++++++++++++++++++++++++ 6 files changed, 262 insertions(+), 44 deletions(-) create mode 100644 src/img/trp17-02.svg create mode 100644 src/img/trpl17-01.svg create mode 100644 src/img/trpl17-02.svg diff --git a/dot/trpl17-01.dot b/dot/trpl17-01.dot index d90c85b8ee..97bd15e894 100644 --- a/dot/trpl17-01.dot +++ b/dot/trpl17-01.dot @@ -1,21 +1,44 @@ digraph { dpi = 300.0; - Parallel [label = "Parallel";shape = "plaintext";]; - rankdir = "TB"; - splines = false; - cluster = true; + rankdir = "LR"; + + // makes ordering between subgraphs work + newrank = true; node [shape = diamond;]; - subgraph cluster_ColleagueA { - newrank = true; - label = "Task 1"; - A1 -> A2 -> A3 -> A4; + subgraph cluster_task_a { + label = "Task A"; + + A1; + A2; + A3; + A4; + + A1 -> A2 -> A3 -> A4 -> A0 [style = invis;]; + + // for vertical alignment purposes only + A0 [style = invis;]; + + // Makes the heights line up between the boxes. + A4 -> A0 [style = invis;]; } - subgraph cluster_ColleagueB { - label = "Task 2"; - B1 -> B2 -> B3; + subgraph cluster_task_b { + label = "Task B"; + + // for horizontal alignment purposes only + // newrank = true; + + B0 [style = invis;]; + + B1; + B2; + B3; + + B0 -> B1 -> B2 -> B3 [style = invis;]; } + + A1 -> B1 -> A2 -> B2 -> A3 -> A4 -> B3; } \ No newline at end of file diff --git a/dot/trpl17-02.dot b/dot/trpl17-02.dot index 3c8d2a18a3..512f33cb9b 100644 --- a/dot/trpl17-02.dot +++ b/dot/trpl17-02.dot @@ -1,46 +1,20 @@ digraph { dpi = 300.0; - Concurrent [label = "Concurrent";shape = "plaintext";]; - rankdir = "TB"; + rankdir = "LR"; splines = false; cluster = true; node [shape = diamond;]; - subgraph cluster_task_a { - label = "Task A"; - - // makes ordering between subgraphs work + subgraph cluster_ColleagueA { newrank = true; - - A1; - A2; - A3; - A4; - - // for vertical alignment purposes only - A0 [style = invis;]; - - edge [style = invis;]; + label = "Task 1"; + A1 -> A2 -> A3 -> A4; } - subgraph cluster_task_b { - label = "Task B"; - cluster = true; - - // for vertical alignment purposes only - newrank = true; - - B0 [style = invis;]; - - B1; - B2; - B3; + subgraph cluster_ColleagueB { + label = "Task 2"; + B1 -> B2 -> B3; } - - A1 -> B1 -> A2 -> B2 -> A3 -> A4 -> B3; - - // Makes the heights line up between the boxes. - A4 -> A0 [style = invis;]; } \ No newline at end of file diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 22f200fa49..e68c7420fc 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -81,10 +81,26 @@ to the other. You are just one person, and you cannot make progress on both tasks at the exact same time—but you can multi-task, making progress on multiple tasks by switching between them. +
+ +Concurrent work flow + +
Figure 17-1: A concurrent workflow, switching between Task A and Task B
+ +
+ When you agree to split up a group of tasks between the people on the team, with each person taking one task and working on it alone, this is *parallelism*. Each person on the team can make progress at the exact same time. +
+ +Concurrent work flow + +
Figure 17-2: A parallel workflow, where work happens on Task A and Task B independently
+ +
+ With both of these situations, you might have to coordinate between different tasks. Maybe you *thought* the task that one person was working on was totally independent from everyone else’s work, but it actually needs something finished diff --git a/src/img/trp17-02.svg b/src/img/trp17-02.svg new file mode 100644 index 0000000000..1ad970d72c --- /dev/null +++ b/src/img/trp17-02.svg @@ -0,0 +1 @@ +Task 1Task 2ParallelA1A2A3A4B1B2B3 \ No newline at end of file diff --git a/src/img/trpl17-01.svg b/src/img/trpl17-01.svg new file mode 100644 index 0000000000..c99989ec31 --- /dev/null +++ b/src/img/trpl17-01.svg @@ -0,0 +1,110 @@ + + + + + + + + +cluster_task_a + +Task A + + +cluster_task_b + +Task B + + + +A1 + +A1 + + + +A2 + +A2 + + + + +B1 + +B1 + + + +A1->B1 + + + + + +A3 + +A3 + + + + +B2 + +B2 + + + +A2->B2 + + + + + +A4 + +A4 + + + + +A3->A4 + + + + + + + + +B3 + +B3 + + + +A4->B3 + + + + + + + +B1->A2 + + + + + + +B2->A3 + + + + + + diff --git a/src/img/trpl17-02.svg b/src/img/trpl17-02.svg new file mode 100644 index 0000000000..1ddb5d4cad --- /dev/null +++ b/src/img/trpl17-02.svg @@ -0,0 +1,94 @@ + + + + + + + + +cluster_ColleagueA + +Task 1 + + +cluster_ColleagueB + +Task 2 + + + +A1 + +A1 + + + +A2 + +A2 + + + +A1->A2 + + + + + +A3 + +A3 + + + +A2->A3 + + + + + +A4 + +A4 + + + +A3->A4 + + + + + +B1 + +B1 + + + +B2 + +B2 + + + +B1->B2 + + + + + +B3 + +B3 + + + +B2->B3 + + + + + From 401132e688be6f5dbbd67a8d0f89fca8969f4fda Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Ribera Costa <56278796+SergioRibera@users.noreply.github.com> Date: Sun, 28 Jul 2024 05:04:39 -0400 Subject: [PATCH 504/720] update rustlanges book url --- src/appendix-06-translation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appendix-06-translation.md b/src/appendix-06-translation.md index ce60180380..c4ea8abb70 100644 --- a/src/appendix-06-translation.md +++ b/src/appendix-06-translation.md @@ -10,7 +10,7 @@ For resources in languages other than English. Most are still in progress; see - [简体中文](https://github.com/KaiserY/trpl-zh-cn) - [正體中文](https://github.com/rust-tw/book-tw) - [Українська](https://github.com/pavloslav/rust-book-uk-ua) -- [Español](https://github.com/thecodix/book), [alternate](https://github.com/ManRR/rust-book-es), [Español por RustLangES](https://github.com/RustLangES/book) +- [Español](https://github.com/thecodix/book), [alternate](https://github.com/ManRR/rust-book-es), [Español por RustLangES](https://github.com/RustLangES/rust-book-es) - [Italiano](https://github.com/EmanueleGurini/book_it) - [Русский](https://github.com/rust-lang-ru/book) - [한국어](https://github.com/rinthel/rust-lang-book-ko) From d179c23616984733a73c4c1a28c7aed7806cba10 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 29 Jul 2024 11:32:29 -0700 Subject: [PATCH 505/720] mdbook-trpl-listing: Add missing elided lifetimes --- packages/mdbook-trpl-listing/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl-listing/src/lib.rs index 7be63e4ae4..619cafdf38 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl-listing/src/lib.rs @@ -157,7 +157,7 @@ fn rewrite_listing(src: &str, mode: Mode) -> Result { } ev => state.events.push(Ok(ev)), }; - Ok::(state) + Ok::, String>(state) }, )?; @@ -190,7 +190,7 @@ struct ListingState<'e> { impl<'e> ListingState<'e> { fn open_listing( &mut self, - tag: pulldown_cmark::CowStr, + tag: pulldown_cmark::CowStr<'_>, mode: Mode, ) -> Result<(), String> { // We do not *keep* the version constructed here, just temporarily @@ -247,7 +247,7 @@ impl<'e> ListingState<'e> { Ok(()) } - fn close_listing(&mut self, tag: pulldown_cmark::CowStr, mode: Mode) { + fn close_listing(&mut self, tag: pulldown_cmark::CowStr<'_>, mode: Mode) { let trailing = if !tag.ends_with('>') { tag.replace("
", "") } else { From de6e35c52fcdb2df7f8b156d72e3588d64f2abc5 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 31 Jul 2024 06:59:05 -0600 Subject: [PATCH 506/720] infra: add robots.txt for GH Pages previews Block *everything*. We do not want any of this to be indexed, because we *only* use it for previews, and do not want its content to be cached or (especially!) surfaced to readers, since it may have a variety of issues ranging from pedagogical missteps to outright errors! --- ADMIN_TASKS.md | 10 ++++++++++ tools/generate-preview.sh | 4 ++++ tools/preview-robots.txt | 2 ++ 3 files changed, 16 insertions(+) create mode 100755 tools/generate-preview.sh create mode 100644 tools/preview-robots.txt diff --git a/ADMIN_TASKS.md b/ADMIN_TASKS.md index 7e9ba2cc04..9caff3004c 100644 --- a/ADMIN_TASKS.md +++ b/ADMIN_TASKS.md @@ -133,3 +133,13 @@ $ dot dot/trpl04-01.dot -Tsvg > src/img/trpl04-01.svg In the generated SVG, remove the width and the height attributes from the `svg` element and set the `viewBox` attribute to `0.00 0.00 1000.00 1000.00` or other values that don't cut off the image. + +## Publish a preview to GitHub Pages + +We sometimes publish to GitHub Pages for in-progress previews. The recommended +flow for publishing is: + +- Install the `ghp-import` tool by running `pip install ghp-import` (or `pipx install ghp-import`, using [pipx][pipx]). +- In the root, run `tools/generate-preview.sh` + +[pipx]: https://pipx.pypa.io/stable/#install-pipx diff --git a/tools/generate-preview.sh b/tools/generate-preview.sh new file mode 100755 index 0000000000..c2b0f2f1da --- /dev/null +++ b/tools/generate-preview.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +mdbook build +cp ./tools/preview-robots.txt ./book/robots.txt diff --git a/tools/preview-robots.txt b/tools/preview-robots.txt new file mode 100644 index 0000000000..1f53798bb4 --- /dev/null +++ b/tools/preview-robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / From df78a37109d23cd15061c36e81956ff9973edd89 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 31 Jul 2024 07:13:14 -0600 Subject: [PATCH 507/720] infra: include ghp-import and git push in generate-preview script --- tools/generate-preview.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/generate-preview.sh b/tools/generate-preview.sh index c2b0f2f1da..a5d9022b9e 100755 --- a/tools/generate-preview.sh +++ b/tools/generate-preview.sh @@ -2,3 +2,5 @@ mdbook build cp ./tools/preview-robots.txt ./book/robots.txt +ghp-import -m "rebuild GitHub Pages from generated-book" book +git push origin gh-pages From 79bce29cd716bd1d387af533661e0cbef3674cbf Mon Sep 17 00:00:00 2001 From: Vox Dai Date: Wed, 7 Aug 2024 22:51:04 +0800 Subject: [PATCH 508/720] Fix: typo Fix a typo in ch03-05-control-flow.md --- src/ch03-05-control-flow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch03-05-control-flow.md b/src/ch03-05-control-flow.md index 0c7aeff13b..3b72b96539 100644 --- a/src/ch03-05-control-flow.md +++ b/src/ch03-05-control-flow.md @@ -191,7 +191,7 @@ 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 -ctrl-c to interrupt a program that is stuck in a continual +ctrl-c to interrupt a program that is stuck in a continual loop. Give it a try: provides functionality that generates random numbers. Most of the time when Rustaceans say “crate”, they mean library crate, and they -use “crate” interchangeably with the general programming concept of a “library". +use “crate” interchangeably with the general programming concept of a “library”. The *crate root* is a source file that the Rust compiler starts from and makes up the root module of your crate (we’ll explain modules in depth in the From 75bc5551057d73c77034f23f0bce1dc444c3ef17 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 13 Aug 2024 13:19:16 -0400 Subject: [PATCH 511/720] Updates to ch7 snapshot, not to send to nostarch --- nostarch/chapter07.md | 131 +++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 67 deletions(-) diff --git a/nostarch/chapter07.md b/nostarch/chapter07.md index 9fef53de79..a9a48eff0f 100644 --- a/nostarch/chapter07.md +++ b/nostarch/chapter07.md @@ -75,7 +75,7 @@ executable. Instead, they define functionality intended to be shared with multiple projects. For example, the `rand` crate we used in Chapter 2 provides functionality that generates random numbers. Most of the time when Rustaceans say “crate”, they mean library crate, and they -use “crate” interchangeably with the general programming concept of a “library". +use “crate” interchangeably with the general programming concept of a “library”. The *crate root* is a source file that the Rust compiler starts from and makes up the root module of your crate (we’ll explain modules in depth in the @@ -139,37 +139,35 @@ in the compiler, and how most developers organize their code. We’ll be going through examples of each of these rules throughout this chapter, but this is a great place to refer to as a reminder of how modules work. -- **Start from the crate root**: When compiling a crate, the compiler first +* **Start from the crate root**: When compiling a crate, the compiler first looks in the crate root file (usually *src/lib.rs* for a library crate or *src/main.rs* for a binary crate) for code to compile. -- **Declaring modules**: In the crate root file, you can declare new modules; -say you declare a “garden” module with `mod garden;`. The compiler will look -for the module’s code in these places: - - Inline, within curly brackets that replace the semicolon following `mod - garden` - - In the file *src/garden.rs* - - In the file *src/garden/mod.rs* -- **Declaring submodules**: In any file other than the crate root, you can +* **Declaring modules**: In the crate root file, you can declare new modules; + say you declare a “garden” module with `mod garden;`. The compiler will look + for the module’s code in these places: + * Inline, within curly brackets that replace the semicolon following `mod garden` + * In the file *src/garden.rs* + * In the file *src/garden/mod.rs* +* **Declaring submodules**: In any file other than the crate root, you can declare submodules. For example, you might declare `mod vegetables;` in *src/garden.rs*. The compiler will look for the submodule’s code within the directory named for the parent module in these places: - - Inline, directly following `mod vegetables`, within curly brackets instead + * Inline, directly following `mod vegetables`, within curly brackets instead of the semicolon - - In the file *src/garden/vegetables.rs* - - In the file *src/garden/vegetables/mod.rs* -- **Paths to code in modules**: Once a module is part of your crate, you can + * In the file *src/garden/vegetables.rs* + * In the file *src/garden/vegetables/mod.rs* +* **Paths to code in modules**: Once a module is part of your crate, you can refer to code in that module from anywhere else in that same crate, as long as the privacy rules allow, using the path to the code. For example, an `Asparagus` type in the garden vegetables module would be found at `crate::garden::vegetables::Asparagus`. -- **Private vs. public**: Code within a module is private from its parent +* **Private vs. public**: Code within a module is private from its parent modules by default. To make a module public, declare it with `pub mod` instead of `mod`. To make items within a public module public as well, use `pub` before their declarations. -- **The `use` keyword**: Within a scope, the `use` keyword creates shortcuts to +* **The `use` keyword**: Within a scope, the `use` keyword creates shortcuts to items to reduce repetition of long paths. In any scope that can refer to - `crate::garden::vegetables::Asparagus`, you can create a shortcut with `use - crate::garden::vegetables::Asparagus;` and from then on you only need to + `crate::garden::vegetables::Asparagus`, you can create a shortcut with `use crate::garden::vegetables::Asparagus;` and from then on you only need to write `Asparagus` to make use of that type in the scope. Here, we create a binary crate named `backyard` that illustrates these rules. @@ -243,8 +241,7 @@ chefs and cooks work in the kitchen, dishwashers clean up, and managers do administrative work. To structure our crate in this way, we can organize its functions into nested -modules. Create a new library named `restaurant` by running `cargo new -restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to +modules. Create a new library named `restaurant` by running `cargo new restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to define some modules and function signatures; this code is the front of house section. @@ -594,26 +591,27 @@ changes to your public API to make it easier for people to depend on your crate. These considerations are out of the scope of this book; if you’re interested in this topic, see The Rust API Guidelines at *https://rust-lang.github.io/api-guidelines/*. -> #### Best Practices for Packages with a Binary and a Library -> -> We mentioned that a package can contain both a *src/main.rs* binary crate -> root as well as a *src/lib.rs* library crate root, and both crates will have -> the package name by default. Typically, packages with this pattern of -> containing both a library and a binary crate will have just enough code in the -> binary crate to start an executable that calls code within the library crate. -> This lets other projects benefit from most of the functionality that the -> package provides because the library crate’s code can be shared. -> -> The module tree should be defined in *src/lib.rs*. Then, any public items can -> be used in the binary crate by starting paths with the name of the package. -> The binary crate becomes a user of the library crate just like a completely -> external crate would use the library crate: it can only use the public API. -> This helps you design a good API; not only are you the author, you’re also a -> client! -> -> In Chapter 12, we’ll demonstrate this organizational -> practice with a command-line program that will contain both a binary crate -> and a library crate. + > + > #### Best Practices for Packages with a Binary and a Library + > + > We mentioned that a package can contain both a *src/main.rs* binary crate + > root as well as a *src/lib.rs* library crate root, and both crates will have + > the package name by default. Typically, packages with this pattern of + > containing both a library and a binary crate will have just enough code in the + > binary crate to start an executable that calls code within the library crate. + > This lets other projects benefit from most of the functionality that the + > package provides because the library crate’s code can be shared. + > + > The module tree should be defined in *src/lib.rs*. Then, any public items can + > be used in the binary crate by starting paths with the name of the package. + > The binary crate becomes a user of the library crate just like a completely + > external crate would use the library crate: it can only use the public API. + > This helps you design a good API; not only are you the author, you’re also a + > client! + > + > In Chapter 12, we’ll demonstrate this organizational + > practice with a command-line program that will contain both a binary crate + > and a library crate. ### Starting Relative Paths with `super` @@ -856,8 +854,7 @@ the shortcut in the parent module with `super::hosting` within the child ### Creating Idiomatic `use` Paths -In Listing 7-11, you might have wondered why we specified `use -crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in +In Listing 7-11, you might have wondered why we specified `use crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in `eat_at_restaurant`, rather than specifying the `use` path all the way out to the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. @@ -1002,8 +999,7 @@ from a new scope with `pub use` Before this change, external code would have to call the `add_to_waitlist` function by using the path `restaurant::front_of_house::hosting::add_to_waitlist()`, which also would have -required the `front_of_house` module to be marked as `pub`. Now that this `pub -use` has re-exported the `hosting` module from the root module, external code +required the `front_of_house` module to be marked as `pub`. Now that this `pub use` has re-exported the `hosting` module from the root module, external code can use the path `restaurant::hosting::add_to_waitlist()` instead. Re-exporting is useful when the internal structure of your code is different @@ -1246,29 +1242,30 @@ root, and not declared as a child of the `front_of_house` module. The compiler’s rules for which files to check for which modules’ code mean the directories and files more closely match the module tree. -> ### Alternate File Paths -> -> So far we’ve covered the most idiomatic file paths the Rust compiler uses, -> but Rust also supports an older style of file path. For a module named -> `front_of_house` declared in the crate root, the compiler will look for the -> module’s code in: -> -> * *src/front_of_house.rs* (what we covered) -> * *src/front_of_house/mod.rs* (older style, still supported path) -> -> For a module named `hosting` that is a submodule of `front_of_house`, the -> compiler will look for the module’s code in: -> -> * *src/front_of_house/hosting.rs* (what we covered) -> * *src/front_of_house/hosting/mod.rs* (older style, still supported path) -> -> If you use both styles for the same module, you’ll get a compiler error. -> Using a mix of both styles for different modules in the same project is -> allowed, but might be confusing for people navigating your project. -> -> The main downside to the style that uses files named *mod.rs* is that your -> project can end up with many files named *mod.rs*, which can get confusing -> when you have them open in your editor at the same time. + > + > ### Alternate File Paths + > + > So far we’ve covered the most idiomatic file paths the Rust compiler uses, + > but Rust also supports an older style of file path. For a module named + > `front_of_house` declared in the crate root, the compiler will look for the + > module’s code in: + > + > * *src/front_of_house.rs* (what we covered) + > * *src/front_of_house/mod.rs* (older style, still supported path) + > + > For a module named `hosting` that is a submodule of `front_of_house`, the + > compiler will look for the module’s code in: + > + > * *src/front_of_house/hosting.rs* (what we covered) + > * *src/front_of_house/hosting/mod.rs* (older style, still supported path) + > + > If you use both styles for the same module, you’ll get a compiler error. + > Using a mix of both styles for different modules in the same project is + > allowed, but might be confusing for people navigating your project. + > + > The main downside to the style that uses files named *mod.rs* is that your + > project can end up with many files named *mod.rs*, which can get confusing + > when you have them open in your editor at the same time. We’ve moved each module’s code to a separate file, and the module tree remains the same. The function calls in `eat_at_restaurant` will work without any From 48a3c173c12462eac754a30648397376606f37ba Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 13 Aug 2024 13:19:29 -0400 Subject: [PATCH 512/720] Upstream changes to ch7 to consider sending to nostarch --- nostarch/chapter07.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nostarch/chapter07.md b/nostarch/chapter07.md index a9a48eff0f..0a7a407935 100644 --- a/nostarch/chapter07.md +++ b/nostarch/chapter07.md @@ -196,7 +196,7 @@ pub mod garden; fn main() { let plant = Asparagus {}; - println!("I'm growing {:?}!", plant); + println!("I'm growing {plant:?}!"); } ``` @@ -563,7 +563,7 @@ and `fn add_to_waitlist` lets us call the function from `eat_at_restaurant` Now the code will compile! To see why adding the `pub` keyword lets us use -these paths in `add_to_waitlist` with respect to the privacy rules, let’s look +these paths in `eat_at_restaurant` with respect to the privacy rules, let’s look at the absolute and the relative paths. In the absolute path, we start with `crate`, the root of our crate’s module From 8880eacd339876c9a53d606720176bb02a4e5b3f Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 13 Aug 2024 13:25:01 -0400 Subject: [PATCH 513/720] Backported edits of ch12 from print to src --- nostarch/chapter12.md | 2 +- src/ch12-00-an-io-project.md | 16 +++-- ...h12-01-accepting-command-line-arguments.md | 16 ++--- src/ch12-02-reading-a-file.md | 12 ++-- ...improving-error-handling-and-modularity.md | 59 +++++++++---------- ...2-04-testing-the-librarys-functionality.md | 54 ++++++++--------- ...2-05-working-with-environment-variables.md | 42 ++++++------- ...-06-writing-to-stderr-instead-of-stdout.md | 9 +-- 8 files changed, 104 insertions(+), 106 deletions(-) diff --git a/nostarch/chapter12.md b/nostarch/chapter12.md index 86e9861731..aa34be3c2a 100644 --- a/nostarch/chapter12.md +++ b/nostarch/chapter12.md @@ -1022,7 +1022,7 @@ principles, we’ll add just enough code to get the test to compile and run by adding a definition of the `search` function that always returns an empty vector, as shown in Listing 12-16. Then the test should compile and fail because an empty vector doesn’t match a vector containing the line `"safe, -fast, productive."`. +fast, productive."` Filename: src/lib.rs diff --git a/src/ch12-00-an-io-project.md b/src/ch12-00-an-io-project.md index bae99c75f7..79e84c943e 100644 --- a/src/ch12-00-an-io-project.md +++ b/src/ch12-00-an-io-project.md @@ -18,8 +18,8 @@ Along the way, we’ll show how to make our command line tool use the terminal features that many other command line tools use. We’ll read the value of an environment variable to allow the user to configure the behavior of our tool. We’ll also print error messages to the standard error console stream (`stderr`) -instead of standard output (`stdout`), so, for example, the user can redirect -successful output to a file while still seeing error messages onscreen. +instead of standard output (`stdout`) so that, for example, the user can +redirect successful output to a file while still seeing error messages onscreen. One Rust community member, Andrew Gallant, has already created a fully featured, very fast version of `grep`, called `ripgrep`. By comparison, our @@ -29,17 +29,15 @@ background knowledge you need to understand a real-world project such as Our `grep` project will combine a number of concepts you’ve learned so far: -* Organizing code (using what you learned about modules in [Chapter 7][ch7]) -* Using vectors and strings (collections, [Chapter 8][ch8]) +* Organizing code ([Chapter 7][ch7]) +* Using vectors and strings ([Chapter 8][ch8]) * Handling errors ([Chapter 9][ch9]) -* Using traits and lifetimes where appropriate ([Chapter 10][ch10]) +* Using traits and lifetimes where appropriate ([Chapter 10][ch10]) * Writing tests ([Chapter 11][ch11]) We’ll also briefly introduce closures, iterators, and trait objects, which -Chapters [13][ch13] and [17][ch17] will cover in -detail. +[Chapter 13][ch13] and [Chapter 17][ch17] will +cover in detail. [ch7]: ch07-00-managing-growing-projects-with-packages-crates-and-modules.html [ch8]: ch08-00-common-collections.html diff --git a/src/ch12-01-accepting-command-line-arguments.md b/src/ch12-01-accepting-command-line-arguments.md index 9dc28209b7..34e4504249 100644 --- a/src/ch12-01-accepting-command-line-arguments.md +++ b/src/ch12-01-accepting-command-line-arguments.md @@ -37,7 +37,7 @@ to turn it into a collection, such as a vector, that contains all the elements the iterator produces. The code in Listing 12-1 allows your `minigrep` program to read any command -line arguments passed to it and then collect the values into a vector. +line arguments passed to it, and then collect the values into a vector. @@ -47,7 +47,7 @@ line arguments passed to it and then collect the values into a vector. -First, we bring the `std::env` module into scope with a `use` statement so we +First we bring the `std::env` module into scope with a `use` statement so we can use its `args` function. Notice that the `std::env::args` function is nested in two levels of modules. As we discussed in [Chapter 7][ch7-idiomatic-use], in cases where the desired function is @@ -63,14 +63,14 @@ mistaken for a function that’s defined in the current module. > Unicode. If your program needs to accept arguments containing invalid > Unicode, use `std::env::args_os` instead. That function returns an iterator > that produces `OsString` values instead of `String` values. We’ve chosen to -> use `std::env::args` here for simplicity, because `OsString` values differ -> per platform and are more complex to work with than `String` values. +> use `std::env::args` here for simplicity because `OsString` values differ per +> platform and are more complex to work with than `String` values. On the first line of `main`, we call `env::args`, and we immediately use `collect` to turn the iterator into a vector containing all the values produced by the iterator. We can use the `collect` function to create many kinds of collections, so we explicitly annotate the type of `args` to specify that we -want a vector of strings. Although we very rarely need to annotate types in +want a vector of strings. Although you very rarely need to annotate types in Rust, `collect` is one function you do often need to annotate because Rust isn’t able to infer the kind of collection you want. @@ -89,8 +89,8 @@ Notice that the first value in the vector is `"target/debug/minigrep"`, which is the name of our binary. This matches the behavior of the arguments list in C, letting programs use the name by which they were invoked in their execution. It’s often convenient to have access to the program name in case you want to -print it in messages or change behavior of the program based on what command -line alias was used to invoke the program. But for the purposes of this +print it in messages or change the behavior of the program based on what +command line alias was used to invoke the program. But for the purposes of this chapter, we’ll ignore it and save only the two arguments we need. ### Saving the Argument Values in Variables @@ -109,7 +109,7 @@ we can use the values throughout the rest of the program. We do that in Listing
As we saw when we printed the vector, the program’s name takes up the first -value in the vector at `args[0]`, so we’re starting arguments at index `1`. The +value in the vector at `args[0]`, so we’re starting arguments at index 1. The first argument `minigrep` takes is the string we’re searching for, so we put a reference to the first argument in the variable `query`. The second argument will be the file path, so we put a reference to the second argument in the diff --git a/src/ch12-02-reading-a-file.md b/src/ch12-02-reading-a-file.md index 910850b06b..e45dded65a 100644 --- a/src/ch12-02-reading-a-file.md +++ b/src/ch12-02-reading-a-file.md @@ -1,13 +1,13 @@ ## Reading a File Now we’ll add functionality to read the file specified in the `file_path` -argument. First, we need a sample file to test it with: we’ll use a file with a +argument. First we need a sample file to test it with: we’ll use a file with a small amount of text over multiple lines with some repeated words. Listing 12-3 has an Emily Dickinson poem that will work well! Create a file called *poem.txt* at the root level of your project, and enter the poem “I’m Nobody! Who are you?” -+ ```text {{#include ../listings/ch12-an-io-project/listing-12-03/poem.txt}} @@ -26,7 +26,7 @@ shown in Listing 12-4. -First, we bring in a relevant part of the standard library with a `use` +First we bring in a relevant part of the standard library with a `use` statement: we need `std::fs` to handle files. In `main`, the new statement `fs::read_to_string` takes the `file_path`, opens @@ -50,6 +50,6 @@ responsibilities: generally, functions are clearer and easier to maintain if each function is responsible for only one idea. The other problem is that we’re not handling errors as well as we could. The program is still small, so these flaws aren’t a big problem, but as the program grows, it will be harder to fix -them cleanly. It’s good practice to begin refactoring early on when developing -a program, because it’s much easier to refactor smaller amounts of code. We’ll -do that next. +them cleanly. It’s a good practice to begin refactoring early on when +developing a program because it’s much easier to refactor smaller amounts of +code. We’ll do that next. diff --git a/src/ch12-03-improving-error-handling-and-modularity.md b/src/ch12-03-improving-error-handling-and-modularity.md index 0de3ec2c22..2e76e82d90 100644 --- a/src/ch12-03-improving-error-handling-and-modularity.md +++ b/src/ch12-03-improving-error-handling-and-modularity.md @@ -41,8 +41,8 @@ community has developed guidelines for splitting the separate concerns of a binary program when `main` starts getting large. This process has the following steps: -* Split your program into a *main.rs* and a *lib.rs* and move your program’s - logic to *lib.rs*. +* Split your program into a *main.rs* file and a *lib.rs* file and move your + program’s logic to *lib.rs*. * As long as your command line parsing logic is small, it can remain in *main.rs*. * When the command line parsing logic starts getting complicated, extract it @@ -57,7 +57,7 @@ should be limited to the following: * Handling the error if `run` returns an error This pattern is about separating concerns: *main.rs* handles running the -program, and *lib.rs* handles all the logic of the task at hand. Because you +program and *lib.rs* handles all the logic of the task at hand. Because you can’t test the `main` function directly, this structure lets you test all of your program’s logic by moving it into functions in *lib.rs*. The code that remains in *main.rs* will be small enough to verify its correctness by reading @@ -163,7 +163,7 @@ named for their purpose. So far, we’ve extracted the logic responsible for parsing the command line arguments from `main` and placed it in the `parse_config` function. Doing so -helped us to see that the `query` and `file_path` values were related and that +helped us see that the `query` and `file_path` values were related, and that relationship should be conveyed in our code. We then added a `Config` struct to name the related purpose of `query` and `file_path` and to be able to return the values’ names as struct field names from the `parse_config` function. @@ -208,8 +208,8 @@ they should do instead. Let’s fix that now. #### Improving the Error Message In Listing 12-8, we add a check in the `new` function that will verify that the -slice is long enough before accessing index 1 and 2. If the slice isn’t long -enough, the program panics and displays a better error message. +slice is long enough before accessing index 1 and index 2. If the slice isn’t +long enough, the program panics and displays a better error message. @@ -222,10 +222,10 @@ enough, the program panics and displays a better error message. This code is similar to [the `Guess::new` function we wrote in Listing 9-13][ch9-custom-types], where we called `panic!` when the `value` argument was out of the range of valid values. Instead of checking for -a range of values here, we’re checking that the length of `args` is at least 3 -and the rest of the function can operate under the assumption that this +a range of values here, we’re checking that the length of `args` is at least +`3` and the rest of the function can operate under the assumption that this condition has been met. If `args` has fewer than three items, this condition -will be true, and we call the `panic!` macro to end the program immediately. +will be `true`, and we call the `panic!` macro to end the program immediately. With these extra few lines of code in `new`, let’s run the program without any arguments again to see what the error looks like now: @@ -235,8 +235,8 @@ arguments again to see what the error looks like now: ``` This output is better: we now have a reasonable error message. However, we also -have extraneous information we don’t want to give to our users. Perhaps using -the technique we used in Listing 9-13 isn’t the best to use here: a call to +have extraneous information we don’t want to give to our users. Perhaps the +technique we used in Listing 9-13 isn’t the best one to use here: a call to `panic!` is more appropriate for a programming problem than a usage problem, [as discussed in Chapter 9][ch9-error-guidelines]. Instead, we’ll use the other technique you learned about in Chapter 9—[returning a @@ -306,15 +306,15 @@ In this listing, we’ve used a method we haven’t covered in detail yet: `unwrap_or_else`, which is defined on `Result` by the standard library. Using `unwrap_or_else` allows us to define some custom, non-`panic!` error handling. If the `Result` is an `Ok` value, this method’s behavior is similar -to `unwrap`: it returns the inner value `Ok` is wrapping. However, if the value -is an `Err` value, this method calls the code in the *closure*, which is an -anonymous function we define and pass as an argument to `unwrap_or_else`. We’ll -cover closures in more detail in [Chapter 13][ch13]. For now, -you just need to know that `unwrap_or_else` will pass the inner value of the -`Err`, which in this case is the static string `"not enough arguments"` that we -added in Listing 12-9, to our closure in the argument `err` that appears -between the vertical pipes. The code in the closure can then use the `err` -value when it runs. +to `unwrap`: it returns the inner value that `Ok` is wrapping. However, if the +value is an `Err` value, this method calls the code in the *closure*, which is +an anonymous function we define and pass as an argument to `unwrap_or_else`. +We’ll cover closures in more detail in [Chapter 13][ch13]. For +now, you just need to know that `unwrap_or_else` will pass the inner value of +the `Err`, which in this case is the static string `"not enough arguments"` +that we added in Listing 12-9, to our closure in the argument `err` that +appears between the vertical pipes. The code in the closure can then use the +`err` value when it runs. We’ve added a new `use` line to bring `process` from the standard library into scope. The code in the closure that will be run in the error case is only two @@ -386,7 +386,7 @@ know that `Box` means the function will return a type that implements the `Error` trait, but we don’t have to specify what particular type the return value will be. This gives us flexibility to return error values that may be of different types in different error cases. The `dyn` keyword is short -for “dynamic.” +for *dynamic*. Second, we’ve removed the call to `expect` in favor of the `?` operator, as we talked about in [Chapter 9][ch9-question-mark]. Rather than @@ -423,11 +423,11 @@ with `Config::build` in Listing 12-10, but with a slight difference: ``` We use `if let` rather than `unwrap_or_else` to check whether `run` returns an -`Err` value and call `process::exit(1)` if it does. The `run` function doesn’t -return a value that we want to `unwrap` in the same way that `Config::build` -returns the `Config` instance. Because `run` returns `()` in the success case, -we only care about detecting an error, so we don’t need `unwrap_or_else` to -return the unwrapped value, which would only be `()`. +`Err` value and to call `process::exit(1)` if it does. The `run` function +doesn’t return a value that we want to `unwrap` in the same way that +`Config::build` returns the `Config` instance. Because `run` returns `()` in +the success case, we only care about detecting an error, so we don’t need +`unwrap_or_else` to return the unwrapped value, which would only be `()`. The bodies of the `if let` and the `unwrap_or_else` functions are the same in both cases: we print the error and exit. @@ -435,10 +435,10 @@ both cases: we print the error and exit. ### Splitting Code into a Library Crate Our `minigrep` project is looking good so far! Now we’ll split the -*src/main.rs* file and put some code into the *src/lib.rs* file. That way we +*src/main.rs* file and put some code into the *src/lib.rs* file. That way, we can test the code and have a *src/main.rs* file with fewer responsibilities. -Let’s move all the code that isn’t the `main` function from *src/main.rs* to +Let’s move all the code that isn’t in the `main` function from *src/main.rs* to *src/lib.rs*: * The `run` function definition @@ -476,8 +476,7 @@ binary crate in *src/main.rs*, as shown in Listing 12-14. We add a `use minigrep::Config` line to bring the `Config` type from the library crate into the binary crate’s scope, and we prefix the `run` function with our crate name. Now all the functionality should be connected and should -work. Run the program with `cargo run` and make sure everything works -correctly. +work. Run the program with `cargo run` and make sure everything works correctly. Whew! That was a lot of work, but we’ve set ourselves up for success in the future. Now it’s much easier to handle errors, and we’ve made the code more diff --git a/src/ch12-04-testing-the-librarys-functionality.md b/src/ch12-04-testing-the-librarys-functionality.md index c4a435bc08..7034783d7c 100644 --- a/src/ch12-04-testing-the-librarys-functionality.md +++ b/src/ch12-04-testing-the-librarys-functionality.md @@ -6,21 +6,21 @@ for the core functionality of our code. We can call functions directly with various arguments and check return values without having to call our binary from the command line. -In this section, we’ll add the searching logic to the `minigrep` program -using the test-driven development (TDD) process with the following steps: +In this section, we’ll add the searching logic to the `minigrep` program using +the test-driven development (TDD) process with the following steps: 1. Write a test that fails and run it to make sure it fails for the reason you expect. 2. Write or modify just enough code to make the new test pass. -3. Refactor the code you just added or changed and make sure the tests - continue to pass. +3. Refactor the code you just added or changed and make sure the tests continue + to pass. 4. Repeat from step 1! Though it’s just one of many ways to write software, TDD can help drive code design. Writing the test before you write the code that makes the test pass helps to maintain high test coverage throughout the process. -We’ll test drive the implementation of the functionality that will actually do +We’ll test-drive the implementation of the functionality that will actually do the searching for the query string in the file contents and produce a list of lines that match the query. We’ll add this functionality in a function called `search`. @@ -29,11 +29,11 @@ lines that match the query. We’ll add this functionality in a function called Because we don’t need them anymore, let’s remove the `println!` statements from *src/lib.rs* and *src/main.rs* that we used to check the program’s behavior. -Then, in *src/lib.rs*, add a `tests` module with a test function, as we did in -[Chapter 11][ch11-anatomy]. The test function specifies the -behavior we want the `search` function to have: it will take a query and the -text to search, and it will return only the lines from the text that contain -the query. Listing 12-15 shows this test, which won’t compile yet. +Then, in *src/lib.rs*, we’ll add a `tests` module with a test function, as we +did in [Chapter 11][ch11-anatomy]. The test function specifies +the behavior we want the `search` function to have: it will take a query and +the text to search, and it will return only the lines from the text that +contain the query. Listing 12-15 shows this test, which won’t compile yet. @@ -44,7 +44,7 @@ the query. Listing 12-15 shows this test, which won’t compile yet. This test searches for the string `"duct"`. The text we’re searching is three -lines, only one of which contains `"duct"` (Note that the backslash after the +lines, only one of which contains `"duct"` (note that the backslash after the opening double quote tells Rust not to put a newline character at the beginning of the contents of this string literal). We assert that the value returned from the `search` function contains only the line we expect. @@ -95,9 +95,9 @@ syntax. Other programming languages don’t require you to connect arguments to return values in the signature, but this practice will get easier over time. You might -want to compare this example with the [“Validating References with -Lifetimes”][validating-references-with-lifetimes] section in -Chapter 10. +want to compare this example with the examples in the [“Validating References +with Lifetimes”][validating-references-with-lifetimes] section +in Chapter 10. Now let’s run the test: @@ -112,19 +112,19 @@ Great, the test fails, exactly as we expected. Let’s get the test to pass! Currently, our test is failing because we always return an empty vector. To fix that and implement `search`, our program needs to follow these steps: -* Iterate through each line of the contents. -* Check whether the line contains our query string. -* If it does, add it to the list of values we’re returning. -* If it doesn’t, do nothing. -* Return the list of results that match. +1. Iterate through each line of the contents. +2. Check whether the line contains our query string. +3. If it does, add it to the list of values we’re returning. +4. If it doesn’t, do nothing. +5. Return the list of results that match. Let’s work through each step, starting with iterating through lines. #### Iterating Through Lines with the `lines` Method Rust has a helpful method to handle line-by-line iteration of strings, -conveniently named `lines`, that works as shown in Listing 12-17. Note this -won’t compile yet. +conveniently named `lines`, that works as shown in Listing 12-17. Note that +this won’t compile yet. @@ -144,7 +144,7 @@ of using an iterator in [Listing 3-5][ch3-iter], where we used a Next, we’ll check whether the current line contains our query string. Fortunately, strings have a helpful method named `contains` that does this for us! Add a call to the `contains` method in the `search` function, as shown in -Listing 12-18. Note this still won’t compile yet. +Listing 12-18. Note that this still won’t compile yet. @@ -154,8 +154,8 @@ Listing 12-18. Note this still won’t compile yet. -At the moment, we’re building up functionality. To get it to compile, we need -to return a value from the body as we indicated we would in the function +At the moment, we’re building up functionality. To get the code to compile, we +need to return a value from the body as we indicated we would in the function signature. #### Storing Matching Lines @@ -205,20 +205,20 @@ will print each line returned from `search`: We’re still using a `for` loop to return each line from `search` and print it. Now the entire program should work! Let’s try it out, first with a word that -should return exactly one line from the Emily Dickinson poem, “frog”: +should return exactly one line from the Emily Dickinson poem: *frog*. ```console {{#include ../listings/ch12-an-io-project/no-listing-02-using-search-in-run/output.txt}} ``` -Cool! Now let’s try a word that will match multiple lines, like “body”: +Cool! Now let’s try a word that will match multiple lines, like *body*: ```console {{#include ../listings/ch12-an-io-project/output-only-03-multiple-matches/output.txt}} ``` And finally, let’s make sure that we don’t get any lines when we search for a -word that isn’t anywhere in the poem, such as “monomorphization”: +word that isn’t anywhere in the poem, such as *monomorphization*: ```console {{#include ../listings/ch12-an-io-project/output-only-04-no-matches/output.txt}} diff --git a/src/ch12-05-working-with-environment-variables.md b/src/ch12-05-working-with-environment-variables.md index f050b5b479..bea2a3f7d7 100644 --- a/src/ch12-05-working-with-environment-variables.md +++ b/src/ch12-05-working-with-environment-variables.md @@ -25,7 +25,7 @@ tests, as shown in Listing 12-20. Note that we’ve edited the old test’s `contents` too. We’ve added a new line -with the text `"Duct tape."` using a capital D that shouldn’t match the query +with the text `"Duct tape."` using a capital *D* that shouldn’t match the query `"duct"` when we’re searching in a case-sensitive manner. Changing the old test in this way helps ensure that we don’t accidentally break the case-sensitive search functionality that we’ve already implemented. This test should pass now @@ -33,9 +33,9 @@ and should continue to pass as we work on the case-insensitive search. The new test for the case-*insensitive* search uses `"rUsT"` as its query. In the `search_case_insensitive` function we’re about to add, the query `"rUsT"` -should match the line containing `"Rust:"` with a capital R and match the line -`"Trust me."` even though both have different casing from the query. This is -our failing test, and it will fail to compile because we haven’t yet defined +should match the line containing `"Rust:"` with a capital *R* and match the +line `"Trust me."` even though both have different casing from the query. This +is our failing test, and it will fail to compile because we haven’t yet defined the `search_case_insensitive` function. Feel free to add a skeleton implementation that always returns an empty vector, similar to the way we did for the `search` function in Listing 12-16 to see the test compile and fail. @@ -44,7 +44,7 @@ for the `search` function in Listing 12-16 to see the test compile and fail. The `search_case_insensitive` function, shown in Listing 12-21, will be almost the same as the `search` function. The only difference is that we’ll lowercase -the `query` and each `line` so whatever the case of the input arguments, +the `query` and each `line` so that whatever the case of the input arguments, they’ll be the same case when we check whether the line contains the query. @@ -55,8 +55,8 @@ they’ll be the same case when we check whether the line contains the query. -First, we lowercase the `query` string and store it in a shadowed variable with -the same name. Calling `to_lowercase` on the query is necessary so no +First we lowercase the `query` string and store it in a shadowed variable with +the same name. Calling `to_lowercase` on the query is necessary so that no matter whether the user’s query is `"rust"`, `"RUST"`, `"Rust"`, or `"rUsT"`, we’ll treat the query as if it were `"rust"` and be insensitive to the case. While `to_lowercase` will handle basic Unicode, it won’t be 100% accurate. If @@ -64,7 +64,7 @@ we were writing a real application, we’d want to do a bit more work here, but this section is about environment variables, not Unicode, so we’ll leave it at that here. -Note that `query` is now a `String` rather than a string slice, because calling +Note that `query` is now a `String` rather than a string slice because calling `to_lowercase` creates new data rather than referencing existing data. Say the query is `"rUsT"`, as an example: that string slice doesn’t contain a lowercase `u` or `t` for us to use, so we have to allocate a new `String` containing @@ -83,10 +83,10 @@ Let’s see if this implementation passes the tests: ``` Great! They passed. Now, let’s call the new `search_case_insensitive` function -from the `run` function. First, we’ll add a configuration option to the -`Config` struct to switch between case-sensitive and case-insensitive search. -Adding this field will cause compiler errors because we aren’t initializing -this field anywhere yet: +from the `run` function. First we’ll add a configuration option to the `Config` +struct to switch between case-sensitive and case-insensitive search. Adding +this field will cause compiler errors because we aren’t initializing this field +anywhere yet: Filename: src/lib.rs @@ -110,7 +110,7 @@ function, as shown in Listing 12-22. This still won’t compile yet. Finally, we need to check for the environment variable. The functions for working with environment variables are in the `env` module in the standard library, so we bring that module into scope at the top of *src/lib.rs*. Then -we’ll use the `var` function from the `env` module to check if any value +we’ll use the `var` function from the `env` module to check to see if any value has been set for an environment variable named `IGNORE_CASE`, as shown in Listing 12-23. @@ -122,7 +122,7 @@ Listing 12-23. -Here, we create a new variable `ignore_case`. To set its value, we call the +Here, we create a new variable, `ignore_case`. To set its value, we call the `env::var` function and pass it the name of the `IGNORE_CASE` environment variable. The `env::var` function returns a `Result` that will be the successful `Ok` variant that contains the value of the environment variable if @@ -132,7 +132,7 @@ if the environment variable is not set. We’re using the `is_ok` method on the `Result` to check whether the environment variable is set, which means the program should do a case-insensitive search. If the `IGNORE_CASE` environment variable isn’t set to anything, `is_ok` will -return false and the program will perform a case-sensitive search. We don’t +return `false` and the program will perform a case-sensitive search. We don’t care about the *value* of the environment variable, just whether it’s set or unset, so we’re checking `is_ok` rather than using `unwrap`, `expect`, or any of the other methods we’ve seen on `Result`. @@ -141,9 +141,9 @@ We pass the value in the `ignore_case` variable to the `Config` instance so the `run` function can read that value and decide whether to call `search_case_insensitive` or `search`, as we implemented in Listing 12-22. -Let’s give it a try! First, we’ll run our program without the environment +Let’s give it a try! First we’ll run our program without the environment variable set and with the query `to`, which should match any line that contains -the word “to” in all lowercase: +the word *to* in all lowercase: ```console {{#include ../listings/ch12-an-io-project/listing-12-23/output.txt}} @@ -163,14 +163,14 @@ run the program as separate commands: PS> $Env:IGNORE_CASE=1; cargo run -- to poem.txt ``` -This will make `IGNORE_CASE` persist for the remainder of your shell -session. It can be unset with the `Remove-Item` cmdlet: +This will make `IGNORE_CASE` persist for the remainder of your shell session. +It can be unset with the `Remove-Item` cmdlet: ```console PS> Remove-Item Env:IGNORE_CASE ``` -We should get lines that contain “to” that might have uppercase letters: +We should get lines that contain *to* that might have uppercase letters: -#### Returning a Result Instead of Calling panic! + + +#### Returning a `Result` Instead of Calling `panic!` We can instead return a `Result` value that will contain a `Config` instance in the successful case and will describe the problem in the error case. We’re also @@ -622,14 +640,14 @@ going to change the function name from `new` to `build` because many programmers expect `new` functions to never fail. When `Config::build` is communicating to `main`, we can use the `Result` type to signal there was a problem. Then we can change `main` to convert an `Err` variant into a more -practical error for our users without the surrounding text about `thread -'main'` and `RUST_BACKTRACE` that a call to `panic!` causes. +practical error for our users without the surrounding text about `thread 'main'` and `RUST_BACKTRACE` that a call to `panic!` causes. Listing 12-9 shows the changes we need to make to the return value of the function we’re now calling `Config::build` and the body of the function needed to return a `Result`. Note that this won’t compile until we update `main` as well, which we’ll do in the next listing. + Filename: src/main.rs ``` @@ -647,7 +665,7 @@ impl Config { } ``` -Listing 12-9: Returning a `Result` from `Config::build` +Listing 12-9: Returning a Result from Config::build Our `build` function returns a `Result` with a `Config` instance in the success case and an `&'static str` in the error case. Our error values will always be @@ -662,7 +680,11 @@ Returning an `Err` value from `Config::build` allows the `main` function to handle the `Result` value returned from the `build` function and exit the process more cleanly in the error case. -#### Calling Config::build and Handling Errors + + + + +#### Calling `Config::build` and Handling Errors To handle the error case and print a user-friendly message, we need to update `main` to handle the `Result` being returned by `Config::build`, as shown in @@ -671,41 +693,42 @@ tool with a nonzero error code away from `panic!` and instead implement it by hand. A nonzero exit status is a convention to signal to the process that called our program that the program exited with an error state. + Filename: src/main.rs ``` -1 use std::process; +use std::process; fn main() { let args: Vec = env::args().collect(); - 2 let config = Config::build(&args).3 unwrap_or_else(|4 err| { - 5 println!("Problem parsing arguments: {err}"); - 6 process::exit(1); + let config = Config::build(&args).unwrap_or_else(|err| { + println!("Problem parsing arguments: {err}"); + process::exit(1); }); - --snip-- + // --snip-- ``` -Listing 12-10: Exiting with an error code if building a `Config` fails +Listing 12-10: Exiting with an error code if building a Config fails In this listing, we’ve used a method we haven’t covered in detail yet: -`unwrap_or_else`, which is defined on `Result` by the standard library -[2]. Using `unwrap_or_else` allows us to define some custom, non-`panic!` error +`unwrap_or_else`, which is defined on `Result` by the standard library. +Using `unwrap_or_else` allows us to define some custom, non-`panic!` error handling. If the `Result` is an `Ok` value, this method’s behavior is similar to `unwrap`: it returns the inner value that `Ok` is wrapping. However, if the value is an `Err` value, this method calls the code in the *closure*, which is -an anonymous function we define and pass as an argument to `unwrap_or_else` -[3]. We’ll cover closures in more detail in Chapter 13. For now, you just need -to know that `unwrap_or_else` will pass the inner value of the `Err`, which in -this case is the static string `"not enough arguments"` that we added in -Listing 12-9, to our closure in the argument `err` that appears between the -vertical pipes [4]. The code in the closure can then use the `err` value when -it runs. +an anonymous function we define and pass as an argument to `unwrap_or_else`. +We’ll cover closures in more detail in Chapter 13. For +now, you just need to know that `unwrap_or_else` will pass the inner value of +the `Err`, which in this case is the static string `"not enough arguments"` +that we added in Listing 12-9, to our closure in the argument `err` that +appears between the vertical pipes. The code in the closure can then use the +`err` value when it runs. We’ve added a new `use` line to bring `process` from the standard library into -scope [1]. The code in the closure that will be run in the error case is only -two lines: we print the `err` value [5] and then call `process::exit` [6]. The +scope. The code in the closure that will be run in the error case is only two +lines: we print the `err` value and then call `process::exit`. The `process::exit` function will stop the program immediately and return the number that was passed as the exit status code. This is similar to the `panic!`-based handling we used in Listing 12-8, but we no longer get all the @@ -721,25 +744,26 @@ Problem parsing arguments: not enough arguments Great! This output is much friendlier for our users. -### Extracting Logic from main +### Extracting Logic from `main` Now that we’ve finished refactoring the configuration parsing, let’s turn to the program’s logic. As we stated in “Separation of Concerns for Binary -Projects” on page XX, we’ll extract a function named `run` that will hold all -the logic currently in the `main` function that isn’t involved with setting up -configuration or handling errors. When we’re done, `main` will be concise and -easy to verify by inspection, and we’ll be able to write tests for all the -other logic. +Projects”, we’ll +extract a function named `run` that will hold all the logic currently in the +`main` function that isn’t involved with setting up configuration or handling +errors. When we’re done, `main` will be concise and easy to verify by +inspection, and we’ll be able to write tests for all the other logic. Listing 12-11 shows the extracted `run` function. For now, we’re just making the small, incremental improvement of extracting the function. We’re still defining the function in *src/main.rs*. + Filename: src/main.rs ``` fn main() { - --snip-- + // --snip-- println!("Searching for {}", config.query); println!("In file {}", config.file_path); @@ -754,17 +778,16 @@ fn run(config: Config) { println!("With text:\n{contents}"); } ---snip-- +// --snip-- ``` -Listing 12-11: Extracting a `run` function containing the rest of the program -logic +Listing 12-11: Extracting a run function containing the rest of the program logic The `run` function now contains all the remaining logic from `main`, starting from reading the file. The `run` function takes the `Config` instance as an argument. -#### Returning Errors from the run Function +#### Returning Errors from the `run` Function With the remaining program logic separated into the `run` function, we can improve the error handling, as we did with `Config::build` in Listing 12-9. @@ -774,42 +797,45 @@ us further consolidate the logic around handling errors into `main` in a user-friendly way. Listing 12-12 shows the changes we need to make to the signature and body of `run`. + Filename: src/main.rs ``` -1 use std::error::Error; +use std::error::Error; ---snip-- +// --snip-- -2 fn run(config: Config) -> Result<(), Box> { - let contents = fs::read_to_string(config.file_path)3 ?; +fn run(config: Config) -> Result<(), Box> { + let contents = fs::read_to_string(config.file_path)?; println!("With text:\n{contents}"); - 4 Ok(()) + Ok(()) } ``` -Listing 12-12: Changing the `run` function to return `Result` +Listing 12-12: Changing the run function to return Result We’ve made three significant changes here. First, we changed the return type of -the `run` function to `Result<(), Box>` [2]. This function -previously returned the unit type, `()`, and we keep that as the value returned -in the `Ok` case. +the `run` function to `Result<(), Box>`. This function previously +returned the unit type, `()`, and we keep that as the value returned in the +`Ok` case. For the error type, we used the *trait object* `Box` (and we’ve -brought `std::error::Error` into scope with a `use` statement at the top [1]). -We’ll cover trait objects in Chapter 17. For now, just know that `Box` means the function will return a type that implements the `Error` -trait, but we don’t have to specify what particular type the return value will -be. This gives us flexibility to return error values that may be of different -types in different error cases. The `dyn` keyword is short for *dynamic*. - -Second, we’ve removed the call to `expect` in favor of the `?` operator [3], as -we talked about in Chapter 9. Rather than `panic!` on an error, `?` will return -the error value from the current function for the caller to handle. - -Third, the `run` function now returns an `Ok` value in the success case [4]. +brought `std::error::Error` into scope with a `use` statement at the top). +We’ll cover trait objects in Chapter 17. For now, just +know that `Box` means the function will return a type that +implements the `Error` trait, but we don’t have to specify what particular type +the return value will be. This gives us flexibility to return error values that +may be of different types in different error cases. The `dyn` keyword is short +for *dynamic*. + +Second, we’ve removed the call to `expect` in favor of the `?` operator, as we +talked about in Chapter 9. Rather than +`panic!` on an error, `?` will return the error value from the current function +for the caller to handle. + +Third, the `run` function now returns an `Ok` value in the success case. We’ve declared the `run` function’s success type as `()` in the signature, which means we need to wrap the unit type value in the `Ok` value. This `Ok(())` syntax might look a bit strange at first, but using `()` like this is @@ -819,6 +845,8 @@ only; it doesn’t return a value we need. When you run this code, it will compile but will display a warning: ``` +$ cargo run -- the poem.txt + Compiling minigrep v0.1.0 (file:///projects/minigrep) warning: unused `Result` that must be used --> src/main.rs:19:5 | @@ -828,6 +856,21 @@ warning: unused `Result` that must be used = note: `#[warn(unused_must_use)]` on by default = note: this `Result` may be an `Err` variant, which should be handled + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.71s + Running `target/debug/minigrep the poem.txt` +Searching for the +In file poem.txt +With text: +I'm nobody! Who are you? +Are you nobody, too? +Then there's a pair of us - don't tell! +They'd banish us, you know. + +How dreary to be somebody! +How public, like a frog +To tell your name the livelong day +To an admiring bog! + ``` Rust tells us that our code ignored the `Result` value and the `Result` value @@ -835,7 +878,7 @@ might indicate that an error occurred. But we’re not checking to see whether o not there was an error, and the compiler reminds us that we probably meant to have some error-handling code here! Let’s rectify that problem now. -#### Handling Errors Returned from run in main +#### Handling Errors Returned from `run` in `main` We’ll check for errors and handle them using a technique similar to one we used with `Config::build` in Listing 12-10, but with a slight difference: @@ -844,7 +887,7 @@ Filename: src/main.rs ``` fn main() { - --snip-- + // --snip-- println!("Searching for {}", config.query); println!("In file {}", config.file_path); @@ -884,6 +927,7 @@ The contents of *src/lib.rs* should have the signatures shown in Listing 12-13 (we’ve omitted the bodies of the functions for brevity). Note that this won’t compile until we modify *src/main.rs* in Listing 12-14. + Filename: src/lib.rs ``` @@ -896,19 +940,17 @@ pub struct Config { } impl Config { - pub fn build( - args: &[String], - ) -> Result { - --snip-- + pub fn build(args: &[String]) -> Result { + // --snip-- } } pub fn run(config: Config) -> Result<(), Box> { - --snip-- + // --snip-- } ``` -Listing 12-13: Moving `Config` and `run` into *src/lib.rs* +Listing 12-13: Moving Config and run into src/lib.rs We’ve made liberal use of the `pub` keyword: on `Config`, on its fields and its `build` method, and on the `run` function. We now have a library crate that has @@ -917,6 +959,7 @@ a public API we can test! Now we need to bring the code we moved to *src/lib.rs* into the scope of the binary crate in *src/main.rs*, as shown in Listing 12-14. + Filename: src/main.rs ``` @@ -926,14 +969,14 @@ use std::process; use minigrep::Config; fn main() { - --snip-- + // --snip-- if let Err(e) = minigrep::run(config) { - --snip-- + // --snip-- } } ``` -Listing 12-14: Using the `minigrep` library crate in *src/main.rs* +Listing 12-14: Using the minigrep library crate in src/main.rs We add a `use minigrep::Config` line to bring the `Config` type from the library crate into the binary crate’s scope, and we prefix the `run` function @@ -960,10 +1003,10 @@ In this section, we’ll add the searching logic to the `minigrep` program using the test-driven development (TDD) process with the following steps: 1. Write a test that fails and run it to make sure it fails for the reason you -expect. + expect. 1. Write or modify just enough code to make the new test pass. 1. Refactor the code you just added or changed and make sure the tests continue -to pass. + to pass. 1. Repeat from step 1! Though it’s just one of many ways to write software, TDD can help drive code @@ -980,10 +1023,11 @@ lines that match the query. We’ll add this functionality in a function called Because we don’t need them anymore, let’s remove the `println!` statements from *src/lib.rs* and *src/main.rs* that we used to check the program’s behavior. Then, in *src/lib.rs*, we’ll add a `tests` module with a test function, as we -did in Chapter 11. The test function specifies the behavior we want the -`search` function to have: it will take a query and the text to search, and it -will return only the lines from the text that contain the query. Listing 12-15 -shows this test, which won’t compile yet. +did in Chapter 11. The test function specifies +the behavior we want the `search` function to have: it will take a query and +the text to search, and it will return only the lines from the text that +contain the query. Listing 12-15 shows this test, which won’t compile yet. + Filename: src/lib.rs @@ -1000,15 +1044,12 @@ Rust: safe, fast, productive. Pick three."; - assert_eq!( - vec!["safe, fast, productive."], - search(query, contents) - ); + assert_eq!(vec!["safe, fast, productive."], search(query, contents)); } } ``` -Listing 12-15: Creating a failing test for the `search` function we wish we had +Listing 12-15: Creating a failing test for the search function we wish we had This test searches for the string `"duct"`. The text we’re searching is three lines, only one of which contains `"duct"` (note that the backslash after the @@ -1021,29 +1062,26 @@ even compile: the `search` function doesn’t exist yet! In accordance with TDD principles, we’ll add just enough code to get the test to compile and run by adding a definition of the `search` function that always returns an empty vector, as shown in Listing 12-16. Then the test should compile and fail -because an empty vector doesn’t match a vector containing the line `"safe, -fast, productive."` +because an empty vector doesn’t match a vector containing the line `"safe, fast, productive."` + Filename: src/lib.rs ``` -pub fn search<'a>( - query: &str, - contents: &'a str, -) -> Vec<&'a str> { +pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> { vec![] } ``` -Listing 12-16: Defining just enough of the `search` function so our test will -compile +Listing 12-16: Defining just enough of the search function so our test will compile Notice that we need to define an explicit lifetime `'a` in the signature of `search` and use that lifetime with the `contents` argument and the return -value. Recall in Chapter 10 that the lifetime parameters specify which argument -lifetime is connected to the lifetime of the return value. In this case, we -indicate that the returned vector should contain string slices that reference -slices of the argument `contents` (rather than the argument `query`). +value. Recall in Chapter 10 that the lifetime +parameters specify which argument lifetime is connected to the lifetime of the +return value. In this case, we indicate that the returned vector should contain +string slices that reference slices of the argument `contents` (rather than the +argument `query`). In other words, we tell Rust that the data returned by the `search` function will live as long as the data passed into the `search` function in the @@ -1056,25 +1094,22 @@ If we forget the lifetime annotations and try to compile this function, we’ll get this error: ``` +$ cargo build + Compiling minigrep v0.1.0 (file:///projects/minigrep) error[E0106]: missing lifetime specifier - --> src/lib.rs:31:10 + --> src/lib.rs:28:51 | -29 | query: &str, - | ---- -30 | contents: &str, - | ---- -31 | ) -> Vec<&str> { - | ^ expected named lifetime parameter +28 | pub fn search(query: &str, contents: &str) -> Vec<&str> { + | ---- ---- ^ expected named lifetime parameter | - = help: this function's return type contains a borrowed value, but the -signature does not say whether it is borrowed from `query` or `contents` + = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `query` or `contents` help: consider introducing a named lifetime parameter | -28 ~ pub fn search<'a>( -29 ~ query: &'a str, -30 ~ contents: &'a str, -31 ~ ) -> Vec<&'a str> { - | +28 | pub fn search<'a>(query: &'a str, contents: &'a str) -> Vec<&'a str> { + | ++++ ++ ++ ++ + +For more information about this error, try `rustc --explain E0106`. +error: could not compile `minigrep` (lib) due to 1 previous error ``` Rust can’t possibly know which of the two arguments we need, so we need to tell @@ -1085,8 +1120,9 @@ syntax. Other programming languages don’t require you to connect arguments to return values in the signature, but this practice will get easier over time. You might -want to compare this example with the examples in “Validating References with -Lifetimes” on page XX. +want to compare this example with the examples in the “Validating References +with Lifetimes” section +in Chapter 10. Now let’s run the test: @@ -1111,8 +1147,7 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: tests::one_result -test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; -finished in 0.00s +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s error: test failed, to rerun pass '--lib' ``` @@ -1132,31 +1167,29 @@ that and implement `search`, our program needs to follow these steps: Let’s work through each step, starting with iterating through lines. -#### Iterating Through Lines with the lines Method +#### Iterating Through Lines with the `lines` Method Rust has a helpful method to handle line-by-line iteration of strings, conveniently named `lines`, that works as shown in Listing 12-17. Note that this won’t compile yet. + Filename: src/lib.rs ``` -pub fn search<'a>( - query: &str, - contents: &'a str, -) -> Vec<&'a str> { +pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> { for line in contents.lines() { // do something with line } } ``` -Listing 12-17: Iterating through each line in `contents` +Listing 12-17: Iterating through each line in contents The `lines` method returns an iterator. We’ll talk about iterators in depth in -Chapter 13, but recall that you saw this way of using an iterator in Listing -3-5, where we used a `for` loop with an iterator to run some code on each item -in a collection. +Chapter 13, but recall that you saw this way +of using an iterator in Listing 3-5, where we used a +`for` loop with an iterator to run some code on each item in a collection. #### Searching Each Line for the Query @@ -1165,13 +1198,11 @@ Fortunately, strings have a helpful method named `contains` that does this for us! Add a call to the `contains` method in the `search` function, as shown in Listing 12-18. Note that this still won’t compile yet. + Filename: src/lib.rs ``` -pub fn search<'a>( - query: &str, - contents: &'a str, -) -> Vec<&'a str> { +pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> { for line in contents.lines() { if line.contains(query) { // do something with line @@ -1180,8 +1211,7 @@ pub fn search<'a>( } ``` -Listing 12-18: Adding functionality to see whether the line contains the string -in `query` +Listing 12-18: Adding functionality to see whether the line contains the string in query At the moment, we’re building up functionality. To get the code to compile, we need to return a value from the body as we indicated we would in the function @@ -1194,13 +1224,11 @@ to return. For that, we can make a mutable vector before the `for` loop and call the `push` method to store a `line` in the vector. After the `for` loop, we return the vector, as shown in Listing 12-19. + Filename: src/lib.rs ``` -pub fn search<'a>( - query: &str, - contents: &'a str, -) -> Vec<&'a str> { +pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> { let mut results = Vec::new(); for line in contents.lines() { @@ -1220,12 +1248,27 @@ and our test should pass. Let’s run the test: ``` $ cargo test ---snip-- + Compiling minigrep v0.1.0 (file:///projects/minigrep) + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.22s + Running unittests src/lib.rs (target/debug/deps/minigrep-9cd200e5fac0fc94) + running 1 test test tests::one_result ... ok -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Running unittests src/main.rs (target/debug/deps/minigrep-9cd200e5fac0fc94) + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests minigrep + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` Our test passed, so we know it works! @@ -1234,10 +1277,10 @@ At this point, we could consider opportunities for refactoring the implementation of the search function while keeping the tests passing to maintain the same functionality. The code in the search function isn’t too bad, but it doesn’t take advantage of some useful features of iterators. We’ll -return to this example in Chapter 13, where we’ll explore iterators in detail, -and look at how to improve it. +return to this example in Chapter 13, where +we’ll explore iterators in detail, and look at how to improve it. -#### Using the search Function in the run Function +#### Using the `search` Function in the `run` Function Now that the `search` function is working and tested, we need to call `search` from our `run` function. We need to pass the `config.query` value and the @@ -1308,7 +1351,7 @@ users enter it each time they want it to apply, but by instead making it an environment variable, we allow our users to set the environment variable once and have all their searches be case insensitive in that terminal session. -### Writing a Failing Test for the Case-Insensitive search Function +### Writing a Failing Test for the Case-Insensitive `search` Function We first add a new `search_case_insensitive` function that will be called when the environment variable has a value. We’ll continue to follow the TDD process, @@ -1317,6 +1360,7 @@ the new `search_case_insensitive` function and rename our old test from `one_result` to `case_sensitive` to clarify the differences between the two tests, as shown in Listing 12-20. + Filename: src/lib.rs ``` @@ -1333,10 +1377,7 @@ safe, fast, productive. Pick three. Duct tape."; - assert_eq!( - vec!["safe, fast, productive."], - search(query, contents) - ); + assert_eq!(vec!["safe, fast, productive."], search(query, contents)); } #[test] @@ -1356,8 +1397,7 @@ Trust me."; } ``` -Listing 12-20: Adding a new failing test for the case-insensitive function -we’re about to add +Listing 12-20: Adding a new failing test for the case-insensitive function we’re about to add Note that we’ve edited the old test’s `contents` too. We’ve added a new line with the text `"Duct tape."` using a capital *D* that shouldn’t match the query @@ -1375,13 +1415,14 @@ the `search_case_insensitive` function. Feel free to add a skeleton implementation that always returns an empty vector, similar to the way we did for the `search` function in Listing 12-16 to see the test compile and fail. -### Implementing the search_case_insensitive Function +### Implementing the `search_case_insensitive` Function The `search_case_insensitive` function, shown in Listing 12-21, will be almost the same as the `search` function. The only difference is that we’ll lowercase the `query` and each `line` so that whatever the case of the input arguments, they’ll be the same case when we check whether the line contains the query. + Filename: src/lib.rs ``` @@ -1389,11 +1430,11 @@ pub fn search_case_insensitive<'a>( query: &str, contents: &'a str, ) -> Vec<&'a str> { - 1 let query = query.to_lowercase(); + let query = query.to_lowercase(); let mut results = Vec::new(); for line in contents.lines() { - if 2 line.to_lowercase().contains(3 &query) { + if line.to_lowercase().contains(&query) { results.push(line); } } @@ -1402,11 +1443,10 @@ pub fn search_case_insensitive<'a>( } ``` -Listing 12-21: Defining the `search_case_insensitive` function to lowercase the -query and the line before comparing them +Listing 12-21: Defining the search_case_insensitive function to lowercase the query and the line before comparing them First we lowercase the `query` string and store it in a shadowed variable with -the same name [1]. Calling `to_lowercase` on the query is necessary so that no +the same name. Calling `to_lowercase` on the query is necessary so that no matter whether the user’s query is `"rust"`, `"RUST"`, `"Rust"`, or `"rUsT"`, we’ll treat the query as if it were `"rust"` and be insensitive to the case. While `to_lowercase` will handle basic Unicode, it won’t be 100% accurate. If @@ -1419,22 +1459,39 @@ Note that `query` is now a `String` rather than a string slice because calling query is `"rUsT"`, as an example: that string slice doesn’t contain a lowercase `u` or `t` for us to use, so we have to allocate a new `String` containing `"rust"`. When we pass `query` as an argument to the `contains` method now, we -need to add an ampersand [3] because the signature of `contains` is defined to -take a string slice. +need to add an ampersand because the signature of `contains` is defined to take +a string slice. Next, we add a call to `to_lowercase` on each `line` to lowercase all -characters [2]. Now that we’ve converted `line` and `query` to lowercase, we’ll +characters. Now that we’ve converted `line` and `query` to lowercase, we’ll find matches no matter what the case of the query is. Let’s see if this implementation passes the tests: ``` +$ cargo test + Compiling minigrep v0.1.0 (file:///projects/minigrep) + Finished `test` profile [unoptimized + debuginfo] target(s) in 1.33s + Running unittests src/lib.rs (target/debug/deps/minigrep-9cd200e5fac0fc94) + running 2 tests test tests::case_insensitive ... ok test tests::case_sensitive ... ok -test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 -filtered out; finished in 0.00s +test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Running unittests src/main.rs (target/debug/deps/minigrep-9cd200e5fac0fc94) + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests minigrep + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + ``` Great! They passed. Now, let’s call the new `search_case_insensitive` function @@ -1458,6 +1515,7 @@ function to check the `ignore_case` field’s value and use that to decide whether to call the `search` function or the `search_case_insensitive` function, as shown in Listing 12-22. This still won’t compile yet. + Filename: src/lib.rs ``` @@ -1478,8 +1536,7 @@ pub fn run(config: Config) -> Result<(), Box> { } ``` -Listing 12-22: Calling either `search` or `search_case_insensitive` based on -the value in `config.ignore_case` +Listing 12-22: Calling either search or search_case_insensitive based on the value in config.ignore_case Finally, we need to check for the environment variable. The functions for working with environment variables are in the `env` module in the standard @@ -1488,16 +1545,15 @@ we’ll use the `var` function from the `env` module to check to see if any valu has been set for an environment variable named `IGNORE_CASE`, as shown in Listing 12-23. + Filename: src/lib.rs ``` use std::env; ---snip-- +// --snip-- impl Config { - pub fn build( - args: &[String] - ) -> Result { + pub fn build(args: &[String]) -> Result { if args.len() < 3 { return Err("not enough arguments"); } @@ -1516,8 +1572,7 @@ impl Config { } ``` -Listing 12-23: Checking for any value in an environment variable named -`IGNORE_CASE` +Listing 12-23: Checking for any value in an environment variable named IGNORE_CASE Here, we create a new variable, `ignore_case`. To set its value, we call the `env::var` function and pass it the name of the `IGNORE_CASE` environment @@ -1574,6 +1629,12 @@ PS> Remove-Item Env:IGNORE_CASE We should get lines that contain *to* that might have uppercase letters: + + ``` Are you nobody, too? How dreary to be somebody! @@ -1653,6 +1714,7 @@ the `eprintln!` macro that prints to the standard error stream, so let’s chang the two places we were calling `println!` to print errors to use `eprintln!` instead. + Filename: src/main.rs ``` @@ -1671,8 +1733,7 @@ fn main() { } ``` -Listing 12-24: Writing error messages to standard error instead of standard -output using `eprintln!` +Listing 12-24: Writing error messages to standard error instead of standard output using eprintln! Let’s now run the program again in the same way, without any arguments and redirecting standard output with `>`: @@ -1717,4 +1778,3 @@ well tested. Next, we’ll explore some Rust features that were influenced by functional languages: closures and iterators. - From e7d217be2a75ef1753f0988d6ccaba4d7e376259 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 13 Aug 2024 20:40:47 -0400 Subject: [PATCH 518/720] Snapshot changes to ch 12 to consider sending to nostarch --- nostarch/chapter12.md | 87 +++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/nostarch/chapter12.md b/nostarch/chapter12.md index f1020eed49..3ce134974b 100644 --- a/nostarch/chapter12.md +++ b/nostarch/chapter12.md @@ -137,7 +137,7 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.61s Running `target/debug/minigrep` -[src/main.rs:5] args = [ +[src/main.rs:5:5] args = [ "target/debug/minigrep", ] ``` @@ -147,7 +147,7 @@ $ cargo run -- needle haystack Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.57s Running `target/debug/minigrep needle haystack` -[src/main.rs:5] args = [ +[src/main.rs:5:5] args = [ "target/debug/minigrep", "needle", "haystack", @@ -181,8 +181,8 @@ fn main() { let query = &args[1]; let file_path = &args[2]; - println!("Searching for {}", query); - println!("In file {}", file_path); + println!("Searching for {query}"); + println!("In file {file_path}"); } ``` @@ -202,7 +202,7 @@ and `sample.txt`: ``` $ cargo run -- test sample.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep test sample.txt` Searching for test In file sample.txt @@ -252,7 +252,7 @@ use std::fs; fn main() { // --snip-- - println!("In file {}", file_path); + println!("In file {file_path}"); let contents = fs::read_to_string(file_path) .expect("Should have been able to read the file"); @@ -267,7 +267,8 @@ First we bring in a relevant part of the standard library with a `use` statement: we need `std::fs` to handle files. In `main`, the new statement `fs::read_to_string` takes the `file_path`, opens -that file, and returns an `std::io::Result` of the file’s contents [2]. +that file, and returns a value of type `std::io::Result` that contains +the file’s contents. After that, we again add a temporary `println!` statement that prints the value of `contents` after the file is read, so we can check that the program is @@ -280,7 +281,7 @@ second argument: ``` $ cargo run -- the poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep the poem.txt` Searching for the In file poem.txt @@ -331,13 +332,13 @@ example, the file could be missing, or we might not have permission to open it. Right now, regardless of the situation, we’d print the same error message for everything, which wouldn’t give the user any information! -Fourth, we use `expect` repeatedly to handle different errors, and if the user -runs our program without specifying enough arguments, they’ll get an `index out -of bounds` error from Rust that doesn’t clearly explain the problem. It would -be best if all the error-handling code were in one place so future maintainers -had only one place to consult the code if the error-handling logic needed to -change. Having all the error-handling code in one place will also ensure that -we’re printing messages that will be meaningful to our end users. +Fourth, we use `expect` to handle an error, and if the user runs our program +without specifying enough arguments, they’ll get an `index out of bounds` error +from Rust that doesn’t clearly explain the problem. It would be best if all the +error-handling code were in one place so future maintainers had only one place +to consult the code if the error-handling logic needed to change. Having all the +error-handling code in one place will also ensure that we’re printing messages +that will be meaningful to our end users. Let’s address these four problems by refactoring our project. @@ -566,12 +567,11 @@ without any arguments; it will look like this: ``` $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep` -thread 'main' panicked at 'index out of bounds: the len is 1 but -the index is 1', src/main.rs:27:21 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +thread 'main' panicked at src/main.rs:27:21: +index out of bounds: the len is 1 but the index is 1 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` The line `index out of bounds: the len is 1 but the index is 1` is an error @@ -612,12 +612,11 @@ arguments again to see what the error looks like now: ``` $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep` -thread 'main' panicked at 'not enough arguments', -src/main.rs:26:13 -note: run with `RUST_BACKTRACE=1` environment variable to display -a backtrace +thread 'main' panicked at src/main.rs:26:13: +not enough arguments +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` This output is better: we now have a reasonable error message. However, we also @@ -668,7 +667,7 @@ impl Config { Listing 12-9: Returning a Result from Config::build Our `build` function returns a `Result` with a `Config` instance in the success -case and an `&'static str` in the error case. Our error values will always be +case and a string literal in the error case. Our error values will always be string literals that have the `'static` lifetime. We’ve made two changes in the body of the function: instead of calling `panic!` @@ -737,7 +736,7 @@ extra output. Let’s try it: ``` $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.48s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s Running `target/debug/minigrep` Problem parsing arguments: not enough arguments ``` @@ -851,11 +850,16 @@ warning: unused `Result` that must be used --> src/main.rs:19:5 | 19 | run(config); - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^ | + = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default - = note: this `Result` may be an `Err` variant, which should be -handled +help: use `let _ = ...` to ignore the resulting value + | +19 | let _ = run(config); + | +++++++ + +warning: `minigrep` (bin "minigrep") generated 1 warning Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.71s Running `target/debug/minigrep the poem.txt` Searching for the @@ -1129,7 +1133,7 @@ Now let’s run the test: ``` $ cargo test Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished test [unoptimized + debuginfo] target(s) in 0.97s + Finished `test` profile [unoptimized + debuginfo] target(s) in 0.97s Running unittests src/lib.rs (target/debug/deps/minigrep-9cd200e5fac0fc94) running 1 test @@ -1138,9 +1142,10 @@ test tests::one_result ... FAILED failures: ---- tests::one_result stdout ---- -thread 'tests::one_result' panicked at 'assertion failed: `(left == right)` - left: `["safe, fast, productive."]`, - right: `[]`', src/lib.rs:47:9 +thread 'tests::one_result' panicked at src/lib.rs:44:9: +assertion `left == right` failed + left: ["safe, fast, productive."] + right: [] note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace @@ -1149,7 +1154,7 @@ failures: test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s -error: test failed, to rerun pass '--lib' +error: test failed, to rerun pass `--lib` ``` Great, the test fails, exactly as we expected. Let’s get the test to pass! @@ -1309,7 +1314,7 @@ should return exactly one line from the Emily Dickinson poem: *frog*. ``` $ cargo run -- frog poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.38s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.38s Running `target/debug/minigrep frog poem.txt` How public, like a frog ``` @@ -1318,7 +1323,8 @@ Cool! Now let’s try a word that will match multiple lines, like *body*: ``` $ cargo run -- body poem.txt - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Compiling minigrep v0.1.0 (file:///projects/minigrep) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep body poem.txt` I'm nobody! Who are you? Are you nobody, too? @@ -1330,7 +1336,8 @@ word that isn’t anywhere in the poem, such as *monomorphization*: ``` $ cargo run -- monomorphization poem.txt - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Compiling minigrep v0.1.0 (file:///projects/minigrep) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep monomorphization poem.txt` ``` @@ -1600,14 +1607,14 @@ the word *to* in all lowercase: ``` $ cargo run -- to poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) - Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep to poem.txt` Are you nobody, too? How dreary to be somebody! ``` Looks like that still works! Now let’s run the program with `IGNORE_CASE` set -to `1` but with the same query `to`: +to `1` but with the same query *to*: ``` $ IGNORE_CASE=1 cargo run -- to poem.txt From a42f27bd552126bb15a6f7ed7bcf5163ba010aee Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Sat, 24 Aug 2024 07:42:06 -0600 Subject: [PATCH 519/720] Ch. 17: Fix up diagrams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Set their view boxes to the original height and width, so they are guaranteed to present correctly. - For Figure 17-02, use the trick of adding a hidden node and hidden arrow to it in “Task 2” to align the two boxes. --- dot/trpl17-02.dot | 23 ++++---- src/img/trp17-02.svg | 1 - src/img/trpl17-01.svg | 6 +-- src/img/trpl17-02.svg | 122 +++++++++++++++++++++--------------------- 4 files changed, 79 insertions(+), 73 deletions(-) delete mode 100644 src/img/trp17-02.svg diff --git a/dot/trpl17-02.dot b/dot/trpl17-02.dot index 512f33cb9b..07d66a3e4b 100644 --- a/dot/trpl17-02.dot +++ b/dot/trpl17-02.dot @@ -1,20 +1,25 @@ digraph { dpi = 300.0; - + rankdir = "LR"; splines = false; cluster = true; - + node [shape = diamond;]; - + + // The graphs end up with the correct order, i.e. Task 1 *above* Task 2, when + // this is first. + subgraph cluster_ColleagueB { + label = "Task 2"; + B1 -> B2 -> B3; + + B0 [style = invis;]; + B3 -> B0 [style = invis;] + } + subgraph cluster_ColleagueA { newrank = true; label = "Task 1"; A1 -> A2 -> A3 -> A4; } - - subgraph cluster_ColleagueB { - label = "Task 2"; - B1 -> B2 -> B3; - } -} \ No newline at end of file +} diff --git a/src/img/trp17-02.svg b/src/img/trp17-02.svg deleted file mode 100644 index 1ad970d72c..0000000000 --- a/src/img/trp17-02.svg +++ /dev/null @@ -1 +0,0 @@ -Task 1Task 2ParallelA1A2A3A4B1B2B3 \ No newline at end of file diff --git a/src/img/trpl17-01.svg b/src/img/trpl17-01.svg index c99989ec31..483bf7216d 100644 --- a/src/img/trpl17-01.svg +++ b/src/img/trpl17-01.svg @@ -1,11 +1,11 @@ - - + diff --git a/src/img/trpl17-02.svg b/src/img/trpl17-02.svg index 1ddb5d4cad..b2df090c23 100644 --- a/src/img/trpl17-02.svg +++ b/src/img/trpl17-02.svg @@ -1,94 +1,96 @@ - - + -cluster_ColleagueA - -Task 1 +cluster_ColleagueB + +Task 2 -cluster_ColleagueB - -Task 2 +cluster_ColleagueA + +Task 1 - + +B1 + +B1 + + + +B2 + +B2 + + + +B1->B2 + + + + + +B3 + +B3 + + + +B2->B3 + + + + + + + A1 - -A1 + +A1 - + A2 - -A2 + +A2 - + A1->A2 - - + + - + A3 - -A3 + +A3 - + A2->A3 - - + + - + A4 - -A4 + +A4 - + A3->A4 - - - - - -B1 - -B1 - - - -B2 - -B2 - - - -B1->B2 - - - - - -B3 - -B3 - - - -B2->B3 - - + + From f812ed07c6a6add5bdae3e2d9d2c059692753e8a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Sat, 24 Aug 2024 07:42:06 -0600 Subject: [PATCH 520/720] =?UTF-8?q?Ch.=2017=C2=A700:=20second=20round=20of?= =?UTF-8?q?=20edits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch17-00-async-await.md | 56 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index e68c7420fc..bb289fdbf7 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -10,19 +10,19 @@ processes to complete. The video export will use as much CPU and GPU power as it can. If you only had one CPU core, and your operating system never paused that export until it completed, you could not do anything else on your computer while it was running. -That would be a pretty frustrating experience, though. Instead, your computer -can (and does!) invisibly interrupt the export often enough to let you get other -work done along the way. - -The file download is different. It does not take up very much CPU time. The CPU -needs to wait on data to arrive from the network. While you can start reading -the data once some of it arrives, it might take a while for the rest to arrive. -Even once the data has all arrived, videos can be quite large, so it might take -some time to load all the data from the network. Maybe it only takes a second or -two—but that is a very long time for a modern processor, which can do billions -of operations every second. It would be nice to be able to put the CPU to use -for other work while waiting for the network call to finish—so, again, your -computer will once again invisibly interrupt your program so other things can +That would be a pretty frustrating experience, though. Instead, your computer’s +operating sysem can (and does!) invisibly interrupt the export often enough to +let you get other work done along the way. + +The file download is different. It does not take up very much CPU time. Instead, +the CPU needs to wait on data to arrive from the network. While you can start +reading the data once some of it arrives, it might take a while for the rest to +arrive. Even once the data has all arrived, a video can be quite large, so it +might take some time to load it all. Maybe it only takes a second or two—but +that is a very long time for a modern processor, which can do billions of +operations every second. It would be nice to be able to put the CPU to use for +other work while waiting for the network call to finish—so, again, your +operating system will invisibly interrupt your program so other things can happen while the network operation is still ongoing. > Note: The video export is the kind of operation which is often described as @@ -33,8 +33,9 @@ happen while the network operation is still ongoing. > *input and output*. It can only go as fast as the data can be sent across the > network. -In both of these examples, the concurrency only happens at the level of a whole -program. The operating system interrupts one program to let other +In both of these examples, the operating system’s invisible interrupts provide a +form of concurrency. That concurrency only happens at the level of a whole +program, though: the operating system interrupts one program to let other programs get work done. In many cases, since we understand our programs at a much more granular level than the operating system does, we can spot lots of opportunities for concurrency that the operating system cannot see. @@ -72,12 +73,14 @@ In the previous chapter we treated parallelism and concurrency as mostly interchangeable. Now we need to distinguish between them more precisely, because the differences will show up as we start working. -Think about working on a software project as a team. +Consider the different ways a team could split up work on a software project. We +could assign a single individual multiple tasks, or we could assign one task per +team member, or we could do a mix of both approaches. When an individual works on several different tasks before any of them is complete, this is *concurrency*. Maybe you have two different projects checked out on your computer, and when you get bored or stuck on one project, you switch -to the other. You are just one person, and you cannot make progress on both +to the other. You are just one person, so you cannot make progress on both tasks tasks at the exact same time—but you can multi-task, making progress on multiple tasks by switching between them. @@ -106,15 +109,14 @@ tasks. Maybe you *thought* the task that one person was working on was totally independent from everyone else’s work, but it actually needs something finished by another person on the team. Some of the work could be done in parallel, but some of it was actually *serial*: it could only happen in a series, one thing -after the other. Likewise, you might realize that one of the tasks you were -working on needs the result from another of your tasks. Now your concurrent work -has also become serial. +after the other. Likewise, you might realize that one of your own tasks depends +on another of your tasks. Now your concurrent work has also become serial. -Parallelism and concurrency can intersect with each other, too. For example, if -it turns out your coworker is waiting on one of your projects to finish, you -might need to focus on that project and not give any time to your other task -until it is done. In that case, you and your coworker are no longer able to work -in parallel *and* you are no longer able to work concurrently. +Parallelism and concurrency can intersect with each other, too. If you learn +that a colleague is stuck until you finish one of your tasks, you will probably +focus all your efforts on that task to “unblock” your colleague. You and your +coworker are no longer able to work in parallel, and you are also no longer able +to work concurrently on your own tasks. The same basic dynamics come into play with software and hardware. On a machine with a single CPU core, the CPU can only do one operation at a time, but it can @@ -127,8 +129,8 @@ time. When working with async in Rust, we are always dealing with concurrency. Depending on the hardware, the operating system, and the async runtime we are -using—more on async runtimes shortly!—that concurrency may or may not also use -parallelism under the hood. +using—more on async runtimes shortly!—that concurrency may also use parallelism +under the hood. Now, let’s dive into how async programming in Rust actually works! In the rest of this chapter, we will: From c648c0e8daa4256d937e5eb12b7f2823f3d19031 Mon Sep 17 00:00:00 2001 From: Bin Wang Date: Fri, 30 Aug 2024 13:41:54 -0400 Subject: [PATCH 521/720] Use immutable borrow of `TcpStream` when creating `BufReader` --- listings/ch20-web-server/listing-20-02/src/main.rs | 2 +- listings/ch20-web-server/listing-20-03/src/main.rs | 2 +- listings/ch20-web-server/listing-20-05/src/main.rs | 2 +- listings/ch20-web-server/listing-20-06/src/main.rs | 2 +- listings/ch20-web-server/listing-20-07/src/main.rs | 2 +- listings/ch20-web-server/listing-20-09/src/main.rs | 2 +- listings/ch20-web-server/listing-20-10/src/main.rs | 2 +- listings/ch20-web-server/listing-20-11/src/main.rs | 2 +- listings/ch20-web-server/listing-20-12/src/main.rs | 2 +- listings/ch20-web-server/listing-20-13/src/main.rs | 2 +- listings/ch20-web-server/listing-20-14/src/main.rs | 2 +- listings/ch20-web-server/listing-20-15/src/main.rs | 2 +- listings/ch20-web-server/listing-20-16/src/main.rs | 2 +- listings/ch20-web-server/listing-20-17/src/main.rs | 2 +- listings/ch20-web-server/listing-20-18/src/main.rs | 2 +- listings/ch20-web-server/listing-20-19/src/main.rs | 2 +- listings/ch20-web-server/listing-20-20/src/main.rs | 2 +- listings/ch20-web-server/listing-20-21/src/main.rs | 2 +- listings/ch20-web-server/listing-20-22/src/main.rs | 2 +- listings/ch20-web-server/listing-20-23/src/main.rs | 2 +- listings/ch20-web-server/listing-20-24/src/main.rs | 2 +- listings/ch20-web-server/listing-20-25/src/main.rs | 2 +- .../no-listing-01-define-threadpool-struct/src/main.rs | 2 +- .../no-listing-02-impl-threadpool-new/src/main.rs | 2 +- .../ch20-web-server/no-listing-03-define-execute/src/main.rs | 2 +- .../no-listing-04-update-worker-definition/src/main.rs | 2 +- .../ch20-web-server/no-listing-05-fix-worker-new/src/main.rs | 2 +- .../no-listing-06-fix-threadpool-drop/src/main.rs | 2 +- listings/ch20-web-server/no-listing-07-final-code/src/main.rs | 2 +- src/ch20-01-single-threaded.md | 4 ++-- 30 files changed, 31 insertions(+), 31 deletions(-) diff --git a/listings/ch20-web-server/listing-20-02/src/main.rs b/listings/ch20-web-server/listing-20-02/src/main.rs index f139846c6d..1eff2eef3a 100644 --- a/listings/ch20-web-server/listing-20-02/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-03/src/main.rs b/listings/ch20-web-server/listing-20-03/src/main.rs index c72d4a9c67..17c8401d4d 100644 --- a/listings/ch20-web-server/listing-20-03/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-05/src/main.rs b/listings/ch20-web-server/listing-20-05/src/main.rs index d4b78b640e..437d9b626e 100644 --- a/listings/ch20-web-server/listing-20-05/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-06/src/main.rs b/listings/ch20-web-server/listing-20-06/src/main.rs index 5523a42d7c..843d846766 100644 --- a/listings/ch20-web-server/listing-20-06/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-07/src/main.rs b/listings/ch20-web-server/listing-20-07/src/main.rs index a14b7d538c..e19467b83b 100644 --- a/listings/ch20-web-server/listing-20-07/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-09/src/main.rs b/listings/ch20-web-server/listing-20-09/src/main.rs index ffc51e803e..0f9356ab02 100644 --- a/listings/ch20-web-server/listing-20-09/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-10/src/main.rs b/listings/ch20-web-server/listing-20-10/src/main.rs index 5a18b45c02..0679ec6002 100644 --- a/listings/ch20-web-server/listing-20-10/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-11/src/main.rs b/listings/ch20-web-server/listing-20-11/src/main.rs index 1181357b0e..075a0d9de6 100644 --- a/listings/ch20-web-server/listing-20-11/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-12/src/main.rs b/listings/ch20-web-server/listing-20-12/src/main.rs index 21b9a80f10..bde3e29d10 100644 --- a/listings/ch20-web-server/listing-20-12/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-13/src/main.rs b/listings/ch20-web-server/listing-20-13/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-13/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-14/src/main.rs b/listings/ch20-web-server/listing-20-14/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-14/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-15/src/main.rs b/listings/ch20-web-server/listing-20-15/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-15/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-16/src/main.rs b/listings/ch20-web-server/listing-20-16/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-16/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-17/src/main.rs b/listings/ch20-web-server/listing-20-17/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-17/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-18/src/main.rs b/listings/ch20-web-server/listing-20-18/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-18/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-19/src/main.rs b/listings/ch20-web-server/listing-20-19/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-19/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-20/src/main.rs b/listings/ch20-web-server/listing-20-20/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-20/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-21/src/main.rs b/listings/ch20-web-server/listing-20-21/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-21/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-22/src/main.rs b/listings/ch20-web-server/listing-20-22/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/listing-20-22/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-23/src/main.rs b/listings/ch20-web-server/listing-20-23/src/main.rs index b6aa046d1b..acd703f274 100644 --- a/listings/ch20-web-server/listing-20-23/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-24/src/main.rs b/listings/ch20-web-server/listing-20-24/src/main.rs index b6aa046d1b..acd703f274 100644 --- a/listings/ch20-web-server/listing-20-24/src/main.rs +++ b/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/listings/ch20-web-server/listing-20-25/src/main.rs b/listings/ch20-web-server/listing-20-25/src/main.rs index 86e8d9e78c..ee0f1efe74 100644 --- a/listings/ch20-web-server/listing-20-25/src/main.rs +++ b/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/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs b/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs index f7b42167f9..e68f72c700 100644 --- a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs +++ b/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/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs +++ b/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/listings/ch20-web-server/no-listing-03-define-execute/src/main.rs b/listings/ch20-web-server/no-listing-03-define-execute/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/no-listing-03-define-execute/src/main.rs +++ b/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/listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs b/listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs +++ b/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/listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs b/listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs index 79efb28a2a..1f075fde59 100644 --- a/listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs +++ b/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/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs b/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs index b6aa046d1b..acd703f274 100644 --- a/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs +++ b/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/listings/ch20-web-server/no-listing-07-final-code/src/main.rs b/listings/ch20-web-server/no-listing-07-final-code/src/main.rs index b6aa046d1b..acd703f274 100644 --- a/listings/ch20-web-server/no-listing-07-final-code/src/main.rs +++ b/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/src/ch20-01-single-threaded.md b/src/ch20-01-single-threaded.md index 9e7fe865b1..b474d926fe 100644 --- a/src/ch20-01-single-threaded.md +++ b/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 From ef4a51843eea837c7982af42e0309d48f68d70ab Mon Sep 17 00:00:00 2001 From: faint <46868845+ficcialfaint@users.noreply.github.com> Date: Sat, 31 Aug 2024 20:38:53 +0300 Subject: [PATCH 522/720] cargo init usage suggestion --- src/ch01-03-hello-cargo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch01-03-hello-cargo.md b/src/ch01-03-hello-cargo.md index 5750e4f015..288ed4d3da 100644 --- a/src/ch01-03-hello-cargo.md +++ b/src/ch01-03-hello-cargo.md @@ -113,7 +113,7 @@ 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, or run `cargo init`. ### Building and Running a Cargo Project From 1de14c81c6c14204216ef28dddeca2579165e106 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Sat, 24 Aug 2024 08:26:56 -0600 Subject: [PATCH 523/720] Ch. 17: start restructuring chapter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create a section (which will be deleted or at least reintegrated once all is said and done) to hold content pulled out of other sections for the sake of clearer flow and understanding. - Pull “advanced” material from 17.00, 17.01, and 17.02 into the holding section and start reorganizing their content to account for shifting around materials. --- src/SUMMARY.md | 1 + src/ch17-01-futures-and-syntax.md | 128 +++++++------------------- src/ch17-02-concurrency-with-async.md | 12 +-- src/ch17-07-wip.md | 102 ++++++++++++++++++++ 4 files changed, 140 insertions(+), 103 deletions(-) create mode 100644 src/ch17-07-wip.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 2645cfcedf..33af2af759 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -108,6 +108,7 @@ - [More Ways of Combining Futures](ch17-04-more-ways-of-combining-futures.md) - [Streams](ch17-05-streams.md) - [Futures, Tasks, and Threads](ch17-06-futures-tasks-threads.md) + - [Restructuring](ch17-07-wip.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 272471247a..014a6dd33b 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -141,6 +141,10 @@ high-throughput web server with many CPU cores and a large amount of RAM has very different different needs than a microcontroller with a single core, a small amount of RAM, and no ability to do heap allocations. +Every async program in Rust has at least one place where it sets up a runtime +and executes the futures. Those runtimes also often supply async versions of +common functionality like file or network I/O. + > ### The `trpl` Crate > > To keep this chapter focused on learning async, rather than juggling parts of @@ -190,101 +194,32 @@ When we run this, we get the behavior we might have expected initially: {{#include ../listings/ch17-async-await/listing-17-04/output.txt}} ``` -Phew: we finally have some working async code! Now we can turn our attention to -how the `Future` trait works. - -### What Are Futures? +Phew: we finally have some working async code! Let’s briefly turn our attention +to how the `Future` trait works. A *future* is a data structure which manages the state of some async operation. -Rust provides the `Future` trait as a building block so different async -operations can be implemented with different data, but with a common interface. -Here is the definition of the trait: - -```rust -use std::pin::Pin; -use std::task::{Context, Poll}; - -pub trait Future { - type Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; -} -``` - -While we often interact with the futures created via async blocks, you can also -implement `Future` on your own data types. Indeed, many of the functions we will -see throughout this chapter return types with their own implementations of -`Future`. - -As we learned earlier, `Future`’s associated type `Output` says what the future -will resolves to. (This is analogous to the `Item` associated type for the -`Iterator` trait.) Beyond that, `Future` also has the `poll` method, which takes -a special `Pin` reference for its `self` parameter and a mutable reference to a -`Context` type, and returns a `Poll`. We will talk a little more -about `Pin` and `Context` later in the chapter. For now, let’s focus on what the -method returns, the `Poll` type: - -```rust -enum Poll { - Ready(T), - Pending -} -``` - -This `Poll` type is a lot like an `Option`: it has one variant which has a value -(`Ready(T)`), and one which does not (`Pending`). It means something quite -different, though! The `Pending` variant indicates that the future still has -work to do, so the caller will need to check again later. The `Ready` variant -indicates that the `Future` has finished its work and the `T` value is -available. - -> Note: With most futures, the caller should not call `poll()` again after the -> future has returned `Ready`. Many futures will panic if polled again after -> becoming ready! Futures which are safe to poll again will say so explicitly in -> their documentation. - -Under the hood, when you call `.await`, Rust compiles that to code which calls -`poll`, kind of (although not exactly ) -like this: - -```rust,ignore -match hello("async").poll() { - Ready(_) => { - // We’re done! - } - Pending => { - // But what goes here? - } -} -``` - -What should we do when the `Future` is still `Pending`? We need some way to try -again… and again, and again, until the future is finally ready. In other words, -a loop: - -```rust,ignore -let hello_fut = hello("async"); -loop { - match hello_fut.poll() { - Ready(_) => { - break; - } - Pending => { - // continue - } - } -} -``` - -If Rust compiled it to exactly that code, though, every `.await` would be -blocking—exactly the opposite of what we were going for! Instead, Rust needs -makes sure that the loop can hand off control to something which can pause work -on this future and work on other futures and check this one again later. That -“something” is an async runtime, and this scheduling and coordination work is -one of the main jobs for a runtime. +It is called a “future” because it represents work which may not be ready now, +but will become ready at some point in the future. (This same concept shows up +in many languages, sometimes under other names like “task” or “promise”.) Rust +provides a `Future` trait as a building block so different async operations can +be implemented with different data structures, but with a common interface. + +Most of the time when writing async Rust, we don’t work directly with the +`Future` trait. Instead, we use the `async` and `await` keywords we saw above. +Rust does the work of compiling them into the appropriate calls to the `Future` +trait, much like it does with `for` loops and the `Iterator` trait. + +We most often interact with the futures created via async blocks, but you can +also implement `Future` on your own data types. Indeed, many of the functions we +will see throughout this chapter return types with their own implementations of +`Future`. We will return to the definition of the trait at the end of the +chapter and dig into more of how it works, but this is enough detail to keep us +moving forward. + + Every *await point*—that is, every place where the code explicitly applies the -`.await` keyword—represents a place where control gets handed back to the +`await` keyword—represents a place where control gets handed back to the runtime. To make that work, Rust needs to keep track of the state involved in the async block, so that the runtime can kick off some other work and then come back when it is ready to try advancing this one again. This is an invisible @@ -311,6 +246,11 @@ structures all apply. Happily, the compiler also handles checking those for us, and has good error messages. We will work through a few of those later in the chapter! + + Now we can understand why the compiler stopped us from making `main` itself an async function in Listing 17-3. If `main` were an async function, something else would need to call `poll()` on whatever `main` returned, but main is the @@ -318,10 +258,6 @@ starting point for the program! Instead, we use the `trpl::block_on` function, which sets up a runtime and polls the `Future` returned by `hello` until it returns `Ready`. -Every async program in Rust has at least one place where it sets up a runtime and -executes the futures. Those runtimes also often supply async versions of common -functionality like file or network I/O. - > Note: We have skipped over some interesting implementation details in this > discussion, because you should not have to think about them when writing Rust. > @@ -343,5 +279,3 @@ of the things we can *do* with async. [crate-source]: https://github.com/rust-lang/book/tree/main/packages/trpl [futures-crate]: https://crates.io/crates/futures [tokio]: https://tokio.rs - - diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index a57d056814..4ac808a86d 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -228,12 +228,12 @@ long as the condition it relies on is true. -The `rx.recv()` call produces a `Future`, which we await. While waiting on -messages to arrive, the future will produce `Poll::Pending`, so the runtime will -pause it until it is time to check it again. Once a message arrives, `rx.recv()` -will respond with `Poll::Ready(Some(message))`. When the channel closes, -`rx.recv()` will respond with `Poll::Ready(None)` to indicate that there are no -more values, and we should stop polling—that is, stop awaiting. +The `rx.recv()` call produces a `Future`, which we await. The runtime will pause +the `Future` until it is ready. Once a message arrives, the future will resolve +to `Some(message)`, as many times as a message arrives. When the channel closes, +regardless of whether *any* messages have arrived, the future will instead +resolve to `None` to indicate that there are no more values, and we should stop +polling—that is, stop awaiting. The `while let` loop pulls all of this together. If the result of calling `rx.recv().await` is `Some(message)`, we get access to the message and we can diff --git a/src/ch17-07-wip.md b/src/ch17-07-wip.md new file mode 100644 index 0000000000..8f3f569203 --- /dev/null +++ b/src/ch17-07-wip.md @@ -0,0 +1,102 @@ +> ## Restructuring +> +> This is just a placeholder for material that needs to be restructured so that +> the earlier sections of the book can avoid getting sidetracked into details of +> things like `Pin` or even just the full gnarliness of the `Future` trait at +> points where it would be better for the text to keep moving. + +--- + +Here is the definition of the trait: + +```rust +use std::pin::Pin; +use std::task::{Context, Poll}; + +pub trait Future { + type Output; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; +} +``` + +As we learned earlier, `Future`’s associated type `Output` says what the future +will resolves to. (This is analogous to the `Item` associated type for the +`Iterator` trait.) Beyond that, `Future` also has the `poll` method, which takes +a special `Pin` reference for its `self` parameter and a mutable reference to a +`Context` type, and returns a `Poll`. We will talk a little more +about `Pin` and `Context` later in the chapter. For now, let’s focus on what the +method returns, the `Poll` type: + +```rust +enum Poll { + Ready(T), + Pending +} +``` + +This `Poll` type is a lot like an `Option`: it has one variant which has a value +(`Ready(T)`), and one which does not (`Pending`). It means something quite +different, though! The `Pending` variant indicates that the future still has +work to do, so the caller will need to check again later. The `Ready` variant +indicates that the `Future` has finished its work and the `T` value is +available. + +> Note: With most futures, the caller should not call `poll()` again after the +> future has returned `Ready`. Many futures will panic if polled again after +> becoming ready! Futures which are safe to poll again will say so explicitly in +> their documentation. + +Under the hood, when you call `.await`, Rust compiles that to code which calls +`poll`, kind of (although not exactly ) +like this: + +```rust,ignore +match hello("async").poll() { + Ready(_) => { + // We’re done! + } + Pending => { + // But what goes here? + } +} +``` + +What should we do when the `Future` is still `Pending`? We need some way to try +again… and again, and again, until the future is finally ready. In other words, +a loop: + +```rust,ignore +let hello_fut = hello("async"); +loop { + match hello_fut.poll() { + Ready(_) => { + break; + } + Pending => { + // continue + } + } +} +``` + +If Rust compiled it to exactly that code, though, every `.await` would be +blocking—exactly the opposite of what we were going for! Instead, Rust needs +makes sure that the loop can hand off control to something which can pause work +on this future and work on other futures and check this one again later. That +“something” is an async runtime, and this scheduling and coordination work is +one of the main jobs for a runtime. + +--- + +Recall our description of how `rx.recv()` waits in the [Counting][counting] +section. The `recv()` call returns a `Future`, and awaiting it polls it. In our +initial discussion, we noted that a runtime will pause the future until it is +ready with either `Some(message)` or `None` when the channel closes. With a +deeper understanding of `Future` in place, and specifically its `poll` method, +we can see how that works. The runtime knows the future is not ready when it +returns `Poll::Pending`. Conversely, the runtime knows the future is ready and +advances it when `poll` returns `Poll::Ready(Some(message))` or +`Poll::Ready(None)`. + +[counting]: /ch17-02-concurrency-with-async.md From 6b6b4501f11382d30144c9f9ca0f32328b8f5f3e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 10 Sep 2024 16:03:08 -0600 Subject: [PATCH 524/720] Upgrade to Rust 1.81 In addition to the baseline changes, skip over non-directory code where directories are needed to deal with things like `.DS_Store` files. Also add a bunch of context on error causes from `std::io::Error` because it was *impossible* to figure out exactly what the source of those were. --- .github/workflows/main.yml | 8 +-- .../listing-02-04/output.txt | 8 ++- .../output.txt | 10 +-- .../output.txt | 8 +-- .../output.txt | 4 +- .../listing-09-10/output.txt | 8 +++ .../listing-13-04/output.txt | 2 +- .../listing-13-05/output.txt | 2 +- .../listing-15-21/output.txt | 2 +- .../listing-16-14/output.txt | 2 +- .../no-listing-18-returns-closure/output.txt | 4 +- .../ch20-web-server/listing-20-22/output.txt | 2 +- .../output.txt | 2 +- packages/tools/src/bin/release_listings.rs | 64 ++++++++++++++++--- rust-toolchain | 2 +- src/title-page.md | 2 +- 16 files changed, 97 insertions(+), 33 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1737bce009..2b3ae3d5c3 100644 --- a/.github/workflows/main.yml +++ b/.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/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index bb997866a2..0f0bc21025 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/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/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt index 73ca9d62fb..85efb431ea 100644 --- a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt +++ b/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/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt index dde05f4b3b..1eb76de43f 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt +++ b/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/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 5232f90378..43acd14d63 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/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/listings/ch09-error-handling/listing-09-10/output.txt b/listings/ch09-error-handling/listing-09-10/output.txt index dbc9bb13dc..f3c1641b24 100644 --- a/listings/ch09-error-handling/listing-09-10/output.txt +++ b/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/listings/ch13-functional-features/listing-13-04/output.txt b/listings/ch13-functional-features/listing-13-04/output.txt index b04a1a36c2..fbc00b5dfc 100644 --- a/listings/ch13-functional-features/listing-13-04/output.txt +++ b/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/listings/ch13-functional-features/listing-13-05/output.txt b/listings/ch13-functional-features/listing-13-05/output.txt index 1fddf5a982..695ee4bee3 100644 --- a/listings/ch13-functional-features/listing-13-05/output.txt +++ b/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/listings/ch15-smart-pointers/listing-15-21/output.txt b/listings/ch15-smart-pointers/listing-15-21/output.txt index 3509e8ec62..8501007f05 100644 --- a/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/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/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index cb4167a5b8..cc96baed1d 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/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/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt index bc736bd689..3a23426392 100644 --- a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt +++ b/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/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 84ebe928b0..554bfd8591 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/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/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 1ffe5206b1..6867dcbcaf 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/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/packages/tools/src/bin/release_listings.rs b/packages/tools/src/bin/release_listings.rs index c9a2f45974..09fb209761 100644 --- a/packages/tools/src/bin/release_listings.rs +++ b/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/rust-toolchain b/rust-toolchain index 17420a571f..ea3769f296 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.79 +1.81 diff --git a/src/title-page.md b/src/title-page.md index dee3c84cb8..613de0ddd7 100644 --- a/src/title-page.md +++ b/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. From 299fd1f3e11dd61ca136fb51d713f6b0ba7515ff Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 11 Sep 2024 16:53:38 -0600 Subject: [PATCH 525/720] Clarify Cargo.toml generation with `cargo init`. --- src/ch01-03-hello-cargo.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch01-03-hello-cargo.md b/src/ch01-03-hello-cargo.md index 288ed4d3da..dea721d38c 100644 --- a/src/ch01-03-hello-cargo.md +++ b/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, or run `cargo init`. +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 From d5932d2f98d62c5612dbeb71ba630b4f92c5347d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 11 Sep 2024 17:22:59 -0600 Subject: [PATCH 526/720] Update build instructions: include mdbook plugins Fixes #4018 --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 8befc1b31e..9648db0ae0 100644 --- a/README.md +++ b/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: From c552952e9fd1300b05080d1a761ceb8face681d7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Sat, 24 Aug 2024 08:26:56 -0600 Subject: [PATCH 527/720] Ch. 17: rename `trpl::block_on` to `trpl::run` The `block_on` name is what both Tokio and smol use, but it is a bit obscure from the point of view of introducing this material. `run` says much more clearly what it does *for the level we care about here*, I think. --- .../listing-17-04/src/main.rs | 2 +- .../listing-17-05/src/main.rs | 2 +- .../listing-17-06/src/main.rs | 2 +- .../listing-17-07/src/main.rs | 2 +- .../listing-17-08/src/main.rs | 2 +- .../listing-17-09/src/main.rs | 2 +- .../listing-17-10/src/main.rs | 2 +- .../listing-17-11/src/main.rs | 2 +- .../listing-17-12/src/main.rs | 2 +- .../listing-17-13/src/main.rs | 2 +- .../listing-17-14/src/main.rs | 2 +- .../listing-17-15/src/main.rs | 2 +- .../listing-17-16/src/main.rs | 2 +- .../listing-17-17/src/main.rs | 2 +- .../listing-17-18/src/main.rs | 2 +- .../listing-17-19/src/main.rs | 2 +- .../listing-17-20/src/main.rs | 2 +- .../listing-17-21/src/main.rs | 2 +- .../listing-17-22/src/main.rs | 2 +- .../listing-17-23/src/main.rs | 2 +- .../listing-17-24/src/main.rs | 2 +- .../listing-17-25/src/main.rs | 2 +- .../listing-17-26/src/main.rs | 2 +- .../listing-17-27/src/main.rs | 2 +- .../listing-17-28/src/main.rs | 2 +- .../listing-17-29/src/main.rs | 2 +- .../listing-17-30/src/main.rs | 2 +- .../listing-17-31/src/main.rs | 2 +- .../listing-17-32/src/main.rs | 2 +- .../listing-17-33/src/main.rs | 2 +- .../listing-17-34/src/main.rs | 2 +- .../listing-17-35/src/main.rs | 2 +- .../listing-17-36/src/main.rs | 2 +- .../listing-17-37/src/main.rs | 2 +- .../listing-17-38/src/main.rs | 2 +- .../listing-17-39/src/main.rs | 2 +- .../listing-17-40/src/main.rs | 2 +- packages/trpl/src/lib.rs | 2 +- packages/trpl/tests/integration/main.rs | 32 +++++++++---------- src/ch17-01-futures-and-syntax.md | 14 ++++---- src/ch17-02-concurrency-with-async.md | 13 ++++---- 41 files changed, 67 insertions(+), 68 deletions(-) diff --git a/listings/ch17-async-await/listing-17-04/src/main.rs b/listings/ch17-async-await/listing-17-04/src/main.rs index 563aee05b7..f3e685ac67 100644 --- a/listings/ch17-async-await/listing-17-04/src/main.rs +++ b/listings/ch17-async-await/listing-17-04/src/main.rs @@ -2,7 +2,7 @@ extern crate trpl; // required for mdbook test // ANCHOR: main fn main() { - trpl::block_on(async { + trpl::run(async { hello("async").await; }); } diff --git a/listings/ch17-async-await/listing-17-05/src/main.rs b/listings/ch17-async-await/listing-17-05/src/main.rs index 2fe6a5f29d..8eb415ee73 100644 --- a/listings/ch17-async-await/listing-17-05/src/main.rs +++ b/listings/ch17-async-await/listing-17-05/src/main.rs @@ -4,7 +4,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { trpl::spawn_task(async { for i in 1..10 { println!("hi number {i} from the first task!"); diff --git a/listings/ch17-async-await/listing-17-06/src/main.rs b/listings/ch17-async-await/listing-17-06/src/main.rs index 67c735fd39..5415e1fcee 100644 --- a/listings/ch17-async-await/listing-17-06/src/main.rs +++ b/listings/ch17-async-await/listing-17-06/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: handle let handle = trpl::spawn_task(async { for i in 1..10 { diff --git a/listings/ch17-async-await/listing-17-07/src/main.rs b/listings/ch17-async-await/listing-17-07/src/main.rs index ef52e32840..2cd5de9bae 100644 --- a/listings/ch17-async-await/listing-17-07/src/main.rs +++ b/listings/ch17-async-await/listing-17-07/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: join let fut1 = async { for i in 1..10 { diff --git a/listings/ch17-async-await/listing-17-08/src/main.rs b/listings/ch17-async-await/listing-17-08/src/main.rs index 743a22e239..56daddc10f 100644 --- a/listings/ch17-async-await/listing-17-08/src/main.rs +++ b/listings/ch17-async-await/listing-17-08/src/main.rs @@ -1,7 +1,7 @@ extern crate trpl; // required for mdbook test fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: channel let (tx, mut rx) = trpl::channel(); diff --git a/listings/ch17-async-await/listing-17-09/src/main.rs b/listings/ch17-async-await/listing-17-09/src/main.rs index 2a98d028bb..e11ae51787 100644 --- a/listings/ch17-async-await/listing-17-09/src/main.rs +++ b/listings/ch17-async-await/listing-17-09/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: many-messages let (tx, mut rx) = trpl::channel(); diff --git a/listings/ch17-async-await/listing-17-10/src/main.rs b/listings/ch17-async-await/listing-17-10/src/main.rs index 1eb0a163ef..5ada1d2f6d 100644 --- a/listings/ch17-async-await/listing-17-10/src/main.rs +++ b/listings/ch17-async-await/listing-17-10/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { let (tx, mut rx) = trpl::channel(); // ANCHOR: futures diff --git a/listings/ch17-async-await/listing-17-11/src/main.rs b/listings/ch17-async-await/listing-17-11/src/main.rs index 025ed3a1ab..95e6480677 100644 --- a/listings/ch17-async-await/listing-17-11/src/main.rs +++ b/listings/ch17-async-await/listing-17-11/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: with-move let (tx, mut rx) = trpl::channel(); diff --git a/listings/ch17-async-await/listing-17-12/src/main.rs b/listings/ch17-async-await/listing-17-12/src/main.rs index 03fa6a61b5..d5a2e56e34 100644 --- a/listings/ch17-async-await/listing-17-12/src/main.rs +++ b/listings/ch17-async-await/listing-17-12/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: here let (tx, mut rx) = trpl::channel(); diff --git a/listings/ch17-async-await/listing-17-13/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs index 87b244daa8..0bb425d366 100644 --- a/listings/ch17-async-await/listing-17-13/src/main.rs +++ b/listings/ch17-async-await/listing-17-13/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs index 684b174bdc..249ffd0f68 100644 --- a/listings/ch17-async-await/listing-17-14/src/main.rs +++ b/listings/ch17-async-await/listing-17-14/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); diff --git a/listings/ch17-async-await/listing-17-15/src/main.rs b/listings/ch17-async-await/listing-17-15/src/main.rs index 5bc9c2c3bd..9fefdcf463 100644 --- a/listings/ch17-async-await/listing-17-15/src/main.rs +++ b/listings/ch17-async-await/listing-17-15/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); diff --git a/listings/ch17-async-await/listing-17-16/src/main.rs b/listings/ch17-async-await/listing-17-16/src/main.rs index 020a4d37f3..1888a53568 100644 --- a/listings/ch17-async-await/listing-17-16/src/main.rs +++ b/listings/ch17-async-await/listing-17-16/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::{future::Future, time::Duration}; fn main() { - trpl::block_on(async { + trpl::run(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); diff --git a/listings/ch17-async-await/listing-17-17/src/main.rs b/listings/ch17-async-await/listing-17-17/src/main.rs index b7fed9b427..7773660519 100644 --- a/listings/ch17-async-await/listing-17-17/src/main.rs +++ b/listings/ch17-async-await/listing-17-17/src/main.rs @@ -7,7 +7,7 @@ use std::{ }; fn main() { - trpl::block_on(async { + trpl::run(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); diff --git a/listings/ch17-async-await/listing-17-18/src/main.rs b/listings/ch17-async-await/listing-17-18/src/main.rs index 2c5748960d..80f546b30d 100644 --- a/listings/ch17-async-await/listing-17-18/src/main.rs +++ b/listings/ch17-async-await/listing-17-18/src/main.rs @@ -7,7 +7,7 @@ use std::{ }; fn main() { - trpl::block_on(async { + trpl::run(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); diff --git a/listings/ch17-async-await/listing-17-19/src/main.rs b/listings/ch17-async-await/listing-17-19/src/main.rs index 2088dbe21a..12ab2704b2 100644 --- a/listings/ch17-async-await/listing-17-19/src/main.rs +++ b/listings/ch17-async-await/listing-17-19/src/main.rs @@ -1,7 +1,7 @@ extern crate trpl; // required for mdbook test fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: here let a = async { 1u32 }; let b = async { "Hello!" }; diff --git a/listings/ch17-async-await/listing-17-20/src/main.rs b/listings/ch17-async-await/listing-17-20/src/main.rs index 0ac89fe6c1..308c14a4ac 100644 --- a/listings/ch17-async-await/listing-17-20/src/main.rs +++ b/listings/ch17-async-await/listing-17-20/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: here let slow = async { println!("'slow' started."); diff --git a/listings/ch17-async-await/listing-17-21/src/main.rs b/listings/ch17-async-await/listing-17-21/src/main.rs index fa5cfe3c80..2dfb52b7d4 100644 --- a/listings/ch17-async-await/listing-17-21/src/main.rs +++ b/listings/ch17-async-await/listing-17-21/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::{thread, time::Duration}; fn main() { - trpl::block_on(async { + trpl::run(async { // We will call `slow` here later }); } diff --git a/listings/ch17-async-await/listing-17-22/src/main.rs b/listings/ch17-async-await/listing-17-22/src/main.rs index 55975462fa..391cf39e19 100644 --- a/listings/ch17-async-await/listing-17-22/src/main.rs +++ b/listings/ch17-async-await/listing-17-22/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::{thread, time::Duration}; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: slow-futures let a = async { println!("'a' started."); diff --git a/listings/ch17-async-await/listing-17-23/src/main.rs b/listings/ch17-async-await/listing-17-23/src/main.rs index f9c795fc0c..961431d396 100644 --- a/listings/ch17-async-await/listing-17-23/src/main.rs +++ b/listings/ch17-async-await/listing-17-23/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::{thread, time::Duration}; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: here let one_ms = Duration::from_millis(1); diff --git a/listings/ch17-async-await/listing-17-24/src/main.rs b/listings/ch17-async-await/listing-17-24/src/main.rs index e95e286a39..165022108b 100644 --- a/listings/ch17-async-await/listing-17-24/src/main.rs +++ b/listings/ch17-async-await/listing-17-24/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::{thread, time::Duration}; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: yields let a = async { println!("'a' started."); diff --git a/listings/ch17-async-await/listing-17-25/src/main.rs b/listings/ch17-async-await/listing-17-25/src/main.rs index eaea8509c3..31ce58d9e9 100644 --- a/listings/ch17-async-await/listing-17-25/src/main.rs +++ b/listings/ch17-async-await/listing-17-25/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::{Duration, Instant}; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: here let one_ns = Duration::from_nanos(1); let start = Instant::now(); diff --git a/listings/ch17-async-await/listing-17-26/src/main.rs b/listings/ch17-async-await/listing-17-26/src/main.rs index 58c83229d4..cdab724687 100644 --- a/listings/ch17-async-await/listing-17-26/src/main.rs +++ b/listings/ch17-async-await/listing-17-26/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::time::Duration; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: here let slow = async { trpl::sleep(Duration::from_millis(100)).await; diff --git a/listings/ch17-async-await/listing-17-27/src/main.rs b/listings/ch17-async-await/listing-17-27/src/main.rs index d30da0d226..6c2ae688e4 100644 --- a/listings/ch17-async-await/listing-17-27/src/main.rs +++ b/listings/ch17-async-await/listing-17-27/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use std::{future::Future, time::Duration}; fn main() { - trpl::block_on(async { + trpl::run(async { let slow = async { trpl::sleep(Duration::from_secs(5)).await; "Finally finished" diff --git a/listings/ch17-async-await/listing-17-28/src/main.rs b/listings/ch17-async-await/listing-17-28/src/main.rs index 20e81e77c4..d34a2a8f0e 100644 --- a/listings/ch17-async-await/listing-17-28/src/main.rs +++ b/listings/ch17-async-await/listing-17-28/src/main.rs @@ -5,7 +5,7 @@ use std::{future::Future, time::Duration}; use trpl::Either; fn main() { - trpl::block_on(async { + trpl::run(async { let slow = async { trpl::sleep(Duration::from_secs(5)).await; "Finally finished" diff --git a/listings/ch17-async-await/listing-17-29/src/main.rs b/listings/ch17-async-await/listing-17-29/src/main.rs index 7900b39ce4..faa6b6a1ca 100644 --- a/listings/ch17-async-await/listing-17-29/src/main.rs +++ b/listings/ch17-async-await/listing-17-29/src/main.rs @@ -1,7 +1,7 @@ extern crate trpl; // required for mdbook test fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: stream let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let iter = values.iter().map(|n| n * 2); diff --git a/listings/ch17-async-await/listing-17-30/src/main.rs b/listings/ch17-async-await/listing-17-30/src/main.rs index 8f8dd7d93f..0a7fc87c21 100644 --- a/listings/ch17-async-await/listing-17-30/src/main.rs +++ b/listings/ch17-async-await/listing-17-30/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use trpl::StreamExt; fn main() { - trpl::block_on(async { + trpl::run(async { let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let iter = values.iter().map(|n| n * 2); let mut stream = trpl::stream_from_iter(iter); diff --git a/listings/ch17-async-await/listing-17-31/src/main.rs b/listings/ch17-async-await/listing-17-31/src/main.rs index d312640b7f..017185bed5 100644 --- a/listings/ch17-async-await/listing-17-31/src/main.rs +++ b/listings/ch17-async-await/listing-17-31/src/main.rs @@ -3,7 +3,7 @@ extern crate trpl; // required for mdbook test use trpl::StreamExt; fn main() { - trpl::block_on(async { + trpl::run(async { let values = 1..101; let iter = values.map(|n| n * 2); let stream = trpl::stream_from_iter(iter); diff --git a/listings/ch17-async-await/listing-17-32/src/main.rs b/listings/ch17-async-await/listing-17-32/src/main.rs index dd1693790d..d9a7733d43 100644 --- a/listings/ch17-async-await/listing-17-32/src/main.rs +++ b/listings/ch17-async-await/listing-17-32/src/main.rs @@ -4,7 +4,7 @@ extern crate trpl; // required for mdbook test use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { let mut messages = get_messages(); while let Some(message) = messages.next().await { diff --git a/listings/ch17-async-await/listing-17-33/src/main.rs b/listings/ch17-async-await/listing-17-33/src/main.rs index 6ad2bc72f9..de919073f8 100644 --- a/listings/ch17-async-await/listing-17-33/src/main.rs +++ b/listings/ch17-async-await/listing-17-33/src/main.rs @@ -5,7 +5,7 @@ use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { let mut messages = pin!(get_messages().timeout(Duration::from_millis(200))); diff --git a/listings/ch17-async-await/listing-17-34/src/main.rs b/listings/ch17-async-await/listing-17-34/src/main.rs index 7446a2e795..b4dda21d52 100644 --- a/listings/ch17-async-await/listing-17-34/src/main.rs +++ b/listings/ch17-async-await/listing-17-34/src/main.rs @@ -5,7 +5,7 @@ use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { let mut messages = pin!(get_messages().timeout(Duration::from_millis(200))); diff --git a/listings/ch17-async-await/listing-17-35/src/main.rs b/listings/ch17-async-await/listing-17-35/src/main.rs index a2b36ca487..13bd0b1121 100644 --- a/listings/ch17-async-await/listing-17-35/src/main.rs +++ b/listings/ch17-async-await/listing-17-35/src/main.rs @@ -5,7 +5,7 @@ use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { let mut messages = pin!(get_messages().timeout(Duration::from_millis(200))); diff --git a/listings/ch17-async-await/listing-17-36/src/main.rs b/listings/ch17-async-await/listing-17-36/src/main.rs index b4cb9c094c..bc10dd48c9 100644 --- a/listings/ch17-async-await/listing-17-36/src/main.rs +++ b/listings/ch17-async-await/listing-17-36/src/main.rs @@ -5,7 +5,7 @@ use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: main let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals(); diff --git a/listings/ch17-async-await/listing-17-37/src/main.rs b/listings/ch17-async-await/listing-17-37/src/main.rs index 4e28174860..72da09d75f 100644 --- a/listings/ch17-async-await/listing-17-37/src/main.rs +++ b/listings/ch17-async-await/listing-17-37/src/main.rs @@ -5,7 +5,7 @@ use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: main let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() diff --git a/listings/ch17-async-await/listing-17-38/src/main.rs b/listings/ch17-async-await/listing-17-38/src/main.rs index 899d14fc23..a5f51618f5 100644 --- a/listings/ch17-async-await/listing-17-38/src/main.rs +++ b/listings/ch17-async-await/listing-17-38/src/main.rs @@ -5,7 +5,7 @@ use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { // ANCHOR: throttle let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() diff --git a/listings/ch17-async-await/listing-17-39/src/main.rs b/listings/ch17-async-await/listing-17-39/src/main.rs index 1b4e686ea2..ecf406e93d 100644 --- a/listings/ch17-async-await/listing-17-39/src/main.rs +++ b/listings/ch17-async-await/listing-17-39/src/main.rs @@ -5,7 +5,7 @@ use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() .map(|count| format!("Interval #{count}")) diff --git a/listings/ch17-async-await/listing-17-40/src/main.rs b/listings/ch17-async-await/listing-17-40/src/main.rs index 7bd605d528..f1f3d4b0c0 100644 --- a/listings/ch17-async-await/listing-17-40/src/main.rs +++ b/listings/ch17-async-await/listing-17-40/src/main.rs @@ -5,7 +5,7 @@ use std::{pin::pin, thread, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { - trpl::block_on(async { + trpl::run(async { let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() .map(|count| format!("Interval #{count}")) diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index e096d9d2cd..6d3a4bdaab 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -63,7 +63,7 @@ pub use tokio_stream::{ /// /// - Not *that* far off from what Tokio itself does under the hood in its own /// `tokio::main` macro for supporting `async fn main`. -pub fn block_on(future: F) -> F::Output { +pub fn run(future: F) -> F::Output { let rt = Runtime::new().unwrap(); rt.block_on(future) } diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index 639c460eb6..b67d8680a7 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -14,20 +14,20 @@ use std::{pin::Pin, time::Duration}; use futures::Future; use trpl::{Either, Receiver, Sender}; -/// This test is foundational for all the others, as they depend on `block_on`. +/// This test is foundational for all the others, as they depend on `run`. /// /// If we mess this up, *all* the tests below will fail -- so by the same token, /// if all the tests below are failing, this one probably is too; fix it and the /// others will likely start working again. #[test] -fn re_exported_block_on_works() { - let val = trpl::block_on(async { "Hello" }); +fn re_exported_run_works() { + let val = trpl::run(async { "Hello" }); assert_eq!(val, "Hello"); } #[test] fn re_exported_spawn_works() { - let result = trpl::block_on(async { + let result = trpl::run(async { let handle_a = trpl::spawn_task(async { "Hello" }); let handle_b = trpl::spawn_task(async { "Goodbye" }); vec![handle_a.await.unwrap(), handle_b.await.unwrap()] @@ -38,7 +38,7 @@ fn re_exported_spawn_works() { #[test] fn re_exported_sleep_works() { - let val = trpl::block_on(async { + let val = trpl::run(async { trpl::sleep(Duration::from_micros(1)).await; "Done!" }); @@ -47,7 +47,7 @@ fn re_exported_sleep_works() { #[test] fn re_exported_channel_apis_work() { - trpl::block_on(async { + trpl::run(async { // Explicitly naming the type to confirm the re-exports are aligned. let (tx, mut rx): (Sender<&str>, Receiver<&str>) = trpl::channel(); @@ -67,7 +67,7 @@ mod re_exported_join_apis_work { #[test] fn join_fn() { - let result = trpl::block_on(async { + let result = trpl::run(async { let a = async { 1 }; let b = async { 2 }; trpl::join(a, b).await @@ -78,7 +78,7 @@ mod re_exported_join_apis_work { #[test] fn join3_fn() { - let result = trpl::block_on(async { + let result = trpl::run(async { let a = async { 1 }; let b = async { 2 }; let c = async { 3 }; @@ -91,7 +91,7 @@ mod re_exported_join_apis_work { #[test] fn join_all_fn() { - let result = trpl::block_on(async { + let result = trpl::run(async { let a = async { format!("{}", 1) }; let b = async { "Hello".to_string() }; @@ -117,7 +117,7 @@ mod re_exported_join_apis_work { #[test] fn join_macro() { - let result = trpl::block_on(async { + let result = trpl::run(async { let a = async { 1 }; let b = async { "Hello" }; @@ -139,7 +139,7 @@ fn race() { #[derive(Debug, PartialEq)] struct Fast; - let val = trpl::block_on(async { + let val = trpl::run(async { let slow = async { trpl::sleep(Duration::from_millis(1_000)).await; Slow @@ -158,7 +158,7 @@ fn race() { #[test] fn yield_now() { - let result = trpl::block_on(async { + let result = trpl::run(async { trpl::yield_now().await; "done" }); @@ -168,7 +168,7 @@ fn yield_now() { #[test] fn read_to_string() { - let result = trpl::block_on(async { + let result = trpl::run(async { trpl::read_to_string("tests/integration/to-read.txt") .await .unwrap() @@ -181,7 +181,7 @@ fn read_to_string() { fn stream_iter() { use trpl::StreamExt; - let result = trpl::block_on(async { + let result = trpl::run(async { let ns = vec![1, 2, 3]; let mut stream = trpl::stream_from_iter(ns); let mut result = vec![]; @@ -202,7 +202,7 @@ fn receiver_stream() { use trpl::ReceiverStream; use trpl::StreamExt; - let result: Vec = trpl::block_on(async { + let result: Vec = trpl::run(async { println!("startup"); let (tx, rx) = trpl::channel(); let rx_stream = ReceiverStream::new(rx); @@ -220,7 +220,7 @@ fn receiver_stream() { fn re_exported_interval_stream_works() { use trpl::{IntervalStream, StreamExt}; - trpl::block_on(async { + trpl::run(async { let mut interval_stream = IntervalStream::new(trpl::interval(Duration::from_millis(1))) .take(1); diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 014a6dd33b..3ee9c3ebca 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -174,13 +174,13 @@ $ cargo add trpl ``` Then, in our `main` function, let’s wrap the call to `hello` with the -`trpl::block_on` function, which takes in a `Future` and runs it until it -completes. Since `hello` returns a `Future`, we could simply wrap it directly in -`trpl::block_on`. However, for most of the examples in the chapter, we will be +`trpl::run` function, which takes in a `Future` and runs it until it completes. +Since `hello` returns a `Future`, we could simply wrap it directly in +`trpl::run`. However, for most of the examples in the chapter, we will be doing more than just one async function call, so instead we will pass an `async` block and explicitly await the result of calling `hello`. -+ ```rust {{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:main}} @@ -254,9 +254,9 @@ chapter! Now we can understand why the compiler stopped us from making `main` itself an async function in Listing 17-3. If `main` were an async function, something else would need to call `poll()` on whatever `main` returned, but main is the -starting point for the program! Instead, we use the `trpl::block_on` function, -which sets up a runtime and polls the `Future` returned by `hello` until it -returns `Ready`. +starting point for the program! Instead, we use the `trpl::run` function, which +sets up a runtime and polls the `Future` returned by `hello` until it returns +`Ready`. > Note: We have skipped over some interesting implementation details in this > discussion, because you should not have to think about them when writing Rust. diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 4ac808a86d..5bebbc20dc 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -26,13 +26,12 @@ to implement the same counting example as with threads, in Listing 17-5. -As our starting point, we set up our `main` function with `trpl::block_on`, so +As our starting point, we set up our `main` function with `trpl::run`, so that our top-level function can be async. > Note: From this point forward in the chapter, every example will include this -> exact same wrapping code with `trpl::block_on` in `main`, so we will often -> skip it just like we do with `main`. Don’t forget to include it in your -> code! +> exact same wrapping code with `trpl::run` in `main`, so we will often skip it +> just like we do with `main`. Don’t forget to include it in your code! Then we write two loops within that block, each with a `trpl::sleep` call in it, which waits for half a second (500 milliseconds) before sending the next @@ -192,9 +191,9 @@ received or the send side of the channel closes. By contrast, we do not await the `send` call, because it does not block. It does not need to, because the channel we are sending it into is unbounded. -> Note: Since this is all wrapped in a `trpl::block_on`, this would effectively -> block anything happening outside that. That is the whole point of `block_on`, -> in fact: to allow you to *choose* where to block on some set of async code to +> Note: Since this is all wrapped in a `trpl::run`, this would effectively block +> anything happening outside that. That is the whole point of `block_on`, in +> fact: to allow you to *choose* where to block on some set of async code to > transition between sync and async code. However, *within* this block, the > `.await` does not block further operations—as we will see! From cd12a1e853b9e0edfc1ad72845ee0c4bc4209454 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 10 Sep 2024 07:22:20 -0600 Subject: [PATCH 528/720] Ch. 17: more edits for first three sections These make up *most* of the rest of the edits I caught while rereading which are not *major structural revisions*, along with some of the bits required for those major structural revisions. --- src/ch17-00-async-await.md | 11 +++-- src/ch17-01-futures-and-syntax.md | 28 ++++------- src/ch17-02-concurrency-with-async.md | 70 ++++++++++++++------------- src/ch17-07-wip.md | 8 +++ 4 files changed, 61 insertions(+), 56 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index bb289fdbf7..5540f0b795 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -16,8 +16,8 @@ let you get other work done along the way. The file download is different. It does not take up very much CPU time. Instead, the CPU needs to wait on data to arrive from the network. While you can start -reading the data once some of it arrives, it might take a while for the rest to -arrive. Even once the data has all arrived, a video can be quite large, so it +reading the data once some of it is present, it might take a while for the rest +to show up. Even once the data is all present, a video can be quite large, so it might take some time to load it all. Maybe it only takes a second or two—but that is a very long time for a modern processor, which can do billions of operations every second. It would be nice to be able to put the CPU to use for @@ -54,9 +54,10 @@ data that they are processing is completely ready. > *non*-blocking. We could avoid blocking our main thread by spawning a dedicated thread to -download each file. But it would be nicer if the call were not blocking in the -first place. It would also be nice if we could write in the same direct style -we use in blocking code. Something like this: +download each file. However, we would eventually find that the overhead of those +threads was a problem. It would also be nicer if the call were not blocking in +the first place. Last but not least, it would be better if we could write in the +same direct style we use in blocking code. Something like this: ```rust,ignore,does_not_compile let data = fetch_data_from(url).await; diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 3ee9c3ebca..dc53ac9eda 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -195,7 +195,7 @@ When we run this, we get the behavior we might have expected initially: ``` Phew: we finally have some working async code! Let’s briefly turn our attention -to how the `Future` trait works. +to how futures actually work. A *future* is a data structure which manages the state of some async operation. It is called a “future” because it represents work which may not be ready now, @@ -204,13 +204,11 @@ in many languages, sometimes under other names like “task” or “promise”. provides a `Future` trait as a building block so different async operations can be implemented with different data structures, but with a common interface. -Most of the time when writing async Rust, we don’t work directly with the -`Future` trait. Instead, we use the `async` and `await` keywords we saw above. -Rust does the work of compiling them into the appropriate calls to the `Future` -trait, much like it does with `for` loops and the `Iterator` trait. - -We most often interact with the futures created via async blocks, but you can -also implement `Future` on your own data types. Indeed, many of the functions we +Most of the time when writing async Rust, we use the `async` and `await` +keywords we saw above. Rust compiles them into equivalent code using the +`Future` trait, much like it compiles `for` loops into equivalent code using the +`Iterator` trait. Because Rust provides the `Future` trait, though, you can also +implement it for your own data types when you need to. Many of the functions we will see throughout this chapter return types with their own implementations of `Future`. We will return to the definition of the trait at the end of the chapter and dig into more of how it works, but this is enough detail to keep us @@ -258,17 +256,11 @@ starting point for the program! Instead, we use the `trpl::run` function, which sets up a runtime and polls the `Future` returned by `hello` until it returns `Ready`. -> Note: We have skipped over some interesting implementation details in this -> discussion, because you should not have to think about them when writing Rust. -> -> If you want to understand how things work “under the hood,” though, the -> official [_Asynchronous Programming in Rust_][async-book] book covers them: -> -> - [Chapter 2: Under the Hood: Executing Futures and Tasks][under-the-hood] -> - [Chapter 4: Pinning][pinning]. +> Note: We skipped over most of the details of how the `Future` trait works so +> far. We will come back to some of those later in the chapter! -Now that you know the basics of how futures and runtimes work, we can see some -of the things we can *do* with async. +Now that you know the basics of working with futures, we can dig into more of +the things we can *do* with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters [iterators-lazy]: ch13-02-iterators.html diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 5bebbc20dc..b785e7dc76 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -7,8 +7,9 @@ threads and futures. In many cases, the APIs for working with concurrency using async are very similar to those for using threads. In other cases, they end up being shaped -fairly differently. Even when the APIs look similar, they often have different -behavior and they nearly always have different performance characteristics. +quite differently. Even when the APIs *look* similar between threads and async, +they often have different behavior—and they nearly always have different +performance characteristics. ### Counting @@ -61,7 +62,11 @@ hi number 5 from the first task! This version stops as soon as the for loop in the body of the main async block finishes, because the task spawned by `spawn_task` is shut down when the main function ends. If you want to run all the way to the completion of the task, you -will need to use a join handle to wait for the first task to complete. +will need to use a join handle to wait for the first task to complete. With +threads, we used the `join` method to “block” until the thread was done running. +In Listing 17-6, we can use `await` to do the same thing, because the task +handle itself is a future. Its `Output` type is a `Result`, so we also unwrap it +after awaiting it. @@ -71,11 +76,7 @@ will need to use a join handle to wait for the first task to complete. -With threads, we used the `join` method to “block” until the thread was done -running. In Listing 17-6, we can use `await` to do the same thing, because the -task handle itself is a future. Its `Output` type is a `Result`, so we also -unwrap it after awaiting it. This updated version runs till *both* loops -finish. +This updated version runs till *both* loops finish. @@ -304,9 +308,9 @@ in Chapter 16, we saw that we often need to use move data into closures when working with threads. The same basic dynamics apply to async blocks, so the `move` keyword works with async blocks just like it does with closures. -In Listing 17-11, we change the async block for sending messages an `async move` -block. When we run *this* version of the code, it shuts down gracefully after -the last message is sent. +In Listing 17-11, we change the async block for sending messages from a plain +`async` block to an `async move` block. When we run *this* version of the code, +it shuts down gracefully after the last message is sent and received. diff --git a/src/ch17-07-wip.md b/src/ch17-07-wip.md index 8f3f569203..a29543b628 100644 --- a/src/ch17-07-wip.md +++ b/src/ch17-07-wip.md @@ -89,6 +89,14 @@ one of the main jobs for a runtime. --- +> Note: If you want to understand how things work “under the hood,” the official +> [_Asynchronous Programming in Rust_][async-book] book covers them: +> +> - [Chapter 2: Under the Hood: Executing Futures and Tasks][under-the-hood] +> - [Chapter 4: Pinning][pinning]. + +--- + Recall our description of how `rx.recv()` waits in the [Counting][counting] section. The `recv()` call returns a `Future`, and awaiting it polls it. In our initial discussion, we noted that a runtime will pause the future until it is From 9b13b95ca11c6c272d8f8b081209488a310991fa Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 10 Sep 2024 16:03:08 -0600 Subject: [PATCH 529/720] Upgrade Ch. 17 listings for Rust 1.81 --- .../ch17-async-await/listing-17-01/output.txt | 6 +- .../ch17-async-await/listing-17-02/output.txt | 10 +-- .../ch17-async-await/listing-17-03/output.txt | 6 +- .../ch17-async-await/listing-17-04/output.txt | 28 +------ .../ch17-async-await/listing-17-16/output.txt | 83 +------------------ .../ch17-async-await/listing-17-18/output.txt | 66 +++------------ .../no-listing-stream-ext/output.txt | 14 +--- src/ch17-03-more-futures.md | 13 +-- 8 files changed, 28 insertions(+), 198 deletions(-) diff --git a/listings/ch17-async-await/listing-17-01/output.txt b/listings/ch17-async-await/listing-17-01/output.txt index 46e6cd3111..92b5d5e4d5 100644 --- a/listings/ch17-async-await/listing-17-01/output.txt +++ b/listings/ch17-async-await/listing-17-01/output.txt @@ -1,9 +1,9 @@ $ cargo run - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-01) + Compiling async_await v0.1.0 (file:///projects/async_await) warning: unused implementer of `Future` that must be used - --> src/main.rs:3:5 + --> src/main.rs:2:5 | -3 | hello("async"); +2 | hello("async"); | ^^^^^^^^^^^^^^ | = note: futures do nothing unless you `.await` or poll them diff --git a/listings/ch17-async-await/listing-17-02/output.txt b/listings/ch17-async-await/listing-17-02/output.txt index 5400d6f5e1..d2809af719 100644 --- a/listings/ch17-async-await/listing-17-02/output.txt +++ b/listings/ch17-async-await/listing-17-02/output.txt @@ -1,11 +1,11 @@ $ cargo run - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-02) + Compiling async_await v0.1.0 (file:///projects/async_await) error[E0728]: `await` is only allowed inside `async` functions and blocks - --> src/main.rs:3:20 + --> src/main.rs:2:20 | -2 | fn main() { - | ---- this is not `async` -3 | hello("async").await; +1 | fn main() { + | --------- this is not `async` +2 | hello("async").await; | ^^^^^ only allowed inside `async` functions and blocks For more information about this error, try `rustc --explain E0728`. diff --git a/listings/ch17-async-await/listing-17-03/output.txt b/listings/ch17-async-await/listing-17-03/output.txt index 17922a261c..e61d87f805 100644 --- a/listings/ch17-async-await/listing-17-03/output.txt +++ b/listings/ch17-async-await/listing-17-03/output.txt @@ -1,9 +1,9 @@ $ cargo run - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-03-fix) + Compiling async_await v0.1.0 (file:///projects/async_await) error[E0752]: `main` function is not allowed to be `async` - --> src/main.rs:2:1 + --> src/main.rs:1:1 | -2 | async fn main() { +1 | async fn main() { | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` For more information about this error, try `rustc --explain E0752`. diff --git a/listings/ch17-async-await/listing-17-04/output.txt b/listings/ch17-async-await/listing-17-04/output.txt index d0d2eb5d91..b928fb6020 100644 --- a/listings/ch17-async-await/listing-17-04/output.txt +++ b/listings/ch17-async-await/listing-17-04/output.txt @@ -1,27 +1 @@ -cargo run - Compiling proc-macro2 v1.0.85 - Compiling unicode-ident v1.0.12 - Compiling autocfg v1.3.0 - Compiling futures-sink v0.3.30 - Compiling pin-project-lite v0.2.14 - Compiling libc v0.2.155 - Compiling futures-core v0.3.30 - Compiling memchr v2.7.2 - Compiling pin-utils v0.1.0 - Compiling futures-io v0.3.30 - Compiling futures-task v0.3.30 - Compiling futures-channel v0.3.30 - Compiling slab v0.4.9 - Compiling num_cpus v1.16.0 - Compiling tokio v1.38.0 - Compiling quote v1.0.36 - Compiling syn v2.0.66 - Compiling futures-macro v0.3.30 - Compiling futures-util v0.3.30 - Compiling futures-executor v0.3.30 - Compiling futures v0.3.30 - Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-03) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.91s - Running `target/debug/async_await` -Hello, async! \ No newline at end of file +$ diff --git a/listings/ch17-async-await/listing-17-16/output.txt b/listings/ch17-async-await/listing-17-16/output.txt index 1fcc787041..b928fb6020 100644 --- a/listings/ch17-async-await/listing-17-16/output.txt +++ b/listings/ch17-async-await/listing-17-16/output.txt @@ -1,82 +1 @@ -cargo run - Compiling proc-macro2 v1.0.82 - Compiling unicode-ident v1.0.12 - Compiling autocfg v1.3.0 - Compiling futures-core v0.3.30 - Compiling pin-project-lite v0.2.14 - Compiling libc v0.2.154 - Compiling futures-sink v0.3.30 - Compiling memchr v2.7.2 - Compiling futures-task v0.3.30 - Compiling futures-io v0.3.30 - Compiling futures-channel v0.3.30 - Compiling pin-utils v0.1.0 - Compiling slab v0.4.9 - Compiling num_cpus v1.16.0 - Compiling tokio v1.37.0 - Compiling quote v1.0.36 - Compiling syn v2.0.63 - Compiling futures-macro v0.3.30 - Compiling futures-util v0.3.30 - Compiling futures-executor v0.3.30 - Compiling futures v0.3.30 - Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-20) -error[E0277]: `dyn std::future::Future` cannot be unpinned - --> src/main.rs:47:24 - | -47 | trpl::join_all(futures).await; - | -------------- ^^^^^^^ the trait `Unpin` is not implemented for `dyn std::future::Future`, which is required by `Box>: std::future::Future` - | | - | required by a bound introduced by this call - | - = note: consider using the `pin!` macro - consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box>` to implement `std::future::Future` -note: required by a bound in `join_all` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 - | -102 | pub fn join_all(iter: I) -> JoinAll - | -------- required by a bound in this function -... -105 | I::Item: Future, - | ^^^^^^ required by this bound in `join_all` - -error[E0277]: `dyn std::future::Future` cannot be unpinned - --> src/main.rs:47:9 - | -47 | trpl::join_all(futures).await; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `dyn std::future::Future`, which is required by `Box>: std::future::Future` - | - = note: consider using the `pin!` macro - consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box>` to implement `std::future::Future` -note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 - | -27 | pub struct JoinAll - | ------- required by a bound in this struct -28 | where -29 | F: Future, - | ^^^^^^ required by this bound in `JoinAll` - -error[E0277]: `dyn std::future::Future` cannot be unpinned - --> src/main.rs:47:33 - | -47 | trpl::join_all(futures).await; - | ^^^^^ the trait `Unpin` is not implemented for `dyn std::future::Future`, which is required by `Box>: std::future::Future` - | - = note: consider using the `pin!` macro - consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box>` to implement `std::future::Future` -note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 - | -27 | pub struct JoinAll - | ------- required by a bound in this struct -28 | where -29 | F: Future, - | ^^^^^^ required by this bound in `JoinAll` - -For more information about this error, try `rustc --explain E0277`. -error: could not compile `async_await` (bin "async_await") due to 3 previous errors +$ diff --git a/listings/ch17-async-await/listing-17-18/output.txt b/listings/ch17-async-await/listing-17-18/output.txt index 365d1f0145..f6a657d5ae 100644 --- a/listings/ch17-async-await/listing-17-18/output.txt +++ b/listings/ch17-async-await/listing-17-18/output.txt @@ -1,54 +1,14 @@ $ cargo run - Updating crates.io index - Compiling proc-macro2 v1.0.82 - Compiling unicode-ident v1.0.12 - Compiling autocfg v1.3.0 - Compiling pin-project-lite v0.2.14 - Compiling libc v0.2.154 - Compiling futures-core v0.3.30 - Compiling futures-sink v0.3.30 - Compiling futures-task v0.3.30 - Compiling futures-io v0.3.30 - Compiling pin-utils v0.1.0 - Compiling memchr v2.7.2 - Compiling futures-channel v0.3.30 - Compiling slab v0.4.9 - Compiling num_cpus v1.16.0 - Compiling quote v1.0.36 - Compiling tokio v1.37.0 - Compiling syn v2.0.63 - Compiling tokio-stream v0.1.15 - Compiling futures-macro v0.3.30 - Compiling futures-util v0.3.30 - Compiling futures-executor v0.3.30 - Compiling futures v0.3.30 - Compiling trpl v0.1.0 (/Users/chris/dev/rust-lang/book/packages/trpl) - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-14) -error[E0308]: mismatched types - --> src/main.rs:43:37 - | -8 | let tx1_fut = async move { - | _______________________- -9 | | let vals = vec![ -10 | | String::from("hi"), -11 | | String::from("from"), -... | -19 | | } -20 | | }; - | |_________- the expected `async` block -21 | -22 | let rx_fut = async { - | ______________________- -23 | | while let Some(value) = rx.recv().await { -24 | | println!("received '{value}'"); -25 | | } -26 | | }; - | |_________- the found `async` block -... -43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; - | ^^^^^^ expected `async` block, found a different `async` block - | - = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` - found `async` block `{async block@src/main.rs:22:22: 26:10}` - = note: no two async blocks, even if identical, have the same type - = help: consider pinning your async block and and casting it to a trait object +error: failed to get `trpl` as a dependency of package `async_await v0.1.0 (/Users/chris/dev/rust-lang/book/tmp/listings/ch17-async-await/listing-17-18)` + +Caused by: + failed to load source for dependency `trpl` + +Caused by: + Unable to update /Users/chris/dev/rust-lang/book/tmp/packages/trpl + +Caused by: + failed to read `/Users/chris/dev/rust-lang/book/tmp/packages/trpl/Cargo.toml` + +Caused by: + No such file or directory (os error 2) diff --git a/listings/ch17-async-await/no-listing-stream-ext/output.txt b/listings/ch17-async-await/no-listing-stream-ext/output.txt index 46e6cd3111..10a18bc488 100644 --- a/listings/ch17-async-await/no-listing-stream-ext/output.txt +++ b/listings/ch17-async-await/no-listing-stream-ext/output.txt @@ -1,14 +1,2 @@ $ cargo run - Compiling async_await v0.1.0 (/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-01) -warning: unused implementer of `Future` that must be used - --> src/main.rs:3:5 - | -3 | hello("async"); - | ^^^^^^^^^^^^^^ - | - = note: futures do nothing unless you `.await` or poll them - = note: `#[warn(unused_must_use)]` on by default - -warning: `async_await` (bin "async_await") generated 1 warning - Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s - Running `target/debug/async_await` +error: a bin target must be available for `cargo run` diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index b27e68ad73..461f9e4c9e 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -40,18 +40,7 @@ Unfortunately, this does not compile. Instead, we get this error: From 3cfdf2d66a40ca2739df1e39a8595ad1a1fa649e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 10 Sep 2024 15:59:07 -0600 Subject: [PATCH 530/720] Ch. 17: rework 17.03 (and overall structure) from my own analysis --- .../listing-17-18/src/main.rs | 13 +- src/ch17-03-more-futures.md | 160 ++---------------- src/ch17-07-wip.md | 139 +++++++++++++++ 3 files changed, 162 insertions(+), 150 deletions(-) diff --git a/listings/ch17-async-await/listing-17-18/src/main.rs b/listings/ch17-async-await/listing-17-18/src/main.rs index 80f546b30d..c5ccc0b5bd 100644 --- a/listings/ch17-async-await/listing-17-18/src/main.rs +++ b/listings/ch17-async-await/listing-17-18/src/main.rs @@ -11,7 +11,10 @@ fn main() { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); + // ANCHOR: here let tx1_fut = pin!(async move { + // snip... + // ANCHOR_END: here let vals = vec![ String::from("hi"), String::from("from"), @@ -23,15 +26,23 @@ fn main() { tx1.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } + // ANCHOR: here }); + // ANCHOR_END: here + // ANCHOR: here let rx_fut = pin!(async { + // snip... + // ANCHOR_END: here while let Some(value) = rx.recv().await { println!("received '{value}'"); } + // ANCHOR: here }); let tx_fut = pin!(async move { + // snip... + // ANCHOR_END: here let vals = vec![ String::from("more"), String::from("messages"), @@ -43,9 +54,9 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } + // ANCHOR: here }); - // ANCHOR: here let futures: Vec>> = vec![tx1_fut, rx_fut, tx_fut]; // ANCHOR_END: here diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 461f9e4c9e..b48247e512 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -19,7 +19,7 @@ This is definitely a nice improvement over needing to swap between `join` and `join3` and `join4` and so on! However, even this macro form only works when we know the number of futures ahead of time. In real-world Rust, though, pushing futures into a collection and then waiting on some or all the futures in that -collection to complete is a very common pattern. +collection to complete is a common pattern. To check all the futures in some collection, we will need to iterate over and join on *all* of them. The `trpl::join_all` function accepts any type which @@ -44,15 +44,6 @@ copy just the compiler error --> - - -> Note: Beta readers, the error version shown here is landing in Rust 1.81.0! -> If you are using an earlier version, you will see a *much* less helpful error -> message here. We fixed it as part of writing this chapter! - ```text error[E0308]: mismatched types --> src/main.rs:43:37 @@ -213,140 +204,11 @@ For more information about an error, try `rustc --explain E0277`. That is a *lot* to digest, so let’s pull it apart. The first part of the message tell us that the first async block (`src/main.rs:8:23: 20:10`) does not implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve -it. The rest of the message tells us *why* that is required: the `JoinAll` -struct returned by `trpl::join_all` is generic over a type `F` which must -implement the `Future` trait, directly awaiting a Future requires that the -future implement the `Unpin` trait. Understanding this error means we need to -dive into a little more of how the `Future` type actually works, in particular -the idea of *pinning*. - -### Pinning and the Pin and Unpin Traits - - - -Let’s look again at the definition of `Future`, focusing now on its `poll` -method’s `self` type: - -```rust -use std::pin::Pin; -use std::task::{Context, Poll}; - -pub trait Future { - type Output; - - // Required method - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; -} -``` - -This is the first time we have seen a method where `self` has a type annotation -like this. When we specify the type of `self` like this, we are telling Rust -what type `self` must be to call this method. These kinds of type annotations -for `self` are similar to those for other function parameters, but with the -restriction that the type annotation has to be the type on which the method is -implemented, or a reference or smart pointer to that type. We will see more on -this syntax in Chapter 18. For now, it is enough to know that if we want to poll -a future (to check whether it is `Pending` or `Ready(Output)`), we need a -mutable reference to the type, which is wrapped in a `Pin`. - -`Pin` is a smart pointer, much like `Box`, `Rc`, and the others we saw in -Chapter 15. Unlike those, however, `Pin` only works with *other pointer types* -like reference (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To -be precise, `Pin` works with types which implement the `Deref` or `DerefMut` -traits, which we covered in Chapter 15. You can think of this restriction as -equivalent to only working with pointers, though, since implementing `Deref` or -`DerefMut` means your type behaves like a pointer type. - -Recalling that `.await` is implemented in terms of calls to `poll()`, this -starts to explain the error message we saw above—but that was in terms of -`Unpin`, not `Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, -and why does `Future` need `self` to be in a `Pin` type to call `poll`? - -In [“What Are Futures”][what-are-futures], we described how a series of await -points in a future get compiled into a state machine—and noted how the compiler -helps make sure that state machine follows all of Rust’s normal rules around -safety, including borrowing and ownership. To make that work, Rust looks at what -data is needed between each await point and the next await point or the end of -the async block. It then creates a corresponding variant in the state machine it -creates. Each variant gets the access it needs to the data that will be used in -that section of the source code, whether by taking ownership of that data or by -getting a mutable or immutable reference to it. - -So far so good: if we get anything wrong about the ownership or references in a -given async block, the borrow checker will tell us. When we want to move around -the future that corresponds to that block—like moving it into a `Vec` to pass to -`join_all`—things get trickier. - -When we move a future—whether by pushing into a data structure to use as an -iterator with `join_all`, or returning them from a function—that actually means -moving the state machine Rust creates for us. And unlike most other types in -Rust, the futures Rust creates for async blocks can end up with references to -themselves in the fields of any given variant. Any object which has a reference -to itself is unsafe to move, though, because references always point to the -actual memory address of the thing they refer to. If you move the data structure -itself, you *have* to update any references to it, or they will be left pointing -to the old location. - -In principle, you could make the Rust compiler try to update every reference to -an object every time it gets moved. That would potentially be a lot of -performance overhead, especially given there can be a whole web of references -that need updating. On the other hand, if we could make sure the data structure -in question *does not move in memory*, we do not have to update any references. -And this is exactly what Rust’s borrow checker already guarantees: you cannot -move an item which has any active references to it using safe code. - -`Pin` builds on that to give us the exact guarantee we need. When we *pin* a -value by wrapping a pointer to it in `Pin`, it can no longer move. Thus, if you -have `Pin>`, you actually pin the `SomeType` value, *not* the -`Box` pointer. In fact, the pinned box pointer can move around freely. Remember: -we care about making sure the data ultimately being referenced stays in its -place. If a pointer moves around, but the data it points to is in the same -place, there is no problem. - -However, most types are perfectly safe to move around, even if they happen to be -behind a `Pin` pointer. We only need to think about pinning when items have -internal references. Primitive values like numbers and booleans do not have any -internal structure like that, so they are obviously safe. Neither do most types -you normally work with in Rust. A `Vec`, for example, does not have any internal -references it needs to keep up to date this way, so you can move it around -without worrying. If you have a `Pin>`, you would have to do -everything via Pin’s safe but restrictive APIs, even though a `Vec` is -always safe to move if there are no other references to it. We need a way to -tell the compiler that it is actually just fine to move items around in cases -like these. For that, we have `Unpin`. - -`Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. -Recall that marker traits have no functionality of their own. They exist only to -tell the compiler that it is safe to use the type which implements a given trait -in a particular context. `Unpin` informs the compiler that a given type does -*not* need to uphold any particular guarantees about whether the value in -question can be moved. - -Just like `Send` and `Sync`, the compiler implements `Unpin` automatically for -all types where it can prove it is safe. Implementing `Unpin` manually is unsafe -because it requires *you* to uphold all the guarantees which make `Pin` and -`Unpin` safe yourself for a type with internal references. In practice, this is -a very rare thing to implement yourself! - -> Note: This combination of `Pin` and `Unpin` allows a whole class of complex -> types to be safe in Rust which are otherwise difficult to implement because -> they are self-referential. Types which require `Pin` show up *most* commonly -> in async Rust today, but you might—very rarely!—see it in other contexts, too. -> -> The specific mechanics for how `Pin` and `Unpin` work under the hood are -> covered extensively in the API documentation for `std::pin`, so if you would -> like to understand them more deeply, that is a great place to start. - -Now we know enough to fix the last errors with `join_all`. We tried to move the -futures produced by an async blocks into a `Vec>>`, -but as we have seen, those futures may have internal references, so they do not -implement `Unpin`. They need to be pinned, and then we can pass the `Pin` type -into the `Vec`, confident that the underlying data in the futures will *not* be -moved. - -Listing 17-17 shows how we put this all into practice. First, we update the type -annotation for `futures`, with a `Pin` wrapping each `Box`. Second, we use -`Box::pin` to pin the futures themselves. +it. Later in the chapter, we will dig into a few more details about `Pin` and +`Unpin`. For the moment, though, we can just follow the compiler’s advice to get +unstuck! In Listing 17-17, we start by updating the type annotation for +`futures`, with a `Pin` wrapping each `Box`. Second, we use `Box::pin` to pin +the futures themselves. @@ -398,11 +260,11 @@ references to the dynamic `Future` type, as in Listing 17-18. -There is another, more serious, issue as well. We got this far by ignoring the -fact that we might have different `Output` types. For example, in Listing 17-19, -the anonymous future for `a` implements `Future`, the anonymous -future for `b` implements `Future`, and the anonymous future for -`c` implements `Future`. +There is one last issue to fix. We got this far by ignoring the fact that we +might have different `Output` types. For example, in Listing 17-19, the +anonymous future for `a` implements `Future`, the anonymous future +for `b` implements `Future`, and the anonymous future for `c` +implements `Future`. diff --git a/src/ch17-07-wip.md b/src/ch17-07-wip.md index a29543b628..8c3f644428 100644 --- a/src/ch17-07-wip.md +++ b/src/ch17-07-wip.md @@ -108,3 +108,142 @@ advances it when `poll` returns `Poll::Ready(Some(message))` or `Poll::Ready(None)`. [counting]: /ch17-02-concurrency-with-async.md + +--- + + + +The rest of the message tells us *why* that is required: the `JoinAll` +struct returned by `trpl::join_all` is generic over a type `F` which must +implement the `Future` trait, directly awaiting a Future requires that the +future implement the `Unpin` trait. Understanding this error means we need to +dive into a little more of how the `Future` type actually works, in particular +the idea of *pinning*. + +### Pinning and the Pin and Unpin Traits + + + +Let’s look again at the definition of `Future`, focusing now on its `poll` +method’s `self` type: + +```rust +use std::pin::Pin; +use std::task::{Context, Poll}; + +pub trait Future { + type Output; + + // Required method + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; +} +``` + +This is the first time we have seen a method where `self` has a type annotation +like this. When we specify the type of `self` like this, we are telling Rust +what type `self` must be to call this method. These kinds of type annotations +for `self` are similar to those for other function parameters, but with the +restriction that the type annotation has to be the type on which the method is +implemented, or a reference or smart pointer to that type. We will see more on +this syntax in Chapter 18. For now, it is enough to know that if we want to poll +a future (to check whether it is `Pending` or `Ready(Output)`), we need a +mutable reference to the type, which is wrapped in a `Pin`. + +`Pin` is a smart pointer, much like `Box`, `Rc`, and the others we saw in +Chapter 15. Unlike those, however, `Pin` only works with *other pointer types* +like reference (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To +be precise, `Pin` works with types which implement the `Deref` or `DerefMut` +traits, which we covered in Chapter 15. You can think of this restriction as +equivalent to only working with pointers, though, since implementing `Deref` or +`DerefMut` means your type behaves like a pointer type. + +Recalling that `.await` is implemented in terms of calls to `poll()`, this +starts to explain the error message we saw above—but that was in terms of +`Unpin`, not `Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, +and why does `Future` need `self` to be in a `Pin` type to call `poll`? + +In [“What Are Futures”][what-are-futures], we described how a series of await +points in a future get compiled into a state machine—and noted how the compiler +helps make sure that state machine follows all of Rust’s normal rules around +safety, including borrowing and ownership. To make that work, Rust looks at what +data is needed between each await point and the next await point or the end of +the async block. It then creates a corresponding variant in the state machine it +creates. Each variant gets the access it needs to the data that will be used in +that section of the source code, whether by taking ownership of that data or by +getting a mutable or immutable reference to it. + +So far so good: if we get anything wrong about the ownership or references in a +given async block, the borrow checker will tell us. When we want to move around +the future that corresponds to that block—like moving it into a `Vec` to pass to +`join_all`—things get trickier. + +When we move a future—whether by pushing into a data structure to use as an +iterator with `join_all`, or returning them from a function—that actually means +moving the state machine Rust creates for us. And unlike most other types in +Rust, the futures Rust creates for async blocks can end up with references to +themselves in the fields of any given variant. Any object which has a reference +to itself is unsafe to move, though, because references always point to the +actual memory address of the thing they refer to. If you move the data structure +itself, you *have* to update any references to it, or they will be left pointing +to the old location. + +In principle, you could make the Rust compiler try to update every reference to +an object every time it gets moved. That would potentially be a lot of +performance overhead, especially given there can be a whole web of references +that need updating. On the other hand, if we could make sure the data structure +in question *does not move in memory*, we do not have to update any references. +And this is exactly what Rust’s borrow checker already guarantees: you cannot +move an item which has any active references to it using safe code. + +`Pin` builds on that to give us the exact guarantee we need. When we *pin* a +value by wrapping a pointer to it in `Pin`, it can no longer move. Thus, if you +have `Pin>`, you actually pin the `SomeType` value, *not* the +`Box` pointer. In fact, the pinned box pointer can move around freely. Remember: +we care about making sure the data ultimately being referenced stays in its +place. If a pointer moves around, but the data it points to is in the same +place, there is no problem. + +However, most types are perfectly safe to move around, even if they happen to be +behind a `Pin` pointer. We only need to think about pinning when items have +internal references. Primitive values like numbers and booleans do not have any +internal structure like that, so they are obviously safe. Neither do most types +you normally work with in Rust. A `Vec`, for example, does not have any internal +references it needs to keep up to date this way, so you can move it around +without worrying. If you have a `Pin>`, you would have to do +everything via Pin’s safe but restrictive APIs, even though a `Vec` is +always safe to move if there are no other references to it. We need a way to +tell the compiler that it is actually just fine to move items around in cases +like these. For that, we have `Unpin`. + +`Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. +Recall that marker traits have no functionality of their own. They exist only to +tell the compiler that it is safe to use the type which implements a given trait +in a particular context. `Unpin` informs the compiler that a given type does +*not* need to uphold any particular guarantees about whether the value in +question can be moved. + +Just like `Send` and `Sync`, the compiler implements `Unpin` automatically for +all types where it can prove it is safe. Implementing `Unpin` manually is unsafe +because it requires *you* to uphold all the guarantees which make `Pin` and +`Unpin` safe yourself for a type with internal references. In practice, this is +a very rare thing to implement yourself! + +> Note: This combination of `Pin` and `Unpin` allows a whole class of complex +> types to be safe in Rust which are otherwise difficult to implement because +> they are self-referential. Types which require `Pin` show up *most* commonly +> in async Rust today, but you might—very rarely!—see it in other contexts, too. +> +> The specific mechanics for how `Pin` and `Unpin` work under the hood are +> covered extensively in the API documentation for `std::pin`, so if you would +> like to understand them more deeply, that is a great place to start. + +Now we know enough to fix the last errors with `join_all`. We tried to move the +futures produced by an async blocks into a `Vec>>`, +but as we have seen, those futures may have internal references, so they do not +implement `Unpin`. They need to be pinned, and then we can pass the `Pin` type +into the `Vec`, confident that the underlying data in the futures will *not* be +moved. From 97902d50a7db50d3f4782f91b64377c34acabf30 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 11 Sep 2024 08:29:03 -0600 Subject: [PATCH 531/720] Ch. 17: rework 17.04 with my own edits and analysis This does *not* yet incorporate any of the relevant feedback from Carol on this, so a couple spots are still pretty messy. --- src/ch17-04-more-ways-of-combining-futures.md | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md index b7f50315cd..b221585b67 100644 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ b/src/ch17-04-more-ways-of-combining-futures.md @@ -47,9 +47,10 @@ But *how* would you hand control back to the runtime in those cases? ### Yielding Let’s simulate a long-running operation. Listing 17-21 introduces a `slow` -function which uses `std::thread::sleep` to block the current thread for some -number of milliseconds. We can use `slow` to stand in for real-world operations -which are both long-running and blocking. +function. It uses `std::thread::sleep` instead of `trpl::sleep` so that calling +`slow` will block the current thread for some number of milliseconds. We can use +`slow` to stand in for real-world operations which are both long-running and +blocking. @@ -163,11 +164,10 @@ lot in one millisecond! You can see this for yourself by setting up a little benchmark, like the one in Listing 17-25. (This is not an especially rigorous way to do performance testing, but it suffices to show the difference here.) Here, we skip all the -status printing, pass a one-nanosecond `Duration` to `sleep`, let each future -run by itself so that they do not interfere with each other, and get rid of all -the status printing that we did to see the back-and-forth between tasks in -Listings 17-23 and 17-24. Then we run for 1,000 iterations and see how long -`sleep` takes vs. `yield_now`. +status printing, pass a one-nanosecond `Duration` to `trple::sleep`, and let +each future run by itself, with no switching between the futures. Then we run +for 1,000 iterations and see how long the future using `trpl::sleep` takes +compared to the future using `trpl::yield_now`. @@ -233,19 +233,21 @@ Listing 17-27 shows this declaration. -The types line up now, so let’s think about the *behavior* we need. We want to -race the future passed in against the duration. We can use `trpl::sleep` to make -a timer future from the duration, and use `trpl::race` to run the future and the -timer against each other. - -When we saw `race` earlier in Listing 17-20, we ignored its return type, because -we were just interested in seeing the behavior of `fast` and `slow` when we ran -the program. Here, though, its return value tells us whether the future or the -sleep finished first. With `race`, both futures passed as arguments can -legitimately “win,” so it does not make sense to use a `Result` to represent the -return type. Instead, it returns a similar type called `Either`. Unlike -`Result`, there is no notion of success or failure baked into `Either`. Instead, -it uses `Left` and `Right` to indicate “one or the other”: +That satisfies our goals for the types. Now let’s think about the *behavior* we +need: we want to race the future passed in against the duration. We can use +`trpl::sleep` to make a timer future from the duration, and use `trpl::race` to +run that timer with the future the caller passes in. + +The `trpl::race` function returns a value to indicate which of the futures +passed to it finishes first. (When we saw `race` earlier in Listing 17-20, we +ignored its return value, because we were only interested in seeing the behavior +of `fast` and `slow` when we ran the program.) Because either future passed as +an argument to `race` can legitimately “win,” it does not make sense to use a +`Result` to represent the return type. Instead, `race` returns a type we have +not seen before, `Either`. The `Either` type is somewhat like a `Result`, in +that it has two cases. Unlike `Result`, though, there is no notion of success or +failure baked into `Either`. Instead, it uses `Left` and `Right` to indicate +“one or the other”. ```rust enum Either { @@ -256,17 +258,19 @@ enum Either { The `race` function returns `Left` if the first argument finishes first, with that future’s output, and `Right` with the second future argument’s output if -*that* one finishes first. We also know that `race` is not fair, and polls -arguments in the order they are passed. For `timeout`, we pass the future to -`race` first so it gets a chance to complete even if `max_time` is a very short -duration. If `future` finishes first, `race` will return `Left` with the output -from `future`. If `timer` finishes first, `race` will return `Right` with the -timer’s output of `()`. +*that* one finishes first. + +We also know that `race` is not fair, and polls arguments in the order they are +passed. Thus, we pass the caller-supplied future to `race` first so it gets a +chance to complete even if `max_time` is a very short duration. If `future` +finishes first, `race` will return `Left` with the output from `future`. If +`timer` finishes first, `race` will return `Right` with the timer’s output of +`()`. In Listing 17-28, we match on the result of awaiting `trpl::race`. If the future succeeded and we get a `Left(output)`, we return `Ok(output)`. If the sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` with -`_` and return `Err(duration)` instead. +`_` and return `Err(max_time)` instead. From 68049c6e152cd71e53b7795ec8149301ba15822b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 11 Sep 2024 11:11:02 -0600 Subject: [PATCH 532/720] Ch. 17: rework 17.05 with my own edits and analysis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Along with the wording and phrasing-level edits, pull out a fair bit of material for the “advanced” section at the end, specifically the details of what `Stream` and `StreamExt` actually do. --- src/ch17-05-streams.md | 215 ++++++++++++++--------------------------- src/ch17-07-wip.md | 78 +++++++++++++++ 2 files changed, 153 insertions(+), 140 deletions(-) diff --git a/src/ch17-05-streams.md b/src/ch17-05-streams.md index 8a44d37059..9fd9049430 100644 --- a/src/ch17-05-streams.md +++ b/src/ch17-05-streams.md @@ -1,22 +1,25 @@ ## Streams -So far in this chapter, we have mostly stuck with individual futures. The one -big exception was the async channel we used. Recall how we used the receiver for -our async channel in the [“Message Passing”][17-02-messages] earlier in the -chapter, which waits on a sequence of items produced over time—a *stream*. +So far in this chapter, we have mostly stuck to individual futures. The one big +exception was the async channel we used. Recall how we used the receiver for our +async channel in the [“Message Passing”][17-02-messages] earlier in the chapter. +The async `recv` method produces a sequence of items over time. This is an +instance of a much more general pattern, often called a *stream*. A sequence of items is something we have seen before, when we looked at the `Iterator` trait in Chapter 13, but there are two differences between iterators and the async channel receiver. The first difference is the element of time: iterators are synchronous, while the channel receiver is asynchronous. The -second difference is the API. With iterators, if we worked with them directly -rather than using `iter` or `.into_iter` (including implicitly with a `for` -loop), we called `next`, whereas with the channel we call `recv`. Otherwise, -these APIs feel very similar. - -That is not a coincidence. A stream—of messages or of anything else—is like an -an asynchronous form of iteration. In fact, we can create a stream from any -iterator. Like an iterator, we can work with a stream by calling its `next` +second difference is the API. When working directly with an `Iterator`, we call +its synchronous `next` method. With a `trpl::Receiver`, we call an asynchronous +`recv` method instead, but these APIs otherwise feel very similar. + +That similarity is not a coincidence. A stream is like an asynchronous form of +iteration. Whereas the `trpl::Receiver` specifically waits to receive messages, +though, a general-purpose stream API needs to be much more general: it will just +provide the next item like `Iterator` does, but asynchronously. In fact, this is +roughly how it works in Rust, so we can actually create a stream from any +iterator. As with an iterator, we can work with a stream by calling its `next` method, and then awaiting the output, as in Listing 17-29. @@ -32,9 +35,8 @@ We start with an array of numbers, which we convert to an iterator and then call using the `trpl::stream_from_iter` function. Then we loop over the items in the stream as they arrive with the `while let` loop -Unfortunately, this does not yet work. When we try to run the code, it does not -compile. Instead, as we can see in the output, it reports that there is no -`next` method available. +Unfortunately, when we try to run the code, it does not compile. Instead, as we +can see in the output, it reports that there is no `next` method available. but there *is* a very common definition used throughout the -ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, -so we can build up to how a `Stream` trait that merges them together might look. - -From `Iterator`, we have the idea of a sequence: its `next` method provides an -`Option`. From `Future`, we have the idea of readiness over time: -its `poll` method provides a `Poll`. To represent a sequence of -items which become ready over time, we define a `Stream` trait which has all of -those features put together: - -```rust -use std::pin::Pin; -use std::task::{Context, Poll}; - -trait Stream { - type Item; - - fn poll_next( - self: Pin<&mut Self>, - cx: &mut Context<'_> - ) -> Poll>; -} -``` - -The `Stream` trait defines an associated type `Item` for the type of the items -produced by the stream. This is like `Iterator`: there may be zero to many of -these, and unlike `Future`, where there was a single `Output`. - -`Stream` also defines a method to get those items. We call it `poll_next`, to -make it clear that it polls like `Future::poll` and produces a sequence of items -like `Iterator::next`. Its return type uses both `Poll` and `Option`. The outer -type is `Poll`, since it has to be checked for readiness, just like a future. -The inner type is `Option`, since it needs to signal whether there are more -messages, just like an iterator. - -Something very similar to this will likely end up standardized as part of Rust’s -standard library. In the meantime, it is part of the toolkit of most runtimes, -so you can rely on it, and everything we cover below should generally apply! - -In the example we saw above, though, we did not use `poll_next` *or* `Stream`, -but instead `next` and `StreamExt`. We *could* work directly in terms of the -`poll_next` API by hand-writing our own `Stream` state machines, of course, just -as we *could* work with futures directly via their `poll` method. Using `await` -is much nicer, though, so the `StreamExt` trait supplies the `next` method so -we can do just that. - -```rust -{{#rustdoc_include ../listings/ch17-async-await/no-listing-stream-ext/src/lib.rs:here}} -``` - - - -> Note: The actual definition we will use looks slightly different than this, -> because it supports versions of Rust which did not yet support using async -> functions in traits. As a result, it looks like this: -> -> ```rust,ignore -> fn next(&mut self) -> Next<'_, Self> where Self: Unpin; -> ``` -> -> That `Next` type is just a simple `struct` which implements `Future` and gives -> a way to name the lifetime of the reference to `self` with `Next<'_, Self>`, -> so that `.await` can work with this! - -The `StreamExt` trait is also the home of all the interesting methods available -to use with streams. `StreamExt` is automatically implemented for every type -which implements `Stream`, but they are separated out so that the community can -iterate on the foundational trait distinctly from the convenience APIs. - -Now that we have a handle on the core traits that make streams work, let’s see -how we can use some of those interesting `StreamExt` methods to combine -streams in interesting ways. +Of course, this is not very interesting. We could do that with normal iterators +and without any async at all. So let’s look at some of the other things we can +do which are unique to streams. ### Composing Streams Lots of things are naturally represented as streams: items becoming available in -a queue over time, or working with more data than can fit in a computer’s memory -by only pulling chunks of it from the file system at a time, or data arriving -over the network over time. And because streams are futures, we can use them -with any other kind of future, and we can combine them in interesting ways. For -example, we can debounce events to avoid triggering too many network calls, set -timeouts on sequences of long-running operations, or throttle user interface -events to avoid doing needless work. +a queue, or working with more data than can fit in a computer’s memory by only +pulling chunks of it from the file system at a time, or data arriving over the +network over time. Because streams are futures, we can use them with any other +kind of future, too, and we can combine them in interesting ways. For example, +we can debounce events to avoid triggering too many network calls, set timeouts +on sequences of long-running operations, or throttle user interface events to +avoid doing needless work. Let’s start by building a little stream of messages, similar to what we might see from a WebSocket or other real-time communication protocols. In Listing @@ -201,9 +133,9 @@ see from a WebSocket or other real-time communication protocols. In Listing String>`. For its implementation, we create an async channel, loop over the first ten letters of the English alphabet, and send them across the channel. -We also use a new type: `ReceiverStream`. This converts the `rx` receiver from -the `trpl::channel` into a stream. Back in `main`, we use a `while let` loop to -print all the messages from the stream. +We also use a new type: `ReceiverStream`, which converts the `rx` receiver from +the `trpl::channel` into a `Stream` with a `next` method. Back in `main`, we use +a `while let` loop to print all the messages from the stream. @@ -236,6 +168,16 @@ We could do this with the regular `Receiver` API, or even the regular `Iterator` API, though. Let’s add something that requires streams, like adding a timeout which applies to every item in the stream, and a delay on the items we emit. +In Listing 17-33, we start by adding a timeout to the stream with the `timeout` +method, which comes from the `StreamExt` trait. Then we update the body of the +`while let` loop, because the stream now returns a `Result`. The `Ok` variant +indicates a message arrived in time; the `Err` variant indicates that the +timeout elapsed before any message arrived. We `match` on that result and either +print the message when we receive it successfully, or print a notice about the +timeout. Finally, notice that we pin the messages after applying the timeout to +them, because the timeout helper produces a future which needs to be pinned to +be polled. + ```rust @@ -244,16 +186,6 @@ which applies to every item in the stream, and a delay on the items we emit. -The first thing we do in Listing 17-33 is add a timeout to the stream with the -`timeout` method, which comes from the `StreamExt` trait. Then we update the -body of the `while let` loop, because the stream now returns a `Result`. The -`Ok` variant indicates a message arrived in time; the `Err` variant indicates -that the timeout elapsed before any message arrived. We `match` on that result -and either print the message when we receive it successfully, or print a notice -about the timeout. Finally, notice that we pinned the messages after applying -the timeout to them, because the timeout helper produces a future which needs -to be pinned to be polled. - However, since there are no delays between messages, this timeout does not change the behavior of the program. Let’s add a variable delay to the messages we send. In `get_messages`, we use the `enumerate` iterator method with the @@ -277,10 +209,11 @@ function, because then we would return a `Future>` instead of just a `Stream>`. The caller would have to await `get_messages` itself to get access to the stream. But remember: everything in a given future happens linearly; concurrency happens *between* -futures. Awaiting `get_messages` would require it to send all the messages, and -sleeping between sending them, before returning the receiver stream. As a -result, The timeout would end up useless, because there would be no delays in -the stream itself: the delays all happen before the stream is even available. +futures. Awaiting `get_messages` would require it to send all the messages, +including sleeping between sending each message, before returning the receiver +stream. As a result, the timeout would end up useless. There would be no delays +in the stream itself: the delays would all happen before the stream was even +available. Instead, we leave `get_messages` as a regular function which returns a stream, and spawn a task to handle the async `sleep` calls. @@ -333,12 +266,13 @@ this stream of messages. ### Merging Streams -First, let’s create another stream, called `get_intervals`, which will emit an -item every millisecond if we let it run directly. For simplicity, we can use the -`sleep` function to send a message on a delay, and combine it with the same -approach of creating a stream from a channel we used in `get_messages`. The -difference is that this time, we are going to send back the count of intervals -which has elapsed, so the return type will be `impl Stream`. +First, let’s create another stream, which will emit an item every millisecond if +we let it run directly. For simplicity, we can use the `sleep` function to send +a message on a delay, and combine it with the same approach of creating a stream +from a channel we used in `get_messages`. The difference is that this time, we +are going to send back the count of intervals which has elapsed, so the return +type will be `impl Stream`, and we can call the function +`get_intervals`. In Listing 17-35, we start by defining a `count` in the task. (We could define it outside the task, too, but it is clearer to limit the scope of any given @@ -358,7 +292,8 @@ the infinite loop. This kind of infinite loop, which only ends when the whole runtime gets torn down, is fairly common in async Rust: many programs need to keep running -indefinitely. With async, this does not block anything else! +indefinitely. With async, this does not block anything else, as long as there is +at least one await point in each iteration through the loop. Back in our main function’s async block, we start by calling `get_intervals`. Then we merge the `messages` and `intervals` streams with the `merge` method. @@ -388,10 +323,10 @@ already in the basic format we want and has to handle timeout errors. First, we can use the `map` helper method to transform the `intervals` into a string. Second, we need to match the `Timeout` from `messages`. Since we do not actually *want* a timeout for `intervals`, though, we can just create a timeout which is -longer than the other durations we are using. Here, we create a 10-second time -out with `Duration::from_secs(10)`. Finally, we need to make `merged` both +longer than the other durations we are using. Here, we create a 10-second +timeout with `Duration::from_secs(10)`. Finally, we need to make `stream` mutable, so that the `while let` loop’s `next` calls can iterate through the -stream, and pinned, so that it is safe to do so. +stream, and pin it so that it is safe to do so. diff --git a/src/ch17-07-wip.md b/src/ch17-07-wip.md index 8c3f644428..7e0fef4bfe 100644 --- a/src/ch17-07-wip.md +++ b/src/ch17-07-wip.md @@ -247,3 +247,81 @@ but as we have seen, those futures may have internal references, so they do not implement `Unpin`. They need to be pinned, and then we can pass the `Pin` type into the `Vec`, confident that the underlying data in the futures will *not* be moved. + +--- + +### The Stream API + +Unlike `Iterator` and `Future`, there is no definition of a `Stream` trait in +the standard library yet as of the time of writing, but there *is* a very common definition used throughout the +ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, +so we can build up to how a `Stream` trait that merges them together might look. + +From `Iterator`, we have the idea of a sequence: its `next` method provides an +`Option`. From `Future`, we have the idea of readiness over time: +its `poll` method provides a `Poll`. To represent a sequence of +items which become ready over time, we define a `Stream` trait which has all of +those features put together: + +```rust +use std::pin::Pin; +use std::task::{Context, Poll}; + +trait Stream { + type Item; + + fn poll_next( + self: Pin<&mut Self>, + cx: &mut Context<'_> + ) -> Poll>; +} +``` + +The `Stream` trait defines an associated type `Item` for the type of the items +produced by the stream. This is like `Iterator`: there may be zero to many of +these, and unlike `Future`, where there was a single `Output`. + +`Stream` also defines a method to get those items. We call it `poll_next`, to +make it clear that it polls like `Future::poll` and produces a sequence of items +like `Iterator::next`. Its return type uses both `Poll` and `Option`. The outer +type is `Poll`, since it has to be checked for readiness, just like a future. +The inner type is `Option`, since it needs to signal whether there are more +messages, just like an iterator. + +Something very similar to this will likely end up standardized as part of Rust’s +standard library. In the meantime, it is part of the toolkit of most runtimes, +so you can rely on it, and everything we cover below should generally apply! + +In the example we saw above, though, we did not use `poll_next` *or* `Stream`, +but instead `next` and `StreamExt`. We *could* work directly in terms of the +`poll_next` API by hand-writing our own `Stream` state machines, of course, just +as we *could* work with futures directly via their `poll` method. Using `await` +is much nicer, though, so the `StreamExt` trait supplies the `next` method so +we can do just that. + +```rust +{{#rustdoc_include ../listings/ch17-async-await/no-listing-stream-ext/src/lib.rs:here}} +``` + + + +> Note: The actual definition we will use looks slightly different than this, +> because it supports versions of Rust which did not yet support using async +> functions in traits. As a result, it looks like this: +> +> ```rust,ignore +> fn next(&mut self) -> Next<'_, Self> where Self: Unpin; +> ``` +> +> That `Next` type is just a simple `struct` which implements `Future` and gives +> a way to name the lifetime of the reference to `self` with `Next<'_, Self>`, +> so that `.await` can work with this! + +The `StreamExt` trait is also the home of all the interesting methods available +to use with streams. `StreamExt` is automatically implemented for every type +which implements `Stream`, but they are separated out so that the community can +iterate on the foundational trait distinctly from the convenience APIs. From 0d8da8bae22843edc88ea25463e198d9af27c934 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 11 Sep 2024 12:28:01 -0600 Subject: [PATCH 533/720] Ch. 17: fold together 17.03 and 17.04 --- src/SUMMARY.md | 5 +- src/ch17-03-more-futures.md | 300 +++++++++++++++++- src/ch17-04-more-ways-of-combining-futures.md | 299 ----------------- ...{ch17-05-streams.md => ch17-04-streams.md} | 0 ...-07-wip.md => ch17-05-traits-for-async.md} | 2 + 5 files changed, 303 insertions(+), 303 deletions(-) delete mode 100644 src/ch17-04-more-ways-of-combining-futures.md rename src/{ch17-05-streams.md => ch17-04-streams.md} (100%) rename src/{ch17-07-wip.md => ch17-05-traits-for-async.md} (99%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 33af2af759..b2af389757 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -105,10 +105,9 @@ - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) - [Concurrency With Async](ch17-02-concurrency-with-async.md) - [Working With More Than Two Futures](ch17-03-more-futures.md) - - [More Ways of Combining Futures](ch17-04-more-ways-of-combining-futures.md) - - [Streams](ch17-05-streams.md) + - [Streams](ch17-04-streams.md) + - [Digging Into the Traits for Async](ch17-05-traits-for-async.md) - [Futures, Tasks, and Threads](ch17-06-futures-tasks-threads.md) - - [Restructuring](ch17-07-wip.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index b48247e512..1affdf7def 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -294,6 +294,304 @@ need to reach for `pin` now and again to use them with those APIs. `Pin` and building a runtime itself, rather than for day to day Rust code. When you see them, though, now you will know what to do! +### Racing futures + +When we “join” futures with the `join` family of functions and macros, we +require *all* of them to finish before we move on. Sometimes, though, we only +need *some* future from a set to finish before we move on—kind of like racing +one future against another. This operation is often named `race` for exactly +that reason. + +In Listing 17-20, we use `race` to run two futures, `slow` and `fast`, against +each other. Each one prints a message when it starts running, pauses for some +amount of time by calling and awaiting `sleep`, and then prints another message +when it finishes. Then we pass both to `trpl::race` and wait for one of them to +finish. (The outcome here won’t be too surprising: `fast` wins!) + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} +``` + + + +Notice that if you flip the order of the arguments to `race`, the order of the +“started” messages changes, even though the `fast` future always completes +first. That is because the implementation of this particular `race` function is +not fair. It always runs the futures passed as arguments in the order they are +passed. Other implementations *are* fair, and will randomly choose which future +to poll first. Regardless of whether the implementation of race we are using is +fair, though, *one* of the futures will run up to the first `.await` in its body +before another task can start. + +Recall from [“What Are Futures?”][futures] that at each await point, Rust pauses +the async block and hands control back to a runtime. The inverse is also true: +Rust *only* pauses async blocks and hands control back to a runtime at an await +point. Everything between await points is synchronous. + +That means if you do a bunch of work in an async block without an await point, +that future will block any other futures from making progress. (You may +sometimes hear this referred to as one future *starving* other futures. And this +applies to threads, too!) In many cases, that may not be a big deal. However, if +you are doing some kind of expensive setup or long-running work, or if you have +a future which will keep doing some particular task indefinitely, you will need +to think about when and where to hand control back to the runtime. + +But *how* would you hand control back to the runtime in those cases? + +### Yielding + +Let’s simulate a long-running operation. Listing 17-21 introduces a `slow` +function. It uses `std::thread::sleep` instead of `trpl::sleep` so that calling +`slow` will block the current thread for some number of milliseconds. We can use +`slow` to stand in for real-world operations which are both long-running and +blocking. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:slow}} +``` + + + +In Listing 17-22, we use `slow` to emulate doing this kind of CPU-bound work in +a pair of futures. To begin, each future only hands control back to the runtime +*after* carrying out a bunch of slow operations. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:slow-futures}} +``` + + + +If you run this, you will see this output: + + + +```text +'a' started. +'a' ran for 30ms +'a' ran for 10ms +'a' ran for 20ms +'b' started. +'b' ran for 75ms +'b' ran for 10ms +'b' ran for 15ms +'b' ran for 350ms +'a' finished. +``` + +As with our earlier example, `race` still finishes as soon as `a` is done. There +is no interleaving between the two futures, though. The `a` future does all of +its work until the `trpl::sleep` call is awaited, then the `b` future does all +of its work until its own `trpl::sleep` call is awaited, and then the `a` future +completes. To allow both futures to make progress between their slow tasks, we +need await points so we can hand control back to the runtime. That means we need +something we can await! + +We can already see this kind of handoff happening in Listing 17-22: if we +removed the `trpl::sleep` at the end of the `a` future, it would complete +without the `b` future running *at all*. Maybe we could use the `sleep` function +as a starting point? + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:here}} +``` + + + +In Listing 17-23, we add `trpl::sleep` calls with await points between each call +to `slow`. Now the two futures’ work is interleaved: + + + +```text +'a' started. +'a' ran for 30ms +'b' started. +'b' ran for 75ms +'a' ran for 10ms +'b' ran for 10ms +'a' ran for 20ms +'b' ran for 15ms +'a' finished. +``` + +The `a` future still runs for a bit before handing off control to `b`, because +it calls `slow` before ever calling `trpl::sleep`, but after that the futures +swap back and forth each time one of them hits an await point. In this case, we +have done that after every call to `slow`, but we could break up the work +however makes the most sense to us. + +We do not really want to *sleep* here, though: we want to make progress as fast +as we can. We just need to hand back control to the runtime. We can do that +directly, using the `yield_now` function. In Listing 17-24, we replace all those +`sleep` calls with `yield_now`. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:yields}} +``` + + + +This is both clearer about the actual intent and can be significantly faster +than using `sleep`, because timers like the one used by `sleep` often have +limits to how granular they can be. The version of `sleep` we are using, for +example, will always sleep for at least a millisecond, even if we pass it a +`Duration` of one nanosecond. Again, modern computers are *fast*: they can do a +lot in one millisecond! + +You can see this for yourself by setting up a little benchmark, like the one in +Listing 17-25. (This is not an especially rigorous way to do performance +testing, but it suffices to show the difference here.) Here, we skip all the +status printing, pass a one-nanosecond `Duration` to `trple::sleep`, and let +each future run by itself, with no switching between the futures. Then we run +for 1,000 iterations and see how long the future using `trpl::sleep` takes +compared to the future using `trpl::yield_now`. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:here}} +``` + + + +The version with `yield_now` is *way* faster! + +This means that async can be useful even for CPU-bound tasks, depending on what +else your program is doing, because it provides a useful tool for structuring +the relationships between different parts of the program. This is a form of +*cooperative multitasking*, where each future has both the power to determine +when it hands over control via await points. Each future therefore also has the +*responsibility* to avoid blocking for too long. In some Rust-based embedded +operating systems, this is the *only* kind of multitasking! + +In real-world code, you will not usually be alternating function calls with +await points on every single line, of course. The underlying dynamic is an +important one to keep in mind, though! + +### Building Our Own Async Abstractions + +We can also compose futures together to create new patterns. For example, we can +build a `timeout` function with async building blocks we already have. When we +are done, the result will be another building block we could use to build up yet +further async abstractions. + +Listing 17-26 shows how we would expect this `timeout` to work with a slow +future. + ++ +```rust,ignore +{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:here}} +``` + + + +Let’s implement this! To begin, let’s think about the API for `timeout`: + +- It needs to be an async function itself so we can await it. +- Its first parameter should be a future to run. We can make it generic to allow + it to work with any future. +- Its second parameter will be the maximum time to wait. If we use a `Duration`, + that will make it easy to pass along to `trpl::sleep`. +- It should return a `Result`. If the future completes successfully, the + `Result` will be `Ok` with the value produced by the future. If the timeout + elapses first, the `Result` will be `Err` with the duration that the timeout + waited for. + +Listing 17-27 shows this declaration. + + + ++ +```rust,ignore +{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:declaration}} +``` + + + +That satisfies our goals for the types. Now let’s think about the *behavior* we +need: we want to race the future passed in against the duration. We can use +`trpl::sleep` to make a timer future from the duration, and use `trpl::race` to +run that timer with the future the caller passes in. + +The `trpl::race` function returns a value to indicate which of the futures +passed to it finishes first. (When we saw `race` earlier in Listing 17-20, we +ignored its return value, because we were only interested in seeing the behavior +of `fast` and `slow` when we ran the program.) Because either future passed as +an argument to `race` can legitimately “win,” it does not make sense to use a +`Result` to represent the return type. Instead, `race` returns a type we have +not seen before, `Either`. The `Either` type is somewhat like a `Result`, in +that it has two cases. Unlike `Result`, though, there is no notion of success or +failure baked into `Either`. Instead, it uses `Left` and `Right` to indicate +“one or the other”. + +```rust +enum Either { + Left(A), + Right(B) +} +``` + +The `race` function returns `Left` if the first argument finishes first, with +that future’s output, and `Right` with the second future argument’s output if +*that* one finishes first. + +We also know that `race` is not fair, and polls arguments in the order they are +passed. Thus, we pass the caller-supplied future to `race` first so it gets a +chance to complete even if `max_time` is a very short duration. If `future` +finishes first, `race` will return `Left` with the output from `future`. If +`timer` finishes first, `race` will return `Right` with the timer’s output of +`()`. + +In Listing 17-28, we match on the result of awaiting `trpl::race`. If the +future succeeded and we get a `Left(output)`, we return `Ok(output)`. If the +sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` with +`_` and return `Err(max_time)` instead. + ++ +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:implementation}} +``` + + + +With that, we have a working `timeout`, built out of two other async helpers. If +we run our code, it will print the failure mode after the timeout: + +```text +Failed after 2 seconds +``` + +Because futures compose with other futures, you can build really powerful tools +using smaller async building blocks. For example, you can use this same approach +to combine timeouts with retries, and in turn use those with things like network +calls—one of the examples from the beginning of the chapter! + +Over the last two sections, we have seen how to work with multiple futures at +the same time. Up next, let’s look at how we can work with multiple futures in a +sequence over time, with *streams*. + [collections]: ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: ch12-03-improving-error-handling-and-modularity.html -[what-are-futures]: ch17-01-futures-and-syntax.html#what-are-futures +[futures]: ch17-01-futures-and-syntax.html#what-are-futures diff --git a/src/ch17-04-more-ways-of-combining-futures.md b/src/ch17-04-more-ways-of-combining-futures.md deleted file mode 100644 index b221585b67..0000000000 --- a/src/ch17-04-more-ways-of-combining-futures.md +++ /dev/null @@ -1,299 +0,0 @@ -## More Ways of Combining Futures - -When we “join” futures with the `join` family of functions and macros, we -require *all* of them to finish before we move on. Sometimes, though, we only -need *some* future from a set to finish before we move on—kind of like racing -one future against another. This operation is often named `race` for exactly -that reason. - -In Listing 17-20, we use `race` to run two futures, `slow` and `fast`, against -each other. Each one prints a message when it starts running, pauses for some -amount of time by calling and awaiting `sleep`, and then prints another message -when it finishes. Then we pass both to `trpl::race` and wait for one of them to -finish. (The outcome here won’t be too surprising: `fast` wins!) - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} -``` - - - -Notice that if you flip the order of the arguments to `race`, the order of the -“started” messages changes, even though the `fast` future always completes -first. That is because the implementation of this particular `race` function is -not fair. It always runs the futures passed as arguments in the order they are -passed. Other implementations *are* fair, and will randomly choose which future -to poll first. Regardless of whether the implementation of race we are using is -fair, though, *one* of the futures will run up to the first `.await` in its body -before another task can start. - -Recall from [“What Are Futures?”][futures] that at each await point, Rust pauses -the async block and hands control back to a runtime. The inverse is also true: -Rust *only* pauses async blocks and hands control back to a runtime at an await -point. Everything between await points is synchronous. - -That means if you do a bunch of work in an async block without an await point, -that future will block any other futures from making progress. (You may -sometimes hear this referred to as one future *starving* other futures. And this -applies to threads, too!) In many cases, that may not be a big deal. However, if -you are doing some kind of expensive setup or long-running work, or if you have -a future which will keep doing some particular task indefinitely, you will need -to think about when and where to hand control back to the runtime. - -But *how* would you hand control back to the runtime in those cases? - -### Yielding - -Let’s simulate a long-running operation. Listing 17-21 introduces a `slow` -function. It uses `std::thread::sleep` instead of `trpl::sleep` so that calling -`slow` will block the current thread for some number of milliseconds. We can use -`slow` to stand in for real-world operations which are both long-running and -blocking. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:slow}} -``` - - - -In Listing 17-22, we use `slow` to emulate doing this kind of CPU-bound work in -a pair of futures. To begin, each future only hands control back to the runtime -*after* carrying out a bunch of slow operations. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:slow-futures}} -``` - - - -If you run this, you will see this output: - - - -```text -'a' started. -'a' ran for 30ms -'a' ran for 10ms -'a' ran for 20ms -'b' started. -'b' ran for 75ms -'b' ran for 10ms -'b' ran for 15ms -'b' ran for 350ms -'a' finished. -``` - -As with our earlier example, `race` still finishes as soon as `a` is done. There -is no interleaving between the two futures, though. The `a` future does all of -its work until the `trpl::sleep` call is awaited, then the `b` future does all -of its work until its own `trpl::sleep` call is awaited, and then the `a` future -completes. To allow both futures to make progress between their slow tasks, we -need await points so we can hand control back to the runtime. That means we need -something we can await! - -We can already see this kind of handoff happening in Listing 17-22: if we -removed the `trpl::sleep` at the end of the `a` future, it would complete -without the `b` future running *at all*. Maybe we could use the `sleep` function -as a starting point? - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:here}} -``` - - - -In Listing 17-23, we add `trpl::sleep` calls with await points between each call -to `slow`. Now the two futures’ work is interleaved: - - - -```text -'a' started. -'a' ran for 30ms -'b' started. -'b' ran for 75ms -'a' ran for 10ms -'b' ran for 10ms -'a' ran for 20ms -'b' ran for 15ms -'a' finished. -``` - -The `a` future still runs for a bit before handing off control to `b`, because -it calls `slow` before ever calling `trpl::sleep`, but after that the futures -swap back and forth each time one of them hits an await point. In this case, we -have done that after every call to `slow`, but we could break up the work -however makes the most sense to us. - -We do not really want to *sleep* here, though: we want to make progress as fast -as we can. We just need to hand back control to the runtime. We can do that -directly, using the `yield_now` function. In Listing 17-24, we replace all those -`sleep` calls with `yield_now`. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:yields}} -``` - - - -This is both clearer about the actual intent and can be significantly faster -than using `sleep`, because timers like the one used by `sleep` often have -limits to how granular they can be. The version of `sleep` we are using, for -example, will always sleep for at least a millisecond, even if we pass it a -`Duration` of one nanosecond. Again, modern computers are *fast*: they can do a -lot in one millisecond! - -You can see this for yourself by setting up a little benchmark, like the one in -Listing 17-25. (This is not an especially rigorous way to do performance -testing, but it suffices to show the difference here.) Here, we skip all the -status printing, pass a one-nanosecond `Duration` to `trple::sleep`, and let -each future run by itself, with no switching between the futures. Then we run -for 1,000 iterations and see how long the future using `trpl::sleep` takes -compared to the future using `trpl::yield_now`. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:here}} -``` - - - -The version with `yield_now` is *way* faster! - -This means that async can be useful even for CPU-bound tasks, depending on what -else your program is doing, because it provides a useful tool for structuring -the relationships between different parts of the program. This is a form of -*cooperative multitasking*, where each future has both the power to determine -when it hands over control via await points. Each future therefore also has the -*responsibility* to avoid blocking for too long. In some Rust-based embedded -operating systems, this is the *only* kind of multitasking! - -In real-world code, you will not usually be alternating function calls with -await points on every single line, of course. The underlying dynamic is an -important one to keep in mind, though! - -### Building Our Own Async Abstractions - -We can also compose futures together to create new patterns. For example, we can -build a `timeout` function with async building blocks we already have. When we -are done, the result will be another building block we could use to build up yet -further async abstractions. - -Listing 17-26 shows how we would expect this `timeout` to work with a slow -future. - -- -```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:here}} -``` - - - -Let’s implement this! To begin, let’s think about the API for `timeout`: - -- It needs to be an async function itself so we can await it. -- Its first parameter should be a future to run. We can make it generic to allow - it to work with any future. -- Its second parameter will be the maximum time to wait. If we use a `Duration`, - that will make it easy to pass along to `trpl::sleep`. -- It should return a `Result`. If the future completes successfully, the - `Result` will be `Ok` with the value produced by the future. If the timeout - elapses first, the `Result` will be `Err` with the duration that the timeout - waited for. - -Listing 17-27 shows this declaration. - - - -- -```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:declaration}} -``` - - - -That satisfies our goals for the types. Now let’s think about the *behavior* we -need: we want to race the future passed in against the duration. We can use -`trpl::sleep` to make a timer future from the duration, and use `trpl::race` to -run that timer with the future the caller passes in. - -The `trpl::race` function returns a value to indicate which of the futures -passed to it finishes first. (When we saw `race` earlier in Listing 17-20, we -ignored its return value, because we were only interested in seeing the behavior -of `fast` and `slow` when we ran the program.) Because either future passed as -an argument to `race` can legitimately “win,” it does not make sense to use a -`Result` to represent the return type. Instead, `race` returns a type we have -not seen before, `Either`. The `Either` type is somewhat like a `Result`, in -that it has two cases. Unlike `Result`, though, there is no notion of success or -failure baked into `Either`. Instead, it uses `Left` and `Right` to indicate -“one or the other”. - -```rust -enum Either { - Left(A), - Right(B) -} -``` - -The `race` function returns `Left` if the first argument finishes first, with -that future’s output, and `Right` with the second future argument’s output if -*that* one finishes first. - -We also know that `race` is not fair, and polls arguments in the order they are -passed. Thus, we pass the caller-supplied future to `race` first so it gets a -chance to complete even if `max_time` is a very short duration. If `future` -finishes first, `race` will return `Left` with the output from `future`. If -`timer` finishes first, `race` will return `Right` with the timer’s output of -`()`. - -In Listing 17-28, we match on the result of awaiting `trpl::race`. If the -future succeeded and we get a `Left(output)`, we return `Ok(output)`. If the -sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` with -`_` and return `Err(max_time)` instead. - -- -```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:implementation}} -``` - - - -With that, we have a working `timeout`, built out of two other async helpers. If -we run our code, it will print the failure mode after the timeout: - -```text -Failed after 2 seconds -``` - -Because futures compose with other futures, you can build really powerful tools -using smaller async building blocks. For example, you can use this same approach -to combine timeouts with retries, and in turn use those with things like network -calls—one of the examples from the beginning of the chapter! - -Over the last two sections, we have seen how to work with multiple futures at -the same time. Up next, let’s look at how we can work with multiple futures in a -sequence over time, with *streams*. - -[futures]: ch17-01-futures-and-syntax.html#what-are-futures diff --git a/src/ch17-05-streams.md b/src/ch17-04-streams.md similarity index 100% rename from src/ch17-05-streams.md rename to src/ch17-04-streams.md diff --git a/src/ch17-07-wip.md b/src/ch17-05-traits-for-async.md similarity index 99% rename from src/ch17-07-wip.md rename to src/ch17-05-traits-for-async.md index 7e0fef4bfe..cc5dc6939e 100644 --- a/src/ch17-07-wip.md +++ b/src/ch17-05-traits-for-async.md @@ -1,3 +1,5 @@ +## Digging Into the Traits for Async + > ## Restructuring > > This is just a placeholder for material that needs to be restructured so that From 7da825f835b30a7d1535567f35355a05b5a9c47f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 11 Sep 2024 12:37:41 -0600 Subject: [PATCH 534/720] Ch. 17: Make the new 17.05 actually work as a deep dive! --- .../no-listing-stream-ext/src/lib.rs | 2 + src/ch17-01-futures-and-syntax.md | 5 +- src/ch17-05-traits-for-async.md | 209 +++++++++++------- 3 files changed, 134 insertions(+), 82 deletions(-) diff --git a/listings/ch17-async-await/no-listing-stream-ext/src/lib.rs b/listings/ch17-async-await/no-listing-stream-ext/src/lib.rs index e236c99260..09a980c04d 100644 --- a/listings/ch17-async-await/no-listing-stream-ext/src/lib.rs +++ b/listings/ch17-async-await/no-listing-stream-ext/src/lib.rs @@ -14,5 +14,7 @@ trait StreamExt: Stream { async fn next(&mut self) -> Option where Self: Unpin; + + // other methods... } // ANCHOR_END: here diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index dc53ac9eda..9dc8d1eff0 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -33,7 +33,7 @@ The warning tells us that just calling `hello` was not enough: we also need to We will work through each of these in turn. We can answer the first question by learning what the syntax means, so let’s start there. -### Async functions +### Async Functions In Rust, writing `async fn` is equivalent to writing a function which returns a *future* of the return type. That is, when the compiler sees a function like @@ -264,9 +264,6 @@ the things we can *do* with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters [iterators-lazy]: ch13-02-iterators.html -[under-the-hood]: https://rust-lang.github.io/async-book/02_execution/01_chapter.html -[pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html -[async-book]: https://rust-lang.github.io/async-book/ [crate-source]: https://github.com/rust-lang/book/tree/main/packages/trpl [futures-crate]: https://crates.io/crates/futures diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index cc5dc6939e..827e625e23 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -1,15 +1,19 @@ ## Digging Into the Traits for Async -> ## Restructuring -> -> This is just a placeholder for material that needs to be restructured so that -> the earlier sections of the book can avoid getting sidetracked into details of -> things like `Pin` or even just the full gnarliness of the `Future` trait at -> points where it would be better for the text to keep moving. +Throughout the chapter, we have used the `Future`, `Pin`, `Unpin`, `Stream`, and +`StreamExt` traits in various ways. So far, though, we have avoided digging too +far into the details of how they work or how they fit together. Much of the time +when writing Rust day to day, this is fine. Sometimes, though, you will hit +situations where understanding a few more of these details matters. In this +section, we will dig down *enough* further to help with those situations—while +still leaving the *really* deep dive for other documentation! + ---- +### Future -Here is the definition of the trait: +Back in [Async Functions][async-functions], we noted that `Future` is a trait. +Let’s start by taking a closer look at how it works. Here is how Rust defines +a `Future`: ```rust use std::pin::Pin; @@ -22,13 +26,16 @@ pub trait Future { } ``` -As we learned earlier, `Future`’s associated type `Output` says what the future -will resolves to. (This is analogous to the `Item` associated type for the -`Iterator` trait.) Beyond that, `Future` also has the `poll` method, which takes -a special `Pin` reference for its `self` parameter and a mutable reference to a -`Context` type, and returns a `Poll`. We will talk a little more -about `Pin` and `Context` later in the chapter. For now, let’s focus on what the -method returns, the `Poll` type: +That trait definition includes a bunch of new types and also some syntax we have +not seen before, so let’s walk through the definition piece by piece. + +First, `Future`’s associated type `Output` says what the future resolves to. +This is analogous to the `Item` associated type for the `Iterator` trait. +Second, `Future` also has the `poll` method, which takes a special `Pin` +reference for its `self` parameter and a mutable reference to a `Context` type, +and returns a `Poll`. We will talk a little more about `Pin` and +`Context` later in the section. For now, let’s focus on what the method returns, +the `Poll` type: ```rust enum Poll { @@ -89,49 +96,68 @@ on this future and work on other futures and check this one again later. That “something” is an async runtime, and this scheduling and coordination work is one of the main jobs for a runtime. ---- - -> Note: If you want to understand how things work “under the hood,” the official -> [_Asynchronous Programming in Rust_][async-book] book covers them: -> -> - [Chapter 2: Under the Hood: Executing Futures and Tasks][under-the-hood] -> - [Chapter 4: Pinning][pinning]. - ---- - -Recall our description of how `rx.recv()` waits in the [Counting][counting] -section. The `recv()` call returns a `Future`, and awaiting it polls it. In our -initial discussion, we noted that a runtime will pause the future until it is -ready with either `Some(message)` or `None` when the channel closes. With a -deeper understanding of `Future` in place, and specifically its `poll` method, -we can see how that works. The runtime knows the future is not ready when it +Recall our description (in the [Counting][counting] section) of waiting on +`rx.recv()` . The `recv()` call returns a `Future`, and awaiting it polls it. In +our initial discussion, we noted that a runtime will pause the future until it +is ready with either `Some(message)` or `None` when the channel closes. With our +deeper understanding of `Future` in place, and specifically `Future::poll`, we +can see how that works. The runtime knows the future is not ready when it returns `Poll::Pending`. Conversely, the runtime knows the future is ready and advances it when `poll` returns `Poll::Ready(Some(message))` or `Poll::Ready(None)`. -[counting]: /ch17-02-concurrency-with-async.md +The exact details of how a runtime does that are more than we will cover in even +this deep dive section. The key here is to see the basic mechanic of futures: a +runtime *polls* each future it is responsible for, putting it back to sleep when +it is not yet ready. ---- +### Pinning and the Pin and Unpin Traits - - > Incoherent sentence and a *lot* of material in it which we do not unpack in this paragraph. - --> +When we introduced the idea of pinning, while working on Listing 17-16, we ran +into a very gnarly error message. Here is the relevant part of it again: -The rest of the message tells us *why* that is required: the `JoinAll` -struct returned by `trpl::join_all` is generic over a type `F` which must -implement the `Future` trait, directly awaiting a Future requires that the -future implement the `Unpin` trait. Understanding this error means we need to -dive into a little more of how the `Future` type actually works, in particular -the idea of *pinning*. + -### Pinning and the Pin and Unpin Traits +```text +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:33 + | +46 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` +note: required by a bound in `JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. +``` - +When we read this error message carefully, it not only tells us that we need to +pin the values but also us why pinning is required. The `trpl::join_all` +function returns a struct called `JoinAll`. That struct in turn is generic over +a type `F`, which is constrained to implement the `Future` trait. Finally, +directly awaiting a Future requires that the future in question implement the +`Unpin` trait. That’s a lot! But we can understand it, if we dive a little +further into how the `Future` type actually works, in particular around +*pinning*. -Let’s look again at the definition of `Future`, focusing now on its `poll` -method’s `self` type: +Let’s look again at the definition of `Future`, focusing specifically on the +`poll` method’s `self` type: ```rust use std::pin::Pin; @@ -155,13 +181,13 @@ this syntax in Chapter 18. For now, it is enough to know that if we want to poll a future (to check whether it is `Pending` or `Ready(Output)`), we need a mutable reference to the type, which is wrapped in a `Pin`. -`Pin` is a smart pointer, much like `Box`, `Rc`, and the others we saw in -Chapter 15. Unlike those, however, `Pin` only works with *other pointer types* -like reference (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To -be precise, `Pin` works with types which implement the `Deref` or `DerefMut` -traits, which we covered in Chapter 15. You can think of this restriction as -equivalent to only working with pointers, though, since implementing `Deref` or -`DerefMut` means your type behaves like a pointer type. +`Pin` is a wrapper type, much like the `Box`, `Rc`, and other smart pointer +types we saw in Chapter 15. Unlike those, however, `Pin` only works with *other +pointer types* like reference (`&` and `&mut`) and smart pointers (`Box`, `Rc`, +and so on). To be precise, `Pin` works with types which implement the `Deref` or +`DerefMut` traits, which we covered in Chapter 15. You can think of this +restriction as equivalent to only working with pointers, though, since +implementing `Deref` or `DerefMut` means your type behaves like a pointer type. Recalling that `.await` is implemented in terms of calls to `poll()`, this starts to explain the error message we saw above—but that was in terms of @@ -234,6 +260,13 @@ because it requires *you* to uphold all the guarantees which make `Pin` and `Unpin` safe yourself for a type with internal references. In practice, this is a very rare thing to implement yourself! +Now we know enough to understand the errors reported for that `join_all` call. +We originally tried to move the futures produced by an async blocks into a +`Vec>>`, but as we have seen, those futures may have +internal references, so they do not implement `Unpin`. They need to be pinned, +and then we can pass the `Pin` type into the `Vec`, confident that the +underlying data in the futures will *not* be moved. + > Note: This combination of `Pin` and `Unpin` allows a whole class of complex > types to be safe in Rust which are otherwise difficult to implement because > they are self-referential. Types which require `Pin` show up *most* commonly @@ -242,29 +275,32 @@ a very rare thing to implement yourself! > The specific mechanics for how `Pin` and `Unpin` work under the hood are > covered extensively in the API documentation for `std::pin`, so if you would > like to understand them more deeply, that is a great place to start. +> +> If you want to understand how things work “under the hood” in even more +> detail, the official [_Asynchronous Programming in Rust_][async-book] book has +> you covered: +> +> - [Chapter 2: Under the Hood: Executing Futures and Tasks][under-the-hood] +> - [Chapter 4: Pinning][pinning]. -Now we know enough to fix the last errors with `join_all`. We tried to move the -futures produced by an async blocks into a `Vec>>`, -but as we have seen, those futures may have internal references, so they do not -implement `Unpin`. They need to be pinned, and then we can pass the `Pin` type -into the `Vec`, confident that the underlying data in the futures will *not* be -moved. - ---- +Now that we have a deeper grasp on the `Future`, `Pin`, and `Unpin` traits, we +can turn our attention to the `Stream` trait. -### The Stream API +### The Stream Trait -Unlike `Iterator` and `Future`, there is no definition of a `Stream` trait in -the standard library yet as of the time of writing, but there *is* a very common definition used throughout the -ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, -so we can build up to how a `Stream` trait that merges them together might look. +ecosystem. -From `Iterator`, we have the idea of a sequence: its `next` method provides an +Let’s review the definitions of the `Iterator` and `Future` traits, so we can +build up to how a `Stream` trait that merges them together might look. From +`Iterator`, we have the idea of a sequence: its `next` method provides an `Option`. From `Future`, we have the idea of readiness over time: its `poll` method provides a `Poll`. To represent a sequence of -items which become ready over time, we define a `Stream` trait which has all of -those features put together: +items which become ready over time, we define a `Stream` trait which puts those +features together: ```rust use std::pin::Pin; @@ -282,11 +318,12 @@ trait Stream { The `Stream` trait defines an associated type `Item` for the type of the items produced by the stream. This is like `Iterator`: there may be zero to many of -these, and unlike `Future`, where there was a single `Output`. +these, and unlike `Future`, where there is always a single `Output` (even if it +the unit type `()`). `Stream` also defines a method to get those items. We call it `poll_next`, to make it clear that it polls like `Future::poll` and produces a sequence of items -like `Iterator::next`. Its return type uses both `Poll` and `Option`. The outer +like `Iterator::next`. Its return type combines `Poll`with `Option`. The outer type is `Poll`, since it has to be checked for readiness, just like a future. The inner type is `Option`, since it needs to signal whether there are more messages, just like an iterator. @@ -295,12 +332,12 @@ Something very similar to this will likely end up standardized as part of Rust standard library. In the meantime, it is part of the toolkit of most runtimes, so you can rely on it, and everything we cover below should generally apply! -In the example we saw above, though, we did not use `poll_next` *or* `Stream`, -but instead `next` and `StreamExt`. We *could* work directly in terms of the -`poll_next` API by hand-writing our own `Stream` state machines, of course, just -as we *could* work with futures directly via their `poll` method. Using `await` -is much nicer, though, so the `StreamExt` trait supplies the `next` method so -we can do just that. +In the example we saw in the section on streaming, though, we did not use +`poll_next` *or* `Stream`, but instead used `next` and `StreamExt`. We *could* +work directly in terms of the `poll_next` API by hand-writing our own `Stream` +state machines, of course, just as we *could* work with futures directly via +their `poll` method. Using `await` is much nicer, though, so the `StreamExt` +trait supplies the `next` method so we can do just that. ```rust {{#rustdoc_include ../listings/ch17-async-await/no-listing-stream-ext/src/lib.rs:here}} @@ -327,3 +364,19 @@ The `StreamExt` trait is also the home of all the interesting methods available to use with streams. `StreamExt` is automatically implemented for every type which implements `Stream`, but they are separated out so that the community can iterate on the foundational trait distinctly from the convenience APIs. + +In the version of `StreamExt` used in the `trpl` crate, the trait not only +defines the `next` method, it also supplies an implementation of `next`, which +correctly handles the details of calling `Stream::poll_next`. This means that +even when you need to write your own streaming data type, you *only* have to +implement `Stream`, and then anyone who uses your data type can use `StreamExt` +and its methods with it automatically. + +[counting]: /ch17-02-concurrency-with-async.md +[async-book]: https://rust-lang.github.io/async-book/ +[under-the-hood]: https://rust-lang.github.io/async-book/02_execution/01_chapter.html +[pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html + +That’s all we’re going to cover for the lower-level details on these traits. To +wrap up, let’s consider how futures (including streams), tasks, and threads all +fit together! From 1d3517ce9993cfb5e6dfdf6d508f250a7afb235b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 11 Sep 2024 16:40:41 -0600 Subject: [PATCH 535/720] Ch. 17: integrate a number of the outstanding review comments Bonus: fix some style guide issues, too! Co-authored-by: Carol (Nichols || Goulding) Co-authored-by: James Munns Co-authored-by: Tim McNamara --- src/SUMMARY.md | 2 +- src/ch17-01-futures-and-syntax.md | 40 ++++++------ src/ch17-02-concurrency-with-async.md | 92 +++++++++++++++------------ src/ch17-03-more-futures.md | 81 +++++++++++++---------- src/ch17-04-streams.md | 4 +- src/ch17-05-traits-for-async.md | 61 ++++++++++-------- 6 files changed, 155 insertions(+), 125 deletions(-) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index b2af389757..40f5c22424 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -104,7 +104,7 @@ - [Async and Await](ch17-00-async-await.md) - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) - [Concurrency With Async](ch17-02-concurrency-with-async.md) - - [Working With More Than Two Futures](ch17-03-more-futures.md) + - [Working With Any Number of Futures](ch17-03-more-futures.md) - [Streams](ch17-04-streams.md) - [Digging Into the Traits for Async](ch17-05-traits-for-async.md) - [Futures, Tasks, and Threads](ch17-06-futures-tasks-threads.md) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 9dc8d1eff0..5ce095f31b 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -78,9 +78,9 @@ returned a `Future`. Then Rust warned us that we did not do anything with the future. This is because futures are *lazy*: they don’t do anything until you ask them to with `await`. This should remind you of our discussion of iterators [back in Chapter -13][iterators-lazy]. Iterators do nothing unless you call their `.next()` -method—whether directly, or using `for` loops or methods like `.map()` which use -`.next()` under the hood. +13][iterators-lazy]. Iterators do nothing unless you call their `next` +method—whether directly, or using `for` loops or methods like `map` which use +`next` under the hood. With futures, the same basic idea applies: they do nothing unless you explicitly ask them to. This laziness allows Rust to avoid running async code until it is @@ -237,27 +237,27 @@ enum MyAsyncStateMachine { Writing that out by hand would be tedious and error-prone, especially when making changes to code later. Instead, the Rust compiler creates and manages the -state machine data structures for async code automatically. +state machine data structures for async code automatically. If you’re wondering: +yep, the normal borrowing and ownership rules around data structures all apply. +Happily, the compiler also handles checking those for us, and has good error +messages. We will work through a few of those later in the chapter! -If you’re wondering: yep, the normal borrowing and ownership rules around data -structures all apply. Happily, the compiler also handles checking those for us, -and has good error messages. We will work through a few of those later in the -chapter! - - +Ultimately, something has to execute that state machine. That something is a +runtime. This is why you may sometimes come across references to *executors* +when looking into runtimes: an executor is the part of a runtime responsible for +executing the async code. Now we can understand why the compiler stopped us from making `main` itself an async function in Listing 17-3. If `main` were an async function, something else -would need to call `poll()` on whatever `main` returned, but main is the -starting point for the program! Instead, we use the `trpl::run` function, which -sets up a runtime and polls the `Future` returned by `hello` until it returns -`Ready`. - -> Note: We skipped over most of the details of how the `Future` trait works so -> far. We will come back to some of those later in the chapter! +would need to manage the state machine for whatever future `main` returned, but +main is the starting point for the program! Instead, we use the `trpl::run` +function, which sets up a runtime and polls the `Future` returned by `hello` +until it returns `Ready`. + +> Note: some runtimes provide macros to make it so you *can* write an async main +> function. Those macros rewrite `async fn main() { ... }` to be a normal `fn +> main` which does the same thing we did by hand in Listing 17-TODO: call a +> function which runs a future to completion the way `trpl::run` does. Now that you know the basics of working with futures, we can dig into more of the things we can *do* with async. diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index b785e7dc76..369cb63b1c 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -103,14 +103,19 @@ with different syntax: using `.await` instead of calling `join` on the join handle, and awaiting the `sleep` calls. The bigger difference is that we did not need to spawn another operating system -thread to do this. In fact, we do not even a task here. Given that async blocks -compile to anonymous futures, we can put each loop in an async block and have -the runtime run them both to completion using `trpl::join`. - - +thread to do this. In fact, we do not even need to spawn a task here. Because +async blocks compile to anonymous futures, we can put each loop in an async +block and have the runtime run them both to completion using the `trpl::join` +function. + +In Chapter 16, we showed how to use the `join` method on the `JoinHandle` type +returned when you call `std::thread::spawn`. The `trpl::join` function is +similar, but for futures. When you give it two futures, it produces a single new +future whose output is a tuple with the output of each of the futures you passed +in once *both* complete. Thus, in Listing 17-7, we use `trpl::join` to wait for +both `fut1` and `fut2` to finish. We do *not* await `fut1` and `fut2`, but +instead the new future produced by `trpl::join`. We ignore the output, because +it is just a tuple with two unit values in it. @@ -147,7 +152,7 @@ what we saw with threads. That is because the `trpl::join` function is *fair*, meaning it checks each future equally often, alternating between them, and never lets one race ahead if the other is ready. With threads, the operating system decides which thread to check and how long to let it run. With async Rust, the -runtime decides which future to check. (In practice, the details get complicated +runtime decides which taks to check. (In practice, the details get complicated because an async runtime might use operating system threads under the hood as part of how it manages concurrency, so guaranteeing fairness can be more work for a runtime—but it is still possible!) Runtimes do not have to guarantee @@ -184,11 +189,11 @@ version of the API is only a little different from the thread-based version: it uses a mutable rather than an immutable receiver `rx`, and its `recv` method produces a future we need to await rather than producing the value directly. Now we can send messages from the sender to the receiver. Notice that we do not have -to spawn a separate thread or even a task; we merely need to await the -`rx.recv()` call. +to spawn a separate thread or even a task; we merely need to await the `rx.recv` +call. -The synchronous `Receiver::recv()` method in `std::mpsc::channel` blocks until -it receives a message. The `trpl::Receiver::recv()` method does not, because it +The synchronous `Receiver::recv` method in `std::mpsc::channel` blocks until +it receives a message. The `trpl::Receiver::recv` method does not, because it is async. Instead of blocking, it hands control back to the runtime until either a message is received or the send side of the channel closes. By contrast, we do not await the `send` call, because it does not block. It does not need to, @@ -221,17 +226,17 @@ know how many messages are coming in. In the real world, though, we will generally be waiting on some *unknown* number of messages. In that case, we need to keep waiting until we determine that there are no more messages. -In synchronous code, we might use a `for` loop to process a sequence of items -like this, regardless of how many items are in the loop. However, Rust does not -yet have a way to write a `for` loop over an *asynchronous* series of items. -Instead, we need to use a new kind of loop we haven’t seen before, the `while -let` conditional loop. A `while let` loop is the loop version of the `if let` -construct we saw back in Chapter 6. The loop while continue executing as long as -the pattern matches. +In Listing 16-10, we used a `for` loop to process all the items received from a +synchronous channel. However, Rust does not yet have a way to write a `for` loop +over an *asynchronous* series of items. Instead, we need to use a new kind of +loop we haven’t seen before, the `while let` conditional loop. A `while let` +loop is the loop version of the `if let` construct we saw back in Chapter 6. The +loop will continue executing as long as the pattern it specifies continues to +match the value. -The `rx.recv()` call produces a `Future`, which we await. The runtime will pause +The `rx.recv` call produces a `Future`, which we await. The runtime will pause the `Future` until it is ready. Once a message arrives, the future will resolve to `Some(message)`, as many times as a message arrives. When the channel closes, regardless of whether *any* messages have arrived, the future will instead @@ -247,8 +252,9 @@ again, so the runtime pauses it again until another message arrives. The code now successfully sends and receives all of the messages. Unfortunately, there are still a couple problems. For one thing, the messages do not arrive at half-second intervals. They arrive all at once, two seconds (2,000 milliseconds) -after we start the program. For another, this program also never stops! You will -need to shut it down using ctrl-c. +after we start the program. For another, this program also never exits! Instead, +it waits forever for new messages. You will need to shut it down using ctrl-c. Let’s start by understanding why the messages all come in at once after the full delay, rather than coming in with delays in between each one. Within a given @@ -263,7 +269,10 @@ let` loop get to go through any of the `.await` points on the `recv` calls. To get the behavior we want, where the sleep delay happens between receiving each message, we need to put the `tx` and `rx` operations in their own async blocks. Then the runtime can execute each of them separately using `trpl::join`, -just like in the counting example. +just like in the counting example. Once again, we await the result of calling +`trpl::join`, not the individual futures. If we awaited the individual futures +in sequence, we would just end up back in a sequential flow—exactly what we are +trying *not* to do. @@ -278,28 +287,28 @@ just like in the counting example. With the updated code in Listing 17-10, the messages get printed at 500-millisecond intervals, rather than all in a rush after two seconds. -The program still never stops, because of the way `while let` loop interacts -with `trpl::join`: +The program still never exits, though, because of the way `while let` loop +interacts with `trpl::join`: * The future returned from `trpl::join` only completes once *both* futures passed to it have completed. * The `tx` future completes once it finishes sleeping after sending the last message in `vals`. * The `rx` future will not complete until the `while let` loop ends. -* The `while let` loop will not end until `rx.recv().await` produces `None`. -* The `rx.recv().await` will only return `None` once the other end of the - channel is closed. -* The channel will only close if we call `rx.close()` or when the sender side, +* The `while let` loop will not end until awaiting `rx.recv` produces `None`. +* Awaiting `rx.recv` will only return `None` once the other end of the channel + is closed. +* The channel will only close if we call `rx.close` or when the sender side, `tx`, is dropped. -* We do not call `rx.close()` anywhere, and `tx` will not be dropped until the - async block ends. -* The block cannot end because it is blocked on `trpl::join` completing, - which takes us back to the top of this list! +* We do not call `rx.close` anywhere, and `tx` will not be dropped until the + outermost async block passed to `trpl::run` ends. +* The block cannot end because it is blocked on `trpl::join` completing, which + takes us back to the top of this list! -We could manually close `rx` by calling `rx.close()` somewhere, but that does -not make much sense. Stopping after handling some arbitrary number of messages -would make the program shut down, but we could miss messages. We need some other -way to make sure that `tx` gets dropped *before* the end of the function. +We could manually close `rx` by calling `rx.close` somewhere, but that does not +make much sense. Stopping after handling some arbitrary number of messages would +make the program shut down, but we could miss messages. We need some other way +to make sure that `tx` gets dropped *before* the end of the function. Right now, the async block where we send the messages only borrows `tx`, but if we could move `tx` into that async block, it would be dropped once that block @@ -324,9 +333,10 @@ This async channel is also a multiple-producer channel, so we can call `clone` on `tx` if we want to send messages from multiple futures. In Listing 17-12, we clone `tx`, creating `tx1` outside the first async block. We move `tx1` into that block just as we did before with `tx`. Then, later, we move the original -`tx` into a *new* async block, where we send more messages on a slightly -slower delay. (We happen to put this new async block after the async block -for receiving messages, but it could go before it just as well.) +`tx` into a *new* async block, where we send more messages on a slightly slower +delay. We happen to put this new async block after the async block for receiving +messages, but it could go before it just as well. They key is the order of the +futures are awaited in, not the order they are created in. Both of the async blocks for sending messages need to be `async move` blocks, so that both `tx` and `tx1` get dropped when those blocks finish. Otherwise we will diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 1affdf7def..9643836686 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -1,11 +1,12 @@ -## Working With More Than Two Futures +## Working With Any Number of Futures When we switched from using two futures to three in the previous section, we also had to switch from using `join` to using `join3`. It would be annoying to -do this every time we changed our code. Happily, we have a macro form of `join` -to which we can pass an arbitrary number of arguments. It also handles awaiting -the futures itself. Thus, we could rewrite the code from Listing 17-12 to use -`join!` instead of `join3`, as in Listing 17-13: +have to call a different function every time we changed the number of futures we +wanted to join. Happily, we have a macro form of `join` to which we can pass an +arbitrary number of arguments. It also handles awaiting the futures itself. +Thus, we could rewrite the code from Listing 17-12 to use `join!` instead of +`join3`, as in Listing 17-13: @@ -96,8 +97,8 @@ implement the `Future` trait. > able to work with a dynamic collection of futures where we do not know what > they will all be until runtime. -We start by wrapping each of the futures in the `vec!` in a `Box::new()`, as -shown in Listing 17-15. +We start by wrapping each of the futures in the `vec!` in a `Box::new`, as shown +in Listing 17-15. @@ -241,7 +242,7 @@ There is a bit more we can explore here. For one thing, using `Pin>` comes with a small amount of extra overhead from putting these futures on the heap with `Box`—and we are only doing that to get the types to line up. We don’t actually *need* the heap allocation, after all: these futures are local to this -particular function. As noted above, `Pin` is itself a smart pointer, so we can +particular function. As noted above, `Pin` is itself a wrapper type, so we can get the benefit of having a single type in the `Vec`—the original reason we reached for `Box`—without doing a heap allocation. We can use `Pin` directly with each future, using the `std::pin::pin` macro. @@ -260,11 +261,10 @@ references to the dynamic `Future` type, as in Listing 17-18. -There is one last issue to fix. We got this far by ignoring the fact that we -might have different `Output` types. For example, in Listing 17-19, the -anonymous future for `a` implements `Future`, the anonymous future -for `b` implements `Future`, and the anonymous future for `c` -implements `Future`. +We got this far by ignoring the fact that we might have different `Output` +types. For example, in Listing 17-19, the anonymous future for `a` implements +`Future`, the anonymous future for `b` implements `Future`, and the anonymous future for `c` implements `Future`. @@ -277,8 +277,7 @@ implements `Future`. We can use `trpl::join!` to await them, because it allows you to pass in multiple future types and produces a tuple of those types. We *cannot* use `trpl::join_all`, because it requires the futures passed in all to have the same -type. (Remember, that error is what got us started on this adventure with -`Pin`!) +type. Remember, that error is what got us started on this adventure with `Pin`! This is a fundamental tradeoff: we can either deal with a dynamic number of futures with `join_all`, as long as they all have the same type, or we can deal @@ -287,13 +286,6 @@ even if they have different types. This is the same as working with any other types in Rust, though. Futures are not special, even though we have some nice syntax for working with them, and that is a good thing. -In practice, you will usually work directly with `async` and `.await`, and -secondarily with functions and macros like `join` or `join_all`. You will only -need to reach for `pin` now and again to use them with those APIs. `Pin` and -`Unpin` are mostly important for building lower-level libraries, or when you are -building a runtime itself, rather than for day to day Rust code. When you see -them, though, now you will know what to do! - ### Racing futures When we “join” futures with the `join` family of functions and macros, we @@ -302,11 +294,16 @@ need *some* future from a set to finish before we move on—kind of like racing one future against another. This operation is often named `race` for exactly that reason. -In Listing 17-20, we use `race` to run two futures, `slow` and `fast`, against -each other. Each one prints a message when it starts running, pauses for some -amount of time by calling and awaiting `sleep`, and then prints another message -when it finishes. Then we pass both to `trpl::race` and wait for one of them to -finish. (The outcome here won’t be too surprising: `fast` wins!) +> Note: Under the hood, `race` is built on a more general function, `select`, +> which you will encounter more often in real-world Rust code. A `select` +> function can do a lot of things that `trpl::race` function cannot, but it also +> has some additional complexity that we can skip over for now. + +In Listing 17-20, we use `trpl::race` to run two futures, `slow` and `fast`, +against each other. Each one prints a message when it starts running, pauses for +some amount of time by calling and awaiting `sleep`, and then prints another +message when it finishes. Then we pass both to `trpl::race` and wait for one of +them to finish. (The outcome here won’t be too surprising: `fast` wins!) @@ -507,12 +504,12 @@ future. Let’s implement this! To begin, let’s think about the API for `timeout`: -- It needs to be an async function itself so we can await it. -- Its first parameter should be a future to run. We can make it generic to allow +* It needs to be an async function itself so we can await it. +* Its first parameter should be a future to run. We can make it generic to allow it to work with any future. -- Its second parameter will be the maximum time to wait. If we use a `Duration`, +* Its second parameter will be the maximum time to wait. If we use a `Duration`, that will make it easy to pass along to `trpl::sleep`. -- It should return a `Result`. If the future completes successfully, the +* It should return a `Result`. If the future completes successfully, the `Result` will be `Ok` with the value produced by the future. If the timeout elapses first, the `Result` will be `Err` with the duration that the timeout waited for. @@ -588,9 +585,25 @@ using smaller async building blocks. For example, you can use this same approach to combine timeouts with retries, and in turn use those with things like network calls—one of the examples from the beginning of the chapter! -Over the last two sections, we have seen how to work with multiple futures at -the same time. Up next, let’s look at how we can work with multiple futures in a -sequence over time, with *streams*. +In practice, you will usually work directly with `async` and `.await`, and +secondarily with functions and macros like `join`, `join_all`, `race`, and so +on. You will only need to reach for `pin` now and again to use them with those +APIs. + +We have now seen a number of ways to work with multiple futures at the same +time. Up next, we will look at how we can work with multiple futures in a +sequence over time, with *streams*. Here are a couple more things you might want +to consider first, though: + +* We used a `Vec` with `join_all` to wait for all of the futures in some group + to finish. How could you use a `Vec` to process a group of futures in + sequence, instead? What are the tradeoffs of doing that? + +* Take a look at the `futures::stream::FuturesUnordered` type from the `futures` + crate. How would using it be different from using a `Vec`? (Don’t worry about + the fact that it is from the `stream` part of the crate; it works just fine + with any collection of futures.) + [collections]: ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: ch12-03-improving-error-handling-and-modularity.html diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 9fd9049430..e4ae1ed7e1 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -129,7 +129,7 @@ avoid doing needless work. Let’s start by building a little stream of messages, similar to what we might see from a WebSocket or other real-time communication protocols. In Listing -17-32, we create a function `get_messages()` which returns `impl Stream`. For its implementation, we create an async channel, loop over the first ten letters of the English alphabet, and send them across the channel. @@ -310,7 +310,7 @@ Finally, we loop over that combined stream instead of over `messages` (Listing At this point, neither `messages` nor `intervals` needs to be pinned or mutable, because both will be combined into the single `merged` stream. However, this -call to `merge` does not type check! (Neither does the `next` call in the `while +call to `merge` does not compile! (Neither does the `next` call in the `while let` loop, but we will come back to that after fixing this.) The two streams have different types. The `messages` stream has the type `Timeout>`, where `Timeout` is the type which implements `Stream` diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 827e625e23..9eb31d2fa4 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -51,10 +51,10 @@ work to do, so the caller will need to check again later. The `Ready` variant indicates that the `Future` has finished its work and the `T` value is available. -> Note: With most futures, the caller should not call `poll()` again after the +> Note: With most futures, the caller should not call `poll` again after the > future has returned `Ready`. Many futures will panic if polled again after > becoming ready! Futures which are safe to poll again will say so explicitly in -> their documentation. +> their documentation. This is similar to how `Iterator::next` behaves! Under the hood, when you call `.await`, Rust compiles that to code which calls `poll`, kind of (although not exactly ) @@ -97,9 +97,9 @@ on this future and work on other futures and check this one again later. That one of the main jobs for a runtime. Recall our description (in the [Counting][counting] section) of waiting on -`rx.recv()` . The `recv()` call returns a `Future`, and awaiting it polls it. In -our initial discussion, we noted that a runtime will pause the future until it -is ready with either `Some(message)` or `None` when the channel closes. With our +`rx.recv`. The `recv` call returns a `Future`, and awaiting it polls it. In our +initial discussion, we noted that a runtime will pause the future until it is +ready with either `Some(message)` or `None` when the channel closes. With our deeper understanding of `Future` in place, and specifically `Future::poll`, we can see how that works. The runtime knows the future is not ready when it returns `Poll::Pending`. Conversely, the runtime knows the future is ready and @@ -176,20 +176,25 @@ like this. When we specify the type of `self` like this, we are telling Rust what type `self` must be to call this method. These kinds of type annotations for `self` are similar to those for other function parameters, but with the restriction that the type annotation has to be the type on which the method is -implemented, or a reference or smart pointer to that type. We will see more on -this syntax in Chapter 18. For now, it is enough to know that if we want to poll -a future (to check whether it is `Pending` or `Ready(Output)`), we need a -mutable reference to the type, which is wrapped in a `Pin`. - -`Pin` is a wrapper type, much like the `Box`, `Rc`, and other smart pointer -types we saw in Chapter 15. Unlike those, however, `Pin` only works with *other -pointer types* like reference (`&` and `&mut`) and smart pointers (`Box`, `Rc`, -and so on). To be precise, `Pin` works with types which implement the `Deref` or -`DerefMut` traits, which we covered in Chapter 15. You can think of this -restriction as equivalent to only working with pointers, though, since -implementing `Deref` or `DerefMut` means your type behaves like a pointer type. - -Recalling that `.await` is implemented in terms of calls to `poll()`, this +implemented, or a reference or smart pointer to that type, or a `Pin` wrapping a +reference to that type. We will see more on this syntax in Chapter 18. For now, +it is enough to know that if we want to poll a future (to check whether it is +`Pending` or `Ready(Output)`), we need a mutable reference to the type, which is +wrapped in a `Pin`. + +`Pin` is a wrapper type. In some ways, it is like the `Box`, `Rc`, and other +smart pointer types we saw in Chapter 15, which also wrap other types. Unlike +those, however, `Pin` only works with *other pointer types* like reference (`&` +and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` +works with types which implement the `Deref` or `DerefMut` traits, which we +covered in Chapter 15. You can think of this restriction as equivalent to only +working with pointers, though, since implementing `Deref` or `DerefMut` means +your type behaves like a pointer type. `Pin` is also not a pointer itself, and +it does not have any behavior of its own like the ref counting of `Rc` or `Arc`. +It is purely a tool the compiler can use to uphold the relevant guarantees, by +wrapping pointers in the type. + +Recalling that `.await` is implemented in terms of calls to `poll`, this starts to explain the error message we saw above—but that was in terms of `Unpin`, not `Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, and why does `Future` need `self` to be in a `Pin` type to call `poll`? @@ -267,6 +272,10 @@ internal references, so they do not implement `Unpin`. They need to be pinned, and then we can pass the `Pin` type into the `Vec`, confident that the underlying data in the futures will *not* be moved. +`Pin` and `Unpin` are mostly important for building lower-level libraries, or +when you are building a runtime itself, rather than for day to day Rust code. +When you see them, though, now you will know what to do! + > Note: This combination of `Pin` and `Unpin` allows a whole class of complex > types to be safe in Rust which are otherwise difficult to implement because > they are self-referential. Types which require `Pin` show up *most* commonly @@ -283,16 +292,14 @@ underlying data in the futures will *not* be moved. > - [Chapter 2: Under the Hood: Executing Futures and Tasks][under-the-hood] > - [Chapter 4: Pinning][pinning]. -Now that we have a deeper grasp on the `Future`, `Pin`, and `Unpin` traits, we -can turn our attention to the `Stream` trait. - ### The Stream Trait -As described in the section introducing streams, streams are like asynchronous -iterators. Unlike `Iterator` and `Future`, there is no definition of a `Stream` -trait in the standard library as of the time of writing, but there *is* a very common definition used throughout the -ecosystem. +Now that we have a deeper grasp on the `Future`, `Pin`, and `Unpin` traits, we +can turn our attention to the `Stream` trait. As described in the section +introducing streams, streams are like asynchronous iterators. Unlike `Iterator` +and `Future`, there is no definition of a `Stream` trait in the standard library +as of the time of writing, but there +*is* a very common definition used throughout the ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, so we can build up to how a `Stream` trait that merges them together might look. From From c4d02bf83bbef781f0541dffaa9dd1414852e410 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 12 Sep 2024 15:28:10 -0600 Subject: [PATCH 536/720] =?UTF-8?q?Ch.=2017:=20address=20the=20rest=20of?= =?UTF-8?q?=20James=E2=80=99=20review=20comments=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: James Munns --- src/ch17-03-more-futures.md | 21 ++++---- src/ch17-06-futures-tasks-threads.md | 74 +++++++++++++++++++++------- 2 files changed, 68 insertions(+), 27 deletions(-) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 9643836686..b9f1fccc65 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -322,18 +322,19 @@ to poll first. Regardless of whether the implementation of race we are using is fair, though, *one* of the futures will run up to the first `.await` in its body before another task can start. -Recall from [“What Are Futures?”][futures] that at each await point, Rust pauses -the async block and hands control back to a runtime. The inverse is also true: -Rust *only* pauses async blocks and hands control back to a runtime at an await -point. Everything between await points is synchronous. +Recall from [“What Are Futures?”][futures] that at each await point, Rust gives +a runtime a chance to pause the task and switch to another one if the future +being awaited is not ready. The inverse is also true: Rust *only* pauses async +blocks and hands control back to a runtime at an await point. Everything between +await points is synchronous. That means if you do a bunch of work in an async block without an await point, -that future will block any other futures from making progress. (You may -sometimes hear this referred to as one future *starving* other futures. And this -applies to threads, too!) In many cases, that may not be a big deal. However, if -you are doing some kind of expensive setup or long-running work, or if you have -a future which will keep doing some particular task indefinitely, you will need -to think about when and where to hand control back to the runtime. +that future will block any other futures from making progress. You may sometimes +hear this referred to as one future *starving* other futures. In many cases, +that may not be a big deal. However, if you are doing some kind of expensive +setup or long-running work, or if you have a future which will keep doing some +particular task indefinitely, you will need to think about when and where to +hand control back to the runtime. But *how* would you hand control back to the runtime in those cases? diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 7ee933c4f7..ad3a4d24da 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -12,8 +12,8 @@ However, they are not without their tradeoffs. On many operating systems, they use a fair bit of memory for each thread, and they come with some overhead for starting up and shutting down. Threads are also only an option when your operating system and hardware support them! Unlike mainstream desktop and mobile -operating systems, many embedded operating systems, like those used on some -microcontrollers, do not have OS-level threads at all. +computers, some embedded systems do not have an OS at all, so they also do not +have threads! The async model provides a different—and ultimately complementary—set of tradeoffs. In the async model, concurrent operations do not require their own @@ -55,21 +55,20 @@ possible both *between* and *within* tasks. In that regard, tasks are kind of like lightweight, runtime-managed threads with added capabilities that come from being managed by a runtime instead of by the operating system. Futures are an even more granular unit of concurrency, where each future may represent a tree -of other futures. +of other futures. That is, the runtime—specifically, its executor—manages tasks, +and tasks manage futures. However, this does not mean that async tasks are always better than threads, any more than that threads are always better than tasks. On the one hand, concurrency with threads is in some ways a simpler programming -model than concurrency with `async`. Threads are somewhat “fire and forget”, and -they only allow interaction with the rest of the program via tools like channels -or their final result via `join`. On the other hand, they have no native -equivalent to a future, so they simply run to completion, without interruption -except by the operating system itself. Threads also have no mechanisms for -cancellation—a subject we have not covered in depth in this chapter, but which -is implicit in the fact that whenever we ended a future, its state got cleaned -up correctly. +model than concurrency with `async`. Threads are somewhat “fire and forget,” +they have no native equivalent to a future, so they simply run to completion, +without interruption except by the operating system itself. That is, they have +no *intra-task concurrency* like futures can. Threads in Rust also have no +mechanisms for cancellation—a subject we have not covered in depth in this +chapter, but which is implicit in the fact that whenever we ended a future, its +state got cleaned up correctly. These limitations make threads harder to compose than futures. It is much more difficult, for example, to build something like the `timeout` we built in @@ -83,10 +82,11 @@ and how to group them. And it turns out that threads and tasks often work very well together, because tasks can (at least in some runtimes) be moved around between threads. We have not mentioned it up until now, but under the hood the `Runtime` we have been using, including the `spawn_blocking` and `spawn_task` -functions, are multithreaded by default! Many runtimes can transparently move -tasks around between threads based on the current utilization of the threads, to -hopefully improve the overall performance of the system. To build that actually -requires threads *and* tasks, and therefore futures. +functions, is multithreaded by default! Many runtimes use an approach called +*work stealing* to transparently move tasks around between threads based on the +current utilization of the threads, with the aim of improving the overall +performance of the system. To build that actually requires threads *and* tasks, +and therefore futures. As a default way of thinking about which to use when: @@ -98,7 +98,47 @@ As a default way of thinking about which to use when: And if you need some mix of parallelism and concurrency, you do not have to choose between threads and async. You can use them together freely, letting each -one serve the part it is best at. +one serve the part it is best at. For example, Listing 17-TODO shows a fairly +common example of this kind of mix in real-world Rust code. + + + ++ +```rust +use std::thread; + +fn main() { + let (tx, mut rx) = trpl::channel(); + + thread::spawn(move || { + for i in 1..11 { + tx.send(i).unwrap(); + thread::sleep(Duration::from_secs(1)); + } + }); + + trpl::run(async { + while let Some(message) = rx.recv().await { + println!("{message}"); + } + }); +} +``` + + + +We begin by creating an async channel. Then we spawn a thread which takes +ownership of the sender side of the channel. Within the thread, we send the +numbers 1 through 10, and sleep for a second in between each. Finally, we run a +future created with an async block passed to `trpl::run` just like we have +throughout the chapter. In that future, we await those messages, just like in +the other message-passing examples we have seen. + +To return to the examples we opened the chapter with: you could imagine running +a set of video encoding tasks using a dedicated thread, since video encoding is +compute bound, but notifying the UI that those operations are done with an async +channel. Examples of this kind of mix abound! ## Summary From c35b7d9453b9ed86b0ace0f46f824f0f36f189ba Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 12 Sep 2024 17:30:24 -0600 Subject: [PATCH 537/720] Ch. 17: address most of the rest of Carol's outstanding comments --- .../listing-17-18/src/main.rs | 6 +- .../listing-17-27/src/main.rs | 2 +- .../listing-17-28/src/main.rs | 10 +++- src/ch17-00-async-await.md | 4 +- src/ch17-02-concurrency-with-async.md | 25 +++++--- src/ch17-03-more-futures.md | 60 +++++++++++-------- src/ch17-04-streams.md | 2 +- 7 files changed, 65 insertions(+), 44 deletions(-) diff --git a/listings/ch17-async-await/listing-17-18/src/main.rs b/listings/ch17-async-await/listing-17-18/src/main.rs index c5ccc0b5bd..41820fc8a5 100644 --- a/listings/ch17-async-await/listing-17-18/src/main.rs +++ b/listings/ch17-async-await/listing-17-18/src/main.rs @@ -13,7 +13,7 @@ fn main() { let tx1 = tx.clone(); // ANCHOR: here let tx1_fut = pin!(async move { - // snip... + // --snip-- // ANCHOR_END: here let vals = vec![ String::from("hi"), @@ -32,7 +32,7 @@ fn main() { // ANCHOR_END: here // ANCHOR: here let rx_fut = pin!(async { - // snip... + // --snip-- // ANCHOR_END: here while let Some(value) = rx.recv().await { println!("received '{value}'"); @@ -41,7 +41,7 @@ fn main() { }); let tx_fut = pin!(async move { - // snip... + // --snip-- // ANCHOR_END: here let vals = vec![ String::from("more"), diff --git a/listings/ch17-async-await/listing-17-27/src/main.rs b/listings/ch17-async-await/listing-17-27/src/main.rs index 6c2ae688e4..d2edded63d 100644 --- a/listings/ch17-async-await/listing-17-27/src/main.rs +++ b/listings/ch17-async-await/listing-17-27/src/main.rs @@ -20,7 +20,7 @@ fn main() { // ANCHOR: declaration async fn timeout( - future: F, + future_to_try: F, max_time: Duration, ) -> Result { // Here is where our implementation will go! diff --git a/listings/ch17-async-await/listing-17-28/src/main.rs b/listings/ch17-async-await/listing-17-28/src/main.rs index d34a2a8f0e..9efb5e7921 100644 --- a/listings/ch17-async-await/listing-17-28/src/main.rs +++ b/listings/ch17-async-await/listing-17-28/src/main.rs @@ -2,8 +2,12 @@ extern crate trpl; // required for mdbook test use std::{future::Future, time::Duration}; +// ANCHOR: implementation use trpl::Either; +// --snip-- +// ANCHOR: implementation + fn main() { trpl::run(async { let slow = async { @@ -11,7 +15,7 @@ fn main() { "Finally finished" }; - match timeout(Duration::from_secs(2), slow).await { + match timeout(slow, Duration::from_secs(2)).await { Ok(message) => println!("Succeeded with '{message}'"), Err(duration) => { println!("Failed after {} seconds", duration.as_secs()) @@ -21,11 +25,11 @@ fn main() { } async fn timeout( + future_to_try: F, max_time: Duration, - future: F, ) -> Result { // ANCHOR: implementation - match trpl::race(future, trpl::sleep(max_time)).await { + match trpl::race(future_to_try, trpl::sleep(max_time)).await { Either::Left(output) => Ok(output), Either::Right(_) => Err(max_time), } diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 5540f0b795..2e20b366cd 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -11,8 +11,8 @@ The video export will use as much CPU and GPU power as it can. If you only had one CPU core, and your operating system never paused that export until it completed, you could not do anything else on your computer while it was running. That would be a pretty frustrating experience, though. Instead, your computer’s -operating sysem can (and does!) invisibly interrupt the export often enough to -let you get other work done along the way. +operating sysem can—and does!—invisibly interrupt the export often enough to let +you get other work done along the way. The file download is different. It does not take up very much CPU time. Instead, the CPU needs to wait on data to arrive from the network. While you can start diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 369cb63b1c..98a4e393d9 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -173,7 +173,11 @@ each case *before* running the code! ### Message Passing Sharing data between futures will also be familiar: we will use message passing -again, but this with async versions of the types and functions. +again, but this with async versions of the types and functions. We will take a +slightly different path than we did in Chapter 16, to illustrate some of the key +differences between thread-based and futures-based concurrency. In Listing 17-8, +we will begin with just a single async block—*not* spawning a separate task like +we spawned a separate thread. @@ -183,7 +187,7 @@ again, but this with async versions of the types and functions. -We start by using `trpl::channel`, an async version of the multiple-producer, +Here, we use `trpl::channel`, an async version of the multiple-producer, single-consumer channel API we used with threads back in Chapter 16. The async version of the API is only a little different from the thread-based version: it uses a mutable rather than an immutable receiver `rx`, and its `recv` method @@ -206,9 +210,13 @@ because the channel we are sending it into is unbounded. > code, and thus where to transition between sync and async code. In most async > runtimes, `run` is actually named `block_on` for exactly this reason. -It is hard to see the effect of async in Listing 17-8, though, since the message -will arrive right away! Let’s go ahead and send a whole series of messages, and -sleep in between them, as shown in Listing 17-9: +Notice two things about this example: First, the message will arrive right away! +Second, although we use a future here, there is no concurrency yet. Everything +in the listing happens in sequence, just as it would if there were no futures +involved. + +Let’s address the first part by sending a series of messages, and sleep in +between them, as shown in Listing 17-9: @@ -262,9 +270,10 @@ async block, the order that `.await` keywords appear in the code is also the order they happen when running the program. There is only one async block in Listing 17-9, so everything in it runs -linearly. All the `tx.send` calls happen, interspersed with all of the -`trpl::sleep` calls and their associated await points. Only then does the `while -let` loop get to go through any of the `.await` points on the `recv` calls. +linearly. There is still no concurrency. All the `tx.send` calls happen, +interspersed with all of the `trpl::sleep` calls and their associated await +points. Only then does the `while let` loop get to go through any of the +`.await` points on the `recv` calls. To get the behavior we want, where the sleep delay happens between receiving each message, we need to put the `tx` and `rx` operations in their own async diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index b9f1fccc65..7a57548d63 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -125,10 +125,10 @@ object (Listing 17-16). The type we had to write here is a little involved, so let’s walk through it: -* The innermost type is the future itself. We note explicitly that it the output - of the future is the unit type `()` by writing `Future`. +* The innermost type is the future itself. We note explicitly that the output of + the future is the unit type `()` by writing `Future`. * Then we annotate the trait with `dyn` to mark it as dynamic. -* The entire trait is wrapped in a `Box`. +* The entire trait reference is wrapped in a `Box`. * Finally, we state explicitly that `futures` is a `Vec` containing these items. That already made a big difference. Now when we run the compiler, we only have @@ -330,12 +330,16 @@ await points is synchronous. That means if you do a bunch of work in an async block without an await point, that future will block any other futures from making progress. You may sometimes -hear this referred to as one future *starving* other futures. In many cases, +hear this referred to as one future *starving* other futures. In some cases, that may not be a big deal. However, if you are doing some kind of expensive setup or long-running work, or if you have a future which will keep doing some particular task indefinitely, you will need to think about when and where to hand control back to the runtime. +By the same token, if you have long-running blocking operations, async can be a +useful tool for providing ways for different parts of the program to relate to +each other. + But *how* would you hand control back to the runtime in those cases? ### Yielding @@ -473,17 +477,21 @@ compared to the future using `trpl::yield_now`. The version with `yield_now` is *way* faster! -This means that async can be useful even for CPU-bound tasks, depending on what -else your program is doing, because it provides a useful tool for structuring -the relationships between different parts of the program. This is a form of -*cooperative multitasking*, where each future has both the power to determine -when it hands over control via await points. Each future therefore also has the -*responsibility* to avoid blocking for too long. In some Rust-based embedded -operating systems, this is the *only* kind of multitasking! +This means that async can be useful even for compute-bound tasks, depending on +what else your program is doing, because it provides a useful tool for +structuring the relationships between different parts of the program. This is a +form of *cooperative multitasking*, where each future has both the power to +determine when it hands over control via await points. Each future therefore +also has the responsibility to avoid blocking for too long. In some Rust-based +embedded operating systems, this is the *only* kind of multitasking! In real-world code, you will not usually be alternating function calls with -await points on every single line, of course. The underlying dynamic is an -important one to keep in mind, though! +await points on every single line, of course. While yielding control like this +is relatively inexpensive, it is not free! In many cases, trying to break up a +compute-bound task might make it significantly slower, so sometimes it is better +for *overall* performance to let an operation block briefly. You should always +measure to see what your code’s actual performance bottlenecks are. The +underlying dynamic is an important one to keep in mind if you *are* seeing a lot of work happening in serial that you expected to happen concurrently, though! ### Building Our Own Async Abstractions @@ -535,13 +543,12 @@ run that timer with the future the caller passes in. The `trpl::race` function returns a value to indicate which of the futures passed to it finishes first. (When we saw `race` earlier in Listing 17-20, we ignored its return value, because we were only interested in seeing the behavior -of `fast` and `slow` when we ran the program.) Because either future passed as -an argument to `race` can legitimately “win,” it does not make sense to use a -`Result` to represent the return type. Instead, `race` returns a type we have -not seen before, `Either`. The `Either` type is somewhat like a `Result`, in -that it has two cases. Unlike `Result`, though, there is no notion of success or -failure baked into `Either`. Instead, it uses `Left` and `Right` to indicate -“one or the other”. +of `fast` and `slow` when we ran the program.) Either future can legitimately +“win,” so it does not make sense to return a `Result`. Instead, `race` returns a +type we have not seen before, `trpl::Either`. The `Either` type is somewhat like +a `Result`, in that it has two cases. Unlike `Result`, though, there is no +notion of success or failure baked into `Either`. Instead, it uses `Left` and +`Right` to indicate “one or the other”. ```rust enum Either { @@ -552,19 +559,20 @@ enum Either { The `race` function returns `Left` if the first argument finishes first, with that future’s output, and `Right` with the second future argument’s output if -*that* one finishes first. +*that* one finishes first. This matches the order the arguments appear when +calling the function: the first argument is to the left of the second argument. We also know that `race` is not fair, and polls arguments in the order they are -passed. Thus, we pass the caller-supplied future to `race` first so it gets a -chance to complete even if `max_time` is a very short duration. If `future` +passed. Thus, we pass `future_to_try` to `race` first so it gets a chance to +complete even if `max_time` is a very short duration. If `future_to_try` finishes first, `race` will return `Left` with the output from `future`. If `timer` finishes first, `race` will return `Right` with the timer’s output of `()`. In Listing 17-28, we match on the result of awaiting `trpl::race`. If the -future succeeded and we get a `Left(output)`, we return `Ok(output)`. If the -sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` with -`_` and return `Err(max_time)` instead. +`future_to_try` succeeded and we get a `Left(output)`, we return `Ok(output)`. +If the sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` +with `_` and return `Err(max_time)` instead. diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index e4ae1ed7e1..3510aa4164 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -123,7 +123,7 @@ a queue, or working with more data than can fit in a computer’s memory by only pulling chunks of it from the file system at a time, or data arriving over the network over time. Because streams are futures, we can use them with any other kind of future, too, and we can combine them in interesting ways. For example, -we can debounce events to avoid triggering too many network calls, set timeouts +we can batch up events to avoid triggering too many network calls, set timeouts on sequences of long-running operations, or throttle user interface events to avoid doing needless work. From 453247c7904db6d6661dd80dbaa80717773b2ffd Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 13 Sep 2024 14:15:44 -0600 Subject: [PATCH 538/720] Ch. 17: address Tim and Carol's outstanding comments Co-authored-by: Tim McNamara Co-authored-by: Carol (Nichols || Goulding) --- src/ch17-01-futures-and-syntax.md | 41 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 5ce095f31b..687ce8870b 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -1,10 +1,30 @@ ## Futures and the Async Syntax -Like other languages with async, Rust uses the `async` and `await` keywords for -async programming. (If you are familiar with other languages’ approach to async, -you may notice some significant differences, though.) In Rust, blocks and -functions can be marked `async`, and you can wait on the result of an `async` -function or block to resolve using the `await` keyword. +They key elements of asynchronous programming in Rust are *futures* and Rust’s +`async` and `await` keywords. + +A future is a value that may not ready yet. Every future holds its own +information about the progress that has been made and what "ready" means. In +Rust, we say that types which implement the `Future` trait are futures. The +`async` keyword can be applied to blocks and functions to specify that they can +be interrupted and resumed. Within an async block or async function, you can use +the `await` keyword to wait for a future to become ready, called *awaiting a +future*. Each place you await a future within an async block or function is a +place that async block or function may get paused and resumed. + +> Note: Many other languages use the `async` and `await` keywords for async +> programming. If you are familiar with other languages’ approach to async, you +> may notice some significant differences in how Rust does things, including how +> it handles the syntax. That is for good reason, as we will see! + +That may all feel a bit abstract. Let’s write our first async program: a little +web scraper. This will have a fair bit of new syntax, but don’t worry. We will +explain it all as we go. + + Let’s write our first async function, and call it: @@ -37,8 +57,8 @@ learning what the syntax means, so let’s start there. In Rust, writing `async fn` is equivalent to writing a function which returns a *future* of the return type. That is, when the compiler sees a function like -`async fn hello` in Listing 17-1, it is basically equivalent to a function -defined like this instead: +`async fn hello` in Listing 17-1, it is equivalent to a function defined like +this instead: ```rust use std::future::Future; @@ -131,8 +151,11 @@ However, we get another compiler error here: {{#include ../listings/ch17-async-await/listing-17-03/output.txt}} ``` -The problem is that async code needs a *runtime*: a Rust crate which manages the -details of executing asynchronous code. +Rust won't allow us too mark `main` as `async`. The underlying problem is that +async code needs a *runtime*: a Rust crate which manages the details of +executing asynchronous code. A program's `main` function can initialize a +runtime, but it is not a runtime itself. (We will see more about why this is a +bit later.) Most languages which support async bundle a runtime with the language. Rust does not. Instead, there are many different async runtimes available, each of which From ccafd066cb6ccb1a99b4409f0dd35f744ff8694a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 13 Sep 2024 17:02:11 -0600 Subject: [PATCH 539/720] Ch. 17: Fix some typos! --- src/ch17-00-async-await.md | 4 ++-- src/ch17-03-more-futures.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 2e20b366cd..1749cc17a7 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -11,8 +11,8 @@ The video export will use as much CPU and GPU power as it can. If you only had one CPU core, and your operating system never paused that export until it completed, you could not do anything else on your computer while it was running. That would be a pretty frustrating experience, though. Instead, your computer’s -operating sysem can—and does!—invisibly interrupt the export often enough to let -you get other work done along the way. +operating system can—and does!—invisibly interrupt the export often enough to +let you get other work done along the way. The file download is different. It does not take up very much CPU time. Instead, the CPU needs to wait on data to arrive from the network. While you can start diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 7a57548d63..1ed95f14cc 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -462,7 +462,7 @@ lot in one millisecond! You can see this for yourself by setting up a little benchmark, like the one in Listing 17-25. (This is not an especially rigorous way to do performance testing, but it suffices to show the difference here.) Here, we skip all the -status printing, pass a one-nanosecond `Duration` to `trple::sleep`, and let +status printing, pass a one-nanosecond `Duration` to `trpl::sleep`, and let each future run by itself, with no switching between the futures. Then we run for 1,000 iterations and see how long the future using `trpl::sleep` takes compared to the future using `trpl::yield_now`. From 6f5773e64dc469b2794a121b70d4be971ac1d2d4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 16 Sep 2024 15:57:18 -0600 Subject: [PATCH 540/720] Remove duplicate integration test from root I accidentally copied these in when pulling in the `trpl-note` mdbook preprocessor many months ago, and we did not notice amidst the many other changes in that PR! --- tests/integration/main.rs | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 tests/integration/main.rs diff --git a/tests/integration/main.rs b/tests/integration/main.rs deleted file mode 100644 index 6944fae693..0000000000 --- a/tests/integration/main.rs +++ /dev/null @@ -1,22 +0,0 @@ -use assert_cmd::Command; - -#[test] -fn supports_html_renderer() { - let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) - .unwrap() - .args(["supports", "html"]) - .ok(); - assert!(cmd.is_ok()); -} - -#[test] -fn errors_for_other_renderers() { - let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) - .unwrap() - .args(["supports", "total-nonsense"]) - .ok(); - assert!(cmd.is_err()); -} - -// It would be nice to add an actual fixture for an mdbook, but doing *that* is -// going to be a bit of a pain, and what I have should cover it for now. From 33d5efb32e03aca0b12a9a913fa49954acd441cb Mon Sep 17 00:00:00 2001 From: Ciro Lo Sapio Date: Fri, 20 Sep 2024 10:44:51 +0200 Subject: [PATCH 541/720] translations: remove broken link --- src/appendix-06-translation.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/appendix-06-translation.md b/src/appendix-06-translation.md index 54d58376ee..82cb447817 100644 --- a/src/appendix-06-translation.md +++ b/src/appendix-06-translation.md @@ -11,7 +11,6 @@ For resources in languages other than English. Most are still in progress; see - [正體中文](https://github.com/rust-tw/book-tw) - [Українська](https://github.com/pavloslav/rust-book-uk-ua) - [Español](https://github.com/thecodix/book), [alternate](https://github.com/ManRR/rust-book-es) -- [Italiano](https://github.com/EmanueleGurini/book_it) - [Русский](https://github.com/rust-lang-ru/book) - [한국어](https://github.com/rinthel/rust-lang-book-ko) - [日本語](https://github.com/rust-lang-ja/book-ja) From cc5db976931262d046bbba8cc25fc80e477f8c1b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 13 Sep 2024 16:21:10 -0600 Subject: [PATCH 542/720] Ch. 17: rewrite 17.01 with a better example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `reqwest` and `scraper` dependencies to the `trpl` crate. Wrap them in `trpl` re-exports which keep the API surface low. Rewrite the whole first section to use `race` along with those `trpl` re-exports to show a more “real” example of async code right form the start, including actual concurrency, unlike the previous introduction. Update 17.03 to account for having introduced `race` already, and update listing numbers for rewritten 17.01. The *inclues* for them were fixed already, but not these! --- Cargo.lock | 1890 +++++++++++++++-- Cargo.toml | 2 +- .../ch17-async-await/listing-17-01/Cargo.lock | 1788 +++++++++++++++- .../ch17-async-await/listing-17-01/Cargo.toml | 5 +- .../ch17-async-await/listing-17-01/output.txt | 14 - .../listing-17-01/src/main.rs | 17 +- .../ch17-async-await/listing-17-02/Cargo.lock | 1788 +++++++++++++++- .../ch17-async-await/listing-17-02/Cargo.toml | 5 +- .../ch17-async-await/listing-17-02/output.txt | 12 - .../listing-17-02/src/main.rs | 18 +- .../ch17-async-await/listing-17-03/Cargo.lock | 1788 +++++++++++++++- .../ch17-async-await/listing-17-03/Cargo.toml | 5 +- .../ch17-async-await/listing-17-03/output.txt | 10 - .../listing-17-03/src/main.rs | 19 +- .../ch17-async-await/listing-17-04/Cargo.lock | 1661 ++++++++++++++- .../ch17-async-await/listing-17-04/Cargo.toml | 6 +- .../ch17-async-await/listing-17-04/output.txt | 4 +- .../listing-17-04/src/main.rs | 24 +- .../ch17-async-await/listing-17-05/Cargo.lock | 1661 ++++++++++++++- .../ch17-async-await/listing-17-05/Cargo.toml | 4 +- .../listing-17-05/src/main.rs | 35 +- .../ch17-async-await/listing-17-06/Cargo.lock | 1706 ++++++++++++++- .../listing-17-06/src/main.rs | 8 +- .../listing-17-07/src/main.rs | 20 +- .../listing-17-08/src/main.rs | 24 +- .../listing-17-09/src/main.rs | 24 +- .../listing-17-10/src/main.rs | 38 +- .../listing-17-11/src/main.rs | 9 +- .../listing-17-12/src/main.rs | 27 +- .../listing-17-13/src/main.rs | 8 +- .../listing-17-14/src/main.rs | 4 +- .../listing-17-15/src/main.rs | 3 +- .../ch17-async-await/listing-17-16/Cargo.lock | 12 + .../listing-17-16/src/main.rs | 6 +- .../ch17-async-await/listing-17-17/Cargo.lock | 12 - .../output.txt | 0 .../listing-17-17/src/main.rs | 22 +- .../listing-17-18/src/main.rs | 17 +- .../output.txt | 0 .../listing-17-19/src/main.rs | 62 +- .../ch17-async-await/listing-17-20/Cargo.lock | 262 +-- .../listing-17-20/src/main.rs | 19 +- .../ch17-async-await/listing-17-21/Cargo.lock | 262 ++- .../listing-17-21/src/main.rs | 25 +- .../listing-17-22/src/main.rs | 25 +- .../listing-17-23/src/main.rs | 17 +- .../listing-17-24/src/main.rs | 20 +- .../ch17-async-await/listing-17-25/Cargo.lock | 262 +-- .../listing-17-25/src/main.rs | 60 +- .../ch17-async-await/listing-17-26/Cargo.lock | 262 ++- .../listing-17-26/src/main.rs | 33 +- .../listing-17-27/src/main.rs | 17 +- .../listing-17-28/src/main.rs | 17 +- .../ch17-async-await/listing-17-29/Cargo.lock | 1714 ++++++++++++++- .../ch17-async-await/listing-17-29/Cargo.toml | 1 + .../listing-17-29/src/main.rs | 36 +- .../listing-17-30/src/main.rs | 4 +- .../listing-17-31/src/main.rs | 11 +- .../listing-17-32/src/main.rs | 26 +- .../listing-17-33/src/main.rs | 17 +- .../listing-17-34/src/main.rs | 18 +- .../listing-17-35/src/main.rs | 19 +- .../listing-17-36/src/main.rs | 11 +- .../listing-17-37/src/main.rs | 7 +- .../listing-17-38/src/main.rs | 9 +- .../listing-17-39/src/main.rs | 22 +- .../listing-17-40/src/main.rs | 12 +- .../ch17-async-await/listing-17-41/Cargo.lock | 292 +++ .../ch17-async-await/listing-17-41/Cargo.toml | 8 + .../listing-17-41/src/main.rs | 67 + packages/trpl/Cargo.lock | 1706 ++++++++++++++- packages/trpl/Cargo.toml | 2 + packages/trpl/src/lib.rs | 51 + packages/trpl/tests/integration/main.rs | 11 + src/ch17-01-futures-and-syntax.md | 450 ++-- src/ch17-02-concurrency-with-async.md | 50 +- src/ch17-03-more-futures.md | 134 +- src/ch17-04-streams.md | 72 +- src/ch17-05-traits-for-async.md | 4 +- src/ch17-06-futures-tasks-threads.md | 8 +- 80 files changed, 16954 insertions(+), 1847 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-01/output.txt delete mode 100644 listings/ch17-async-await/listing-17-02/output.txt delete mode 100644 listings/ch17-async-await/listing-17-03/output.txt rename listings/ch17-async-await/{listing-17-16 => listing-17-17}/output.txt (100%) rename listings/ch17-async-await/{listing-17-18 => listing-17-19}/output.txt (100%) create mode 100644 listings/ch17-async-await/listing-17-41/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-41/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-41/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index d54e8284e1..21c0d5e8a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,278 +2,1806 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cc" +version = "1.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "docopt" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" +dependencies = [ + "lazy_static", + "regex", + "serde", + "strsim", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", +] + +[[package]] +name = "flate2" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "listing-scraper-01" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.4", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags 2.5.0", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rust-book-tools" +version = "0.0.1" +dependencies = [ + "docopt", + "flate2", + "lazy_static", + "regex", + "serde", + "tar", + "walkdir", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +dependencies = [ + "bitflags 2.5.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags 2.5.0", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ - "memchr", + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", ] [[package]] -name = "bitflags" -version = "1.3.2" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] -name = "bitflags" -version = "2.5.0" +name = "subtle" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] -name = "cfg-if" -version = "1.0.0" +name = "syn" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] -name = "crc32fast" -version = "1.4.0" +name = "sync_wrapper" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" dependencies = [ - "cfg-if", + "futures-core", ] [[package]] -name = "docopt" -version = "1.1.1" +name = "system-configuration" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "lazy_static", - "regex", - "serde", - "strsim", + "bitflags 2.5.0", + "core-foundation", + "system-configuration-sys", ] [[package]] -name = "errno" -version = "0.3.8" +name = "system-configuration-sys" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" dependencies = [ + "core-foundation-sys", "libc", - "windows-sys", ] [[package]] -name = "filetime" -version = "0.2.23" +name = "tar" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" dependencies = [ - "cfg-if", + "filetime", "libc", - "redox_syscall", - "windows-sys", + "xattr", ] [[package]] -name = "flate2" -version = "1.0.30" +name = "tempfile" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ - "crc32fast", - "miniz_oxide", + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", ] [[package]] -name = "lazy_static" -version = "1.4.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] [[package]] -name = "libc" -version = "0.2.153" +name = "tinyvec" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] [[package]] -name = "linux-raw-sys" -version = "0.4.13" +name = "tinyvec_macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] -name = "memchr" -version = "2.7.2" +name = "tokio" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "tokio-native-tls" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ - "adler", + "native-tls", + "tokio", ] [[package]] -name = "proc-macro2" -version = "1.0.80" +name = "tokio-rustls" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "unicode-ident", + "rustls", + "rustls-pki-types", + "tokio", ] [[package]] -name = "quote" -version = "1.0.36" +name = "tokio-stream" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ - "proc-macro2", + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] -name = "redox_syscall" -version = "0.4.1" +name = "tokio-util" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ - "bitflags 1.3.2", + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", ] [[package]] -name = "regex" -version = "1.10.4" +name = "tower" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", ] [[package]] -name = "regex-automata" -version = "0.4.6" +name = "tower-layer" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", + "pin-project-lite", + "tracing-core", ] [[package]] -name = "regex-syntax" -version = "0.8.3" +name = "tracing-core" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] [[package]] -name = "rust-book-tools" -version = "0.0.1" +name = "trpl" +version = "0.1.0" dependencies = [ - "docopt", - "flate2", - "lazy_static", - "regex", - "serde", - "tar", - "walkdir", + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", ] [[package]] -name = "rustix" -version = "0.38.34" +name = "try-lock" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", + "tinyvec", ] [[package]] -name = "same-file" -version = "1.0.6" +name = "unicode-width" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ + "same-file", "winapi-util", ] [[package]] -name = "serde" -version = "1.0.197" +name = "want" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "serde_derive", + "try-lock", ] [[package]] -name = "serde_derive" -version = "1.0.197" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ + "bumpalo", + "log", + "once_cell", "proc-macro2", "quote", "syn", + "wasm-bindgen-shared", ] [[package]] -name = "strsim" -version = "0.10.0" +name = "wasm-bindgen-futures" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] [[package]] -name = "syn" -version = "2.0.59" +name = "wasm-bindgen-macro" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ - "proc-macro2", "quote", - "unicode-ident", + "wasm-bindgen-macro-support", ] [[package]] -name = "tar" -version = "0.4.40" +name = "wasm-bindgen-macro-support" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ - "filetime", - "libc", - "xattr", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", ] [[package]] -name = "unicode-ident" -version = "1.0.0" +name = "wasm-bindgen-shared" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] -name = "walkdir" -version = "2.5.0" +name = "web-sys" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ - "same-file", - "winapi-util", + "js-sys", + "wasm-bindgen", ] [[package]] @@ -307,6 +1835,36 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -316,11 +1874,20 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -334,51 +1901,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "xattr" @@ -390,3 +1957,30 @@ dependencies = [ "linux-raw-sys", "rustix", ] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index 20fc14643d..5b7ef40548 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["packages/tools"] +members = [ "listings/ch17-async-await/listing-scraper-01","packages/tools"] default-members = ["packages/tools"] resolver = "2" exclude = [ diff --git a/listings/ch17-async-await/listing-17-01/Cargo.lock b/listings/ch17-async-await/listing-17-01/Cargo.lock index d30b928a6c..207879da8f 100644 --- a/listings/ch17-async-await/listing-17-01/Cargo.lock +++ b/listings/ch17-async-await/listing-17-01/Cargo.lock @@ -3,5 +3,1791 @@ version = 3 [[package]] -name = "async_await" +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + +[[package]] +name = "cc" +version = "1.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "listing-scraper-01" version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-01/Cargo.toml b/listings/ch17-async-await/listing-17-01/Cargo.toml index 67729afc80..9fad6d6a96 100644 --- a/listings/ch17-async-await/listing-17-01/Cargo.toml +++ b/listings/ch17-async-await/listing-17-01/Cargo.toml @@ -1,6 +1,7 @@ [package] -name = "async_await" +name = "listing-scraper-01" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-01/output.txt b/listings/ch17-async-await/listing-17-01/output.txt deleted file mode 100644 index 92b5d5e4d5..0000000000 --- a/listings/ch17-async-await/listing-17-01/output.txt +++ /dev/null @@ -1,14 +0,0 @@ -$ cargo run - Compiling async_await v0.1.0 (file:///projects/async_await) -warning: unused implementer of `Future` that must be used - --> src/main.rs:2:5 - | -2 | hello("async"); - | ^^^^^^^^^^^^^^ - | - = note: futures do nothing unless you `.await` or poll them - = note: `#[warn(unused_must_use)]` on by default - -warning: `async_await` (bin "async_await") generated 1 warning - Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s - Running `target/debug/async_await` diff --git a/listings/ch17-async-await/listing-17-01/src/main.rs b/listings/ch17-async-await/listing-17-01/src/main.rs index 68c82536aa..b4d9323f5f 100644 --- a/listings/ch17-async-await/listing-17-01/src/main.rs +++ b/listings/ch17-async-await/listing-17-01/src/main.rs @@ -1,10 +1,17 @@ -// ANCHOR: all +extern crate trpl; // required for mdbook test + fn main() { - hello("async"); + // TODO: we'll add this next! } -async fn hello(name: &str) { - let greeting = format!("Hello, {name}!"); - println!("{greeting}"); +// ANCHOR: all +use trpl::Html; + +async fn page_title(url: &str) -> Option { + let response = trpl::get(url).await; + let response_text = response.text().await; + Html::parse(&response_text) + .select_first("title") + .map(|title_element| title_element.inner_html()) } // ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-02/Cargo.lock b/listings/ch17-async-await/listing-17-02/Cargo.lock index d30b928a6c..cb7d407618 100644 --- a/listings/ch17-async-await/listing-17-02/Cargo.lock +++ b/listings/ch17-async-await/listing-17-02/Cargo.lock @@ -3,5 +3,1791 @@ version = 3 [[package]] -name = "async_await" +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cc" +version = "1.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "listing-scraper-01" version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-02/Cargo.toml b/listings/ch17-async-await/listing-17-02/Cargo.toml index 67729afc80..9fad6d6a96 100644 --- a/listings/ch17-async-await/listing-17-02/Cargo.toml +++ b/listings/ch17-async-await/listing-17-02/Cargo.toml @@ -1,6 +1,7 @@ [package] -name = "async_await" +name = "listing-scraper-01" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-02/output.txt b/listings/ch17-async-await/listing-17-02/output.txt deleted file mode 100644 index d2809af719..0000000000 --- a/listings/ch17-async-await/listing-17-02/output.txt +++ /dev/null @@ -1,12 +0,0 @@ -$ cargo run - Compiling async_await v0.1.0 (file:///projects/async_await) -error[E0728]: `await` is only allowed inside `async` functions and blocks - --> src/main.rs:2:20 - | -1 | fn main() { - | --------- this is not `async` -2 | hello("async").await; - | ^^^^^ only allowed inside `async` functions and blocks - -For more information about this error, try `rustc --explain E0728`. -error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-02/src/main.rs b/listings/ch17-async-await/listing-17-02/src/main.rs index 153458bc0a..e9c43b34d7 100644 --- a/listings/ch17-async-await/listing-17-02/src/main.rs +++ b/listings/ch17-async-await/listing-17-02/src/main.rs @@ -1,10 +1,16 @@ -// ANCHOR: main +extern crate trpl; // required for mdbook test + +use trpl::Html; + fn main() { - hello("async").await; + // TODO: we'll add this next! } -// ANCHOR_END: main -async fn hello(name: &str) { - let greeting = format!("Hello, {name}!"); - println!("{greeting}"); +async fn page_title(url: &str) -> Option { + // ANCHOR: chaining + let response_text = trpl::get(url).await.text().await; + // ANCHOR_END: chaining + Html::parse(&response_text) + .select_first("title") + .map(|title_element| title_element.inner_html()) } diff --git a/listings/ch17-async-await/listing-17-03/Cargo.lock b/listings/ch17-async-await/listing-17-03/Cargo.lock index d30b928a6c..cb7d407618 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.lock +++ b/listings/ch17-async-await/listing-17-03/Cargo.lock @@ -3,5 +3,1791 @@ version = 3 [[package]] -name = "async_await" +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cc" +version = "1.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "listing-scraper-01" version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-03/Cargo.toml b/listings/ch17-async-await/listing-17-03/Cargo.toml index 67729afc80..9fad6d6a96 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.toml +++ b/listings/ch17-async-await/listing-17-03/Cargo.toml @@ -1,6 +1,7 @@ [package] -name = "async_await" +name = "listing-scraper-01" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-03/output.txt b/listings/ch17-async-await/listing-17-03/output.txt deleted file mode 100644 index e61d87f805..0000000000 --- a/listings/ch17-async-await/listing-17-03/output.txt +++ /dev/null @@ -1,10 +0,0 @@ -$ cargo run - Compiling async_await v0.1.0 (file:///projects/async_await) -error[E0752]: `main` function is not allowed to be `async` - --> src/main.rs:1:1 - | -1 | async fn main() { - | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` - -For more information about this error, try `rustc --explain E0752`. -error: could not compile `async_await` (bin "async_await") due to 1 previous error diff --git a/listings/ch17-async-await/listing-17-03/src/main.rs b/listings/ch17-async-await/listing-17-03/src/main.rs index 443cadcc0e..23290fff4a 100644 --- a/listings/ch17-async-await/listing-17-03/src/main.rs +++ b/listings/ch17-async-await/listing-17-03/src/main.rs @@ -1,10 +1,21 @@ +extern crate trpl; // required for mdbook test + +use trpl::Html; + // ANCHOR: main async fn main() { - hello("async").await; + let args: Vec = std::env::args().collect(); + let url = &args[1]; + match page_title(url).await { + Some(title) => println!("The title for {url} was {title}"), + None => println!("{url} had no title"), + } } // ANCHOR_END: main -async fn hello(name: &str) { - let greeting = format!("Hello, {name}!"); - println!("{greeting}"); +async fn page_title(url: &str) -> Option { + let response_text = trpl::get(url).await.text().await; + Html::parse(&response_text) + .select_first("title") + .map(|title_element| title_element.inner_html()) } diff --git a/listings/ch17-async-await/listing-17-04/Cargo.lock b/listings/ch17-async-await/listing-17-04/Cargo.lock index b6971aa2e9..cb7d407618 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.lock +++ b/listings/ch17-async-await/listing-17-04/Cargo.lock @@ -4,26 +4,38 @@ version = 3 [[package]] name = "addr2line" -version = "0.22.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" dependencies = [ "gimli", ] [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] -name = "async_await" -version = "0.1.0" +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "trpl", + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -32,24 +44,57 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", + "windows-targets", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + [[package]] name = "cc" -version = "1.0.99" +version = "1.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" +checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -57,6 +102,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,11 +333,65 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hermit-abi" @@ -159,134 +400,1394 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "libc" -version = "0.2.155" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "memchr" -version = "2.7.2" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] [[package]] -name = "miniz_oxide" -version = "0.7.3" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "adler", + "bytes", + "http", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", ] [[package]] -name = "object" -version = "0.36.0" +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "memchr", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper-util" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] -name = "quote" -version = "1.0.36" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "indexmap" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] [[package]] -name = "slab" -version = "0.4.9" +name = "ipnet" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "listing-scraper-01" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", + "scopeguard", ] [[package]] -name = "syn" -version = "2.0.66" +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "adler2", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "mio" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-04/Cargo.toml b/listings/ch17-async-await/listing-17-04/Cargo.toml index 5f2e9ac2d0..9fad6d6a96 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.toml +++ b/listings/ch17-async-await/listing-17-04/Cargo.toml @@ -1,9 +1,7 @@ [package] -name = "async_await" +name = "listing-scraper-01" version = "0.1.0" edition = "2021" [dependencies] -trpl = { version = "0.1.0", path = "../../../packages/trpl" } - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-04/output.txt b/listings/ch17-async-await/listing-17-04/output.txt index b928fb6020..a9b7a86ff3 100644 --- a/listings/ch17-async-await/listing-17-04/output.txt +++ b/listings/ch17-async-await/listing-17-04/output.txt @@ -1 +1,3 @@ -$ +$ cargo run "http://www.rust-lang.org" +The title for http://www.rust-lang.org was + Rust Programming Language diff --git a/listings/ch17-async-await/listing-17-04/src/main.rs b/listings/ch17-async-await/listing-17-04/src/main.rs index f3e685ac67..dbc0d4c6e1 100644 --- a/listings/ch17-async-await/listing-17-04/src/main.rs +++ b/listings/ch17-async-await/listing-17-04/src/main.rs @@ -1,14 +1,24 @@ extern crate trpl; // required for mdbook test -// ANCHOR: main +use trpl::Html; + fn main() { + let args: Vec = std::env::args().collect(); + + // ANCHOR: run trpl::run(async { - hello("async").await; - }); + let url = &args[1]; + match page_title(url).await { + Some(title) => println!("The title for {url} was {title}"), + None => println!("{url} had no title"), + } + }) + // ANCHOR_END: run } -// ANCHOR_END: main -async fn hello(name: &str) { - let greeting = format!("Hello, {name}!"); - println!("{greeting}"); +async fn page_title(url: &str) -> Option { + let response_text = trpl::get(url).await.text().await; + Html::parse(&response_text) + .select_first("title") + .map(|title_element| title_element.inner_html()) } diff --git a/listings/ch17-async-await/listing-17-05/Cargo.lock b/listings/ch17-async-await/listing-17-05/Cargo.lock index 2e0f3ebedb..cb7d407618 100644 --- a/listings/ch17-async-await/listing-17-05/Cargo.lock +++ b/listings/ch17-async-await/listing-17-05/Cargo.lock @@ -4,26 +4,38 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" dependencies = [ "gimli", ] [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] -name = "async_await" -version = "0.1.0" +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "trpl", + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -32,24 +44,57 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", + "windows-targets", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + [[package]] name = "cc" -version = "1.0.97" +version = "1.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -57,6 +102,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,11 +333,65 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" -version = "0.28.1" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hermit-abi" @@ -159,134 +400,1394 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "libc" -version = "0.2.154" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "memchr" -version = "2.7.2" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "adler", + "bytes", + "http", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", ] [[package]] -name = "object" -version = "0.32.2" +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "memchr", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper-util" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] -name = "quote" -version = "1.0.36" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "indexmap" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] [[package]] -name = "slab" -version = "0.4.9" +name = "ipnet" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "listing-scraper-01" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", + "scopeguard", ] [[package]] -name = "syn" -version = "2.0.63" +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "adler2", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "mio" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-05/Cargo.toml b/listings/ch17-async-await/listing-17-05/Cargo.toml index 349041d3eb..9fad6d6a96 100644 --- a/listings/ch17-async-await/listing-17-05/Cargo.toml +++ b/listings/ch17-async-await/listing-17-05/Cargo.toml @@ -1,9 +1,7 @@ [package] -name = "async_await" +name = "listing-scraper-01" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-05/src/main.rs b/listings/ch17-async-await/listing-17-05/src/main.rs index 8eb415ee73..8a5546afd5 100644 --- a/listings/ch17-async-await/listing-17-05/src/main.rs +++ b/listings/ch17-async-await/listing-17-05/src/main.rs @@ -1,21 +1,34 @@ extern crate trpl; // required for mdbook test // ANCHOR: all -use std::time::Duration; +use trpl::{Either, Html}; fn main() { + let args: Vec = std::env::args().collect(); + trpl::run(async { - trpl::spawn_task(async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(500)).await; - } - }); + let title_fut_1 = page_title(&args[1]); + let title_fut_2 = page_title(&args[2]); + + let (url, maybe_title) = + match trpl::race(title_fut_1, title_fut_2).await { + Either::Left(left) => left, + Either::Right(right) => right, + }; - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(500)).await; + println!("{url} returned first"); + match maybe_title { + Some(title) => println!("Its page title is: '{title}'"), + None => println!("Its title could not be parsed."), } - }); + }) +} + +async fn page_title(url: &str) -> (&str, Option) { + let text = trpl::get(url).await.text().await; + let title = Html::parse(&text) + .select_first("title") + .map(|title| title.inner_html()); + (url, title) } // ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-06/Cargo.lock b/listings/ch17-async-await/listing-17-06/Cargo.lock index 2e0f3ebedb..a55aeb1e1c 100644 --- a/listings/ch17-async-await/listing-17-06/Cargo.lock +++ b/listings/ch17-async-await/listing-17-06/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1488 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-06/src/main.rs b/listings/ch17-async-await/listing-17-06/src/main.rs index 5415e1fcee..8eb415ee73 100644 --- a/listings/ch17-async-await/listing-17-06/src/main.rs +++ b/listings/ch17-async-await/listing-17-06/src/main.rs @@ -1,11 +1,11 @@ extern crate trpl; // required for mdbook test +// ANCHOR: all use std::time::Duration; fn main() { trpl::run(async { - // ANCHOR: handle - let handle = trpl::spawn_task(async { + trpl::spawn_task(async { for i in 1..10 { println!("hi number {i} from the first task!"); trpl::sleep(Duration::from_millis(500)).await; @@ -16,8 +16,6 @@ fn main() { println!("hi number {i} from the second task!"); trpl::sleep(Duration::from_millis(500)).await; } - - handle.await.unwrap(); - // ANCHOR_END: handle }); } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-07/src/main.rs b/listings/ch17-async-await/listing-17-07/src/main.rs index 2cd5de9bae..5415e1fcee 100644 --- a/listings/ch17-async-await/listing-17-07/src/main.rs +++ b/listings/ch17-async-await/listing-17-07/src/main.rs @@ -4,22 +4,20 @@ use std::time::Duration; fn main() { trpl::run(async { - // ANCHOR: join - let fut1 = async { + // ANCHOR: handle + let handle = trpl::spawn_task(async { for i in 1..10 { println!("hi number {i} from the first task!"); trpl::sleep(Duration::from_millis(500)).await; } - }; + }); - let fut2 = async { - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(500)).await; - } - }; + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(500)).await; + } - trpl::join(fut1, fut2).await; - // ANCHOR_END: join + handle.await.unwrap(); + // ANCHOR_END: handle }); } diff --git a/listings/ch17-async-await/listing-17-08/src/main.rs b/listings/ch17-async-await/listing-17-08/src/main.rs index 56daddc10f..2cd5de9bae 100644 --- a/listings/ch17-async-await/listing-17-08/src/main.rs +++ b/listings/ch17-async-await/listing-17-08/src/main.rs @@ -1,15 +1,25 @@ extern crate trpl; // required for mdbook test +use std::time::Duration; + fn main() { trpl::run(async { - // ANCHOR: channel - let (tx, mut rx) = trpl::channel(); + // ANCHOR: join + let fut1 = async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(500)).await; + } + }; - let val = String::from("hi"); - tx.send(val).unwrap(); + let fut2 = async { + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(500)).await; + } + }; - let received = rx.recv().await.unwrap(); - println!("Got: {received}"); - // ANCHOR_END: channel + trpl::join(fut1, fut2).await; + // ANCHOR_END: join }); } diff --git a/listings/ch17-async-await/listing-17-09/src/main.rs b/listings/ch17-async-await/listing-17-09/src/main.rs index e11ae51787..56daddc10f 100644 --- a/listings/ch17-async-await/listing-17-09/src/main.rs +++ b/listings/ch17-async-await/listing-17-09/src/main.rs @@ -1,27 +1,15 @@ extern crate trpl; // required for mdbook test -use std::time::Duration; - fn main() { trpl::run(async { - // ANCHOR: many-messages + // ANCHOR: channel let (tx, mut rx) = trpl::channel(); - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_millis(500)).await; - } + let val = String::from("hi"); + tx.send(val).unwrap(); - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR_END: many-messages + let received = rx.recv().await.unwrap(); + println!("Got: {received}"); + // ANCHOR_END: channel }); } diff --git a/listings/ch17-async-await/listing-17-10/src/main.rs b/listings/ch17-async-await/listing-17-10/src/main.rs index 5ada1d2f6d..e11ae51787 100644 --- a/listings/ch17-async-await/listing-17-10/src/main.rs +++ b/listings/ch17-async-await/listing-17-10/src/main.rs @@ -4,32 +4,24 @@ use std::time::Duration; fn main() { trpl::run(async { + // ANCHOR: many-messages let (tx, mut rx) = trpl::channel(); - // ANCHOR: futures - let tx_fut = async { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_millis(500)).await; - } - }; + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } - let rx_fut = async { - // ANCHOR: loop - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - // ANCHOR_END: loop - }; - - trpl::join(tx_fut, rx_fut).await; - // ANCHOR_END: futures + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR_END: many-messages }); } diff --git a/listings/ch17-async-await/listing-17-11/src/main.rs b/listings/ch17-async-await/listing-17-11/src/main.rs index 95e6480677..f8e641d6d0 100644 --- a/listings/ch17-async-await/listing-17-11/src/main.rs +++ b/listings/ch17-async-await/listing-17-11/src/main.rs @@ -4,10 +4,10 @@ use std::time::Duration; fn main() { trpl::run(async { - // ANCHOR: with-move let (tx, mut rx) = trpl::channel(); - let tx_fut = async move { + // ANCHOR: futures + let tx_fut = async { let vals = vec![ String::from("hi"), String::from("from"), @@ -23,12 +23,11 @@ fn main() { let rx_fut = async { while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); + println!("received '{value}'"); } }; trpl::join(tx_fut, rx_fut).await; - // ANCHOR_END: with-move + // ANCHOR_END: futures }); } -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-12/src/main.rs b/listings/ch17-async-await/listing-17-12/src/main.rs index d5a2e56e34..c22b7d2d75 100644 --- a/listings/ch17-async-await/listing-17-12/src/main.rs +++ b/listings/ch17-async-await/listing-17-12/src/main.rs @@ -4,11 +4,10 @@ use std::time::Duration; fn main() { trpl::run(async { - // ANCHOR: here + // ANCHOR: with-move let (tx, mut rx) = trpl::channel(); - let tx1 = tx.clone(); - let tx1_fut = async move { + let tx_fut = async move { let vals = vec![ String::from("hi"), String::from("from"), @@ -17,32 +16,18 @@ fn main() { ]; for val in vals { - tx1.send(val).unwrap(); + tx.send(val).unwrap(); trpl::sleep(Duration::from_millis(500)).await; } }; let rx_fut = async { while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; - - let tx_fut = async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_millis(1500)).await; + eprintln!("received '{value}'"); } }; - trpl::join3(tx1_fut, tx_fut, rx_fut).await; - // ANCHOR_END: here + trpl::join(tx_fut, rx_fut).await; + // ANCHOR_END: with-move }); } diff --git a/listings/ch17-async-await/listing-17-13/src/main.rs b/listings/ch17-async-await/listing-17-13/src/main.rs index 0bb425d366..d5a2e56e34 100644 --- a/listings/ch17-async-await/listing-17-13/src/main.rs +++ b/listings/ch17-async-await/listing-17-13/src/main.rs @@ -4,6 +4,7 @@ use std::time::Duration; fn main() { trpl::run(async { + // ANCHOR: here let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); @@ -17,7 +18,7 @@ fn main() { for val in vals { tx1.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; + trpl::sleep(Duration::from_millis(500)).await; } }; @@ -37,12 +38,11 @@ fn main() { for val in vals { tx.send(val).unwrap(); - trpl::sleep(Duration::from_secs(1)).await; + trpl::sleep(Duration::from_millis(1500)).await; } }; - // ANCHOR: here - trpl::join!(tx1_fut, tx_fut, rx_fut); + trpl::join3(tx1_fut, tx_fut, rx_fut).await; // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-14/src/main.rs b/listings/ch17-async-await/listing-17-14/src/main.rs index 249ffd0f68..0bb425d366 100644 --- a/listings/ch17-async-await/listing-17-14/src/main.rs +++ b/listings/ch17-async-await/listing-17-14/src/main.rs @@ -42,9 +42,7 @@ fn main() { }; // ANCHOR: here - let futures = vec![tx1_fut, rx_fut, tx_fut]; - - trpl::join_all(futures).await; + trpl::join!(tx1_fut, tx_fut, rx_fut); // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-15/src/main.rs b/listings/ch17-async-await/listing-17-15/src/main.rs index 9fefdcf463..249ffd0f68 100644 --- a/listings/ch17-async-await/listing-17-15/src/main.rs +++ b/listings/ch17-async-await/listing-17-15/src/main.rs @@ -42,8 +42,7 @@ fn main() { }; // ANCHOR: here - let futures = - vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + let futures = vec![tx1_fut, rx_fut, tx_fut]; trpl::join_all(futures).await; // ANCHOR_END: here diff --git a/listings/ch17-async-await/listing-17-16/Cargo.lock b/listings/ch17-async-await/listing-17-16/Cargo.lock index c0e8bb2b3f..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-16/Cargo.lock +++ b/listings/ch17-async-await/listing-17-16/Cargo.lock @@ -265,12 +265,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-16/src/main.rs b/listings/ch17-async-await/listing-17-16/src/main.rs index 1888a53568..9fefdcf463 100644 --- a/listings/ch17-async-await/listing-17-16/src/main.rs +++ b/listings/ch17-async-await/listing-17-16/src/main.rs @@ -1,6 +1,6 @@ extern crate trpl; // required for mdbook test -use std::{future::Future, time::Duration}; +use std::time::Duration; fn main() { trpl::run(async { @@ -42,10 +42,10 @@ fn main() { }; // ANCHOR: here - let futures: Vec>> = + let futures = vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; - // ANCHOR_END: here trpl::join_all(futures).await; + // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-17/Cargo.lock b/listings/ch17-async-await/listing-17-17/Cargo.lock index 2e0f3ebedb..c0e8bb2b3f 100644 --- a/listings/ch17-async-await/listing-17-17/Cargo.lock +++ b/listings/ch17-async-await/listing-17-17/Cargo.lock @@ -265,24 +265,12 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "tokio-stream" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "trpl" version = "0.1.0" dependencies = [ "futures", "tokio", - "tokio-stream", ] [[package]] diff --git a/listings/ch17-async-await/listing-17-16/output.txt b/listings/ch17-async-await/listing-17-17/output.txt similarity index 100% rename from listings/ch17-async-await/listing-17-16/output.txt rename to listings/ch17-async-await/listing-17-17/output.txt diff --git a/listings/ch17-async-await/listing-17-17/src/main.rs b/listings/ch17-async-await/listing-17-17/src/main.rs index 7773660519..1888a53568 100644 --- a/listings/ch17-async-await/listing-17-17/src/main.rs +++ b/listings/ch17-async-await/listing-17-17/src/main.rs @@ -1,17 +1,13 @@ extern crate trpl; // required for mdbook test -use std::{ - future::Future, - pin::{pin, Pin}, - time::Duration, -}; +use std::{future::Future, time::Duration}; fn main() { trpl::run(async { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); - let tx1_fut = pin!(async move { + let tx1_fut = async move { let vals = vec![ String::from("hi"), String::from("from"), @@ -23,15 +19,15 @@ fn main() { tx1.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }); + }; - let rx_fut = pin!(async { + let rx_fut = async { while let Some(value) = rx.recv().await { println!("received '{value}'"); } - }); + }; - let tx_fut = pin!(async move { + let tx_fut = async move { let vals = vec![ String::from("more"), String::from("messages"), @@ -43,11 +39,11 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - }); + }; // ANCHOR: here - let futures: Vec>>> = - vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; + let futures: Vec>> = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; // ANCHOR_END: here trpl::join_all(futures).await; diff --git a/listings/ch17-async-await/listing-17-18/src/main.rs b/listings/ch17-async-await/listing-17-18/src/main.rs index 41820fc8a5..7773660519 100644 --- a/listings/ch17-async-await/listing-17-18/src/main.rs +++ b/listings/ch17-async-await/listing-17-18/src/main.rs @@ -11,10 +11,7 @@ fn main() { let (tx, mut rx) = trpl::channel(); let tx1 = tx.clone(); - // ANCHOR: here let tx1_fut = pin!(async move { - // --snip-- - // ANCHOR_END: here let vals = vec![ String::from("hi"), String::from("from"), @@ -26,23 +23,15 @@ fn main() { tx1.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - // ANCHOR: here }); - // ANCHOR_END: here - // ANCHOR: here let rx_fut = pin!(async { - // --snip-- - // ANCHOR_END: here while let Some(value) = rx.recv().await { println!("received '{value}'"); } - // ANCHOR: here }); let tx_fut = pin!(async move { - // --snip-- - // ANCHOR_END: here let vals = vec![ String::from("more"), String::from("messages"), @@ -54,11 +43,11 @@ fn main() { tx.send(val).unwrap(); trpl::sleep(Duration::from_secs(1)).await; } - // ANCHOR: here }); - let futures: Vec>> = - vec![tx1_fut, rx_fut, tx_fut]; + // ANCHOR: here + let futures: Vec>>> = + vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; // ANCHOR_END: here trpl::join_all(futures).await; diff --git a/listings/ch17-async-await/listing-17-18/output.txt b/listings/ch17-async-await/listing-17-19/output.txt similarity index 100% rename from listings/ch17-async-await/listing-17-18/output.txt rename to listings/ch17-async-await/listing-17-19/output.txt diff --git a/listings/ch17-async-await/listing-17-19/src/main.rs b/listings/ch17-async-await/listing-17-19/src/main.rs index 12ab2704b2..41820fc8a5 100644 --- a/listings/ch17-async-await/listing-17-19/src/main.rs +++ b/listings/ch17-async-await/listing-17-19/src/main.rs @@ -1,14 +1,66 @@ extern crate trpl; // required for mdbook test +use std::{ + future::Future, + pin::{pin, Pin}, + time::Duration, +}; + fn main() { trpl::run(async { + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); // ANCHOR: here - let a = async { 1u32 }; - let b = async { "Hello!" }; - let c = async { true }; + let tx1_fut = pin!(async move { + // --snip-- + // ANCHOR_END: here + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR: here + }); - let (a_result, b_result, c_result) = trpl::join!(a, b, c); - println!("{a_result}, {b_result}, {c_result}"); // ANCHOR_END: here + // ANCHOR: here + let rx_fut = pin!(async { + // --snip-- + // ANCHOR_END: here + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + // ANCHOR: here + }); + + let tx_fut = pin!(async move { + // --snip-- + // ANCHOR_END: here + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_secs(1)).await; + } + // ANCHOR: here + }); + + let futures: Vec>> = + vec![tx1_fut, rx_fut, tx_fut]; + // ANCHOR_END: here + + trpl::join_all(futures).await; }); } diff --git a/listings/ch17-async-await/listing-17-20/Cargo.lock b/listings/ch17-async-await/listing-17-20/Cargo.lock index 3be4eaaa53..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-20/Cargo.lock +++ b/listings/ch17-async-await/listing-17-20/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", ] [[package]] -name = "tokio-macros" -version = "2.2.0" +name = "tokio-stream" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ - "proc-macro2", - "quote", - "syn", + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] @@ -386,6 +282,7 @@ version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] @@ -393,148 +290,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-20/src/main.rs b/listings/ch17-async-await/listing-17-20/src/main.rs index 308c14a4ac..12ab2704b2 100644 --- a/listings/ch17-async-await/listing-17-20/src/main.rs +++ b/listings/ch17-async-await/listing-17-20/src/main.rs @@ -1,23 +1,14 @@ extern crate trpl; // required for mdbook test -use std::time::Duration; - fn main() { trpl::run(async { // ANCHOR: here - let slow = async { - println!("'slow' started."); - trpl::sleep(Duration::from_millis(100)).await; - println!("'slow' finished."); - }; - - let fast = async { - println!("'fast' started."); - trpl::sleep(Duration::from_millis(50)).await; - println!("'fast' finished."); - }; + let a = async { 1u32 }; + let b = async { "Hello!" }; + let c = async { true }; - trpl::race(slow, fast).await; + let (a_result, b_result, c_result) = trpl::join!(a, b, c); + println!("{a_result}, {b_result}, {c_result}"); // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-21/Cargo.lock b/listings/ch17-async-await/listing-17-21/Cargo.lock index 2e0f3ebedb..3be4eaaa53 100644 --- a/listings/ch17-async-await/listing-17-21/Cargo.lock +++ b/listings/ch17-async-await/listing-17-21/Cargo.lock @@ -45,6 +45,18 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + [[package]] name = "cc" version = "1.0.97" @@ -164,6 +176,16 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "memchr" version = "2.7.2" @@ -179,6 +201,17 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -198,6 +231,29 @@ dependencies = [ "memchr", ] +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -228,12 +284,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.9" @@ -243,6 +323,22 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "syn" version = "2.0.63" @@ -261,19 +357,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", + "bytes", + "libc", + "mio", "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "tokio-macros" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -282,7 +386,6 @@ version = "0.1.0" dependencies = [ "futures", "tokio", - "tokio-stream", ] [[package]] @@ -290,3 +393,148 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-21/src/main.rs b/listings/ch17-async-await/listing-17-21/src/main.rs index 2dfb52b7d4..308c14a4ac 100644 --- a/listings/ch17-async-await/listing-17-21/src/main.rs +++ b/listings/ch17-async-await/listing-17-21/src/main.rs @@ -1,16 +1,23 @@ extern crate trpl; // required for mdbook test -use std::{thread, time::Duration}; +use std::time::Duration; fn main() { trpl::run(async { - // We will call `slow` here later - }); -} + // ANCHOR: here + let slow = async { + println!("'slow' started."); + trpl::sleep(Duration::from_millis(100)).await; + println!("'slow' finished."); + }; -// ANCHOR: slow -fn slow(name: &str, ms: u64) { - thread::sleep(Duration::from_millis(ms)); - println!("'{name}' ran for {ms}ms"); + let fast = async { + println!("'fast' started."); + trpl::sleep(Duration::from_millis(50)).await; + println!("'fast' finished."); + }; + + trpl::race(slow, fast).await; + // ANCHOR_END: here + }); } -// ANCHOR_END: slow diff --git a/listings/ch17-async-await/listing-17-22/src/main.rs b/listings/ch17-async-await/listing-17-22/src/main.rs index 391cf39e19..2dfb52b7d4 100644 --- a/listings/ch17-async-await/listing-17-22/src/main.rs +++ b/listings/ch17-async-await/listing-17-22/src/main.rs @@ -4,32 +4,13 @@ use std::{thread, time::Duration}; fn main() { trpl::run(async { - // ANCHOR: slow-futures - let a = async { - println!("'a' started."); - slow("a", 30); - slow("a", 10); - slow("a", 20); - trpl::sleep(Duration::from_millis(50)).await; - println!("'a' finished."); - }; - - let b = async { - println!("'b' started."); - slow("b", 75); - slow("b", 10); - slow("b", 15); - slow("b", 350); - trpl::sleep(Duration::from_millis(50)).await; - println!("'b' finished."); - }; - - trpl::race(a, b).await; - // ANCHOR_END: slow-futures + // We will call `slow` here later }); } +// ANCHOR: slow fn slow(name: &str, ms: u64) { thread::sleep(Duration::from_millis(ms)); println!("'{name}' ran for {ms}ms"); } +// ANCHOR_END: slow diff --git a/listings/ch17-async-await/listing-17-23/src/main.rs b/listings/ch17-async-await/listing-17-23/src/main.rs index 961431d396..391cf39e19 100644 --- a/listings/ch17-async-await/listing-17-23/src/main.rs +++ b/listings/ch17-async-await/listing-17-23/src/main.rs @@ -4,35 +4,28 @@ use std::{thread, time::Duration}; fn main() { trpl::run(async { - // ANCHOR: here - let one_ms = Duration::from_millis(1); - + // ANCHOR: slow-futures let a = async { println!("'a' started."); slow("a", 30); - trpl::sleep(one_ms).await; slow("a", 10); - trpl::sleep(one_ms).await; slow("a", 20); - trpl::sleep(one_ms).await; + trpl::sleep(Duration::from_millis(50)).await; println!("'a' finished."); }; let b = async { println!("'b' started."); slow("b", 75); - trpl::sleep(one_ms).await; slow("b", 10); - trpl::sleep(one_ms).await; slow("b", 15); - trpl::sleep(one_ms).await; - slow("b", 35); - trpl::sleep(one_ms).await; + slow("b", 350); + trpl::sleep(Duration::from_millis(50)).await; println!("'b' finished."); }; - // ANCHOR_END: here trpl::race(a, b).await; + // ANCHOR_END: slow-futures }); } diff --git a/listings/ch17-async-await/listing-17-24/src/main.rs b/listings/ch17-async-await/listing-17-24/src/main.rs index 165022108b..961431d396 100644 --- a/listings/ch17-async-await/listing-17-24/src/main.rs +++ b/listings/ch17-async-await/listing-17-24/src/main.rs @@ -4,31 +4,33 @@ use std::{thread, time::Duration}; fn main() { trpl::run(async { - // ANCHOR: yields + // ANCHOR: here + let one_ms = Duration::from_millis(1); + let a = async { println!("'a' started."); slow("a", 30); - trpl::yield_now().await; + trpl::sleep(one_ms).await; slow("a", 10); - trpl::yield_now().await; + trpl::sleep(one_ms).await; slow("a", 20); - trpl::yield_now().await; + trpl::sleep(one_ms).await; println!("'a' finished."); }; let b = async { println!("'b' started."); slow("b", 75); - trpl::yield_now().await; + trpl::sleep(one_ms).await; slow("b", 10); - trpl::yield_now().await; + trpl::sleep(one_ms).await; slow("b", 15); - trpl::yield_now().await; + trpl::sleep(one_ms).await; slow("b", 35); - trpl::yield_now().await; + trpl::sleep(one_ms).await; println!("'b' finished."); }; - // ANCHOR_END: yields + // ANCHOR_END: here trpl::race(a, b).await; }); diff --git a/listings/ch17-async-await/listing-17-25/Cargo.lock b/listings/ch17-async-await/listing-17-25/Cargo.lock index 3be4eaaa53..2e0f3ebedb 100644 --- a/listings/ch17-async-await/listing-17-25/Cargo.lock +++ b/listings/ch17-async-await/listing-17-25/Cargo.lock @@ -45,18 +45,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cc" version = "1.0.97" @@ -176,16 +164,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.2" @@ -201,17 +179,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -231,29 +198,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -284,36 +228,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -323,22 +243,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "syn" version = "2.0.63" @@ -357,27 +261,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", - "bytes", - "libc", - "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", ] [[package]] -name = "tokio-macros" -version = "2.2.0" +name = "tokio-stream" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ - "proc-macro2", - "quote", - "syn", + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] @@ -386,6 +282,7 @@ version = "0.1.0" dependencies = [ "futures", "tokio", + "tokio-stream", ] [[package]] @@ -393,148 +290,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-25/src/main.rs b/listings/ch17-async-await/listing-17-25/src/main.rs index 31ce58d9e9..165022108b 100644 --- a/listings/ch17-async-await/listing-17-25/src/main.rs +++ b/listings/ch17-async-await/listing-17-25/src/main.rs @@ -1,36 +1,40 @@ extern crate trpl; // required for mdbook test -use std::time::{Duration, Instant}; +use std::{thread, time::Duration}; fn main() { trpl::run(async { - // ANCHOR: here - let one_ns = Duration::from_nanos(1); - let start = Instant::now(); - async { - for _ in 1..1000 { - trpl::sleep(one_ns).await; - } - } - .await; - let time = Instant::now() - start; - println!( - "'sleep' version finished after {} seconds.", - time.as_secs_f32() - ); + // ANCHOR: yields + let a = async { + println!("'a' started."); + slow("a", 30); + trpl::yield_now().await; + slow("a", 10); + trpl::yield_now().await; + slow("a", 20); + trpl::yield_now().await; + println!("'a' finished."); + }; - let start = Instant::now(); - async { - for _ in 1..1000 { - trpl::yield_now().await; - } - } - .await; - let time = Instant::now() - start; - println!( - "'yield' version finished after {} seconds.", - time.as_secs_f32() - ); - // ANCHOR_END: here + let b = async { + println!("'b' started."); + slow("b", 75); + trpl::yield_now().await; + slow("b", 10); + trpl::yield_now().await; + slow("b", 15); + trpl::yield_now().await; + slow("b", 35); + trpl::yield_now().await; + println!("'b' finished."); + }; + // ANCHOR_END: yields + + trpl::race(a, b).await; }); } + +fn slow(name: &str, ms: u64) { + thread::sleep(Duration::from_millis(ms)); + println!("'{name}' ran for {ms}ms"); +} diff --git a/listings/ch17-async-await/listing-17-26/Cargo.lock b/listings/ch17-async-await/listing-17-26/Cargo.lock index 2e0f3ebedb..3be4eaaa53 100644 --- a/listings/ch17-async-await/listing-17-26/Cargo.lock +++ b/listings/ch17-async-await/listing-17-26/Cargo.lock @@ -45,6 +45,18 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + [[package]] name = "cc" version = "1.0.97" @@ -164,6 +176,16 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "memchr" version = "2.7.2" @@ -179,6 +201,17 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -198,6 +231,29 @@ dependencies = [ "memchr", ] +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -228,12 +284,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.9" @@ -243,6 +323,22 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "syn" version = "2.0.63" @@ -261,19 +357,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", + "bytes", + "libc", + "mio", "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "tokio-macros" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -282,7 +386,6 @@ version = "0.1.0" dependencies = [ "futures", "tokio", - "tokio-stream", ] [[package]] @@ -290,3 +393,148 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/listings/ch17-async-await/listing-17-26/src/main.rs b/listings/ch17-async-await/listing-17-26/src/main.rs index cdab724687..31ce58d9e9 100644 --- a/listings/ch17-async-await/listing-17-26/src/main.rs +++ b/listings/ch17-async-await/listing-17-26/src/main.rs @@ -1,21 +1,36 @@ extern crate trpl; // required for mdbook test -use std::time::Duration; +use std::time::{Duration, Instant}; fn main() { trpl::run(async { // ANCHOR: here - let slow = async { - trpl::sleep(Duration::from_millis(100)).await; - "I finished!" - }; + let one_ns = Duration::from_nanos(1); + let start = Instant::now(); + async { + for _ in 1..1000 { + trpl::sleep(one_ns).await; + } + } + .await; + let time = Instant::now() - start; + println!( + "'sleep' version finished after {} seconds.", + time.as_secs_f32() + ); - match timeout(slow, Duration::from_millis(10)).await { - Ok(message) => println!("Succeeded with '{message}'"), - Err(duration) => { - println!("Failed after {} seconds", duration.as_secs()) + let start = Instant::now(); + async { + for _ in 1..1000 { + trpl::yield_now().await; } } + .await; + let time = Instant::now() - start; + println!( + "'yield' version finished after {} seconds.", + time.as_secs_f32() + ); // ANCHOR_END: here }); } diff --git a/listings/ch17-async-await/listing-17-27/src/main.rs b/listings/ch17-async-await/listing-17-27/src/main.rs index d2edded63d..cdab724687 100644 --- a/listings/ch17-async-await/listing-17-27/src/main.rs +++ b/listings/ch17-async-await/listing-17-27/src/main.rs @@ -1,12 +1,13 @@ extern crate trpl; // required for mdbook test -use std::{future::Future, time::Duration}; +use std::time::Duration; fn main() { trpl::run(async { + // ANCHOR: here let slow = async { - trpl::sleep(Duration::from_secs(5)).await; - "Finally finished" + trpl::sleep(Duration::from_millis(100)).await; + "I finished!" }; match timeout(slow, Duration::from_millis(10)).await { @@ -15,14 +16,6 @@ fn main() { println!("Failed after {} seconds", duration.as_secs()) } } + // ANCHOR_END: here }); } - -// ANCHOR: declaration -async fn timeout( - future_to_try: F, - max_time: Duration, -) -> Result { - // Here is where our implementation will go! -} -// ANCHOR_END: declaration diff --git a/listings/ch17-async-await/listing-17-28/src/main.rs b/listings/ch17-async-await/listing-17-28/src/main.rs index 9efb5e7921..d2edded63d 100644 --- a/listings/ch17-async-await/listing-17-28/src/main.rs +++ b/listings/ch17-async-await/listing-17-28/src/main.rs @@ -2,12 +2,6 @@ extern crate trpl; // required for mdbook test use std::{future::Future, time::Duration}; -// ANCHOR: implementation -use trpl::Either; - -// --snip-- -// ANCHOR: implementation - fn main() { trpl::run(async { let slow = async { @@ -15,7 +9,7 @@ fn main() { "Finally finished" }; - match timeout(slow, Duration::from_secs(2)).await { + match timeout(slow, Duration::from_millis(10)).await { Ok(message) => println!("Succeeded with '{message}'"), Err(duration) => { println!("Failed after {} seconds", duration.as_secs()) @@ -24,14 +18,11 @@ fn main() { }); } +// ANCHOR: declaration async fn timeout( future_to_try: F, max_time: Duration, ) -> Result { - // ANCHOR: implementation - match trpl::race(future_to_try, trpl::sleep(max_time)).await { - Either::Left(output) => Ok(output), - Either::Right(_) => Err(max_time), - } - // ANCHOR_END: implementation + // Here is where our implementation will go! } +// ANCHOR_END: declaration diff --git a/listings/ch17-async-await/listing-17-29/Cargo.lock b/listings/ch17-async-await/listing-17-29/Cargo.lock index 36905af42a..a55aeb1e1c 100644 --- a/listings/ch17-async-await/listing-17-29/Cargo.lock +++ b/listings/ch17-async-await/listing-17-29/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.22.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -32,9 +51,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -45,11 +64,41 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" -version = "1.0.99" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" [[package]] name = "cfg-if" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,11 +337,65 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" -version = "0.29.0" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hermit-abi" @@ -159,134 +404,1457 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "libc" -version = "0.2.155" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "memchr" -version = "2.7.4" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "adler", + "bytes", + "http", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", ] [[package]] -name = "object" -version = "0.36.0" +name = "httparse" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "memchr", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper-util" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] -name = "quote" -version = "1.0.36" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "indexmap" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] [[package]] -name = "slab" -version = "0.4.9" +name = "ipnet" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", + "scopeguard", ] [[package]] -name = "syn" -version = "2.0.66" +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "adler", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "mio" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "libc", + "wasi", + "windows-sys 0.48.0", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "new_debug_unreachable" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-29/Cargo.toml b/listings/ch17-async-await/listing-17-29/Cargo.toml index e094f067f1..349041d3eb 100644 --- a/listings/ch17-async-await/listing-17-29/Cargo.toml +++ b/listings/ch17-async-await/listing-17-29/Cargo.toml @@ -4,5 +4,6 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + [dependencies] trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-29/src/main.rs b/listings/ch17-async-await/listing-17-29/src/main.rs index faa6b6a1ca..9efb5e7921 100644 --- a/listings/ch17-async-await/listing-17-29/src/main.rs +++ b/listings/ch17-async-await/listing-17-29/src/main.rs @@ -1,15 +1,37 @@ extern crate trpl; // required for mdbook test +use std::{future::Future, time::Duration}; + +// ANCHOR: implementation +use trpl::Either; + +// --snip-- +// ANCHOR: implementation + fn main() { trpl::run(async { - // ANCHOR: stream - let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - let iter = values.iter().map(|n| n * 2); - let mut stream = trpl::stream_from_iter(iter); + let slow = async { + trpl::sleep(Duration::from_secs(5)).await; + "Finally finished" + }; - while let Some(value) = stream.next().await { - println!("The value was: {value}"); + match timeout(slow, Duration::from_secs(2)).await { + Ok(message) => println!("Succeeded with '{message}'"), + Err(duration) => { + println!("Failed after {} seconds", duration.as_secs()) + } } - // ANCHOR_END: stream }); } + +async fn timeout( + future_to_try: F, + max_time: Duration, +) -> Result { + // ANCHOR: implementation + match trpl::race(future_to_try, trpl::sleep(max_time)).await { + Either::Left(output) => Ok(output), + Either::Right(_) => Err(max_time), + } + // ANCHOR_END: implementation +} diff --git a/listings/ch17-async-await/listing-17-30/src/main.rs b/listings/ch17-async-await/listing-17-30/src/main.rs index 0a7fc87c21..faa6b6a1ca 100644 --- a/listings/ch17-async-await/listing-17-30/src/main.rs +++ b/listings/ch17-async-await/listing-17-30/src/main.rs @@ -1,9 +1,8 @@ extern crate trpl; // required for mdbook test -use trpl::StreamExt; - fn main() { trpl::run(async { + // ANCHOR: stream let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let iter = values.iter().map(|n| n * 2); let mut stream = trpl::stream_from_iter(iter); @@ -11,5 +10,6 @@ fn main() { while let Some(value) = stream.next().await { println!("The value was: {value}"); } + // ANCHOR_END: stream }); } diff --git a/listings/ch17-async-await/listing-17-31/src/main.rs b/listings/ch17-async-await/listing-17-31/src/main.rs index 017185bed5..0a7fc87c21 100644 --- a/listings/ch17-async-await/listing-17-31/src/main.rs +++ b/listings/ch17-async-await/listing-17-31/src/main.rs @@ -4,14 +4,11 @@ use trpl::StreamExt; fn main() { trpl::run(async { - let values = 1..101; - let iter = values.map(|n| n * 2); - let stream = trpl::stream_from_iter(iter); + let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let iter = values.iter().map(|n| n * 2); + let mut stream = trpl::stream_from_iter(iter); - let mut filtered = - stream.filter(|value| value % 3 == 0 || value % 5 == 0); - - while let Some(value) = filtered.next().await { + while let Some(value) = stream.next().await { println!("The value was: {value}"); } }); diff --git a/listings/ch17-async-await/listing-17-32/src/main.rs b/listings/ch17-async-await/listing-17-32/src/main.rs index d9a7733d43..017185bed5 100644 --- a/listings/ch17-async-await/listing-17-32/src/main.rs +++ b/listings/ch17-async-await/listing-17-32/src/main.rs @@ -1,26 +1,18 @@ extern crate trpl; // required for mdbook test -// ANCHOR: all -use trpl::{ReceiverStream, Stream, StreamExt}; +use trpl::StreamExt; fn main() { trpl::run(async { - let mut messages = get_messages(); + let values = 1..101; + let iter = values.map(|n| n * 2); + let stream = trpl::stream_from_iter(iter); - while let Some(message) = messages.next().await { - println!("{message}"); + let mut filtered = + stream.filter(|value| value % 3 == 0 || value % 5 == 0); + + while let Some(value) = filtered.next().await { + println!("The value was: {value}"); } }); } - -fn get_messages() -> impl Stream { - let (tx, rx) = trpl::channel(); - - let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; - for message in messages { - tx.send(format!("Message: '{message}'")).unwrap(); - } - - ReceiverStream::new(rx) -} -// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-33/src/main.rs b/listings/ch17-async-await/listing-17-33/src/main.rs index de919073f8..d9a7733d43 100644 --- a/listings/ch17-async-await/listing-17-33/src/main.rs +++ b/listings/ch17-async-await/listing-17-33/src/main.rs @@ -1,23 +1,17 @@ extern crate trpl; // required for mdbook test -// ANCHOR: timeout -use std::{pin::pin, time::Duration}; +// ANCHOR: all use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { trpl::run(async { - let mut messages = - pin!(get_messages().timeout(Duration::from_millis(200))); + let mut messages = get_messages(); - while let Some(result) = messages.next().await { - match result { - Ok(message) => println!("{message}"), - Err(reason) => eprintln!("Problem: {reason:?}"), - } + while let Some(message) = messages.next().await { + println!("{message}"); } - }) + }); } -// ANCHOR_END: timeout fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); @@ -29,3 +23,4 @@ fn get_messages() -> impl Stream { ReceiverStream::new(rx) } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-34/src/main.rs b/listings/ch17-async-await/listing-17-34/src/main.rs index b4dda21d52..de919073f8 100644 --- a/listings/ch17-async-await/listing-17-34/src/main.rs +++ b/listings/ch17-async-await/listing-17-34/src/main.rs @@ -1,7 +1,7 @@ extern crate trpl; // required for mdbook test +// ANCHOR: timeout use std::{pin::pin, time::Duration}; - use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { @@ -17,21 +17,15 @@ fn main() { } }) } +// ANCHOR_END: timeout -// ANCHOR: messages fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); - trpl::spawn_task(async move { - let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; - for (index, message) in messages.into_iter().enumerate() { - let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; - trpl::sleep(Duration::from_millis(time_to_sleep)).await; - - tx.send(format!("Message: '{message}'")).unwrap(); - } - }); + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for message in messages { + tx.send(format!("Message: '{message}'")).unwrap(); + } ReceiverStream::new(rx) } -// ANCHOR_END: messages diff --git a/listings/ch17-async-await/listing-17-35/src/main.rs b/listings/ch17-async-await/listing-17-35/src/main.rs index 13bd0b1121..b4dda21d52 100644 --- a/listings/ch17-async-await/listing-17-35/src/main.rs +++ b/listings/ch17-async-await/listing-17-35/src/main.rs @@ -18,6 +18,7 @@ fn main() { }) } +// ANCHOR: messages fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); @@ -33,20 +34,4 @@ fn get_messages() -> impl Stream { ReceiverStream::new(rx) } - -// ANCHOR: intervals -fn get_intervals() -> impl Stream { - let (tx, rx) = trpl::channel(); - - trpl::spawn_task(async move { - let mut count = 0; - loop { - trpl::sleep(Duration::from_millis(1)).await; - count += 1; - tx.send(count).unwrap(); - } - }); - - ReceiverStream::new(rx) -} -// ANCHOR_END: intervals +// ANCHOR_END: messages diff --git a/listings/ch17-async-await/listing-17-36/src/main.rs b/listings/ch17-async-await/listing-17-36/src/main.rs index bc10dd48c9..13bd0b1121 100644 --- a/listings/ch17-async-await/listing-17-36/src/main.rs +++ b/listings/ch17-async-await/listing-17-36/src/main.rs @@ -6,13 +6,10 @@ use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { trpl::run(async { - // ANCHOR: main - let messages = get_messages().timeout(Duration::from_millis(200)); - let intervals = get_intervals(); - let merged = messages.merge(intervals); - // ANCHOR_END: main + let mut messages = + pin!(get_messages().timeout(Duration::from_millis(200))); - while let Some(result) = merged.next().await { + while let Some(result) = messages.next().await { match result { Ok(message) => println!("{message}"), Err(reason) => eprintln!("Problem: {reason:?}"), @@ -37,6 +34,7 @@ fn get_messages() -> impl Stream { ReceiverStream::new(rx) } +// ANCHOR: intervals fn get_intervals() -> impl Stream { let (tx, rx) = trpl::channel(); @@ -51,3 +49,4 @@ fn get_intervals() -> impl Stream { ReceiverStream::new(rx) } +// ANCHOR_END: intervals diff --git a/listings/ch17-async-await/listing-17-37/src/main.rs b/listings/ch17-async-await/listing-17-37/src/main.rs index 72da09d75f..bc10dd48c9 100644 --- a/listings/ch17-async-await/listing-17-37/src/main.rs +++ b/listings/ch17-async-await/listing-17-37/src/main.rs @@ -8,14 +8,11 @@ fn main() { trpl::run(async { // ANCHOR: main let messages = get_messages().timeout(Duration::from_millis(200)); - let intervals = get_intervals() - .map(|count| format!("Interval: {count}")) - .timeout(Duration::from_secs(10)); + let intervals = get_intervals(); let merged = messages.merge(intervals); - let mut stream = pin!(merged); // ANCHOR_END: main - while let Some(result) = stream.next().await { + while let Some(result) = merged.next().await { match result { Ok(message) => println!("{message}"), Err(reason) => eprintln!("Problem: {reason:?}"), diff --git a/listings/ch17-async-await/listing-17-38/src/main.rs b/listings/ch17-async-await/listing-17-38/src/main.rs index a5f51618f5..72da09d75f 100644 --- a/listings/ch17-async-await/listing-17-38/src/main.rs +++ b/listings/ch17-async-await/listing-17-38/src/main.rs @@ -6,15 +6,14 @@ use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { trpl::run(async { - // ANCHOR: throttle + // ANCHOR: main let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() - .map(|count| format!("Interval #{count}")) - .throttle(Duration::from_millis(100)) + .map(|count| format!("Interval: {count}")) .timeout(Duration::from_secs(10)); - let merged = messages.merge(intervals).take(20); + let merged = messages.merge(intervals); let mut stream = pin!(merged); - // ANCHOR_END: throttle + // ANCHOR_END: main while let Some(result) = stream.next().await { match result { diff --git a/listings/ch17-async-await/listing-17-39/src/main.rs b/listings/ch17-async-await/listing-17-39/src/main.rs index ecf406e93d..a5f51618f5 100644 --- a/listings/ch17-async-await/listing-17-39/src/main.rs +++ b/listings/ch17-async-await/listing-17-39/src/main.rs @@ -6,38 +6,35 @@ use trpl::{ReceiverStream, Stream, StreamExt}; fn main() { trpl::run(async { + // ANCHOR: throttle let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() .map(|count| format!("Interval #{count}")) - .throttle(Duration::from_millis(500)) + .throttle(Duration::from_millis(100)) .timeout(Duration::from_secs(10)); let merged = messages.merge(intervals).take(20); let mut stream = pin!(merged); + // ANCHOR_END: throttle while let Some(result) = stream.next().await { match result { - Ok(item) => println!("{item}"), + Ok(message) => println!("{message}"), Err(reason) => eprintln!("Problem: {reason:?}"), } } - }); + }) } -// ANCHOR: errors fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); trpl::spawn_task(async move { let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; - for (index, message) in messages.into_iter().enumerate() { let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; trpl::sleep(Duration::from_millis(time_to_sleep)).await; - if let Err(send_error) = tx.send(format!("Message: '{message}'")) { - eprintln!("Cannot send message '{message}': {send_error}"); - break; - } + tx.send(format!("Message: '{message}'")).unwrap(); } }); @@ -52,14 +49,9 @@ fn get_intervals() -> impl Stream { loop { trpl::sleep(Duration::from_millis(1)).await; count += 1; - - if let Err(send_error) = tx.send(count) { - eprintln!("Could not send interval {count}: {send_error}"); - break; - }; + tx.send(count).unwrap(); } }); ReceiverStream::new(rx) } -// ANCHOR_END: errors diff --git a/listings/ch17-async-await/listing-17-40/src/main.rs b/listings/ch17-async-await/listing-17-40/src/main.rs index f1f3d4b0c0..ecf406e93d 100644 --- a/listings/ch17-async-await/listing-17-40/src/main.rs +++ b/listings/ch17-async-await/listing-17-40/src/main.rs @@ -1,6 +1,6 @@ extern crate trpl; // required for mdbook test -use std::{pin::pin, thread, time::Duration}; +use std::{pin::pin, time::Duration}; use trpl::{ReceiverStream, Stream, StreamExt}; @@ -23,6 +23,7 @@ fn main() { }); } +// ANCHOR: errors fn get_messages() -> impl Stream { let (tx, rx) = trpl::channel(); @@ -43,16 +44,13 @@ fn get_messages() -> impl Stream { ReceiverStream::new(rx) } -// ANCHOR: threads fn get_intervals() -> impl Stream { let (tx, rx) = trpl::channel(); - // This is *not* `trpl::spawn` but `std::thread::spawn`! - thread::spawn(move || { + trpl::spawn_task(async move { let mut count = 0; loop { - // Likewise, this is *not* `trpl::sleep` but `std::thread::sleep`! - thread::sleep(Duration::from_millis(1)); + trpl::sleep(Duration::from_millis(1)).await; count += 1; if let Err(send_error) = tx.send(count) { @@ -64,4 +62,4 @@ fn get_intervals() -> impl Stream { ReceiverStream::new(rx) } -// ANCHOR_END: threads +// ANCHOR_END: errors diff --git a/listings/ch17-async-await/listing-17-41/Cargo.lock b/listings/ch17-async-await/listing-17-41/Cargo.lock new file mode 100644 index 0000000000..36905af42a --- /dev/null +++ b/listings/ch17-async-await/listing-17-41/Cargo.lock @@ -0,0 +1,292 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "tokio", + "tokio-stream", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch17-async-await/listing-17-41/Cargo.toml b/listings/ch17-async-await/listing-17-41/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-41/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-41/src/main.rs b/listings/ch17-async-await/listing-17-41/src/main.rs new file mode 100644 index 0000000000..f1f3d4b0c0 --- /dev/null +++ b/listings/ch17-async-await/listing-17-41/src/main.rs @@ -0,0 +1,67 @@ +extern crate trpl; // required for mdbook test + +use std::{pin::pin, thread, time::Duration}; + +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::run(async { + let messages = get_messages().timeout(Duration::from_millis(200)); + let intervals = get_intervals() + .map(|count| format!("Interval #{count}")) + .throttle(Duration::from_millis(500)) + .timeout(Duration::from_secs(10)); + let merged = messages.merge(intervals).take(20); + let mut stream = pin!(merged); + + while let Some(result) = stream.next().await { + match result { + Ok(item) => println!("{item}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }); +} + +fn get_messages() -> impl Stream { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + if let Err(send_error) = tx.send(format!("Message: '{message}'")) { + eprintln!("Cannot send message '{message}': {send_error}"); + break; + } + } + }); + + ReceiverStream::new(rx) +} + +// ANCHOR: threads +fn get_intervals() -> impl Stream { + let (tx, rx) = trpl::channel(); + + // This is *not* `trpl::spawn` but `std::thread::spawn`! + thread::spawn(move || { + let mut count = 0; + loop { + // Likewise, this is *not* `trpl::sleep` but `std::thread::sleep`! + thread::sleep(Duration::from_millis(1)); + count += 1; + + if let Err(send_error) = tx.send(count) { + eprintln!("Could not send interval {count}: {send_error}"); + break; + }; + } + }); + + ReceiverStream::new(rx) +} +// ANCHOR_END: threads diff --git a/packages/trpl/Cargo.lock b/packages/trpl/Cargo.lock index 03bebc8dd8..bc42cb8b60 100644 --- a/packages/trpl/Cargo.lock +++ b/packages/trpl/Cargo.lock @@ -17,6 +17,25 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -38,6 +57,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + [[package]] name = "cc" version = "1.0.98" @@ -50,6 +99,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -139,6 +330,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -146,140 +366,1488 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.3" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] -name = "proc-macro2" -version = "1.0.84" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/packages/trpl/Cargo.toml b/packages/trpl/Cargo.toml index 5fd0029ac7..62a602ea19 100644 --- a/packages/trpl/Cargo.toml +++ b/packages/trpl/Cargo.toml @@ -12,6 +12,8 @@ authors = ["Chris Krycho "] [dependencies] futures = "0.3" +reqwest = "0.12" +scraper = "0.20" tokio = { version = "1", default-features = false, features = [ "fs", "rt-multi-thread", diff --git a/packages/trpl/src/lib.rs b/packages/trpl/src/lib.rs index 6d3a4bdaab..999cb6e273 100644 --- a/packages/trpl/src/lib.rs +++ b/packages/trpl/src/lib.rs @@ -97,3 +97,54 @@ where Either::Right((b, _f1)) => Either::Right(b), } } + +/// Fetch data from a URL. For more convenient use in _The Rust Programming +/// Language_, panics instead of returning a [`Result`] if the request fails. +pub async fn get(url: &str) -> Response { + Response(reqwest::get(url).await.unwrap()) +} + +/// A thin wrapper around [`reqwest::Response`] to make the demos in _The Rust +/// Programming Language_ substantially nicer to use. +pub struct Response(reqwest::Response); + +impl Response { + /// Get the full response text. + /// + /// If the response cannot be deserialized, this panics instead of returning + /// a [`Result`] (for convenience in the demo). + pub async fn text(self) -> String { + self.0.text().await.unwrap() + } +} + +/// A thin wrapper around [`scraper::Html`] to make the demos in _The Rust +/// Programming Language_ substantially nicer to use. +pub struct Html { + inner: scraper::Html, +} + +impl Html { + /// Parse an HTML document from a string. + /// + /// This is just a thin wrapper around `scraper::Html::parse_document` to + /// keep the exported API surface simpler. + pub fn parse(source: &str) -> Html { + Html { + inner: scraper::Html::parse_document(source), + } + } + + /// Get the first item in the document matching a string selector. Returns + /// Some() + /// + /// If the selector is not a valid CSS selector, panics rather than + /// returning a [`Result`] for convenience. + pub fn select_first<'a>( + &'a self, + selector: &'a str, + ) -> Option> { + let selector = scraper::Selector::parse(selector).unwrap(); + self.inner.select(&selector).nth(0) + } +} diff --git a/packages/trpl/tests/integration/main.rs b/packages/trpl/tests/integration/main.rs index b67d8680a7..afc5f81864 100644 --- a/packages/trpl/tests/integration/main.rs +++ b/packages/trpl/tests/integration/main.rs @@ -229,3 +229,14 @@ fn re_exported_interval_stream_works() { assert!(interval_stream.next().await.is_none()); }); } + +#[test] +fn re_exported_html() { + use trpl::Html; + + let doc = Html::parse( + "

Hello!

", + ); + let p = doc.select_first("p").map(|el| el.inner_html()); + assert_eq!(p, Some(String::from("Hello!"))); +} diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 687ce8870b..bf7e26bde0 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -1,72 +1,163 @@ ## Futures and the Async Syntax -They key elements of asynchronous programming in Rust are *futures* and Rust’s +The key elements of asynchronous programming in Rust are *futures* and Rust’s `async` and `await` keywords. -A future is a value that may not ready yet. Every future holds its own -information about the progress that has been made and what "ready" means. In -Rust, we say that types which implement the `Future` trait are futures. The -`async` keyword can be applied to blocks and functions to specify that they can -be interrupted and resumed. Within an async block or async function, you can use -the `await` keyword to wait for a future to become ready, called *awaiting a +A *future* is a value which may not be ready now, but will become ready at some +point in the future. (This same concept shows up in many languages, sometimes +under other names like “task” or “promise”.) Rust provides a `Future` trait as a +building block so different async operations can be implemented with different +data structures, but with a common interface. In Rust, we say that types which +implement the `Future` trait are futures. Each type which implements `Future` +holds its own information about the progress that has been made and what "ready" +means. + +The `async` keyword can be applied to blocks and functions to specify that they +can be interrupted and resumed. Within an async block or async function, you can +use the `await` keyword to wait for a future to become ready, called *awaiting a future*. Each place you await a future within an async block or function is a place that async block or function may get paused and resumed. -> Note: Many other languages use the `async` and `await` keywords for async -> programming. If you are familiar with other languages’ approach to async, you -> may notice some significant differences in how Rust does things, including how -> it handles the syntax. That is for good reason, as we will see! +Some other languages also use `async` and `await` keywords for async +programming. If you are familiar with those languages, you may notice some +significant differences in how Rust does things, including how it handles the +syntax. That is for good reason, as we will see! + +Most of the time when writing async Rust, we use the `async` and `await` +keywords. Rust compiles them into equivalent code using the `Future` trait, much +like it compiles `for` loops into equivalent code using the `Iterator` trait. +Because Rust provides the `Future` trait, though, you can also implement it for +your own data types when you need to. Many of the functions we will see +throughout this chapter return types with their own implementations of `Future`. +We will return to the definition of the trait at the end of the chapter and dig +into more of how it works, but this is enough detail to keep us moving forward. That may all feel a bit abstract. Let’s write our first async program: a little -web scraper. This will have a fair bit of new syntax, but don’t worry. We will -explain it all as we go. +web scraper. We will pass in two URLs from the command line, fetch both of them +concurrently, and return the result of whichever one finishes first. This +example will have a fair bit of new syntax, but don’t worry. We will explain +everything you need to know as we go. - +### Our First Async Program + +To keep this chapter focused on learning async, rather than juggling parts of +the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust +Programming Language”). It re-exports all the types, traits, and functions you +will need, primarily from the [`futures`][futures-crate] and [`tokio`][tokio] +crates. + +- The `futures` crate is an official home for Rust experimentation for async + code, and is actually where the `Future` type was originally designed. + +- Tokio is the most widely used async runtime in Rust today, especially (but + not only!) for web applications. There are other great runtimes out there, + and they may be more suitable for your purposes. We use Tokio under the hood + for `trpl` because it is good and widely used. + +In some cases, `trpl` also renames or wraps the original APIs to let us stay +focused on the details relevant to chapter. If you want to understand what the +crate does, we encourage you to check out [its source code][crate-source]. You +will be able to see what crate each re-export comes from, and we have left +extensive comments explaining what the crate does. + +Go ahead and add the `trpl` crate to your `hello-async` project: + +```console +$ cargo add trpl +``` -Let’s write our first async function, and call it: +Now we can use the various pieces provided by `trpl` to write our first async +program. We will build a little command line tool which fetches two web pages, +pulls the `` element from each, and prints out the title of whichever +finishes that whole process first. -<Listing number="17-1" file-name="src/main.rs" caption="Defining a very simple async function"> +<Listing number="17-1" file-name="src/main.rs" caption="Defining an async function to get the title element from an HTML page"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:all}} +{{#include ../listings/ch17-async-await/listing-17-01/src/main.rs:all}} ``` </Listing> -If we compile and run this… nothing happens, and we get a compiler warning: +In Listing 17-1, we define a function named `page_title`, and we mark it with +the `async` keyword. Then we use the `trpl::get` function to fetch whatever URL +is passed in, and, and we await the response by using the `await` keyword. Then +we get the text of the response by calling its `text` method and once again +awaiting it with the `await` keyword. Both of these steps are asynchronous. For +`get`, we need to wait for the server to send back the first part of its +response, which will include HTTP headers, cookies, and so on. That part of the +response can be delivered separately from the body of the request. Especially if +the body is very large, it can take some time for it all to arrive. Thus, we +have to wait for the *entirety* of the response to arrive, so the `text` method +is also async. + +We have to explicitly await both of these futures, because futures in Rust are +*lazy*: they don’t do anything until you ask them to with `await`. (In fact, +Rust will show a compiler warning if you do not use a future.) This should +remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. +Iterators do nothing unless you call their `next` method—whether directly, or +using `for` loops or methods like `map` which use `next` under the hood. With +futures, the same basic idea applies: they do nothing unless you explicitly ask +them to. This laziness allows Rust to avoid running async code until it is +actually needed. -```console -{{#include ../listings/ch17-async-await/listing-17-01/output.txt}} -``` +> Note: This is different from the behavior we saw when using `thread::spawn` in +> the previous chapter, where the closure we passed to another thread started +> running immediately. It is also different from how many other languages +> approach async! But it is important for Rust. We will see why that is later. -The warning tells us that just calling `hello` was not enough: we also need to -`.await` or poll the future it returns. This raises some important questions: +Once we have `response_text`, we can then parse it into an instance of the +`Html` type using `Html::parse`. Instead of a raw string, we now have a data +type we can use to work with the HTML as a richer data structure. In particular, +we can use the `select_first` method to find the first instance of a given CSS +selector. By passing the string `"title"`, we will get the first `<title>` +element in the document, if there is one. Since there may not be any matching +element, `select_first` returns an `Option<ElementRef>`. Finally, we use the +`Option::map` method, which lets us work with the item in the `Option` if it is +present, and do nothing if it is not. (We could also use a `match` expression +here, but `map` is more idiomatic.) In the body of the function we supply to +`map`, we call `inner_html` on the `title_element` to get its content, which is +a `String`. When all is said and done, we have an `Option<String>`. + +Notice that Rust’s `await` keyword goes after the expression you are awaiting, +not before it. That is, it is a *postfix keyword*. This may be different from +what you might be used to if you have used async in other languages. Rust chose +this because it makes chains of methods much nicer to work with. As a result, we +can change the body of `page_url_for` to chain the `trpl::get` and `text` +function calls together with `await` between them, as shown in Listing 17-2: + +<Listing number="17-2" file-name="src/main.rs" caption="Chaining with the `await` keyword"> -- Given there is no return type on the function, how is it returning a future? -- What exactly is a future? -- Why do we need to `.await` or poll futures to make them do something? -- How do `.await` and polling relate to each other? +```rust +{{#include ../listings/ch17-async-await/listing-17-02/src/main.rs:chaining}} +``` + +</Listing> -We will work through each of these in turn. We can answer the first question by -learning what the syntax means, so let’s start there. +With that, we have successfully written our first async function! Before we add +some code in `main` to call it, let’s talk a little more about what we have +written and what it means. -### Async Functions +When Rust sees a block marked with the `async` keyword, it compiles it into a +unique, anonymous data type which implements the `Future` trait. When Rust +sees a function marked with `async`, it compiles it into a non-async function +whose body is an async block. Thus, an async function’s return type is the type +of the anonymous data type the compiler creates for that async block. -In Rust, writing `async fn` is equivalent to writing a function which returns a -*future* of the return type. That is, when the compiler sees a function like -`async fn hello` in Listing 17-1, it is equivalent to a function defined like -this instead: +Thus, writing `async fn` is equivalent to writing a function which returns a +*future* of the return type. When the compiler sees a function like `async fn +page_title` in Listing 17-1, it is equivalent to a non-async function defined +like this: ```rust use std::future::Future; -fn hello<'a>(name: &'a str) -> impl Future<Output = ()> + 'a { +fn page_title(url: &str) -> impl Future<Output = Option<String>> + '_ { async move { - let greeting = format!("Hello, {name}!"); - println!("{greeting}"); + let text = trpl::get(url).await.text().await; + Html::parse(&text) + .select_first("title") + .map(|title| title.inner_html()) } } ``` @@ -76,137 +167,90 @@ Let’s walk through each part of the transformed version: * It uses the `impl Trait` syntax we discussed back in the [“Traits as Parameters”][impl-trait] section in Chapter 10. * The returned trait is a `Future`, with an associated type of `Output`. Notice - that the `Output` type is `()`, which is the same as the the original return - type from the `async fn` version of `hello`. + that the `Output` type is `Option<String>`, which is the same as the the + original return type from the `async fn` version of `page_title`. * All of the code called in the body of the original function is wrapped in an `async move` block. Remember that blocks are expressions. This whole block is the expression returned from the function. +* This async block produces a value with the type `Option<String>`, as described + above. That value matches the `Output` type in the return type. This is just + like other blocks you have seen. * The new function body is an `async move` block because of how it uses the - `name` argument. -* The new version of the function makes the lifetime of the `name` parameter - explicit so that it can reference it in the output type. -* The async block itself has the “unit” value `()`, since it ends with a - `println!` statement. That value matches the `Output` type in the return type. - -An `async` block corresponds to a data type which implements the `Future` trait, -and the result of the async block will be the `Output` of the `Future`. Thus, an -`async fn`’s return type is an anonymous data type the compiler creates for us, -which implements `Future`. The associated `Output` type for the `Future` is the -return type of the original `async fn`. Thus, calling `hello` in Listing 17-1 -returned a `Future<Output = ()>`. - -Then Rust warned us that we did not do anything with the future. This is because -futures are *lazy*: they don’t do anything until you ask them to with `await`. -This should remind you of our discussion of iterators [back in Chapter -13][iterators-lazy]. Iterators do nothing unless you call their `next` -method—whether directly, or using `for` loops or methods like `map` which use -`next` under the hood. - -With futures, the same basic idea applies: they do nothing unless you explicitly -ask them to. This laziness allows Rust to avoid running async code until it is -actually needed. - -> Note: This is different from the behavior we saw when using `thread::spawn` in -> the previous chapter, where the closure we passed to another thread started -> running immediately. It is also different from how many other languages -> approach async! But it is important for Rust. We will see why that is later. -<!-- TODO: we need to pay off that promise later in the chapter! --> - -For now, let’s start by awaiting the future returned by `hello` to actually have -it run. Rust’s `await` keyword goes after the expression you are awaiting, not -before it. That is, it is a *postfix keyword*. (This is different from what you -might be used to if you have used async in languages like JavaScript or C#. Rust -chose this because it makes chains of methods much nicer to work with.) In -Listing 17-2, we add `.await` to the `hello` call in `main`. - -<Listing number="17-2" caption="Attempting to fix a compiler warning by awaiting a future" file-name="src/main.rs"> + `name` argument. (We will talk about `async` vs. `async move` much more later + in the chapter.) +* The new version of the function has a kind of lifetime we have not seen before + in the output type: `'_`. Because the function returns a `Future` which refers + to a reference—in this case, the reference from the `url` parameter—we need to + tell Rust that we mean for that reference to be included. We do not have to + name the lifetime here, because Rust is smart enough to know there is only one + reference which could be involved, but we *do* have to be explicit that the + resulting `Future` is bound by that lifetime. + +Now we can call `page_title` in `main`. To start, we will just get the title for +a single page. In Listing 17-3, we follow the same pattern we used for getting +command line arguments back in Chapter 12. Then we pass the first URL +`page_title`, and await the result. Since the value produced by the future is an +`Option<String>`, we use a `match` expression to print different messages to +account for whether the page had a `<title>`. + +<Listing number="17-3" file-name="src/main.rs" caption="Calling the `page_title` function from `main` with a user-supplied argument"> -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-02/src/main.rs:main}} +```rust +{{#include ../listings/ch17-async-await/listing-17-03/src/main.rs:main}} ``` </Listing> -Oh no! We have gone from a compiler warning to an actual error: - -```console -{{#include ../listings/ch17-async-await/listing-17-02/output.txt}} -``` - -This time, the compiler is informing us we cannot use `.await` in `main`, -because `main` is not an `async` function. Your first thought might be to make -`main` an async function then, as in Listing 17-3. - -<Listing number="17-3" caption="Attempting to make `main` an `async fn`" file-name="src/main.rs"> - -```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-03/src/main.rs:main}} -``` - -</Listing> +Unfortunately, this does not compile. The only place we can use the `await` +keyword is in async functions or blocks, so Rust will not let us mark `main` as +`async`. -However, we get another compiler error here: +<!-- manual-regeneration +cd listings/ch17-async-await/listing-17-03 +cargo build +copy just the compiler error +--> -```console -{{#include ../listings/ch17-async-await/listing-17-03/output.txt}} +```text +error[E0752]: `main` function is not allowed to be `async` + --> src/main.rs:6:1 + | +6 | async fn main() { + | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` ``` -Rust won't allow us too mark `main` as `async`. The underlying problem is that -async code needs a *runtime*: a Rust crate which manages the details of -executing asynchronous code. A program's `main` function can initialize a -runtime, but it is not a runtime itself. (We will see more about why this is a -bit later.) +The reason is that async code needs a *runtime*: a Rust crate which manages the +details of executing asynchronous code. A program's `main` function can +initialize a runtime, but it is not a runtime itself. (We will see more about +why this is a bit later.) Every async program in Rust has at least one place +where it sets up a runtime and executes the futures. Most languages which support async bundle a runtime with the language. Rust does not. Instead, there are many different async runtimes available, each of which makes different tradeoffs suitable to the use case they target. For example, a high-throughput web server with many CPU cores and a large amount of RAM has very different different needs than a microcontroller with a single core, a -small amount of RAM, and no ability to do heap allocations. - -Every async program in Rust has at least one place where it sets up a runtime -and executes the futures. Those runtimes also often supply async versions of -common functionality like file or network I/O. - -> ### The `trpl` Crate -> -> To keep this chapter focused on learning async, rather than juggling parts of -> the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust -> Programming Language”). It re-exports all the types, traits, and functions you -> will need, primarily from the [`futures`][futures-crate] and [`tokio`][tokio] -> crates. -> -> - The `futures` crate is an official home for Rust experimentation for async -> code, and is actually where the `Future` type was originally designed. -> -> - Tokio is the most widely used async runtime in Rust today, especially (but -> not only!) for web applications. There are other great runtimes out there, -> and they may be more suitable for your purposes. We use Tokio under the hood -> for `trpl` because it is good and widely used. -> -> In some cases, `trpl` also renames or wraps the original APIs to let us stay -> focused on the details relevant to chapter. If you want to understand what the -> crate does, we encourage you to check out [its source code][crate-source]. You -> will be able to see what crate each re-export comes from, and we have left -> extensive comments explaining what the crate does. +small amount of RAM, and no ability to do heap allocations. The crates which +provide those runtimes also often supply async versions of common functionality +like file or network I/O. -Go ahead and add the `trpl` crate to your `hello-async` project: - -```console -$ cargo add trpl -``` +Here, and throughout the rest of this chapter, we will use the `run` function +from the `trpl` crate, which takes a future as an argument and runs it to +completion. Behind the scenes, calling `run` sets up a runtime to use to run the +future passed in. Once the future completes, `run` returns whatever value the +future produced. -Then, in our `main` function, let’s wrap the call to `hello` with the -`trpl::run` function, which takes in a `Future` and runs it until it completes. -Since `hello` returns a `Future`, we could simply wrap it directly in -`trpl::run`. However, for most of the examples in the chapter, we will be -doing more than just one async function call, so instead we will pass an `async` -block and explicitly await the result of calling `hello`. +We could pass the future returned by `page_title` directly to `run`. Once it +completed, we would be able to match on the resulting `Option<String>`, the way +we tried to do in Listing 17-3. However, for most of the examples in the chapter +(and most async code in the real world!), we will be doing more than just one +async function call, so instead we will pass an `async` block and explicitly +await the result of calling `page_title`, as in Listing 17-4. -<Listing number="17-4" caption="Using the `run` helper function to wait on a future in non-async code" file-name="src/main.rs"> +<Listing number="17-4" caption="Awaiting an async block with `trpl::run`" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:run}} ``` </Listing> @@ -217,44 +261,27 @@ When we run this, we get the behavior we might have expected initially: {{#include ../listings/ch17-async-await/listing-17-04/output.txt}} ``` -Phew: we finally have some working async code! Let’s briefly turn our attention -to how futures actually work. - -A *future* is a data structure which manages the state of some async operation. -It is called a “future” because it represents work which may not be ready now, -but will become ready at some point in the future. (This same concept shows up -in many languages, sometimes under other names like “task” or “promise”.) Rust -provides a `Future` trait as a building block so different async operations can -be implemented with different data structures, but with a common interface. +Phew: we finally have some working async code! This now compiles, and we can run +it. Pick a couple URLs and run the command line tool. You may discover that some +sites are reliably faster than others, while in other cases which site “wins” +varies from run to run. Let’s briefly turn our attention back to how futures +work. -Most of the time when writing async Rust, we use the `async` and `await` -keywords we saw above. Rust compiles them into equivalent code using the -`Future` trait, much like it compiles `for` loops into equivalent code using the -`Iterator` trait. Because Rust provides the `Future` trait, though, you can also -implement it for your own data types when you need to. Many of the functions we -will see throughout this chapter return types with their own implementations of -`Future`. We will return to the definition of the trait at the end of the -chapter and dig into more of how it works, but this is enough detail to keep us -moving forward. - -<!-- TODO: need to introduce/transition with this next paragraph. --> - -Every *await point*—that is, every place where the code explicitly applies the -`await` keyword—represents a place where control gets handed back to the -runtime. To make that work, Rust needs to keep track of the state involved in -the async block, so that the runtime can kick off some other work and then come -back when it is ready to try advancing this one again. This is an invisible -state machine, as if you wrote something like this: +Each *await point*—that is, every place where the code uses the `await` +keyword—represents a place where control gets handed back to the runtime. To +make that work, Rust needs to keep track of the state involved in the async +block, so that the runtime can kick off some other work and then come back when +it is ready to try advancing this one again. This is an invisible state machine, +as if you wrote something like this: ```rust -enum MyAsyncStateMachine { - FirstAwaitPoint { - // the state used up to the first await point... +enum PageTitleFuture<'a> { + GetAwaitPoint { + url: &'a str, }, - SecondAwaitPoint { - // the state used up to the second await point... + TextAwaitPoint { + response: trpl::Response, }, - // etc. for each `.await` point... } ``` @@ -266,24 +293,69 @@ Happily, the compiler also handles checking those for us, and has good error messages. We will work through a few of those later in the chapter! Ultimately, something has to execute that state machine. That something is a -runtime. This is why you may sometimes come across references to *executors* +runtime. (This is why you may sometimes come across references to *executors* when looking into runtimes: an executor is the part of a runtime responsible for -executing the async code. +executing the async code.) Now we can understand why the compiler stopped us from making `main` itself an -async function in Listing 17-3. If `main` were an async function, something else -would need to manage the state machine for whatever future `main` returned, but -main is the starting point for the program! Instead, we use the `trpl::run` -function, which sets up a runtime and polls the `Future` returned by `hello` +async function back in Listing 17-3. If `main` were an async function, something +else would need to manage the state machine for whatever future `main` returned, +but main is the starting point for the program! Instead, we use the `trpl::run` +function, which sets up a runtime and runs the future returned by `page_title` until it returns `Ready`. > Note: some runtimes provide macros to make it so you *can* write an async main > function. Those macros rewrite `async fn main() { ... }` to be a normal `fn -> main` which does the same thing we did by hand in Listing 17-TODO: call a +> main` which does the same thing we did by hand in Listing 17-5: call a > function which runs a future to completion the way `trpl::run` does. -Now that you know the basics of working with futures, we can dig into more of -the things we can *do* with async. +Let’s put these pieces together and see how we can write concurrent code, by +calling `page_title_for` with two different URLs passed in from the command line +and racing it. + +<Listing number="17-5" caption="" file-name="src/main.rs"> + +```rust +{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:all}} +``` + +</Listing> + +In Listing 17-5, we begin by calling `page_title` with both of the user-supplied +URLs. We save the futures produced by calling `page_title` as `title_fut_1` and +`title_fut_2`. Remember, these don’t do anything yet, because futures are lazy, +and we have not yet awaited them. Then we pass the futures `trpl::race`, which +returns a value to indicate which of the futures passed to it finishes first. + +Either future can legitimately “win,” so it does not make sense to return a +`Result`. Instead, `race` returns a type we have not seen before, +`trpl::Either`. The `Either` type is somewhat like a `Result`, in that it has +two cases. Unlike `Result`, though, there is no notion of success or failure +baked into `Either`. Instead, it uses `Left` and `Right` to indicate “one or the +other”. + +```rust +enum Either<A, B> { + Left(A), + Right(B) +} +``` + +The `race` function returns `Left` if the first argument finishes first, with +that future’s output, and `Right` with the second future argument’s output if +*that* one finishes first. This matches the order the arguments appear when +calling the function: the first argument is to the left of the second argument. + +We also update `page_title_for` to return the same URL passed in. That way, if +the page which returns first does not have a `<title>` we can resolve, we can +still print a meaningful message. With that information available, we wrap up by +updating our `println!` output to indicate both which URL finished first and +what the `<title>` was for the web page at that URL, if any. + +You have built a small working web scraper now, which we could extend in a bunch +of different directions. More importantly, you have learned the basics of +working with futures, so we can now dig into even more of the things we can *do* +with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters [iterators-lazy]: ch13-02-iterators.html diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 98a4e393d9..9449910c3e 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -17,12 +17,12 @@ The first task we tackled in Chapter 16 was counting up on two separate threads. Let’s do the same using async. The `trpl` crate supplies a `spawn_task` function which looks very similar to the `thread::spawn` API, and a `sleep` function which is an async version of the `thread::sleep` API. We can use these together -to implement the same counting example as with threads, in Listing 17-5. +to implement the same counting example as with threads, in Listing 17-6. -<Listing number="17-5" caption="Using `spawn_task` to count with two" file-name="src/main.rs"> +<Listing number="17-6" caption="Using `spawn_task` to count with two" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-06/src/main.rs:all}} ``` </Listing> @@ -64,14 +64,14 @@ finishes, because the task spawned by `spawn_task` is shut down when the main function ends. If you want to run all the way to the completion of the task, you will need to use a join handle to wait for the first task to complete. With threads, we used the `join` method to “block” until the thread was done running. -In Listing 17-6, we can use `await` to do the same thing, because the task +In Listing 17-7, we can use `await` to do the same thing, because the task handle itself is a future. Its `Output` type is a `Result`, so we also unwrap it after awaiting it. -<Listing number="17-6" caption="Using `.await` with a join handle to run a task to completion" file-name="src/main.rs"> +<Listing number="17-7" caption="Using `.await` with a join handle to run a task to completion" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-06/src/main.rs:handle}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-07/src/main.rs:handle}} ``` </Listing> @@ -112,15 +112,15 @@ In Chapter 16, we showed how to use the `join` method on the `JoinHandle` type returned when you call `std::thread::spawn`. The `trpl::join` function is similar, but for futures. When you give it two futures, it produces a single new future whose output is a tuple with the output of each of the futures you passed -in once *both* complete. Thus, in Listing 17-7, we use `trpl::join` to wait for +in once *both* complete. Thus, in Listing 17-8, we use `trpl::join` to wait for both `fut1` and `fut2` to finish. We do *not* await `fut1` and `fut2`, but instead the new future produced by `trpl::join`. We ignore the output, because it is just a tuple with two unit values in it. -<Listing number="17-7" caption="Using `trpl::join` to await two anonymous futures" file-name="src/main.rs"> +<Listing number="17-8" caption="Using `trpl::join` to await two anonymous futures" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-07/src/main.rs:join}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:join}} ``` </Listing> @@ -175,14 +175,14 @@ each case *before* running the code! Sharing data between futures will also be familiar: we will use message passing again, but this with async versions of the types and functions. We will take a slightly different path than we did in Chapter 16, to illustrate some of the key -differences between thread-based and futures-based concurrency. In Listing 17-8, +differences between thread-based and futures-based concurrency. In Listing 17-9, we will begin with just a single async block—*not* spawning a separate task like we spawned a separate thread. -<Listing number="17-8" caption="Creating an async channel and assigning the two halves to `tx` and `rx`" file-name="src/main.rs"> +<Listing number="17-9" caption="Creating an async channel and assigning the two halves to `tx` and `rx`" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-08/src/main.rs:channel}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-09/src/main.rs:channel}} ``` </Listing> @@ -216,14 +216,14 @@ in the listing happens in sequence, just as it would if there were no futures involved. Let’s address the first part by sending a series of messages, and sleep in -between them, as shown in Listing 17-9: +between them, as shown in Listing 17-10: <!-- We cannot test this one because it never stops! --> -<Listing number="17-9" caption="Sending and receiving multiple messages over the async channel and sleeping with an `.await` between each message" file-name="src/main.rs"> +<Listing number="17-10" caption="Sending and receiving multiple messages over the async channel and sleeping with an `.await` between each message" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-09/src/main.rs:many-messages}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:many-messages}} ``` </Listing> @@ -269,7 +269,7 @@ delay, rather than coming in with delays in between each one. Within a given async block, the order that `.await` keywords appear in the code is also the order they happen when running the program. -There is only one async block in Listing 17-9, so everything in it runs +There is only one async block in Listing 17-10, so everything in it runs linearly. There is still no concurrency. All the `tx.send` calls happen, interspersed with all of the `trpl::sleep` calls and their associated await points. Only then does the `while let` loop get to go through any of the @@ -285,15 +285,15 @@ trying *not* to do. <!-- We cannot test this one because it never stops! --> -<Listing number="17-10" caption="Separating `send` and `recv` into their own `async` blocks and awaiting the futures for those blocks" file-name="src/main.rs"> +<Listing number="17-11" caption="Separating `send` and `recv` into their own `async` blocks and awaiting the futures for those blocks" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:futures}} ``` </Listing> -With the updated code in Listing 17-10, the messages get printed at +With the updated code in Listing 17-11, the messages get printed at 500-millisecond intervals, rather than all in a rush after two seconds. The program still never exits, though, because of the way `while let` loop @@ -326,20 +326,20 @@ in Chapter 16, we saw that we often need to use move data into closures when working with threads. The same basic dynamics apply to async blocks, so the `move` keyword works with async blocks just like it does with closures. -In Listing 17-11, we change the async block for sending messages from a plain +In Listing 17-12, we change the async block for sending messages from a plain `async` block to an `async move` block. When we run *this* version of the code, it shuts down gracefully after the last message is sent and received. -<Listing number="17-11" caption="A working example of sending and receiving messages between futures which correctly shuts down when complete" file-name="src/main.rs"> +<Listing number="17-12" caption="A working example of sending and receiving messages between futures which correctly shuts down when complete" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:with-move}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:with-move}} ``` </Listing> This async channel is also a multiple-producer channel, so we can call `clone` -on `tx` if we want to send messages from multiple futures. In Listing 17-12, we +on `tx` if we want to send messages from multiple futures. In Listing 17-13, we clone `tx`, creating `tx1` outside the first async block. We move `tx1` into that block just as we did before with `tx`. Then, later, we move the original `tx` into a *new* async block, where we send more messages on a slightly slower @@ -352,10 +352,10 @@ that both `tx` and `tx1` get dropped when those blocks finish. Otherwise we will end up back in the same infinite loop we started out in. Finally, we switch from `trpl::join` to `trpl::join3` to handle the additional future. -<Listing number="17-12" caption="Using multiple producers with async blocks" file-name="src/main.rs"> +<Listing number="17-13" caption="Using multiple producers with async blocks" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} ``` </Listing> diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 1ed95f14cc..d4dddb636e 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -5,13 +5,13 @@ also had to switch from using `join` to using `join3`. It would be annoying to have to call a different function every time we changed the number of futures we wanted to join. Happily, we have a macro form of `join` to which we can pass an arbitrary number of arguments. It also handles awaiting the futures itself. -Thus, we could rewrite the code from Listing 17-12 to use `join!` instead of -`join3`, as in Listing 17-13: +Thus, we could rewrite the code from Listing 17-13 to use `join!` instead of +`join3`, as in Listing 17-14: -<Listing number="17-13" caption="Using `join!` to wait for multiple futures" file-name="src/main.rs"> +<Listing number="17-14" caption="Using `join!` to wait for multiple futures" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} ``` </Listing> @@ -28,10 +28,10 @@ implements the `Iterator` trait, which we learned about back in Chapter 13, so it seems like just the ticket. Let’s try putting our futures in a vector, and replace `join!` with `join_all`. -<Listing number="17-14" caption="Storing anonymous futures in a vector and calling `join_all`"> +<Listing number="17-15" caption="Storing anonymous futures in a vector and calling `join_all`"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-16/src/main.rs:here}} ``` </Listing> @@ -39,7 +39,7 @@ replace `join!` with `join_all`. Unfortunately, this does not compile. Instead, we get this error: <!-- manual-regeneration -cd listings/ch17-async-await/listing-17-14/ +cd listings/ch17-async-await/listing-17-16/ cargo build copy just the compiler error --> @@ -98,12 +98,12 @@ implement the `Future` trait. > they will all be until runtime. We start by wrapping each of the futures in the `vec!` in a `Box::new`, as shown -in Listing 17-15. +in Listing 17-16. -<Listing number="17-15" caption="Trying to use `Box::new` to align the types of the futures in a `Vec`" file-name="src/main.rs"> +<Listing number="17-16" caption="Trying to use `Box::new` to align the types of the futures in a `Vec`" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-17/src/main.rs:here}} ``` </Listing> @@ -113,12 +113,12 @@ error we did before, but we get one for both the second and third `Box::new` calls, and we also get new errors referring to the `Unpin` trait. We will come back to the `Unpin` errors in a moment. First, let’s fix the type errors on the `Box::new` calls, by explicitly providing the type of `futures` as a trait -object (Listing 17-16). +object (Listing 17-17). -<Listing number="17-16" caption="Fixing the rest of the type mismatch errors by using an explicit type declaration" file-name="src/main.rs"> +<Listing number="17-17" caption="Fixing the rest of the type mismatch errors by using an explicit type declaration" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-16/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-18/src/main.rs:here}} ``` </Listing> @@ -136,7 +136,7 @@ the errors mentioning `Unpin`. Although there are three of them, notice that each is very similar in its contents. <!-- manual-regeneration -cd listings/ch17-async-await/listing-17-16 +cd listings/ch17-async-await/listing-17-18 cargo build copy *only* the errors --> @@ -207,14 +207,14 @@ tell us that the first async block (`src/main.rs:8:23: 20:10`) does not implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve it. Later in the chapter, we will dig into a few more details about `Pin` and `Unpin`. For the moment, though, we can just follow the compiler’s advice to get -unstuck! In Listing 17-17, we start by updating the type annotation for +unstuck! In Listing 17-18, we start by updating the type annotation for `futures`, with a `Pin` wrapping each `Box`. Second, we use `Box::pin` to pin the futures themselves. -<Listing number="17-17" caption="Using `Pin` and `Box::pin` to make the `Vec` type check" file-name="src/main.rs"> +<Listing number="17-18" caption="Using `Pin` and `Box::pin` to make the `Vec` type check" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-17/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} ``` </Listing> @@ -251,25 +251,25 @@ However, we must still be explicit about the type of the pinned reference; otherwise Rust will still not know to interpret these as dynamic trait objects, which is what we need them to be in the `Vec`. We therefore `pin!` each future when we define it, and define `futures` as a `Vec` containing pinned mutable -references to the dynamic `Future` type, as in Listing 17-18. +references to the dynamic `Future` type, as in Listing 17-19. -<Listing number="17-18" caption="Using `Pin` directly with the `pin!` macro to avoid unnecessary heap allocations" file-name="src/main.rs"> +<Listing number="17-19" caption="Using `Pin` directly with the `pin!` macro to avoid unnecessary heap allocations" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-18/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} ``` </Listing> We got this far by ignoring the fact that we might have different `Output` -types. For example, in Listing 17-19, the anonymous future for `a` implements +types. For example, in Listing 17-20, the anonymous future for `a` implements `Future<Output = u32>`, the anonymous future for `b` implements `Future<Output = &str>`, and the anonymous future for `c` implements `Future<Output = bool>`. -<Listing number="17-19" caption="Three futures with distinct types" file-name="src/main.rs"> +<Listing number="17-20" caption="Three futures with distinct types" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:here}} ``` </Listing> @@ -299,16 +299,19 @@ that reason. > function can do a lot of things that `trpl::race` function cannot, but it also > has some additional complexity that we can skip over for now. -In Listing 17-20, we use `trpl::race` to run two futures, `slow` and `fast`, +In Listing 17-21, we use `trpl::race` to run two futures, `slow` and `fast`, against each other. Each one prints a message when it starts running, pauses for some amount of time by calling and awaiting `sleep`, and then prints another message when it finishes. Then we pass both to `trpl::race` and wait for one of -them to finish. (The outcome here won’t be too surprising: `fast` wins!) +them to finish. (The outcome here won’t be too surprising: `fast` wins!) Note +that unlike the first time we used `race` back in [Our First Async +Program][async-program], we just ignore the `Either` instance it returns here, +because all of the interesting behavior happens in the body of the async blocks. -<Listing number="17-20" caption="Using `race` to get the result of whichever future finishes first" file-name="src/main.rs"> +<Listing number="17-21" caption="Using `race` to get the result of whichever future finishes first" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:here}} ``` </Listing> @@ -344,28 +347,28 @@ But *how* would you hand control back to the runtime in those cases? ### Yielding -Let’s simulate a long-running operation. Listing 17-21 introduces a `slow` +Let’s simulate a long-running operation. Listing 17-22 introduces a `slow` function. It uses `std::thread::sleep` instead of `trpl::sleep` so that calling `slow` will block the current thread for some number of milliseconds. We can use `slow` to stand in for real-world operations which are both long-running and blocking. -<Listing number="17-21" caption="Using `thread::sleep` to simulate slow operations" file-name="src/main.rs"> +<Listing number="17-22" caption="Using `thread::sleep` to simulate slow operations" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:slow}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:slow}} ``` </Listing> -In Listing 17-22, we use `slow` to emulate doing this kind of CPU-bound work in +In Listing 17-23, we use `slow` to emulate doing this kind of CPU-bound work in a pair of futures. To begin, each future only hands control back to the runtime *after* carrying out a bunch of slow operations. -<Listing number="17-22" caption="Using `thread::sleep` to simulate slow operations" file-name="src/main.rs"> +<Listing number="17-23" caption="Using `thread::sleep` to simulate slow operations" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:slow-futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:slow-futures}} ``` </Listing> @@ -373,7 +376,7 @@ a pair of futures. To begin, each future only hands control back to the runtime If you run this, you will see this output: <!-- manual-regeneration -cd listings/ch17-async-await/listing-17-22/ +cd listings/ch17-async-await/listing-17-24/ cargo run copy just the output --> @@ -399,24 +402,24 @@ completes. To allow both futures to make progress between their slow tasks, we need await points so we can hand control back to the runtime. That means we need something we can await! -We can already see this kind of handoff happening in Listing 17-22: if we +We can already see this kind of handoff happening in Listing 17-23: if we removed the `trpl::sleep` at the end of the `a` future, it would complete without the `b` future running *at all*. Maybe we could use the `sleep` function as a starting point? -<Listing number="17-23" caption="Using `sleep` to let operations switch off making progress" file-name="src/main.rs"> +<Listing number="17-24" caption="Using `sleep` to let operations switch off making progress" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:here}} ``` </Listing> -In Listing 17-23, we add `trpl::sleep` calls with await points between each call +In Listing 17-24, we add `trpl::sleep` calls with await points between each call to `slow`. Now the two futures’ work is interleaved: <!-- manual-regeneration -cd listings/ch17-async-await/listing-17-23/ +cd listings/ch17-async-await/listing-17-25/ cargo run copy just the output --> @@ -441,13 +444,13 @@ however makes the most sense to us. We do not really want to *sleep* here, though: we want to make progress as fast as we can. We just need to hand back control to the runtime. We can do that -directly, using the `yield_now` function. In Listing 17-24, we replace all those +directly, using the `yield_now` function. In Listing 17-25, we replace all those `sleep` calls with `yield_now`. -<Listing number="17-24" caption="Using `yield_now` to let operations switch off making progress" file-name="src/main.rs"> +<Listing number="17-25" caption="Using `yield_now` to let operations switch off making progress" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:yields}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:yields}} ``` </Listing> @@ -460,17 +463,17 @@ example, will always sleep for at least a millisecond, even if we pass it a lot in one millisecond! You can see this for yourself by setting up a little benchmark, like the one in -Listing 17-25. (This is not an especially rigorous way to do performance +Listing 17-26. (This is not an especially rigorous way to do performance testing, but it suffices to show the difference here.) Here, we skip all the status printing, pass a one-nanosecond `Duration` to `trpl::sleep`, and let each future run by itself, with no switching between the futures. Then we run for 1,000 iterations and see how long the future using `trpl::sleep` takes compared to the future using `trpl::yield_now`. -<Listing number="17-25" caption="Comparing the performance of `sleep` and `yield_now`" file-name="src/main.rs"> +<Listing number="17-26" caption="Comparing the performance of `sleep` and `yield_now`" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:here}} ``` </Listing> @@ -500,13 +503,13 @@ build a `timeout` function with async building blocks we already have. When we are done, the result will be another building block we could use to build up yet further async abstractions. -Listing 17-26 shows how we would expect this `timeout` to work with a slow +Listing 17-27 shows how we would expect this `timeout` to work with a slow future. -<Listing number="17-26" caption="Using our imagined `timeout` to run a slow operation with a time limit" file-name="src/main.rs"> +<Listing number="17-27" caption="Using our imagined `timeout` to run a slow operation with a time limit" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:here}} ``` </Listing> @@ -523,14 +526,14 @@ Let’s implement this! To begin, let’s think about the API for `timeout`: elapses first, the `Result` will be `Err` with the duration that the timeout waited for. -Listing 17-27 shows this declaration. +Listing 17-28 shows this declaration. <!-- This is not tested because it intentionally does not compile. --> -<Listing number="17-27" caption="Defining the signature of `timeout`" file-name="src/main.rs"> +<Listing number="17-28" caption="Defining the signature of `timeout`" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:declaration}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:declaration}} ``` </Listing> @@ -540,28 +543,6 @@ need: we want to race the future passed in against the duration. We can use `trpl::sleep` to make a timer future from the duration, and use `trpl::race` to run that timer with the future the caller passes in. -The `trpl::race` function returns a value to indicate which of the futures -passed to it finishes first. (When we saw `race` earlier in Listing 17-20, we -ignored its return value, because we were only interested in seeing the behavior -of `fast` and `slow` when we ran the program.) Either future can legitimately -“win,” so it does not make sense to return a `Result`. Instead, `race` returns a -type we have not seen before, `trpl::Either`. The `Either` type is somewhat like -a `Result`, in that it has two cases. Unlike `Result`, though, there is no -notion of success or failure baked into `Either`. Instead, it uses `Left` and -`Right` to indicate “one or the other”. - -```rust -enum Either<A, B> { - Left(A), - Right(B) -} -``` - -The `race` function returns `Left` if the first argument finishes first, with -that future’s output, and `Right` with the second future argument’s output if -*that* one finishes first. This matches the order the arguments appear when -calling the function: the first argument is to the left of the second argument. - We also know that `race` is not fair, and polls arguments in the order they are passed. Thus, we pass `future_to_try` to `race` first so it gets a chance to complete even if `max_time` is a very short duration. If `future_to_try` @@ -569,15 +550,15 @@ finishes first, `race` will return `Left` with the output from `future`. If `timer` finishes first, `race` will return `Right` with the timer’s output of `()`. -In Listing 17-28, we match on the result of awaiting `trpl::race`. If the +In Listing 17-29, we match on the result of awaiting `trpl::race`. If the `future_to_try` succeeded and we get a `Left(output)`, we return `Ok(output)`. If the sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` with `_` and return `Err(max_time)` instead. -<Listing number="17-28" caption="Defining `timeout` with `race` and `sleep`" file-name="src/main.rs"> +<Listing number="17-29" caption="Defining `timeout` with `race` and `sleep`" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:implementation}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-30/src/main.rs:implementation}} ``` </Listing> @@ -617,3 +598,4 @@ to consider first, though: [collections]: ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: ch12-03-improving-error-handling-and-modularity.html [futures]: ch17-01-futures-and-syntax.html#what-are-futures +[async-program]: ch17-01-futures-and-syntax.html#our-first-async-program diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 3510aa4164..674f52a7d5 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -20,12 +20,12 @@ though, a general-purpose stream API needs to be much more general: it will just provide the next item like `Iterator` does, but asynchronously. In fact, this is roughly how it works in Rust, so we can actually create a stream from any iterator. As with an iterator, we can work with a stream by calling its `next` -method, and then awaiting the output, as in Listing 17-29. +method, and then awaiting the output, as in Listing 17-30. -<Listing number="17-29" caption="Creating a stream from an iterator and printing its values" file-name="src/main.rs"> +<Listing number="17-30" caption="Creating a stream from an iterator and printing its values" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:stream}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs:stream}} ``` </Listing> @@ -40,7 +40,7 @@ can see in the output, it reports that there is no `next` method available. <!-- TODO: fix up the path here? --> <!-- manual-regeneration -cd listings/chapter-17-async-await/listing-17-29 +cd listings/chapter-17-async-await/listing-17-31 cargo build copy only the error output --> @@ -52,7 +52,7 @@ error[E0599]: no method named `next` found for struct `Iter` in the current scop 8 | while let Some(value) = stream.next().await { | ^^^^ | - = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-29/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' + = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-31/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' = note: consider using `--verbose` to print the full type name to the console = help: items from traits can only be used if the trait is in scope help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them @@ -89,25 +89,25 @@ return to the `Stream` and `StreamExt` traits in a bit more detail at the end of the chapter. For now, this is enough to let us keep moving. All we need to do here is add a `use` statement for `trpl::StreamExt`, as in -Listing 17-30. +Listing 17-31. -<Listing number="17-30" caption="Successfully using an iterator as the basis for a stream" file-name="src/main.rs"> +<Listing number="17-31" caption="Successfully using an iterator as the basis for a stream" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-30/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs}} ``` </Listing> With all those pieces put together, things work the way we want! What is more, now that we have `StreamExt` in scope, we can use all of its utility methods, -just like with iterators. For example, in Listing 17-31, we use the `filter` +just like with iterators. For example, in Listing 17-32, we use the `filter` method to filter out everything but multiples of three and five. -<Listing number="17-31" caption="Filtering a `Stream` with the `StreamExt::filter` method" file-name="src/main.rs"> +<Listing number="17-32" caption="Filtering a `Stream` with the `StreamExt::filter` method" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-33/src/main.rs}} ``` </Listing> @@ -129,7 +129,7 @@ avoid doing needless work. Let’s start by building a little stream of messages, similar to what we might see from a WebSocket or other real-time communication protocols. In Listing -17-32, we create a function `get_messages` which returns `impl Stream<Item = +17-33, we create a function `get_messages` which returns `impl Stream<Item = String>`. For its implementation, we create an async channel, loop over the first ten letters of the English alphabet, and send them across the channel. @@ -137,10 +137,10 @@ We also use a new type: `ReceiverStream`, which converts the `rx` receiver from the `trpl::channel` into a `Stream` with a `next` method. Back in `main`, we use a `while let` loop to print all the messages from the stream. -<Listing number="17-32" caption="Using the `rx` receiver as a `ReceiverStream`" file-name="src/main.rs"> +<Listing number="17-33" caption="Using the `rx` receiver as a `ReceiverStream`" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-34/src/main.rs:all}} ``` </Listing> @@ -168,7 +168,7 @@ We could do this with the regular `Receiver` API, or even the regular `Iterator` API, though. Let’s add something that requires streams, like adding a timeout which applies to every item in the stream, and a delay on the items we emit. -In Listing 17-33, we start by adding a timeout to the stream with the `timeout` +In Listing 17-34, we start by adding a timeout to the stream with the `timeout` method, which comes from the `StreamExt` trait. Then we update the body of the `while let` loop, because the stream now returns a `Result`. The `Ok` variant indicates a message arrived in time; the `Err` variant indicates that the @@ -178,10 +178,10 @@ timeout. Finally, notice that we pin the messages after applying the timeout to them, because the timeout helper produces a future which needs to be pinned to be polled. -<Listing number="17-33" caption="Using the `StreamExt::timeout` method to set a time limit on the items in a stream" file-name="src/main.rs"> +<Listing number="17-34" caption="Using the `StreamExt::timeout` method to set a time limit on the items in a stream" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-33/src/main.rs:timeout}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-35/src/main.rs:timeout}} ``` </Listing> @@ -195,10 +195,10 @@ and a 300 millisecond delay to odd-index items, to simulate the different delays we might see from a stream of messages in the real world. Because our timeout is for 200 milliseconds, this should affect half of the messages. -<Listing number="17-34" caption="Sending messages through `tx` with an async delay without making `get_messages` an async function" file-name="src/main.rs"> +<Listing number="17-35" caption="Sending messages through `tx` with an async delay without making `get_messages` an async function" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-34/src/main.rs:messages}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-36/src/main.rs:messages}} ``` </Listing> @@ -230,7 +230,7 @@ Now our code has a much more interesting result! Between every other pair of messages, we see an error reported: `Problem: Elapsed(())`. <!-- manual-regeneration -cd listings/listing-17-34 +cd listings/listing-17-36 cargo run copy only the program output, *not* the compiler output --> @@ -274,7 +274,7 @@ are going to send back the count of intervals which has elapsed, so the return type will be `impl Stream<Item = u32>`, and we can call the function `get_intervals`. -In Listing 17-35, we start by defining a `count` in the task. (We could define +In Listing 17-36, we start by defining a `count` in the task. (We could define it outside the task, too, but it is clearer to limit the scope of any given variable.) Then we create a an infinite loop. Each iteration of the loop asynchronously sleeps for one millisecond, increments the count, and then sends @@ -282,10 +282,10 @@ it over the channel. Since this is all wrapped in the task created by `spawn_task`, all of it will get cleaned up along with the runtime, including the infinite loop. -<Listing number="17-35" caption="Creating a stream with a counter that will be emitted once every millisecond" file-name="src/main.rs"> +<Listing number="17-36" caption="Creating a stream with a counter that will be emitted once every millisecond" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-35/src/main.rs:intervals}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-37/src/main.rs:intervals}} ``` </Listing> @@ -298,12 +298,12 @@ at least one await point in each iteration through the loop. Back in our main function’s async block, we start by calling `get_intervals`. Then we merge the `messages` and `intervals` streams with the `merge` method. Finally, we loop over that combined stream instead of over `messages` (Listing -17-36). +17-37). -<Listing number="17-36" caption="Attempting to merge streams of messages and intervals" file-name="src/main.rs"> +<Listing number="17-37" caption="Attempting to merge streams of messages and intervals" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-36/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-38/src/main.rs:main}} ``` </Listing> @@ -318,7 +318,7 @@ for a `timeout` call. Meanwhile, the `intervals` stream has the type `impl Stream<Item = u32>`. To merge these two streams, we need to transform one of them to match the other. -In Listing 17-37, we rework with the `intervals` stream, since `messages` is +In Listing 17-38, we rework with the `intervals` stream, since `messages` is already in the basic format we want and has to handle timeout errors. First, we can use the `map` helper method to transform the `intervals` into a string. Second, we need to match the `Timeout` from `messages`. Since we do not actually @@ -330,10 +330,10 @@ stream, and pin it so that it is safe to do so. <!-- We cannot directly test this one, because it never stops. --> -<Listing number="17-37" caption="Aligning the types of the the `intervals` stream with the type of the `messages` stream" file-name="src/main.rs"> +<Listing number="17-38" caption="Aligning the types of the the `intervals` stream with the type of the `messages` stream" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-37/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-39/src/main.rs:main}} ``` </Listing> @@ -361,7 +361,7 @@ Interval: 43 --snip-- ``` -Listing 17-38 shows one way to solve these last two problems. First, we use the +Listing 17-39 shows one way to solve these last two problems. First, we use the `throttle` method on the `intervals` stream, so that it does not overwhelm the `messages` stream. Throttling is a way of limiting the rate at which a function will be called—or, in this case, how often the stream will be polled. Once every @@ -372,10 +372,10 @@ To limit the number of items we will accept from a stream, we can use the `take` method. We apply it to the *merged* stream, because we want to limit the final output, not just one stream or the other. -<Listing number="17-38" caption="Using `throttle` and `take` to manage the merged streams" file-name="src/main.rs"> +<Listing number="17-39" caption="Using `throttle` and `take` to manage the merged streams" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-38/src/main.rs:throttle}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:throttle}} ``` </Listing> @@ -393,7 +393,7 @@ never produce those interval messages in the first place! This is the inherent performance characteristics. <!-- manual-regeneration -cd listings/listing-17-38 +cd listings/listing-17-40 cargo run copy and paste only the program output --> @@ -426,15 +426,15 @@ channel-based streams, the `send` calls could fail when the other side of the channel closes—and that is just a matter of how the runtime executes the futures which make up the stream. Up till now we have ignored this by calling `unwrap`, but in a well-behaved app, we should explicitly handle the error, at minimum by -ending the loop so we do not try to send any more messages! Listing 17-39 shows +ending the loop so we do not try to send any more messages! Listing 17-40 shows a simple error strategy: print the issue and then `break` from the loops. As usual, the correct way to handle a message send error will vary—just make sure you have a strategy. -<Listing number="17-39" caption="Handling errors and shutting down the loops"> +<Listing number="17-40" caption="Handling errors and shutting down the loops"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-39/src/main.rs:errors}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-41/src/main.rs:errors}} ``` </Listing> diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 9eb31d2fa4..0a5ee1f89e 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -115,11 +115,11 @@ it is not yet ready. <!-- TODO: get a *very* careful technical review of this section! --> -When we introduced the idea of pinning, while working on Listing 17-16, we ran +When we introduced the idea of pinning, while working on Listing 17-17, we ran into a very gnarly error message. Here is the relevant part of it again: <!-- manual-regeneration -cd listings/ch17-async-await/listing-17-16 +cd listings/ch17-async-await/listing-17-18 cargo build copy *only* the final `error` block from the errors --> diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index ad3a4d24da..3753120192 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -24,15 +24,15 @@ is managed by library-level code: the runtime. In the previous section, we saw that we could build a `Stream` by using an async channel and spawning an async task which we could call from synchronous code. We -could do the exact same thing with a thread! In Listing 17-39, we used -`trpl::spawn_task` and `trpl::sleep`. In Listing 17-40, we replace those with +could do the exact same thing with a thread! In Listing 17-40, we used +`trpl::spawn_task` and `trpl::sleep`. In Listing 17-41, we replace those with the `thread::spawn` and `thread::sleep` APIs from the standard library in the `get_intervals` function. -<Listing number="17-40" caption="Using the `std::thread` APIs instead of the async `trpl` APIs for the `get_intervals` function" file-name="src/main.rs"> +<Listing number="17-41" caption="Using the `std::thread` APIs instead of the async `trpl` APIs for the `get_intervals` function" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:threads}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-41/src/main.rs:threads}} ``` </Listing> From 573a6ca4bafb8f72ab867a2071ccece6478b8600 Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Fri, 20 Sep 2024 15:42:27 -0600 Subject: [PATCH 543/720] Ch. 17: fix mdbook test output This gets CI working again. The problem was basically a mix of a few silly mistakes: - Using `include` instead of `rustdoc_include` in several places. - Having rewritten the listing numbers incorrectly. --- Cargo.lock | 1866 ++--------------- Cargo.toml | 2 +- README.md | 3 +- .../ch17-async-await/listing-17-01/Cargo.lock | 14 +- .../ch17-async-await/listing-17-01/Cargo.toml | 2 +- .../ch17-async-await/listing-17-02/Cargo.lock | 14 +- .../ch17-async-await/listing-17-02/Cargo.toml | 2 +- .../ch17-async-await/listing-17-03/Cargo.toml | 2 +- .../ch17-async-await/listing-17-04/Cargo.toml | 2 +- .../ch17-async-await/listing-17-05/Cargo.toml | 2 +- .../ch17-async-await/listing-17-42/Cargo.lock | 1860 ++++++++++++++++ .../ch17-async-await/listing-17-42/Cargo.toml | 8 + .../listing-17-42/src/main.rs | 22 + src/ch17-01-futures-and-syntax.md | 21 +- src/ch17-02-concurrency-with-async.md | 8 +- src/ch17-03-more-futures.md | 36 +- src/ch17-04-streams.md | 30 +- src/ch17-06-futures-tasks-threads.md | 21 +- 18 files changed, 2101 insertions(+), 1814 deletions(-) create mode 100644 listings/ch17-async-await/listing-17-42/Cargo.lock create mode 100644 listings/ch17-async-await/listing-17-42/Cargo.toml create mode 100644 listings/ch17-async-await/listing-17-42/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 21c0d5e8a8..493ab8e687 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,1806 +2,278 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - [[package]] name = "adler" version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "getrandom", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" - -[[package]] -name = "cc" -version = "1.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800" -dependencies = [ - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - -[[package]] -name = "crc32fast" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "cssparser" -version = "0.31.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" -dependencies = [ - "cssparser-macros", - "dtoa-short", - "itoa", - "phf 0.11.2", - "smallvec", -] - -[[package]] -name = "cssparser-macros" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "derive_more" -version = "0.99.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "docopt" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" -dependencies = [ - "lazy_static", - "regex", - "serde", - "strsim", -] - -[[package]] -name = "dtoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" - -[[package]] -name = "dtoa-short" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" -dependencies = [ - "dtoa", -] - -[[package]] -name = "ego-tree" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" - -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - -[[package]] -name = "filetime" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.4.1", - "windows-sys 0.52.0", -] - -[[package]] -name = "flate2" -version = "1.0.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futf" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" -dependencies = [ - "mac", - "new_debug_unreachable", -] - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "getopts" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "html5ever" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" -dependencies = [ - "log", - "mac", - "markup5ever", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "http" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" -dependencies = [ - "bytes", - "futures-util", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" - -[[package]] -name = "hyper" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "itoa", - "pin-project-lite", - "smallvec", - "tokio", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.27.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" -dependencies = [ - "futures-util", - "http", - "hyper", - "hyper-util", - "rustls", - "rustls-pki-types", - "tokio", - "tokio-rustls", - "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "hyper", - "pin-project-lite", - "socket2", - "tokio", - "tower", - "tower-service", - "tracing", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "ipnet" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "js-sys" -version = "0.3.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - -[[package]] -name = "listing-scraper-01" -version = "0.1.0" -dependencies = [ - "trpl", -] - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - -[[package]] -name = "mac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" - -[[package]] -name = "markup5ever" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" -dependencies = [ - "log", - "phf 0.11.2", - "phf_codegen 0.11.2", - "string_cache", - "string_cache_codegen", - "tendril", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" -dependencies = [ - "hermit-abi", - "libc", - "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - -[[package]] -name = "new_debug_unreachable" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" - -[[package]] -name = "object" -version = "0.36.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" - -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags 2.5.0", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.5.4", - "smallvec", - "windows-targets", -] - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "phf" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" -dependencies = [ - "phf_shared 0.10.0", -] - -[[package]] -name = "phf" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" -dependencies = [ - "phf_macros", - "phf_shared 0.11.2", -] - -[[package]] -name = "phf_codegen" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" -dependencies = [ - "phf_generator 0.10.0", - "phf_shared 0.10.0", -] - -[[package]] -name = "phf_codegen" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" -dependencies = [ - "phf_generator 0.11.2", - "phf_shared 0.11.2", -] - -[[package]] -name = "phf_generator" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" -dependencies = [ - "phf_shared 0.10.0", - "rand", -] - -[[package]] -name = "phf_generator" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" -dependencies = [ - "phf_shared 0.11.2", - "rand", -] - -[[package]] -name = "phf_macros" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" -dependencies = [ - "phf_generator 0.11.2", - "phf_shared 0.11.2", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - -[[package]] -name = "phf_shared" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" -dependencies = [ - "siphasher", -] - -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - -[[package]] -name = "proc-macro2" -version = "1.0.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" -dependencies = [ - "bitflags 2.5.0", -] - -[[package]] -name = "regex" -version = "1.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" - -[[package]] -name = "reqwest" -version = "0.12.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", - "hyper-tls", - "hyper-util", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "rustls-pemfile", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "system-configuration", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "windows-registry", -] - -[[package]] -name = "ring" -version = "0.17.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "spin", - "untrusted", - "windows-sys 0.52.0", -] - -[[package]] -name = "rust-book-tools" -version = "0.0.1" -dependencies = [ - "docopt", - "flate2", - "lazy_static", - "regex", - "serde", - "tar", - "walkdir", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustls" -version = "0.23.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" -dependencies = [ - "once_cell", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pemfile" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" -dependencies = [ - "base64", - "rustls-pki-types", -] - -[[package]] -name = "rustls-pki-types" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" - -[[package]] -name = "rustls-webpki" -version = "0.102.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "scraper" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" -dependencies = [ - "ahash", - "cssparser", - "ego-tree", - "getopts", - "html5ever", - "once_cell", - "selectors", - "tendril", -] - -[[package]] -name = "security-framework" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" -dependencies = [ - "bitflags 2.5.0", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "selectors" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" -dependencies = [ - "bitflags 2.5.0", - "cssparser", - "derive_more", - "fxhash", - "log", - "new_debug_unreachable", - "phf 0.10.1", - "phf_codegen 0.10.0", - "precomputed-hash", - "servo_arc", - "smallvec", -] - -[[package]] -name = "serde" -version = "1.0.197" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.197" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.128" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "servo_arc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" -dependencies = [ - "stable_deref_trait", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "siphasher" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - -[[package]] -name = "string_cache" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" -dependencies = [ - "new_debug_unreachable", - "once_cell", - "parking_lot", - "phf_shared 0.10.0", - "precomputed-hash", - "serde", -] - -[[package]] -name = "string_cache_codegen" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" -dependencies = [ - "phf_generator 0.10.0", - "phf_shared 0.10.0", - "proc-macro2", - "quote", -] +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] -name = "strsim" -version = "0.10.0" +name = "aho-corasick" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] [[package]] -name = "subtle" -version = "2.6.1" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "syn" -version = "2.0.59" +name = "bitflags" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] -name = "sync_wrapper" -version = "1.0.1" +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" -dependencies = [ - "futures-core", -] +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "system-configuration" -version = "0.6.1" +name = "crc32fast" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ - "bitflags 2.5.0", - "core-foundation", - "system-configuration-sys", + "cfg-if", ] [[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "docopt" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" dependencies = [ - "core-foundation-sys", - "libc", + "lazy_static", + "regex", + "serde", + "strsim", ] [[package]] -name = "tar" -version = "0.4.40" +name = "errno" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "filetime", "libc", - "xattr", + "windows-sys", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "filetime" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "libc", + "redox_syscall", + "windows-sys", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "flate2" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ - "futf", - "mac", - "utf-8", + "crc32fast", + "miniz_oxide", ] [[package]] -name = "tinyvec" -version = "1.8.0" +name = "lazy_static" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" -dependencies = [ - "tinyvec_macros", -] +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] -name = "tinyvec_macros" -version = "0.1.1" +name = "libc" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] -name = "tokio" -version = "1.40.0" +name = "linux-raw-sys" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "pin-project-lite", - "socket2", - "windows-sys 0.52.0", -] +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] -name = "tokio-native-tls" -version = "0.3.1" +name = "memchr" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] -name = "tokio-rustls" -version = "0.26.0" +name = "miniz_oxide" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ - "rustls", - "rustls-pki-types", - "tokio", + "adler", ] [[package]] -name = "tokio-stream" -version = "0.1.16" +name = "proc-macro2" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "unicode-ident", ] [[package]] -name = "tokio-util" -version = "0.7.12" +name = "quote" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", + "proc-macro2", ] [[package]] -name = "tower" -version = "0.4.13" +name = "redox_syscall" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", + "bitflags 1.3.2", ] [[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - -[[package]] -name = "tower-service" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" - -[[package]] -name = "tracing" -version = "0.1.40" +name = "regex" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ - "pin-project-lite", - "tracing-core", + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", ] [[package]] -name = "tracing-core" -version = "0.1.32" +name = "regex-automata" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", -] - -[[package]] -name = "trpl" -version = "0.1.0" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ - "futures", - "reqwest", - "scraper", - "tokio", - "tokio-stream", + "aho-corasick", + "memchr", + "regex-syntax", ] [[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - -[[package]] -name = "unicode-ident" -version = "1.0.0" +name = "regex-syntax" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +name = "rust-book-tools" +version = "0.0.1" dependencies = [ - "tinyvec", + "docopt", + "flate2", + "lazy_static", + "regex", + "serde", + "tar", + "walkdir", ] [[package]] -name = "unicode-width" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" - -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "url" -version = "2.5.2" +name = "rustix" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", ] [[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "walkdir" -version = "2.5.0" +name = "same-file" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ - "same-file", "winapi-util", ] [[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.93" +name = "serde" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ - "cfg-if", - "once_cell", - "wasm-bindgen-macro", + "serde_derive", ] [[package]] -name = "wasm-bindgen-backend" -version = "0.2.93" +name = "serde_derive" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ - "bumpalo", - "log", - "once_cell", "proc-macro2", "quote", "syn", - "wasm-bindgen-shared", ] [[package]] -name = "wasm-bindgen-futures" -version = "0.4.43" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] -name = "wasm-bindgen-macro" -version = "0.2.93" +name = "syn" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ + "proc-macro2", "quote", - "wasm-bindgen-macro-support", + "unicode-ident", ] [[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.93" +name = "tar" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", + "filetime", + "libc", + "xattr", ] [[package]] -name = "wasm-bindgen-shared" -version = "0.2.93" +name = "unicode-ident" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" [[package]] -name = "web-sys" -version = "0.3.70" +name = "walkdir" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ - "js-sys", - "wasm-bindgen", + "same-file", + "winapi-util", ] [[package]] @@ -1835,36 +307,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-registry" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" -dependencies = [ - "windows-result", - "windows-strings", - "windows-targets", -] - -[[package]] -name = "windows-result" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-strings" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" -dependencies = [ - "windows-result", - "windows-targets", -] - [[package]] name = "windows-sys" version = "0.52.0" @@ -1874,15 +316,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" @@ -1957,30 +390,3 @@ dependencies = [ "linux-raw-sys", "rustix", ] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index 5b7ef40548..20fc14643d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [ "listings/ch17-async-await/listing-scraper-01","packages/tools"] +members = ["packages/tools"] default-members = ["packages/tools"] resolver = "2" exclude = [ diff --git a/README.md b/README.md index 9648db0ae0..b4426bd492 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,8 @@ $ start chrome.exe .\book\index.html # Windows (Cmd) To run the tests: ```bash -$ mdbook test +$ cd packages/trpl +$ mdbook test --library-path packages/trpl/target/debug/deps ``` ## Contributing diff --git a/listings/ch17-async-await/listing-17-01/Cargo.lock b/listings/ch17-async-await/listing-17-01/Cargo.lock index 207879da8f..1109eb84f5 100644 --- a/listings/ch17-async-await/listing-17-01/Cargo.lock +++ b/listings/ch17-async-await/listing-17-01/Cargo.lock @@ -30,6 +30,13 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -579,13 +586,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "listing-scraper-01" -version = "0.1.0" -dependencies = [ - "trpl", -] - [[package]] name = "lock_api" version = "0.4.12" diff --git a/listings/ch17-async-await/listing-17-01/Cargo.toml b/listings/ch17-async-await/listing-17-01/Cargo.toml index 9fad6d6a96..57fe49bfe5 100644 --- a/listings/ch17-async-await/listing-17-01/Cargo.toml +++ b/listings/ch17-async-await/listing-17-01/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "listing-scraper-01" +name = "async_await" version = "0.1.0" edition = "2021" diff --git a/listings/ch17-async-await/listing-17-02/Cargo.lock b/listings/ch17-async-await/listing-17-02/Cargo.lock index cb7d407618..1bd5f08c34 100644 --- a/listings/ch17-async-await/listing-17-02/Cargo.lock +++ b/listings/ch17-async-await/listing-17-02/Cargo.lock @@ -30,6 +30,13 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -579,13 +586,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "listing-scraper-01" -version = "0.1.0" -dependencies = [ - "trpl", -] - [[package]] name = "lock_api" version = "0.4.12" diff --git a/listings/ch17-async-await/listing-17-02/Cargo.toml b/listings/ch17-async-await/listing-17-02/Cargo.toml index 9fad6d6a96..57fe49bfe5 100644 --- a/listings/ch17-async-await/listing-17-02/Cargo.toml +++ b/listings/ch17-async-await/listing-17-02/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "listing-scraper-01" +name = "async_await" version = "0.1.0" edition = "2021" diff --git a/listings/ch17-async-await/listing-17-03/Cargo.toml b/listings/ch17-async-await/listing-17-03/Cargo.toml index 9fad6d6a96..57fe49bfe5 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.toml +++ b/listings/ch17-async-await/listing-17-03/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "listing-scraper-01" +name = "async_await" version = "0.1.0" edition = "2021" diff --git a/listings/ch17-async-await/listing-17-04/Cargo.toml b/listings/ch17-async-await/listing-17-04/Cargo.toml index 9fad6d6a96..57fe49bfe5 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.toml +++ b/listings/ch17-async-await/listing-17-04/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "listing-scraper-01" +name = "async_await" version = "0.1.0" edition = "2021" diff --git a/listings/ch17-async-await/listing-17-05/Cargo.toml b/listings/ch17-async-await/listing-17-05/Cargo.toml index 9fad6d6a96..57fe49bfe5 100644 --- a/listings/ch17-async-await/listing-17-05/Cargo.toml +++ b/listings/ch17-async-await/listing-17-05/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "listing-scraper-01" +name = "async_await" version = "0.1.0" edition = "2021" diff --git a/listings/ch17-async-await/listing-17-42/Cargo.lock b/listings/ch17-async-await/listing-17-42/Cargo.lock new file mode 100644 index 0000000000..35391aee48 --- /dev/null +++ b/listings/ch17-async-await/listing-17-42/Cargo.lock @@ -0,0 +1,1860 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-42/Cargo.toml b/listings/ch17-async-await/listing-17-42/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/listing-17-42/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/listing-17-42/src/main.rs b/listings/ch17-async-await/listing-17-42/src/main.rs new file mode 100644 index 0000000000..1a508bf582 --- /dev/null +++ b/listings/ch17-async-await/listing-17-42/src/main.rs @@ -0,0 +1,22 @@ +extern crate trpl; // for mdbook test + +// ANCHOR: all +use std::{thread, time::Duration}; + +fn main() { + let (tx, mut rx) = trpl::channel(); + + thread::spawn(move || { + for i in 1..11 { + tx.send(i).unwrap(); + thread::sleep(Duration::from_secs(1)); + } + }); + + trpl::run(async { + while let Some(message) = rx.recv().await { + println!("{message}"); + } + }); +} +// ANCHOR_END: all diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index bf7e26bde0..a072263732 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -74,7 +74,7 @@ finishes that whole process first. <Listing number="17-1" file-name="src/main.rs" caption="Defining an async function to get the title element from an HTML page"> ```rust -{{#include ../listings/ch17-async-await/listing-17-01/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-01/src/main.rs:all}} ``` </Listing> @@ -129,7 +129,7 @@ function calls together with `await` between them, as shown in Listing 17-2: <Listing number="17-2" file-name="src/main.rs" caption="Chaining with the `await` keyword"> ```rust -{{#include ../listings/ch17-async-await/listing-17-02/src/main.rs:chaining}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-02/src/main.rs:chaining}} ``` </Listing> @@ -150,7 +150,9 @@ page_title` in Listing 17-1, it is equivalent to a non-async function defined like this: ```rust +# extern crate trpl; // required for mdbook test use std::future::Future; +use trpl::Html; fn page_title(url: &str) -> impl Future<Output = Option<String>> + '_ { async move { @@ -172,7 +174,7 @@ Let’s walk through each part of the transformed version: * All of the code called in the body of the original function is wrapped in an `async move` block. Remember that blocks are expressions. This whole block is the expression returned from the function. -* This async block produces a value with the type `Option<String>`, as described +* This async block produces a value with the type `Option<String>`, as described above. That value matches the `Output` type in the return type. This is just like other blocks you have seen. * The new function body is an `async move` block because of how it uses the @@ -195,8 +197,8 @@ account for whether the page had a `<title>`. <Listing number="17-3" file-name="src/main.rs" caption="Calling the `page_title` function from `main` with a user-supplied argument"> -```rust -{{#include ../listings/ch17-async-await/listing-17-03/src/main.rs:main}} +```rust,ignore,does_not_compile +{{#rustdoc_include ../listings/ch17-async-await/listing-17-03/src/main.rs:main}} ``` </Listing> @@ -249,7 +251,9 @@ await the result of calling `page_title`, as in Listing 17-4. <Listing number="17-4" caption="Awaiting an async block with `trpl::run`" file-name="src/main.rs"> -```rust +<!-- should_panic,noplayground because mdbook does not pass args --> + +```rust,should_panic,noplayground {{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:run}} ``` @@ -275,6 +279,7 @@ it is ready to try advancing this one again. This is an invisible state machine, as if you wrote something like this: ```rust +# extern crate trpl; // required for mdbook test enum PageTitleFuture<'a> { GetAwaitPoint { url: &'a str, @@ -315,7 +320,9 @@ and racing it. <Listing number="17-5" caption="" file-name="src/main.rs"> -```rust +<!-- should_panic,noplayground because mdbook does not pass args --> + +```rust,should_panic,noplayground {{#rustdoc_include ../listings/ch17-async-await/listing-17-05/src/main.rs:all}} ``` diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 9449910c3e..8f3ed136e2 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -223,7 +223,7 @@ between them, as shown in Listing 17-10: <Listing number="17-10" caption="Sending and receiving multiple messages over the async channel and sleeping with an `.await` between each message" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:many-messages}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:many-messages}} ``` </Listing> @@ -288,7 +288,7 @@ trying *not* to do. <Listing number="17-11" caption="Separating `send` and `recv` into their own `async` blocks and awaiting the futures for those blocks" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-11/src/main.rs:futures}} ``` </Listing> @@ -333,7 +333,7 @@ it shuts down gracefully after the last message is sent and received. <Listing number="17-12" caption="A working example of sending and receiving messages between futures which correctly shuts down when complete" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:with-move}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-12/src/main.rs:with-move}} ``` </Listing> @@ -355,7 +355,7 @@ end up back in the same infinite loop we started out in. Finally, we switch from <Listing number="17-13" caption="Using multiple producers with async blocks" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-13/src/main.rs:here}} ``` </Listing> diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index d4dddb636e..2e9ac581ec 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -11,7 +11,7 @@ Thus, we could rewrite the code from Listing 17-13 to use `join!` instead of <Listing number="17-14" caption="Using `join!` to wait for multiple futures" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-14/src/main.rs:here}} ``` </Listing> @@ -31,7 +31,7 @@ replace `join!` with `join_all`. <Listing number="17-15" caption="Storing anonymous futures in a vector and calling `join_all`"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-16/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-15/src/main.rs:here}} ``` </Listing> @@ -103,7 +103,7 @@ in Listing 17-16. <Listing number="17-16" caption="Trying to use `Box::new` to align the types of the futures in a `Vec`" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-17/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-16/src/main.rs:here}} ``` </Listing> @@ -118,7 +118,7 @@ object (Listing 17-17). <Listing number="17-17" caption="Fixing the rest of the type mismatch errors by using an explicit type declaration" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-18/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-17/src/main.rs:here}} ``` </Listing> @@ -136,7 +136,7 @@ the errors mentioning `Unpin`. Although there are three of them, notice that each is very similar in its contents. <!-- manual-regeneration -cd listings/ch17-async-await/listing-17-18 +cd listings/ch17-async-await/listing-17-17 cargo build copy *only* the errors --> @@ -214,7 +214,7 @@ the futures themselves. <Listing number="17-18" caption="Using `Pin` and `Box::pin` to make the `Vec` type check" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-18/src/main.rs:here}} ``` </Listing> @@ -256,7 +256,7 @@ references to the dynamic `Future` type, as in Listing 17-19. <Listing number="17-19" caption="Using `Pin` directly with the `pin!` macro to avoid unnecessary heap allocations" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-19/src/main.rs:here}} ``` </Listing> @@ -269,7 +269,7 @@ types. For example, in Listing 17-20, the anonymous future for `a` implements <Listing number="17-20" caption="Three futures with distinct types" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-20/src/main.rs:here}} ``` </Listing> @@ -311,7 +311,7 @@ because all of the interesting behavior happens in the body of the async blocks. <Listing number="17-21" caption="Using `race` to get the result of whichever future finishes first" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-21/src/main.rs:here}} ``` </Listing> @@ -356,7 +356,7 @@ blocking. <Listing number="17-22" caption="Using `thread::sleep` to simulate slow operations" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:slow}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-22/src/main.rs:slow}} ``` </Listing> @@ -368,7 +368,7 @@ a pair of futures. To begin, each future only hands control back to the runtime <Listing number="17-23" caption="Using `thread::sleep` to simulate slow operations" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:slow-futures}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-23/src/main.rs:slow-futures}} ``` </Listing> @@ -410,7 +410,7 @@ as a starting point? <Listing number="17-24" caption="Using `sleep` to let operations switch off making progress" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-24/src/main.rs:here}} ``` </Listing> @@ -419,7 +419,7 @@ In Listing 17-24, we add `trpl::sleep` calls with await points between each call to `slow`. Now the two futures’ work is interleaved: <!-- manual-regeneration -cd listings/ch17-async-await/listing-17-25/ +cd listings/ch17-async-await/listing-17-24 cargo run copy just the output --> @@ -450,7 +450,7 @@ directly, using the `yield_now` function. In Listing 17-25, we replace all those <Listing number="17-25" caption="Using `yield_now` to let operations switch off making progress" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:yields}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-25/src/main.rs:yields}} ``` </Listing> @@ -473,7 +473,7 @@ compared to the future using `trpl::yield_now`. <Listing number="17-26" caption="Comparing the performance of `sleep` and `yield_now`" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-26/src/main.rs:here}} ``` </Listing> @@ -509,7 +509,7 @@ future. <Listing number="17-27" caption="Using our imagined `timeout` to run a slow operation with a time limit" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:here}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-27/src/main.rs:here}} ``` </Listing> @@ -533,7 +533,7 @@ Listing 17-28 shows this declaration. <Listing number="17-28" caption="Defining the signature of `timeout`" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:declaration}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-28/src/main.rs:declaration}} ``` </Listing> @@ -558,7 +558,7 @@ with `_` and return `Err(max_time)` instead. <Listing number="17-29" caption="Defining `timeout` with `race` and `sleep`" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-30/src/main.rs:implementation}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-29/src/main.rs:implementation}} ``` </Listing> diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 674f52a7d5..439e0db2ff 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -25,7 +25,7 @@ method, and then awaiting the output, as in Listing 17-30. <Listing number="17-30" caption="Creating a stream from an iterator and printing its values" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs:stream}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-30/src/main.rs:stream}} ``` </Listing> @@ -40,7 +40,7 @@ can see in the output, it reports that there is no `next` method available. <!-- TODO: fix up the path here? --> <!-- manual-regeneration -cd listings/chapter-17-async-await/listing-17-31 +cd listings/chapter-17-async-await/listing-17-30 cargo build copy only the error output --> @@ -52,7 +52,7 @@ error[E0599]: no method named `next` found for struct `Iter` in the current scop 8 | while let Some(value) = stream.next().await { | ^^^^ | - = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-31/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' + = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-30/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' = note: consider using `--verbose` to print the full type name to the console = help: items from traits can only be used if the trait is in scope help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them @@ -94,7 +94,7 @@ Listing 17-31. <Listing number="17-31" caption="Successfully using an iterator as the basis for a stream" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs}} ``` </Listing> @@ -107,7 +107,7 @@ method to filter out everything but multiples of three and five. <Listing number="17-32" caption="Filtering a `Stream` with the `StreamExt::filter` method" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-33/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs}} ``` </Listing> @@ -140,7 +140,7 @@ a `while let` loop to print all the messages from the stream. <Listing number="17-33" caption="Using the `rx` receiver as a `ReceiverStream`" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-34/src/main.rs:all}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-33/src/main.rs:all}} ``` </Listing> @@ -181,7 +181,7 @@ be polled. <Listing number="17-34" caption="Using the `StreamExt::timeout` method to set a time limit on the items in a stream" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-35/src/main.rs:timeout}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-34/src/main.rs:timeout}} ``` </Listing> @@ -198,7 +198,7 @@ for 200 milliseconds, this should affect half of the messages. <Listing number="17-35" caption="Sending messages through `tx` with an async delay without making `get_messages` an async function" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-36/src/main.rs:messages}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-35/src/main.rs:messages}} ``` </Listing> @@ -230,7 +230,7 @@ Now our code has a much more interesting result! Between every other pair of messages, we see an error reported: `Problem: Elapsed(())`. <!-- manual-regeneration -cd listings/listing-17-36 +cd listings/listing-17-35 cargo run copy only the program output, *not* the compiler output --> @@ -285,7 +285,7 @@ the infinite loop. <Listing number="17-36" caption="Creating a stream with a counter that will be emitted once every millisecond" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-37/src/main.rs:intervals}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-36/src/main.rs:intervals}} ``` </Listing> @@ -303,7 +303,7 @@ Finally, we loop over that combined stream instead of over `messages` (Listing <Listing number="17-37" caption="Attempting to merge streams of messages and intervals" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-38/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-37/src/main.rs:main}} ``` </Listing> @@ -333,7 +333,7 @@ stream, and pin it so that it is safe to do so. <Listing number="17-38" caption="Aligning the types of the the `intervals` stream with the type of the `messages` stream" file-name="src/main.rs"> ```rust,ignore -{{#rustdoc_include ../listings/ch17-async-await/listing-17-39/src/main.rs:main}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-38/src/main.rs:main}} ``` </Listing> @@ -375,7 +375,7 @@ output, not just one stream or the other. <Listing number="17-39" caption="Using `throttle` and `take` to manage the merged streams" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:throttle}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-39/src/main.rs:throttle}} ``` </Listing> @@ -393,7 +393,7 @@ never produce those interval messages in the first place! This is the inherent performance characteristics. <!-- manual-regeneration -cd listings/listing-17-40 +cd listings/listing-17-39 cargo run copy and paste only the program output --> @@ -434,7 +434,7 @@ you have a strategy. <Listing number="17-40" caption="Handling errors and shutting down the loops"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-41/src/main.rs:errors}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-40/src/main.rs:errors}} ``` </Listing> diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 3753120192..0832d058eb 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -103,27 +103,10 @@ common example of this kind of mix in real-world Rust code. <!-- TODO: extract into a listing file! --> -<Listing number="17-TODO" caption="Sending messages with blocking code in a thread and awaiting the messages in an async block" file-name="src/main.rs"> +<Listing number="17-42" caption="Sending messages with blocking code in a thread and awaiting the messages in an async block" file-name="src/main.rs"> ```rust -use std::thread; - -fn main() { - let (tx, mut rx) = trpl::channel(); - - thread::spawn(move || { - for i in 1..11 { - tx.send(i).unwrap(); - thread::sleep(Duration::from_secs(1)); - } - }); - - trpl::run(async { - while let Some(message) = rx.recv().await { - println!("{message}"); - } - }); -} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-42/src/main.rs}} ``` </Listing> From b265249e480d8120aed9f374c54d5aaa05227fd3 Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 23 Sep 2024 09:03:05 -0600 Subject: [PATCH 544/720] Ch. 17: Fix spelling and internal links --- ci/dictionary.txt | 7 +++++++ src/ch17-02-concurrency-with-async.md | 4 ++-- src/ch17-03-more-futures.md | 11 +++++------ src/ch17-04-streams.md | 2 +- src/ch17-05-traits-for-async.md | 12 +++++++----- src/ch17-06-futures-tasks-threads.md | 4 ++-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 9fd8e33e41..057d2a7f6e 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -152,6 +152,7 @@ ebook ebooks Edsger egular +ElementRef else's emoji encodings @@ -191,6 +192,8 @@ FrenchToast FromIterator FromResidual frontend +FuturesUnordered +GetAwaitPoint getrandom getter getters @@ -248,6 +251,7 @@ internet interoperate IntoFuture IntoIterator +intra InvalidDigit invariants ioerror @@ -295,6 +299,7 @@ lval macOS Matsakis mathematic +mdbook memoization metadata Metadata @@ -370,6 +375,7 @@ OurError OutlinePrint overloadable overread +PageTitleFuture PanicPayload parallelizable param @@ -521,6 +527,7 @@ TcpListener TcpStream templating test's +TextAwaitPoint TextField That'd there'd diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 8f3ed136e2..a302b5aa2e 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -152,7 +152,7 @@ what we saw with threads. That is because the `trpl::join` function is *fair*, meaning it checks each future equally often, alternating between them, and never lets one race ahead if the other is ready. With threads, the operating system decides which thread to check and how long to let it run. With async Rust, the -runtime decides which taks to check. (In practice, the details get complicated +runtime decides which task to check. (In practice, the details get complicated because an async runtime might use operating system threads under the hood as part of how it manages concurrency, so guaranteeing fairness can be more work for a runtime—but it is still possible!) Runtimes do not have to guarantee @@ -382,4 +382,4 @@ received 'you' This is a good start, but it limits us to just a handful of futures: two with `join`, or three with `join3`. Let’s see how we might work with more futures. -[streams]: /ch17-05-streams.md +[streams]: ch17-05-streams.html diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 2e9ac581ec..35e919249f 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -325,11 +325,11 @@ to poll first. Regardless of whether the implementation of race we are using is fair, though, *one* of the futures will run up to the first `.await` in its body before another task can start. -Recall from [“What Are Futures?”][futures] that at each await point, Rust gives -a runtime a chance to pause the task and switch to another one if the future -being awaited is not ready. The inverse is also true: Rust *only* pauses async -blocks and hands control back to a runtime at an await point. Everything between -await points is synchronous. +Recall from [Our First Async Program][async-program] that at each await point, +Rust gives a runtime a chance to pause the task and switch to another one if the +future being awaited is not ready. The inverse is also true: Rust *only* pauses +async blocks and hands control back to a runtime at an await point. Everything +between await points is synchronous. That means if you do a bunch of work in an async block without an await point, that future will block any other futures from making progress. You may sometimes @@ -597,5 +597,4 @@ to consider first, though: [collections]: ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: ch12-03-improving-error-handling-and-modularity.html -[futures]: ch17-01-futures-and-syntax.html#what-are-futures [async-program]: ch17-01-futures-and-syntax.html#our-first-async-program diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 439e0db2ff..b3e4cac9a7 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -443,4 +443,4 @@ That is a good note to turn to our final section and wrap up this walk through async in Rust, by discussing how futures (including streams), tasks, and threads relate to each other, and how you can use them together. -[17-02-messages]: ch17-02-concurrency-with-async.md#message-passing +[17-02-messages]: ch17-02-concurrency-with-async.html#message-passing diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 0a5ee1f89e..91193a4542 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -11,9 +11,9 @@ still leaving the *really* deep dive for other documentation! ### Future -Back in [Async Functions][async-functions], we noted that `Future` is a trait. -Let’s start by taking a closer look at how it works. Here is how Rust defines -a `Future`: +Back in [Futures and the Async Syntax][futures-syntax], we noted that `Future` +is a trait. Let’s start by taking a closer look at how it works. Here is how +Rust defines a `Future`: ```rust use std::pin::Pin; @@ -199,7 +199,7 @@ starts to explain the error message we saw above—but that was in terms of `Unpin`, not `Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, and why does `Future` need `self` to be in a `Pin` type to call `poll`? -In [“What Are Futures”][what-are-futures], we described how a series of await +In [Our First Async Program][first-async], we described how a series of await points in a future get compiled into a state machine—and noted how the compiler helps make sure that state machine follows all of Rust’s normal rules around safety, including borrowing and ownership. To make that work, Rust looks at what @@ -379,10 +379,12 @@ even when you need to write your own streaming data type, you *only* have to implement `Stream`, and then anyone who uses your data type can use `StreamExt` and its methods with it automatically. -[counting]: /ch17-02-concurrency-with-async.md +[futures-syntax]: ch17-01-futures-and-syntax.html +[counting]: ch17-02-concurrency-with-async.html [async-book]: https://rust-lang.github.io/async-book/ [under-the-hood]: https://rust-lang.github.io/async-book/02_execution/01_chapter.html [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html +[first-async]: ch17-01-futures-and-syntax.html#our-first-async-program That’s all we’re going to cover for the lower-level details on these traits. To wrap up, let’s consider how futures (including streams), tasks, and threads all diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 0832d058eb..a10b391bf6 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -139,5 +139,5 @@ as your Rust programs get bigger. In addition, we’ll discuss how Rust’s idio relate to those you might be familiar with from object-oriented programming. -[combining-futures]: ch17-04-more-ways-of-combining-futures.md#building-our-own-async-abstractions -[streams]: ch17-05-streams.md#composing-streams +[combining-futures]: ch17-03-more-futures.html#building-our-own-async-abstractions +[streams]: ch17-04-streams.html#composing-streams From dd80496a982306e40aeceb29009240299ba9de2c Mon Sep 17 00:00:00 2001 From: Pavloslav <pavloslav@ukr.net> Date: Tue, 24 Sep 2024 11:52:00 +0300 Subject: [PATCH 545/720] Fixed Ukrainian translation link to community repo --- src/appendix-06-translation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appendix-06-translation.md b/src/appendix-06-translation.md index 82cb447817..ef78fc2547 100644 --- a/src/appendix-06-translation.md +++ b/src/appendix-06-translation.md @@ -9,7 +9,7 @@ For resources in languages other than English. Most are still in progress; see - [Português](https://github.com/nunojesus/rust-book-pt-pt) (PT) - [简体中文](https://github.com/KaiserY/trpl-zh-cn) - [正體中文](https://github.com/rust-tw/book-tw) -- [Українська](https://github.com/pavloslav/rust-book-uk-ua) +- [Українська](https://rust-lang-ua.github.io/rustbook_ukrainian) - [Español](https://github.com/thecodix/book), [alternate](https://github.com/ManRR/rust-book-es) - [Русский](https://github.com/rust-lang-ru/book) - [한국어](https://github.com/rinthel/rust-lang-book-ko) From 42b59635d223abd7c065798c719451a31dda640b Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 23 Sep 2024 15:07:44 -0600 Subject: [PATCH 546/720] Ch. 17: General cleanup and edits to esp. 17.05 - Introduce diagrams into 17.05 to break up the wall of text and make it easier to visualize. - Extract the state machine code to make it easier to reference. - Standardize on `await` instead of `.await` for inline code references. - Move note about `race` and `select` up to 17.01 since the text now references it there, and update the text in 17.03 to account for already having introduced the function. - Fix up a number of code samples to avoid showing `extern crate trpl;`. - Rewrite the transition between 17.04 and 17.05 to account for having restructured the chapter. - Rework the example code in 17.05 to refer to the `page_title` example from the rewritten 17.01 instead of the (now-removed) `hello`. - When discussing the `Future::poll` method, explicitly address the `cx` parameter: note what it is used for, and then move on. --- dot/trpl17-01.dot | 3 - dot/trpl17-03.dot | 19 + dot/trpl17-04.dot | 32 + .../listing-17-31/src/main.rs | 2 + .../listing-17-32/src/main.rs | 2 + .../no-listing-state-machine/Cargo.lock | 1793 +++++++++++++++++ .../no-listing-state-machine/Cargo.toml | 8 + .../no-listing-state-machine/output.txt | 2 + .../no-listing-state-machine/src/lib.rs | 8 + src/ch17-00-async-await.md | 2 +- src/ch17-01-futures-and-syntax.md | 20 +- src/ch17-02-concurrency-with-async.md | 14 +- src/ch17-03-more-futures.md | 30 +- src/ch17-04-streams.md | 14 +- src/ch17-05-traits-for-async.md | 169 +- src/ch17-06-futures-tasks-threads.md | 4 +- src/img/trpl17-03.svg | 30 + src/img/trpl17-04.svg | 46 + 18 files changed, 2081 insertions(+), 117 deletions(-) create mode 100644 dot/trpl17-03.dot create mode 100644 dot/trpl17-04.dot create mode 100644 listings/ch17-async-await/no-listing-state-machine/Cargo.lock create mode 100644 listings/ch17-async-await/no-listing-state-machine/Cargo.toml create mode 100644 listings/ch17-async-await/no-listing-state-machine/output.txt create mode 100644 listings/ch17-async-await/no-listing-state-machine/src/lib.rs create mode 100644 src/img/trpl17-03.svg create mode 100644 src/img/trpl17-04.svg diff --git a/dot/trpl17-01.dot b/dot/trpl17-01.dot index 97bd15e894..ed2d969f2f 100644 --- a/dot/trpl17-01.dot +++ b/dot/trpl17-01.dot @@ -28,9 +28,6 @@ digraph { subgraph cluster_task_b { label = "Task B"; - // for horizontal alignment purposes only - // newrank = true; - B0 [style = invis;]; B1; diff --git a/dot/trpl17-03.dot b/dot/trpl17-03.dot new file mode 100644 index 0000000000..6c63b7bde4 --- /dev/null +++ b/dot/trpl17-03.dot @@ -0,0 +1,19 @@ +digraph { + rankdir = RL; + overlap = false; + dpi = 300.0; + splines = false; + cluster = true; + + node [shape = "plaintext";]; + + fut1 [label = <<table border="0" cellborder="1" cellspacing="0"> + <tr><td sides="B">fut1</td></tr> + <tr><td>0</td></tr> + <tr><td port="target">1</td></tr> + <tr><td port="source"> </td></tr> + </table>>;]; + + edge [tailclip = "false";]; + fut1:source:c -> fut1:target [dir = forward;]; +} \ No newline at end of file diff --git a/dot/trpl17-04.dot b/dot/trpl17-04.dot new file mode 100644 index 0000000000..afcf8e77a1 --- /dev/null +++ b/dot/trpl17-04.dot @@ -0,0 +1,32 @@ +digraph { + rankdir = RL; + overlap = false; + dpi = 300.0; + splines = false; + cluster = true; + + node [shape = "plaintext";]; + + // Group the two together, which results in the desired alignment. + subgraph { + // But don't show the frame! + style = "invis"; + + fut1 [label = <<table border="0" cellborder="1" cellspacing="0" bgcolor="gray"> + <tr><td sides="B">fut1</td></tr> + <tr><td>?</td></tr> + <tr><td port="target">?</td></tr> + <tr><td>?</td></tr> + </table>>;]; + + fut2 [label = <<table border="0" cellborder="1" cellspacing="0"> + <tr><td sides="B">fut2</td></tr> + <tr><td>0</td></tr> + <tr><td>1</td></tr> + <tr><td port="source"> </td></tr> + </table>>;]; + + edge [tailclip = "false"; dir = forward]; + fut2:source:c -> fut1:target:e; + } +} \ No newline at end of file diff --git a/listings/ch17-async-await/listing-17-31/src/main.rs b/listings/ch17-async-await/listing-17-31/src/main.rs index 0a7fc87c21..f03a460aa8 100644 --- a/listings/ch17-async-await/listing-17-31/src/main.rs +++ b/listings/ch17-async-await/listing-17-31/src/main.rs @@ -1,5 +1,6 @@ extern crate trpl; // required for mdbook test +// ANCHOR: all use trpl::StreamExt; fn main() { @@ -13,3 +14,4 @@ fn main() { } }); } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/listing-17-32/src/main.rs b/listings/ch17-async-await/listing-17-32/src/main.rs index 017185bed5..2667c5e9ae 100644 --- a/listings/ch17-async-await/listing-17-32/src/main.rs +++ b/listings/ch17-async-await/listing-17-32/src/main.rs @@ -1,5 +1,6 @@ extern crate trpl; // required for mdbook test +// ANCHOR: all use trpl::StreamExt; fn main() { @@ -16,3 +17,4 @@ fn main() { } }); } +// ANCHOR_END: all diff --git a/listings/ch17-async-await/no-listing-state-machine/Cargo.lock b/listings/ch17-async-await/no-listing-state-machine/Cargo.lock new file mode 100644 index 0000000000..5e72795fea --- /dev/null +++ b/listings/ch17-async-await/no-listing-state-machine/Cargo.lock @@ -0,0 +1,1793 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + +[[package]] +name = "cc" +version = "1.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.1.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/no-listing-state-machine/Cargo.toml b/listings/ch17-async-await/no-listing-state-machine/Cargo.toml new file mode 100644 index 0000000000..e094f067f1 --- /dev/null +++ b/listings/ch17-async-await/no-listing-state-machine/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async_await" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[dependencies] +trpl = { path = "../../../packages/trpl" } diff --git a/listings/ch17-async-await/no-listing-state-machine/output.txt b/listings/ch17-async-await/no-listing-state-machine/output.txt new file mode 100644 index 0000000000..10a18bc488 --- /dev/null +++ b/listings/ch17-async-await/no-listing-state-machine/output.txt @@ -0,0 +1,2 @@ +$ cargo run +error: a bin target must be available for `cargo run` diff --git a/listings/ch17-async-await/no-listing-state-machine/src/lib.rs b/listings/ch17-async-await/no-listing-state-machine/src/lib.rs new file mode 100644 index 0000000000..f718ba8e08 --- /dev/null +++ b/listings/ch17-async-await/no-listing-state-machine/src/lib.rs @@ -0,0 +1,8 @@ +extern crate trpl; // required for mdbook test + +// ANCHOR: enum +enum PageTitleFuture<'a> { + GetAwaitPoint { url: &'a str }, + TextAwaitPoint { response: trpl::Response }, +} +// ANCHOR_END: enum diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 1749cc17a7..ecd9fb14b3 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -136,7 +136,7 @@ under the hood. Now, let’s dive into how async programming in Rust actually works! In the rest of this chapter, we will: -* see how to use Rust’s `async` and `.await` syntax +* see how to use Rust’s `async` and `await` syntax * explore how to use the async model to solve some of the same challenges we looked at in Chapter 16 * look at how multithreading and async provide complementary solutions, which diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index a072263732..8197b8e6c0 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -279,15 +279,7 @@ it is ready to try advancing this one again. This is an invisible state machine, as if you wrote something like this: ```rust -# extern crate trpl; // required for mdbook test -enum PageTitleFuture<'a> { - GetAwaitPoint { - url: &'a str, - }, - TextAwaitPoint { - response: trpl::Response, - }, -} +{{#rustdoc_include ../listings/ch17-async-await/no-listing-state-machine/src/lib.rs:enum}} ``` Writing that out by hand would be tedious and error-prone, especially when @@ -331,8 +323,14 @@ and racing it. In Listing 17-5, we begin by calling `page_title` with both of the user-supplied URLs. We save the futures produced by calling `page_title` as `title_fut_1` and `title_fut_2`. Remember, these don’t do anything yet, because futures are lazy, -and we have not yet awaited them. Then we pass the futures `trpl::race`, which -returns a value to indicate which of the futures passed to it finishes first. +and we have not yet awaited them. Then we pass the futures to `trpl::race`, +which returns a value to indicate which of the futures passed to it finishes +first. + +> Note: Under the hood, `race` is built on a more general function, `select`, +> which you will encounter more often in real-world Rust code. A `select` +> function can do a lot of things that `trpl::race` function cannot, but it also +> has some additional complexity that we can skip over for now. Either future can legitimately “win,” so it does not make sense to return a `Result`. Instead, `race` returns a type we have not seen before, diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index a302b5aa2e..a222b851d8 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -37,7 +37,7 @@ that our top-level function can be async. Then we write two loops within that block, each with a `trpl::sleep` call in it, which waits for half a second (500 milliseconds) before sending the next message. We put one loop in the body of a `trpl::spawn_task` and the other in a -top-level `for` loop. We also add an `.await` after the `sleep` calls. +top-level `for` loop. We also add an `await` after the `sleep` calls. This does something similar to the thread-based implementation—including the fact that you may see the messages appear in a different order in your own @@ -68,7 +68,7 @@ In Listing 17-7, we can use `await` to do the same thing, because the task handle itself is a future. Its `Output` type is a `Result`, so we also unwrap it after awaiting it. -<Listing number="17-7" caption="Using `.await` with a join handle to run a task to completion" file-name="src/main.rs"> +<Listing number="17-7" caption="Using `await` with a join handle to run a task to completion" file-name="src/main.rs"> ```rust {{#rustdoc_include ../listings/ch17-async-await/listing-17-07/src/main.rs:handle}} @@ -99,7 +99,7 @@ hi number 9 from the first task! ``` So far, it looks like async and threads give us the same basic outcomes, just -with different syntax: using `.await` instead of calling `join` on the join +with different syntax: using `await` instead of calling `join` on the join handle, and awaiting the `sleep` calls. The bigger difference is that we did not need to spawn another operating system @@ -220,7 +220,7 @@ between them, as shown in Listing 17-10: <!-- We cannot test this one because it never stops! --> -<Listing number="17-10" caption="Sending and receiving multiple messages over the async channel and sleeping with an `.await` between each message" file-name="src/main.rs"> +<Listing number="17-10" caption="Sending and receiving multiple messages over the async channel and sleeping with an `await` between each message" file-name="src/main.rs"> ```rust,ignore {{#rustdoc_include ../listings/ch17-async-await/listing-17-10/src/main.rs:many-messages}} @@ -266,14 +266,14 @@ class="keystroke">ctrl-c</span>. Let’s start by understanding why the messages all come in at once after the full delay, rather than coming in with delays in between each one. Within a given -async block, the order that `.await` keywords appear in the code is also the +async block, the order that `await` keywords appear in the code is also the order they happen when running the program. There is only one async block in Listing 17-10, so everything in it runs linearly. There is still no concurrency. All the `tx.send` calls happen, interspersed with all of the `trpl::sleep` calls and their associated await -points. Only then does the `while let` loop get to go through any of the -`.await` points on the `recv` calls. +points. Only then does the `while let` loop get to go through any of the `await` +points on the `recv` calls. To get the behavior we want, where the sleep delay happens between receiving each message, we need to put the `tx` and `rx` operations in their own async diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 35e919249f..ea9c7460ad 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -291,22 +291,16 @@ syntax for working with them, and that is a good thing. When we “join” futures with the `join` family of functions and macros, we require *all* of them to finish before we move on. Sometimes, though, we only need *some* future from a set to finish before we move on—kind of like racing -one future against another. This operation is often named `race` for exactly -that reason. - -> Note: Under the hood, `race` is built on a more general function, `select`, -> which you will encounter more often in real-world Rust code. A `select` -> function can do a lot of things that `trpl::race` function cannot, but it also -> has some additional complexity that we can skip over for now. - -In Listing 17-21, we use `trpl::race` to run two futures, `slow` and `fast`, -against each other. Each one prints a message when it starts running, pauses for -some amount of time by calling and awaiting `sleep`, and then prints another -message when it finishes. Then we pass both to `trpl::race` and wait for one of -them to finish. (The outcome here won’t be too surprising: `fast` wins!) Note -that unlike the first time we used `race` back in [Our First Async -Program][async-program], we just ignore the `Either` instance it returns here, -because all of the interesting behavior happens in the body of the async blocks. +one future against another. + +In Listing 17-21, we once again use `trpl::race` to run two futures, `slow` and +`fast`, against each other. Each one prints a message when it starts running, +pauses for some amount of time by calling and awaiting `sleep`, and then prints +another message when it finishes. Then we pass both to `trpl::race` and wait for +one of them to finish. (The outcome here won’t be too surprising: `fast` wins!) +Unlike when we used `race` back in [Our First Async Program][async-program], we +just ignore the `Either` instance it returns here, because all of the +interesting behavior happens in the body of the async blocks. <Listing number="17-21" caption="Using `race` to get the result of whichever future finishes first" file-name="src/main.rs"> @@ -322,7 +316,7 @@ first. That is because the implementation of this particular `race` function is not fair. It always runs the futures passed as arguments in the order they are passed. Other implementations *are* fair, and will randomly choose which future to poll first. Regardless of whether the implementation of race we are using is -fair, though, *one* of the futures will run up to the first `.await` in its body +fair, though, *one* of the futures will run up to the first `await` in its body before another task can start. Recall from [Our First Async Program][async-program] that at each await point, @@ -575,7 +569,7 @@ using smaller async building blocks. For example, you can use this same approach to combine timeouts with retries, and in turn use those with things like network calls—one of the examples from the beginning of the chapter! -In practice, you will usually work directly with `async` and `.await`, and +In practice, you will usually work directly with `async` and `await`, and secondarily with functions and macros like `join`, `join_all`, `race`, and so on. You will only need to reach for `pin` now and again to use them with those APIs. diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index b3e4cac9a7..28e8d9793f 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -88,13 +88,13 @@ method and also many other utility methods like those from `Iterator`. We will return to the `Stream` and `StreamExt` traits in a bit more detail at the end of the chapter. For now, this is enough to let us keep moving. -All we need to do here is add a `use` statement for `trpl::StreamExt`, as in -Listing 17-31. +All we need to do is add a `use` statement for `trpl::StreamExt`, as in Listing +17-31. <Listing number="17-31" caption="Successfully using an iterator as the basis for a stream" file-name="src/main.rs"> ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs:all}} ``` </Listing> @@ -107,7 +107,7 @@ method to filter out everything but multiples of three and five. <Listing number="17-32" caption="Filtering a `Stream` with the `StreamExt::filter` method" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-32/src/main.rs:all}} ``` </Listing> @@ -439,8 +439,8 @@ you have a strategy. </Listing> -That is a good note to turn to our final section and wrap up this walk through -async in Rust, by discussing how futures (including streams), tasks, and threads -relate to each other, and how you can use them together. +Now that we have seen a bunch of async in practice, let’s take a step back and +dig into a few of the details of how `Future`, `Stream`, and the other key +traits which Rust uses to make async work. [17-02-messages]: ch17-02-concurrency-with-async.html#message-passing diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 91193a4542..56e3def6bb 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -56,14 +56,16 @@ available. > becoming ready! Futures which are safe to poll again will say so explicitly in > their documentation. This is similar to how `Iterator::next` behaves! -Under the hood, when you call `.await`, Rust compiles that to code which calls -`poll`, kind of (although not exactly <!-- TODO: describe `IntoFuture`? -->) -like this: +Under the hood, when you see code which uses `await`, Rust compiles that to code +which calls `poll`. If you look back at Listing 17-4, where we printed out the +page title for a single URL once it resolved, Rust compiles it into something +kind of (although not exactly) like this: ```rust,ignore -match hello("async").poll() { - Ready(_) => { - // We’re done! +match page_title(url).poll() { + Ready(page_title) => match page_title { + Some(title) => println!("The title for {url} was {title}"), + None => println!("{url} had no title"), } Pending => { // But what goes here? @@ -76,11 +78,12 @@ again… and again, and again, until the future is finally ready. In other words a loop: ```rust,ignore -let hello_fut = hello("async"); +let mut page_title_fut = page_title(url); loop { - match hello_fut.poll() { - Ready(_) => { - break; + match page_title_fut.poll() { + Ready(value) => match page_title { + Some(title) => println!("The title for {url} was {title}"), + None => println!("{url} had no title"), } Pending => { // continue @@ -89,7 +92,7 @@ loop { } ``` -If Rust compiled it to exactly that code, though, every `.await` would be +If Rust compiled it to exactly that code, though, every `await` would be blocking—exactly the opposite of what we were going for! Instead, Rust needs makes sure that the loop can hand off control to something which can pause work on this future and work on other futures and check this one again later. That @@ -119,7 +122,7 @@ When we introduced the idea of pinning, while working on Listing 17-17, we ran into a very gnarly error message. Here is the relevant part of it again: <!-- manual-regeneration -cd listings/ch17-async-await/listing-17-18 +cd listings/ch17-async-await/listing-17-17 cargo build copy *only* the final `error` block from the errors --> @@ -156,8 +159,7 @@ directly awaiting a Future requires that the future in question implement the further into how the `Future` type actually works, in particular around *pinning*. -Let’s look again at the definition of `Future`, focusing specifically on the -`poll` method’s `self` type: +Let’s look again at the definition of `Future`: ```rust use std::pin::Pin; @@ -171,33 +173,38 @@ pub trait Future { } ``` -This is the first time we have seen a method where `self` has a type annotation -like this. When we specify the type of `self` like this, we are telling Rust -what type `self` must be to call this method. These kinds of type annotations -for `self` are similar to those for other function parameters, but with the -restriction that the type annotation has to be the type on which the method is -implemented, or a reference or smart pointer to that type, or a `Pin` wrapping a -reference to that type. We will see more on this syntax in Chapter 18. For now, -it is enough to know that if we want to poll a future (to check whether it is -`Pending` or `Ready(Output)`), we need a mutable reference to the type, which is -wrapped in a `Pin`. +The `cx` parameter and its `Context` type is interesting, but is beyond the +scope of this chapter: you generally only need to worry about it when writing a +custom `Future` implementation. + +Instead, we will focus on the type for `self`. This is the first time we have +seen a method where `self` has a type annotation. A type annotation for `self` +is similar to type annotations for other function parameters, with two key +differences. First, when we specify the type of `self` like this, we are telling +Rust what type `self` must be to call this method. Second, a type annotation on +`self` cannot be just any type. It is only allowed to be the type on which the +method is implemented, or a reference or smart pointer to that type, or a `Pin` +wrapping a reference to that type. We will see more on this syntax in Chapter +18. For now, it is enough to know that if we want to poll a future (to check +whether it is `Pending` or `Ready(Output)`), we need a mutable reference to the +type, which is wrapped in a `Pin`. `Pin` is a wrapper type. In some ways, it is like the `Box`, `Rc`, and other smart pointer types we saw in Chapter 15, which also wrap other types. Unlike -those, however, `Pin` only works with *other pointer types* like reference (`&` -and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` -works with types which implement the `Deref` or `DerefMut` traits, which we -covered in Chapter 15. You can think of this restriction as equivalent to only -working with pointers, though, since implementing `Deref` or `DerefMut` means -your type behaves like a pointer type. `Pin` is also not a pointer itself, and -it does not have any behavior of its own like the ref counting of `Rc` or `Arc`. -It is purely a tool the compiler can use to uphold the relevant guarantees, by +those, however, `Pin` only works with *pointer types* like references (`&` and +`&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` works +with types which implement the `Deref` or `DerefMut` traits, which we covered in +Chapter 15. You can think of this restriction as equivalent to only working with +pointers, though, since implementing `Deref` or `DerefMut` means your type +behaves like a pointer type. `Pin` is also not a pointer itself, and it does not +have any behavior of its own like the ref counting of `Rc` or `Arc`. It is +purely a tool the compiler can use to uphold the relevant guarantees, by wrapping pointers in the type. -Recalling that `.await` is implemented in terms of calls to `poll`, this -starts to explain the error message we saw above—but that was in terms of -`Unpin`, not `Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, -and why does `Future` need `self` to be in a `Pin` type to call `poll`? +Recalling that `await` is implemented in terms of calls to `poll`, this starts +to explain the error message we saw above—but that was in terms of `Unpin`, not +`Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, and why does +`Future` need `self` to be in a `Pin` type to call `poll`? In [Our First Async Program][first-async], we described how a series of await points in a future get compiled into a state machine—and noted how the compiler @@ -212,33 +219,58 @@ getting a mutable or immutable reference to it. So far so good: if we get anything wrong about the ownership or references in a given async block, the borrow checker will tell us. When we want to move around the future that corresponds to that block—like moving it into a `Vec` to pass to -`join_all`—things get trickier. +`join_all`, the way we did back in—things get trickier. When we move a future—whether by pushing into a data structure to use as an iterator with `join_all`, or returning them from a function—that actually means moving the state machine Rust creates for us. And unlike most other types in Rust, the futures Rust creates for async blocks can end up with references to -themselves in the fields of any given variant. Any object which has a reference -to itself is unsafe to move, though, because references always point to the -actual memory address of the thing they refer to. If you move the data structure -itself, you *have* to update any references to it, or they will be left pointing -to the old location. - -In principle, you could make the Rust compiler try to update every reference to -an object every time it gets moved. That would potentially be a lot of -performance overhead, especially given there can be a whole web of references -that need updating. On the other hand, if we could make sure the data structure -in question *does not move in memory*, we do not have to update any references. -And this is exactly what Rust’s borrow checker already guarantees: you cannot -move an item which has any active references to it using safe code. +themselves in the fields of any given variant, as in Figure 17-3 (a simplified +illustration to help you get a feel for the idea, rather than digging into what +are often fairly complicated details). + +<figure> + +<img alt="Concurrent work flow" src="img/trpl17-03.svg" class="center" /> + +<figcaption>Figure 17-3: A self-referential data type.</figcaption> + +</figure> + +By default, though, any object which has a reference to itself is unsafe to +move, because references always point to the actual memory address of the thing +they refer to. If you move the data structure itself, those internal references +will be left pointing to the old location. However, that memory location is now +invalid. For one thing, its value will not be updated when you make changes to +the data structure. For another—and more importantly!—the computer is now free +to reuse that memory for other things! You could end up reading completely +unrelated data later. + +<figure> + +<img alt="Concurrent work flow" src="img/trpl17-04.svg" class="center" /> + +<figcaption>Figure 17-4: The unsafe result of moving a self-referential data type.</figcaption> + +</figure> + +In principle, the Rust compiler could try to update every reference to an object +every time it gets moved. That would potentially be a lot of performance +overhead, especially given there can be a whole web of references that need +updating. On the other hand, if we could make sure the data structure in +question *does not move in memory*, we do not have to update any references. +This is exactly what Rust’s borrow checker requires: you cannot move an item +which has any active references to it using safe code. `Pin` builds on that to give us the exact guarantee we need. When we *pin* a -value by wrapping a pointer to it in `Pin`, it can no longer move. Thus, if you -have `Pin<Box<SomeType>>`, you actually pin the `SomeType` value, *not* the -`Box` pointer. In fact, the pinned box pointer can move around freely. Remember: -we care about making sure the data ultimately being referenced stays in its -place. If a pointer moves around, but the data it points to is in the same -place, there is no problem. +value by wrapping a pointer to that value in `Pin`, it can no longer move. Thus, +if you have `Pin<Box<SomeType>>`, you actually pin the `SomeType` value, *not* +the `Box` pointer. In fact, the `Box` pointer can still move around freely. +Remember: we care about making sure the data ultimately being referenced stays +in its place. If a pointer moves around, but the data it points to is in the +same place, there is no problem. + +<!-- TODO: diagram of `Pin` --> However, most types are perfectly safe to move around, even if they happen to be behind a `Pin` pointer. We only need to think about pinning when items have @@ -247,10 +279,10 @@ internal structure like that, so they are obviously safe. Neither do most types you normally work with in Rust. A `Vec`, for example, does not have any internal references it needs to keep up to date this way, so you can move it around without worrying. If you have a `Pin<Vec<String>>`, you would have to do -everything via Pin’s safe but restrictive APIs, even though a `Vec<String>` is -always safe to move if there are no other references to it. We need a way to -tell the compiler that it is actually just fine to move items around in cases -like these. For that, we have `Unpin`. +everything via the safe but restrictive APIs provided by `Pin`, even though a +`Vec<String>` is always safe to move if there are no other references to it. We +need a way to tell the compiler that it is actually just fine to move items +around in cases like these. For that, we have `Unpin`. `Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. Recall that marker traits have no functionality of their own. They exist only to @@ -259,6 +291,8 @@ in a particular context. `Unpin` informs the compiler that a given type does *not* need to uphold any particular guarantees about whether the value in question can be moved. +<!-- TODO: a diagram for `Unpin`? I have no idea what or how, though. Hmm. --> + Just like `Send` and `Sync`, the compiler implements `Unpin` automatically for all types where it can prove it is safe. Implementing `Unpin` manually is unsafe because it requires *you* to uphold all the guarantees which make `Pin` and @@ -281,9 +315,10 @@ When you see them, though, now you will know what to do! > they are self-referential. Types which require `Pin` show up *most* commonly > in async Rust today, but you might—very rarely!—see it in other contexts, too. > -> The specific mechanics for how `Pin` and `Unpin` work under the hood are -> covered extensively in the API documentation for `std::pin`, so if you would -> like to understand them more deeply, that is a great place to start. +> The specifics of how `Pin` and `Unpin` work, and the rules they are required +> to uphold, are covered extensively in the API documentation for `std::pin`, so +> if you would like to understand them more deeply, that is a great place to +> start. > > If you want to understand how things work “under the hood” in even more > detail, the official [_Asynchronous Programming in Rust_][async-book] book has @@ -355,9 +390,9 @@ TODO: update this if/when tokio/etc. update their MSRV and switch to using async in traits, since the lack thereof is the reason they do not yet have this. --> -> Note: The actual definition we will use looks slightly different than this, -> because it supports versions of Rust which did not yet support using async -> functions in traits. As a result, it looks like this: +> Note: The actual definition we used earlier in the chapter looks slightly +> different than this, because it supports versions of Rust which did not yet +> support using async functions in traits. As a result, it looks like this: > > ```rust,ignore > fn next(&mut self) -> Next<'_, Self> where Self: Unpin; @@ -365,7 +400,7 @@ in traits, since the lack thereof is the reason they do not yet have this. > > That `Next` type is just a simple `struct` which implements `Future` and gives > a way to name the lifetime of the reference to `self` with `Next<'_, Self>`, -> so that `.await` can work with this! +> so that `await` can work with this! The `StreamExt` trait is also the home of all the interesting methods available to use with streams. `StreamExt` is automatically implemented for every type diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index a10b391bf6..b54117ccc4 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -1,4 +1,4 @@ -# Futures, Tasks, and Threads +## Futures, Tasks, and Threads As we saw in the previous chapter, threads provide one approach to concurrency. We have seen another approach to concurrency in this chapter, using async with @@ -101,8 +101,6 @@ choose between threads and async. You can use them together freely, letting each one serve the part it is best at. For example, Listing 17-TODO shows a fairly common example of this kind of mix in real-world Rust code. -<!-- TODO: extract into a listing file! --> - <Listing number="17-42" caption="Sending messages with blocking code in a thread and awaiting the messages in an async block" file-name="src/main.rs"> ```rust diff --git a/src/img/trpl17-03.svg b/src/img/trpl17-03.svg new file mode 100644 index 0000000000..fed6c36040 --- /dev/null +++ b/src/img/trpl17-03.svg @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<!-- Generated by graphviz version 12.1.1 (20240910.0053) + --> +<!-- Pages: 1 --> +<svg height="150pt" + viewBox="0.00 0.00 371.00 442.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> +<g id="graph0" class="graph" transform="scale(4.16667 4.16667) rotate(0) translate(4 102)"> +<polygon fill="white" stroke="none" points="-4,4 -4,-102 85,-102 85,4 -4,4"/> +<!-- fut1 --> +<g id="node1" class="node"> +<title>fut1 + +fut1 + +0 + +1 + +   + + + +fut1:c->fut1:target + + + + + diff --git a/src/img/trpl17-04.svg b/src/img/trpl17-04.svg new file mode 100644 index 0000000000..e3472baa7c --- /dev/null +++ b/src/img/trpl17-04.svg @@ -0,0 +1,46 @@ + + + + + + + + +%3 + + + +fut1 + + +fut1 + +? + +? + +? + + + +fut2 + +fut2 + +0 + +1 + + + + + +fut2:c->fut1:c + + + + + From beac73a818a459ce5e3dd3f7eeb6bf7518552e8e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 23 Sep 2024 15:07:44 -0600 Subject: [PATCH 547/720] Ch. 17: introduce diagrams for `Pin` and `Unpin`. --- dot/trpl17-05.dot | 42 ++++++++++++++++ dot/trpl17-06.dot | 64 ++++++++++++++++++++++++ dot/trpl17-07.dot | 39 +++++++++++++++ dot/trpl17-08.dot | 62 ++++++++++++++++++++++++ src/ch17-05-traits-for-async.md | 70 ++++++++++++++++++++++----- src/img/trpl17-05.svg | 69 ++++++++++++++++++++++++++ src/img/trpl17-06.svg | 86 +++++++++++++++++++++++++++++++++ src/img/trpl17-07.svg | 57 ++++++++++++++++++++++ src/img/trpl17-08.svg | 85 ++++++++++++++++++++++++++++++++ 9 files changed, 561 insertions(+), 13 deletions(-) create mode 100644 dot/trpl17-05.dot create mode 100644 dot/trpl17-06.dot create mode 100644 dot/trpl17-07.dot create mode 100644 dot/trpl17-08.dot create mode 100644 src/img/trpl17-05.svg create mode 100644 src/img/trpl17-06.svg create mode 100644 src/img/trpl17-07.svg create mode 100644 src/img/trpl17-08.svg diff --git a/dot/trpl17-05.dot b/dot/trpl17-05.dot new file mode 100644 index 0000000000..e036a385c3 --- /dev/null +++ b/dot/trpl17-05.dot @@ -0,0 +1,42 @@ +digraph { + rankdir = LR; + dpi = 300.0; + + node [shape = "plaintext";]; + + pinned_box [label = < + + +
Pin
>;]; + + subgraph cluster_box { + label = ""; + peripheries = 0; + + subgraph cluster_box_internal { + peripheries = 1; + label = "b1"; + shape = box; + style = solid; + pin [shape = "point";]; + } + } + + subgraph cluster_deref { + style = bold; + label = "pinned"; + + box [label = < + + + + + +
fut
0
...
1
>;]; + } + + edge [tailclip = false;]; + pinned_box -> pin [tailport = "source:c"; arrowhead = "none";]; + pin -> box [headport = "target";]; + box -> box [tailport = "source:c"; headport = "internal";]; +} \ No newline at end of file diff --git a/dot/trpl17-06.dot b/dot/trpl17-06.dot new file mode 100644 index 0000000000..11b79574c4 --- /dev/null +++ b/dot/trpl17-06.dot @@ -0,0 +1,64 @@ +digraph { + rankdir = LR; + newrank = true; + dpi = 300.0; + + node [shape = "plaintext";]; + + + subgraph cluster_not_fut { + peripheries = 0; + + pin [label = < + + +
Pin
>;]; + + subgraph cluster_boxes { + peripheries = 0; + rank = same; + + subgraph cluster_box_1 { + subgraph cluster_box_2_internal { + label = "b1"; + shape = box; + style = solid; + style = filled; + peripheries = 1; + box1 [shape = "point";style = "invis";]; + } + } + + subgraph cluster_box_2 { + subgraph cluster_box_2_internal { + label = "b2"; + shape = box; + style = solid; + peripheries = 1; + box2 [shape = "point";]; + } + } + } + } + subgraph cluster_target { + style = bold; + label = "pinned"; + + fut [label = < + + + + + +
fut
0
...
1
>;]; + } + + + box1 -> box2 [rankdir = TB; style = invis;]; + + edge [tailclip = false;]; + pin -> box1 [style = "invis";]; + pin -> box2 [tailport = "source:c"; arrowhead = "none";]; + box2 -> fut [headport = "target";]; + fut -> fut [tailport = "source:c"; headport = "internal";]; +} \ No newline at end of file diff --git a/dot/trpl17-07.dot b/dot/trpl17-07.dot new file mode 100644 index 0000000000..8e9897f46d --- /dev/null +++ b/dot/trpl17-07.dot @@ -0,0 +1,39 @@ +digraph { + rankdir = LR; + overlap = false; + dpi = 300.0; + splines = false; + cluster = true; + newrank = true; + outputorder = in; + compound = true; + labelloc = "c"; + + node [shape = "plaintext";]; + + pinned_box [label = < + + +
Pin
>;]; + + + subgraph cluster_deref { + style = dashed; + label = "String"; + + pin [shape = "point";]; + + fut [label = < + + + + + + +
5usizehello
>;]; + } + + edge [tailclip = false;]; + pinned_box -> pin [tailport = "source:c"; arrowhead = "none";]; + pin -> fut [headport = "target";]; +} \ No newline at end of file diff --git a/dot/trpl17-08.dot b/dot/trpl17-08.dot new file mode 100644 index 0000000000..de73007511 --- /dev/null +++ b/dot/trpl17-08.dot @@ -0,0 +1,62 @@ +digraph { + rankdir = LR; + overlap = false; + dpi = 300.0; + splines = false; + cluster = true; + newrank = true; + outputorder = in; + compound = true; + labelloc = "c"; + + node [shape = "plaintext";]; + + pinned_box [label = < + + +
Pin
>;]; + + subgraph cluster_both { + peripheries = 0; + + + + string1 [label = < + + + + + + + + + +
s1
5usizehello
>;]; + + subgraph cluster_deref { + style = dashed; + label = "String"; + peripheries = 1; + + pin [shape = "point";]; + + string2 [label = < + + + + + + + + + + + +
s2
7usizegoodbye
>;]; + } + } + + edge [tailclip = false;]; + pinned_box -> pin [tailport = "source:c"; arrowhead = "none";]; + pin -> string2 [headport = "target";]; +} \ No newline at end of file diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 56e3def6bb..91a78a7a56 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -265,12 +265,33 @@ which has any active references to it using safe code. `Pin` builds on that to give us the exact guarantee we need. When we *pin* a value by wrapping a pointer to that value in `Pin`, it can no longer move. Thus, if you have `Pin>`, you actually pin the `SomeType` value, *not* -the `Box` pointer. In fact, the `Box` pointer can still move around freely. -Remember: we care about making sure the data ultimately being referenced stays -in its place. If a pointer moves around, but the data it points to is in the -same place, there is no problem. +the `Box` pointer. Figure 17-5 illustrates this: - +
+ +Concurrent work flow + +
Figure 17-5: Pinning a `Box` which points to a self-referential future type.
+ +
+ +In fact, the `Box` pointer can still move around freely. Remember: we care about +making sure the data ultimately being referenced stays in its place. If a +pointer moves around, but the data it points to is in the same place, as in +Figure 17-6, there is no potential problem. (How you would do this with a `Pin` +wrapping a `Box` is more than we will get into in this particular discussion, +but it would make for a good exercise! If you look at the docs for the types as +well as the `std::pin` module, you might be able to work out how you would do +that.) The key is that the self-referential type itself cannot move, because it +is still pinned. + +
+ +Concurrent work flow + +
Figure 17-6: Moving a `Box` which points to a self-referential future type.
+ +
However, most types are perfectly safe to move around, even if they happen to be behind a `Pin` pointer. We only need to think about pinning when items have @@ -291,20 +312,43 @@ in a particular context. `Unpin` informs the compiler that a given type does *not* need to uphold any particular guarantees about whether the value in question can be moved. - - Just like `Send` and `Sync`, the compiler implements `Unpin` automatically for all types where it can prove it is safe. Implementing `Unpin` manually is unsafe because it requires *you* to uphold all the guarantees which make `Pin` and `Unpin` safe yourself for a type with internal references. In practice, this is a very rare thing to implement yourself! -Now we know enough to understand the errors reported for that `join_all` call. -We originally tried to move the futures produced by an async blocks into a -`Vec>>`, but as we have seen, those futures may have -internal references, so they do not implement `Unpin`. They need to be pinned, -and then we can pass the `Pin` type into the `Vec`, confident that the -underlying data in the futures will *not* be moved. +To make that concrete, think about a `String`: it has a length and the Unicode +characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure +17-7. However + +
+ +Concurrent work flow + +
Figure 17-7: Pinning a String, with a dotted line indicating that the String implements the `Unpin` trait, so it is not pinned.
+ +
+ +This means that we can do things like replace one string with another at the +exact same location in memory as in Figure 17-8. This does not violate the `Pin` +contract because `String`—like most other types in Rust—implements `Unpin`, +because it has no internal references that make it unsafe to move around! + +
+ +Concurrent work flow + +
Figure 17-8: Replacing the String with an entirely different String in memory.
+ +
+ +Now we know enough to understand the errors reported for that `join_all` call +from back in Listing 17-17. We originally tried to move the futures produced by +an async blocks into a `Vec>>`, but as we have seen, +those futures may have internal references, so they do not implement `Unpin`. +They need to be pinned, and then we can pass the `Pin` type into the `Vec`, +confident that the underlying data in the futures will *not* be moved. `Pin` and `Unpin` are mostly important for building lower-level libraries, or when you are building a runtime itself, rather than for day to day Rust code. diff --git a/src/img/trpl17-05.svg b/src/img/trpl17-05.svg new file mode 100644 index 0000000000..443bb568dc --- /dev/null +++ b/src/img/trpl17-05.svg @@ -0,0 +1,69 @@ + + + + + + + + +cluster_box + + +cluster_box_internal + +b1 + + +cluster_deref + +pinned + + + +pinned_box + +Pin + + + + + +pin + + + + +pinned_box:c->pin + + + + +box + +fut + +0 + + + +... + +1 + + + +pin->box:target + + + + + +box:c->box:internal + + + + + diff --git a/src/img/trpl17-06.svg b/src/img/trpl17-06.svg new file mode 100644 index 0000000000..712e3006f6 --- /dev/null +++ b/src/img/trpl17-06.svg @@ -0,0 +1,86 @@ + + + + + + + + +cluster_not_fut + + +cluster_boxes + + +cluster_box_1 + + +cluster_box_2_internal + +b1 + + +cluster_box_2 + + +cluster_box_2_internal + +b2 + + +cluster_target + +pinned + + + +pin + +Pin + + + + + + + +box2 + + + + +pin:c->box2 + + + + + +fut + +fut + +0 + + + +... + +1 + + + +box2->fut:target + + + + + +fut:c->fut:internal + + + + + diff --git a/src/img/trpl17-07.svg b/src/img/trpl17-07.svg new file mode 100644 index 0000000000..b2275ac19f --- /dev/null +++ b/src/img/trpl17-07.svg @@ -0,0 +1,57 @@ + + + + + + + + +cluster_deref + +String + + + +pinned_box + +Pin + + + + + +pin + + + + +pinned_box:c->pin + + + + +fut + +5usize + +h + +e + +l + +l + +o + + + +pin->fut:target + + + + + diff --git a/src/img/trpl17-08.svg b/src/img/trpl17-08.svg new file mode 100644 index 0000000000..997d9b82e1 --- /dev/null +++ b/src/img/trpl17-08.svg @@ -0,0 +1,85 @@ + + + + + + + + +cluster_both + + +cluster_deref + +String + + + +pinned_box + +Pin + + + + + +pin + + + + +pinned_box:c->pin + + + + +string1 + + +s1 + +5usize + +h + +e + +l + +l + +o + + + +string2 + +s2 + +7usize + +g + +o + +o + +d + +b + +y + +e + + + +pin->string2:target + + + + + From 0388426c51de9be7f489ccff9701f0d1e3d4747f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 25 Sep 2024 15:19:16 -0600 Subject: [PATCH 548/720] Ch. 17: Fix no-listing code for state machine enum --- listings/ch17-async-await/no-listing-state-machine/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/listings/ch17-async-await/no-listing-state-machine/src/lib.rs b/listings/ch17-async-await/no-listing-state-machine/src/lib.rs index f718ba8e08..1273283140 100644 --- a/listings/ch17-async-await/no-listing-state-machine/src/lib.rs +++ b/listings/ch17-async-await/no-listing-state-machine/src/lib.rs @@ -2,6 +2,7 @@ extern crate trpl; // required for mdbook test // ANCHOR: enum enum PageTitleFuture<'a> { + Initial { url: &'a str }, GetAwaitPoint { url: &'a str }, TextAwaitPoint { response: trpl::Response }, } From 75ec154789ea6fe3b1ffe5d7e1e49e884b4f5f3e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 25 Sep 2024 15:21:27 -0600 Subject: [PATCH 549/720] infra: publish trpl@0.2.0 w/new features from edits --- packages/trpl/Cargo.lock | 2 +- packages/trpl/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/trpl/Cargo.lock b/packages/trpl/Cargo.lock index bc42cb8b60..475f5d6d00 100644 --- a/packages/trpl/Cargo.lock +++ b/packages/trpl/Cargo.lock @@ -1478,7 +1478,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/packages/trpl/Cargo.toml b/packages/trpl/Cargo.toml index 62a602ea19..61c46319cc 100644 --- a/packages/trpl/Cargo.toml +++ b/packages/trpl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trpl" -version = "0.1.0" +version = "0.2.0" edition = "2021" license = "MIT OR Apache-2.0" description = "A support crate for The Rust Programming Language book" From 0a3135500400634753be42f5369ea0cd3585671e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Thu, 26 Sep 2024 21:53:15 +0100 Subject: [PATCH 550/720] Convert ch04 to `` --- src/ch04-01-what-is-ownership.md | 24 ++++++++++++------------ src/ch04-02-references-and-borrowing.md | 4 ++-- src/ch04-03-slices.md | 15 +++++++-------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/ch04-01-what-is-ownership.md b/src/ch04-01-what-is-ownership.md index 5249c2dd77..b8f14fd49e 100644 --- a/src/ch04-01-what-is-ownership.md +++ b/src/ch04-01-what-is-ownership.md @@ -113,12 +113,13 @@ hardcoded into the text of our program. The variable is valid from the point at which it’s declared until the end of the current *scope*. Listing 4-1 shows a program with comments annotating where the variable `s` would be valid. ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-01/src/main.rs:here}} ``` -Listing 4-1: A variable and the scope in which it is -valid + In other words, there are two important points in time here: @@ -239,12 +240,13 @@ we’ve allocated on the heap. Let’s explore some of those situations now. Multiple variables can interact with the same data in different ways in Rust. Let’s look at an example using an integer in Listing 4-2. ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-02/src/main.rs:here}} ``` -Listing 4-2: Assigning the integer value of variable `x` -to `y` + We can probably guess what this is doing: “bind the value `5` to `x`; then make a copy of the value in `x` and bind it to `y`.” We now have two variables, `x` @@ -429,14 +431,13 @@ assigning a value to a variable. Passing a variable to a function will move or copy, just as assignment does. Listing 4-3 has an example with some annotations showing where variables go into and out of scope. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-03/src/main.rs}} ``` -Listing 4-3: Functions with ownership and scope -annotated + If we tried to use `s` after the call to `takes_ownership`, Rust would throw a compile-time error. These static checks protect us from mistakes. Try adding @@ -449,14 +450,13 @@ Returning values can also transfer ownership. Listing 4-4 shows an example of a function that returns some value, with similar annotations as those in Listing 4-3. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-04/src/main.rs}} ``` -Listing 4-4: Transferring ownership of return -values + The ownership of a variable follows the same pattern every time: assigning a value to another variable moves it. When a variable that includes data on the @@ -471,13 +471,13 @@ from the body of the function that we might want to return as well. Rust does let us return multiple values using a tuple, as shown in Listing 4-5. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-05/src/main.rs}} ``` -Listing 4-5: Returning ownership of parameters + But this is too much ceremony and a lot of work for a concept that should be common. Luckily for us, Rust has a feature for using a value without diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index ea2d8d2029..9eb8c0057b 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -67,13 +67,13 @@ to give it back. You don’t own it. So, what happens if we try to modify something we’re borrowing? Try the code in Listing 4-6. Spoiler alert: it doesn’t work! -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-06/src/main.rs}} ``` -Listing 4-6: Attempting to modify a borrowed value + Here’s the error: diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 7f8c9b7af2..0d94433652 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -21,14 +21,13 @@ ownership, so this is fine. But what should we return? We don’t really have a way to talk about *part* of a string. However, we could return the index of the end of the word, indicated by a space. Let’s try that, as shown in Listing 4-7. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:here}} ``` -Listing 4-7: The `first_word` function that returns a -byte index value into the `String` parameter + Because we need to go through the `String` element by element and check whether a value is a space, we’ll convert our `String` to an array of bytes using the @@ -73,14 +72,13 @@ because it’s a separate value from the `String`, there’s no guarantee that i will still be valid in the future. Consider the program in Listing 4-8 that uses the `first_word` function from Listing 4-7. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-08/src/main.rs:here}} ``` -Listing 4-8: Storing the result from calling the -`first_word` function and then changing the `String` contents + This program compiles without any errors and would also do so if we used `word` after calling `s.clear()`. Because `word` isn’t connected to the state of `s` @@ -257,12 +255,13 @@ A more experienced Rustacean would write the signature shown in Listing 4-9 instead because it allows us to use the same function on both `&String` values and `&str` values. ++ ```rust,ignore {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-09/src/main.rs:here}} ``` -Listing 4-9: Improving the `first_word` function by using -a string slice for the type of the `s` parameter + If we have a string slice, we can pass that directly. If we have a `String`, we can pass a slice of the `String` or a reference to the `String`. This From df49c42aac78f37e42a26f488f3fe7a506311a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Thu, 26 Sep 2024 22:09:01 +0100 Subject: [PATCH 551/720] The ones without listing numbers --- src/ch04-02-references-and-borrowing.md | 20 +++++++++++++++----- src/ch04-03-slices.md | 12 +++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 9eb8c0057b..04dd601c7d 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -12,12 +12,14 @@ particular type for the life of that reference. Here is how you would define and use a `calculate_length` function that has a reference to an object as a parameter instead of taking ownership of the value: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs:all}} ``` + + First, notice that all the tuple code in the variable declaration and the function return value is gone. Second, note that we pass `&s1` into `calculate_length` and, in its definition, we take `&String` rather than @@ -89,12 +91,14 @@ allowed to modify something we have a reference to. We can fix the code from Listing 4-6 to allow us to modify a borrowed value with just a few small tweaks that use, instead, a *mutable reference*: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-09-fixes-listing-04-06/src/main.rs}} ``` + + First we change `s` to be `mut`. Then we create a mutable reference with `&mut s` where we call the `change` function, and update the function signature to accept a mutable reference with `some_string: &mut String`. This makes it very @@ -104,12 +108,14 @@ Mutable references have one big restriction: if you have a mutable reference to a value, you can have no other references to that value. This code that attempts to create two mutable references to `s` will fail: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/src/main.rs:here}} ``` + + Here’s the error: ```console @@ -198,12 +204,14 @@ reference to the data does. Let’s try to create a dangling reference to see how Rust prevents them with a compile-time error: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-14-dangling-reference/src/main.rs}} ``` + + Here’s the error: ```console @@ -222,12 +230,14 @@ for it to be borrowed from Let’s take a closer look at exactly what’s happening at each stage of our `dangle` code: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-15-dangling-reference-annotated/src/main.rs:here}} ``` + + Because `s` is created inside `dangle`, when the code of `dangle` is finished, `s` will be deallocated. But we tried to return a reference to it. That means this reference would be pointing to an invalid `String`. That’s no good! Rust diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 0d94433652..69fb35f82d 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -174,12 +174,14 @@ let slice = &s[..]; With all this information in mind, let’s rewrite `first_word` to return a slice. The type that signifies “string slice” is written as `&str`: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-18-first-word-slice/src/main.rs:here}} ``` + + We get the index for the end of the word the same way we did in Listing 4-7, by looking for the first occurrence of a space. When we find a space, we return a string slice using the start of the string and the index of the space as the @@ -205,12 +207,14 @@ string. Slices make this bug impossible and let us know we have a problem with our code much sooner. Using the slice version of `first_word` will throw a compile-time error: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-19-slice-error/src/main.rs:here}} ``` + + Here’s the compiler error: ```console @@ -272,12 +276,14 @@ Methods”][deref-coercions] section of Chapter 15. Defining a function to take a string slice instead of a reference to a `String` makes our API more general and useful without losing any functionality: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-09/src/main.rs:usage}} ``` + + ### Other Slices String slices, as you might imagine, are specific to strings. But there’s a From d7c8e047fd8ff25968a2910027dc9f0c7268d758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Thu, 26 Sep 2024 22:18:28 +0100 Subject: [PATCH 552/720] The ones without number, caption, and file name --- src/ch04-01-what-is-ownership.md | 36 +++++++++++++++ src/ch04-02-references-and-borrowing.md | 44 ++++++++++++++++++ src/ch04-03-slices.md | 60 +++++++++++++++++++++++++ 3 files changed, 140 insertions(+) diff --git a/src/ch04-01-what-is-ownership.md b/src/ch04-01-what-is-ownership.md index b8f14fd49e..05f5111164 100644 --- a/src/ch04-01-what-is-ownership.md +++ b/src/ch04-01-what-is-ownership.md @@ -104,10 +104,14 @@ As a first example of ownership, we’ll look at the *scope* of some variables. scope is the range within a program for which an item is valid. Take the following variable: ++ ```rust let s = "hello"; ``` + + The variable `s` refers to a string literal, where the value of the string is hardcoded into the text of our program. The variable is valid from the point at which it’s declared until the end of the current *scope*. Listing 4-1 shows a @@ -156,10 +160,14 @@ data allocated on the heap and as such is able to store an amount of text that is unknown to us at compile time. You can create a `String` from a string literal using the `from` function, like so: ++ ```rust let s = String::from("hello"); ``` + + The double colon `::` operator allows us to namespace this particular `from` function under the `String` type rather than using some sort of name like `string_from`. We’ll discuss this syntax more in the [“Method @@ -169,10 +177,14 @@ Module Tree”][paths-module-tree] in Chapter 7. This kind of string *can* be mutated: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-01-can-mutate-string/src/main.rs:here}} ``` + + So, what’s the difference here? Why can `String` be mutated but literals cannot? The difference is in how these two types deal with memory. @@ -211,10 +223,14 @@ Rust takes a different path: the memory is automatically returned once the variable that owns it goes out of scope. Here’s a version of our scope example from Listing 4-1 using a `String` instead of a string literal: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-02-string-scope/src/main.rs:here}} ``` + + There is a natural point at which we can return the memory our `String` needs to the allocator: when `s` goes out of scope. When a variable goes out of scope, Rust calls a special function for us. This function is called @@ -256,10 +272,14 @@ onto the stack. Now let’s look at the `String` version: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-03-string-move/src/main.rs:here}} ``` + + This looks very similar, so we might assume that the way it works would be the same: that is, the second line would make a copy of the value in `s1` and bind it to `s2`. But this isn’t quite what happens. @@ -322,17 +342,25 @@ no longer valid. Therefore, Rust doesn’t need to free anything when `s1` goes out of scope. Check out what happens when you try to use `s1` after `s2` is created; it won’t work: ++ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/src/main.rs:here}} ``` + + You’ll get an error like this because Rust prevents you from using the invalidated reference: ++ ```console {{#include ../listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt}} ``` + + If you’ve heard the terms *shallow copy* and *deep copy* while working with other languages, the concept of copying the pointer, length, and capacity without copying the data probably sounds like making a shallow copy. But @@ -368,10 +396,14 @@ programming languages, you’ve probably seen them before. Here’s an example of the `clone` method in action: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs:here}} ``` + + This works just fine and explicitly produces the behavior shown in Figure 4-3, where the heap data *does* get copied. @@ -384,10 +416,14 @@ different is going on. There’s another wrinkle we haven’t talked about yet. This code using integers—part of which was shown in Listing 4-2—works and is valid: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs:here}} ``` + + But this code seems to contradict what we just learned: we don’t have a call to `clone`, but `x` is still valid and wasn’t moved into `y`. diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 04dd601c7d..4933ec89c6 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -40,10 +40,14 @@ s1` Let’s take a closer look at the function call here: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs:here}} ``` + + The `&s1` syntax lets us create a reference that *refers* to the value of `s1` but does not own it. Because it does not own it, the value it points to will not be dropped when the reference stops being used. @@ -51,10 +55,14 @@ not be dropped when the reference stops being used. Likewise, the signature of the function uses `&` to indicate that the type of the parameter `s` is a reference. Let’s add some explanatory annotations: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs:here}} ``` + + The scope in which the variable `s` is valid is the same as any function parameter’s scope, but the value pointed to by the reference is not dropped when `s` stops being used, because `s` doesn’t have ownership. When functions @@ -79,10 +87,14 @@ Listing 4-6. Spoiler alert: it doesn’t work! Here’s the error: ++ ```console {{#include ../listings/ch04-understanding-ownership/listing-04-06/output.txt}} ``` + + Just as variables are immutable by default, so are references. We’re not allowed to modify something we have a reference to. @@ -118,10 +130,14 @@ attempts to create two mutable references to `s` will fail: Here’s the error: ++ ```console {{#include ../listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt}} ``` + + This error says that this code is invalid because we cannot borrow `s` as mutable more than once at a time. The first mutable borrow is in `r1` and must last until it’s used in the `println!`, but between the creation of that @@ -146,23 +162,35 @@ refusing to compile code with data races! As always, we can use curly brackets to create a new scope, allowing for multiple mutable references, just not *simultaneous* ones: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-11-muts-in-separate-scopes/src/main.rs:here}} ``` + + Rust enforces a similar rule for combining mutable and immutable references. This code results in an error: ++ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/src/main.rs:here}} ``` + + Here’s the error: ++ ```console {{#include ../listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt}} ``` + + Whew! We *also* cannot have a mutable reference while we have an immutable one to the same value. @@ -176,10 +204,14 @@ through the last time that reference is used. For instance, this code will compile because the last usage of the immutable references, the `println!`, occurs before the mutable reference is introduced: ++ ```rust,edition2021 {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-13-reference-scope-ends/src/main.rs:here}} ``` + + The scopes of the immutable references `r1` and `r2` end after the `println!` where they are last used, which is before the mutable reference `r3` is created. These scopes don’t overlap, so this code is allowed: the compiler can @@ -214,19 +246,27 @@ compile-time error: Here’s the error: ++ ```console {{#include ../listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt}} ``` + + This error message refers to a feature we haven’t covered yet: lifetimes. We’ll discuss lifetimes in detail in Chapter 10. But, if you disregard the parts about lifetimes, the message does contain the key to why this code is a problem: ++ ```text this function's return type contains a borrowed value, but there is no value for it to be borrowed from ``` + + Let’s take a closer look at exactly what’s happening at each stage of our `dangle` code: @@ -245,10 +285,14 @@ won’t let us do this. The solution here is to return the `String` directly: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-16-no-dangle/src/main.rs:here}} ``` + + This works without any problems. Ownership is moved out, and nothing is deallocated. diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 69fb35f82d..9948b14862 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -12,10 +12,14 @@ one word, so the entire string should be returned. Let’s work through how we’d write the signature of this function without using slices, to understand the problem that slices will solve: ++ ```rust,ignore fn first_word(s: &String) -> ? ``` + + The `first_word` function has a `&String` as a parameter. We don’t want ownership, so this is fine. But what should we return? We don’t really have a way to talk about *part* of a string. However, we could return the index of the @@ -33,16 +37,24 @@ Because we need to go through the `String` element by element and check whether a value is a space, we’ll convert our `String` to an array of bytes using the `as_bytes` method. ++ ```rust,ignore {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:as_bytes}} ``` + + Next, we create an iterator over the array of bytes using the `iter` method: ++ ```rust,ignore {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:iter}} ``` + + We’ll discuss iterators in more detail in [Chapter 13][ch13]. For now, know that `iter` is a method that returns each element in a collection and that `enumerate` wraps the result of `iter` and returns each element as @@ -61,10 +73,14 @@ Inside the `for` loop, we search for the byte that represents the space by using the byte literal syntax. If we find a space, we return the position. Otherwise, we return the length of the string by using `s.len()`. ++ ```rust,ignore {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:inside_for}} ``` + + We now have a way to find out the index of the end of the first word in the string, but there’s a problem. We’re returning a `usize` on its own, but it’s only a meaningful number in the context of the `&String`. In other words, @@ -90,10 +106,14 @@ Having to worry about the index in `word` getting out of sync with the data in `s` is tedious and error prone! Managing these indices is even more brittle if we write a `second_word` function. Its signature would have to look like this: ++ ```rust,ignore fn second_word(s: &String) -> (usize, usize) { ``` + + Now we’re tracking a starting *and* an ending index, and we have even more values that were calculated from data in a particular state but aren’t tied to that state at all. We have three unrelated variables floating around that need @@ -105,10 +125,14 @@ Luckily, Rust has a solution to this problem: string slices. A *string slice* is a reference to part of a `String`, and it looks like this: ++ ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-17-slice/src/main.rs:here}} ``` + + Rather than a reference to the entire `String`, `hello` is a reference to a portion of the `String`, specified in the extra `[0..5]` bit. We create slices using a range within brackets by specifying `[starting_index..ending_index]`, @@ -133,6 +157,8 @@ src="img/trpl04-06.svg" class="center" style="width: 50%;" /> With Rust’s `..` range syntax, if you want to start at index 0, you can drop the value before the two periods. In other words, these are equal: ++ ```rust let s = String::from("hello"); @@ -140,9 +166,13 @@ let slice = &s[0..2]; let slice = &s[..2]; ``` + + By the same token, if your slice includes the last byte of the `String`, you can drop the trailing number. That means these are equal: ++ ```rust let s = String::from("hello"); @@ -152,9 +182,13 @@ let slice = &s[3..len]; let slice = &s[3..]; ``` + + You can also drop both values to take a slice of the entire string. So these are equal: ++ ```rust let s = String::from("hello"); @@ -164,6 +198,8 @@ let slice = &s[0..len]; let slice = &s[..]; ``` + + > Note: String slice range indices must occur at valid UTF-8 character > boundaries. If you attempt to create a string slice in the middle of a > multibyte character, your program will exit with an error. For the purposes @@ -193,10 +229,14 @@ the slice and the number of elements in the slice. Returning a slice would also work for a `second_word` function: ++ ```rust,ignore fn second_word(s: &String) -> &str { ``` + + We now have a straightforward API that’s much harder to mess up because the compiler will ensure the references into the `String` remain valid. Remember the bug in the program in Listing 4-8, when we got the index to the end of the @@ -217,10 +257,14 @@ compile-time error: Here’s the compiler error: ++ ```console {{#include ../listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt}} ``` + + Recall from the borrowing rules that if we have an immutable reference to something, we cannot also take a mutable reference. Because `clear` needs to truncate the `String`, it needs to get a mutable reference. The `println!` @@ -238,10 +282,14 @@ but it has also eliminated an entire class of errors at compile time! Recall that we talked about string literals being stored inside the binary. Now that we know about slices, we can properly understand string literals: ++ ```rust let s = "Hello, world!"; ``` + + The type of `s` here is `&str`: it’s a slice pointing to that specific point of the binary. This is also why string literals are immutable; `&str` is an immutable reference. @@ -251,10 +299,14 @@ immutable reference. Knowing that you can take slices of literals and `String` values leads us to one more improvement on `first_word`, and that’s its signature: ++ ```rust,ignore fn first_word(s: &String) -> &str { ``` + + A more experienced Rustacean would write the signature shown in Listing 4-9 instead because it allows us to use the same function on both `&String` values and `&str` values. @@ -289,13 +341,19 @@ makes our API more general and useful without losing any functionality: String slices, as you might imagine, are specific to strings. But there’s a more general slice type too. Consider this array: ++ ```rust let a = [1, 2, 3, 4, 5]; ``` + + Just as we might want to refer to part of a string, we might want to refer to part of an array. We’d do so like this: ++ ```rust let a = [1, 2, 3, 4, 5]; @@ -304,6 +362,8 @@ let slice = &a[1..3]; assert_eq!(slice, &[2, 3]); ``` + + This slice has the type `&[i32]`. It works the same way as string slices do, by storing a reference to the first element and a length. You’ll use this kind of slice for all sorts of other collections. We’ll discuss these collections in From 72ef94c3388001e0848f6e684115a301dcc38d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sat, 28 Sep 2024 08:37:39 +0100 Subject: [PATCH 553/720] Revert "The ones without number, caption, and file name" This reverts commit d7c8e047fd8ff25968a2910027dc9f0c7268d758. --- src/ch04-01-what-is-ownership.md | 36 --------------- src/ch04-02-references-and-borrowing.md | 44 ------------------ src/ch04-03-slices.md | 60 ------------------------- 3 files changed, 140 deletions(-) diff --git a/src/ch04-01-what-is-ownership.md b/src/ch04-01-what-is-ownership.md index 05f5111164..b8f14fd49e 100644 --- a/src/ch04-01-what-is-ownership.md +++ b/src/ch04-01-what-is-ownership.md @@ -104,14 +104,10 @@ As a first example of ownership, we’ll look at the *scope* of some variables. scope is the range within a program for which an item is valid. Take the following variable: -- ```rust let s = "hello"; ``` - - The variable `s` refers to a string literal, where the value of the string is hardcoded into the text of our program. The variable is valid from the point at which it’s declared until the end of the current *scope*. Listing 4-1 shows a @@ -160,14 +156,10 @@ data allocated on the heap and as such is able to store an amount of text that is unknown to us at compile time. You can create a `String` from a string literal using the `from` function, like so: -- ```rust let s = String::from("hello"); ``` - - The double colon `::` operator allows us to namespace this particular `from` function under the `String` type rather than using some sort of name like `string_from`. We’ll discuss this syntax more in the [“Method @@ -177,14 +169,10 @@ Module Tree”][paths-module-tree] in Chapter 7. This kind of string *can* be mutated: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-01-can-mutate-string/src/main.rs:here}} ``` - - So, what’s the difference here? Why can `String` be mutated but literals cannot? The difference is in how these two types deal with memory. @@ -223,14 +211,10 @@ Rust takes a different path: the memory is automatically returned once the variable that owns it goes out of scope. Here’s a version of our scope example from Listing 4-1 using a `String` instead of a string literal: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-02-string-scope/src/main.rs:here}} ``` - - There is a natural point at which we can return the memory our `String` needs to the allocator: when `s` goes out of scope. When a variable goes out of scope, Rust calls a special function for us. This function is called @@ -272,14 +256,10 @@ onto the stack. Now let’s look at the `String` version: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-03-string-move/src/main.rs:here}} ``` - - This looks very similar, so we might assume that the way it works would be the same: that is, the second line would make a copy of the value in `s1` and bind it to `s2`. But this isn’t quite what happens. @@ -342,25 +322,17 @@ no longer valid. Therefore, Rust doesn’t need to free anything when `s1` goes out of scope. Check out what happens when you try to use `s1` after `s2` is created; it won’t work: -- ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/src/main.rs:here}} ``` - - You’ll get an error like this because Rust prevents you from using the invalidated reference: -- ```console {{#include ../listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt}} ``` - - If you’ve heard the terms *shallow copy* and *deep copy* while working with other languages, the concept of copying the pointer, length, and capacity without copying the data probably sounds like making a shallow copy. But @@ -396,14 +368,10 @@ programming languages, you’ve probably seen them before. Here’s an example of the `clone` method in action: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs:here}} ``` - - This works just fine and explicitly produces the behavior shown in Figure 4-3, where the heap data *does* get copied. @@ -416,14 +384,10 @@ different is going on. There’s another wrinkle we haven’t talked about yet. This code using integers—part of which was shown in Listing 4-2—works and is valid: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs:here}} ``` - - But this code seems to contradict what we just learned: we don’t have a call to `clone`, but `x` is still valid and wasn’t moved into `y`. diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 4933ec89c6..04dd601c7d 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -40,14 +40,10 @@ s1` Let’s take a closer look at the function call here: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs:here}} ``` - - The `&s1` syntax lets us create a reference that *refers* to the value of `s1` but does not own it. Because it does not own it, the value it points to will not be dropped when the reference stops being used. @@ -55,14 +51,10 @@ not be dropped when the reference stops being used. Likewise, the signature of the function uses `&` to indicate that the type of the parameter `s` is a reference. Let’s add some explanatory annotations: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs:here}} ``` - - The scope in which the variable `s` is valid is the same as any function parameter’s scope, but the value pointed to by the reference is not dropped when `s` stops being used, because `s` doesn’t have ownership. When functions @@ -87,14 +79,10 @@ Listing 4-6. Spoiler alert: it doesn’t work! Here’s the error: -- ```console {{#include ../listings/ch04-understanding-ownership/listing-04-06/output.txt}} ``` - - Just as variables are immutable by default, so are references. We’re not allowed to modify something we have a reference to. @@ -130,14 +118,10 @@ attempts to create two mutable references to `s` will fail: Here’s the error: -- ```console {{#include ../listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt}} ``` - - This error says that this code is invalid because we cannot borrow `s` as mutable more than once at a time. The first mutable borrow is in `r1` and must last until it’s used in the `println!`, but between the creation of that @@ -162,35 +146,23 @@ refusing to compile code with data races! As always, we can use curly brackets to create a new scope, allowing for multiple mutable references, just not *simultaneous* ones: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-11-muts-in-separate-scopes/src/main.rs:here}} ``` - - Rust enforces a similar rule for combining mutable and immutable references. This code results in an error: -- ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/src/main.rs:here}} ``` - - Here’s the error: -- ```console {{#include ../listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt}} ``` - - Whew! We *also* cannot have a mutable reference while we have an immutable one to the same value. @@ -204,14 +176,10 @@ through the last time that reference is used. For instance, this code will compile because the last usage of the immutable references, the `println!`, occurs before the mutable reference is introduced: -- ```rust,edition2021 {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-13-reference-scope-ends/src/main.rs:here}} ``` - - The scopes of the immutable references `r1` and `r2` end after the `println!` where they are last used, which is before the mutable reference `r3` is created. These scopes don’t overlap, so this code is allowed: the compiler can @@ -246,27 +214,19 @@ compile-time error: Here’s the error: -- ```console {{#include ../listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt}} ``` - - This error message refers to a feature we haven’t covered yet: lifetimes. We’ll discuss lifetimes in detail in Chapter 10. But, if you disregard the parts about lifetimes, the message does contain the key to why this code is a problem: -- ```text this function's return type contains a borrowed value, but there is no value for it to be borrowed from ``` - - Let’s take a closer look at exactly what’s happening at each stage of our `dangle` code: @@ -285,14 +245,10 @@ won’t let us do this. The solution here is to return the `String` directly: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-16-no-dangle/src/main.rs:here}} ``` - - This works without any problems. Ownership is moved out, and nothing is deallocated. diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 9948b14862..69fb35f82d 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -12,14 +12,10 @@ one word, so the entire string should be returned. Let’s work through how we’d write the signature of this function without using slices, to understand the problem that slices will solve: -- ```rust,ignore fn first_word(s: &String) -> ? ``` - - The `first_word` function has a `&String` as a parameter. We don’t want ownership, so this is fine. But what should we return? We don’t really have a way to talk about *part* of a string. However, we could return the index of the @@ -37,24 +33,16 @@ Because we need to go through the `String` element by element and check whether a value is a space, we’ll convert our `String` to an array of bytes using the `as_bytes` method. -- ```rust,ignore {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:as_bytes}} ``` - - Next, we create an iterator over the array of bytes using the `iter` method: -- ```rust,ignore {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:iter}} ``` - - We’ll discuss iterators in more detail in [Chapter 13][ch13]. For now, know that `iter` is a method that returns each element in a collection and that `enumerate` wraps the result of `iter` and returns each element as @@ -73,14 +61,10 @@ Inside the `for` loop, we search for the byte that represents the space by using the byte literal syntax. If we find a space, we return the position. Otherwise, we return the length of the string by using `s.len()`. -- ```rust,ignore {{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:inside_for}} ``` - - We now have a way to find out the index of the end of the first word in the string, but there’s a problem. We’re returning a `usize` on its own, but it’s only a meaningful number in the context of the `&String`. In other words, @@ -106,14 +90,10 @@ Having to worry about the index in `word` getting out of sync with the data in `s` is tedious and error prone! Managing these indices is even more brittle if we write a `second_word` function. Its signature would have to look like this: -- ```rust,ignore fn second_word(s: &String) -> (usize, usize) { ``` - - Now we’re tracking a starting *and* an ending index, and we have even more values that were calculated from data in a particular state but aren’t tied to that state at all. We have three unrelated variables floating around that need @@ -125,14 +105,10 @@ Luckily, Rust has a solution to this problem: string slices. A *string slice* is a reference to part of a `String`, and it looks like this: -- ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-17-slice/src/main.rs:here}} ``` - - Rather than a reference to the entire `String`, `hello` is a reference to a portion of the `String`, specified in the extra `[0..5]` bit. We create slices using a range within brackets by specifying `[starting_index..ending_index]`, @@ -157,8 +133,6 @@ src="img/trpl04-06.svg" class="center" style="width: 50%;" /> With Rust’s `..` range syntax, if you want to start at index 0, you can drop the value before the two periods. In other words, these are equal: -- ```rust let s = String::from("hello"); @@ -166,13 +140,9 @@ let slice = &s[0..2]; let slice = &s[..2]; ``` - - By the same token, if your slice includes the last byte of the `String`, you can drop the trailing number. That means these are equal: -- ```rust let s = String::from("hello"); @@ -182,13 +152,9 @@ let slice = &s[3..len]; let slice = &s[3..]; ``` - - You can also drop both values to take a slice of the entire string. So these are equal: -- ```rust let s = String::from("hello"); @@ -198,8 +164,6 @@ let slice = &s[0..len]; let slice = &s[..]; ``` - - > Note: String slice range indices must occur at valid UTF-8 character > boundaries. If you attempt to create a string slice in the middle of a > multibyte character, your program will exit with an error. For the purposes @@ -229,14 +193,10 @@ the slice and the number of elements in the slice. Returning a slice would also work for a `second_word` function: -- ```rust,ignore fn second_word(s: &String) -> &str { ``` - - We now have a straightforward API that’s much harder to mess up because the compiler will ensure the references into the `String` remain valid. Remember the bug in the program in Listing 4-8, when we got the index to the end of the @@ -257,14 +217,10 @@ compile-time error: Here’s the compiler error: -- ```console {{#include ../listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt}} ``` - - Recall from the borrowing rules that if we have an immutable reference to something, we cannot also take a mutable reference. Because `clear` needs to truncate the `String`, it needs to get a mutable reference. The `println!` @@ -282,14 +238,10 @@ but it has also eliminated an entire class of errors at compile time! Recall that we talked about string literals being stored inside the binary. Now that we know about slices, we can properly understand string literals: -- ```rust let s = "Hello, world!"; ``` - - The type of `s` here is `&str`: it’s a slice pointing to that specific point of the binary. This is also why string literals are immutable; `&str` is an immutable reference. @@ -299,14 +251,10 @@ immutable reference. Knowing that you can take slices of literals and `String` values leads us to one more improvement on `first_word`, and that’s its signature: -- ```rust,ignore fn first_word(s: &String) -> &str { ``` - - A more experienced Rustacean would write the signature shown in Listing 4-9 instead because it allows us to use the same function on both `&String` values and `&str` values. @@ -341,19 +289,13 @@ makes our API more general and useful without losing any functionality: String slices, as you might imagine, are specific to strings. But there’s a more general slice type too. Consider this array: -- ```rust let a = [1, 2, 3, 4, 5]; ``` - - Just as we might want to refer to part of a string, we might want to refer to part of an array. We’d do so like this: -- ```rust let a = [1, 2, 3, 4, 5]; @@ -362,8 +304,6 @@ let slice = &a[1..3]; assert_eq!(slice, &[2, 3]); ``` - - This slice has the type `&[i32]`. It works the same way as string slices do, by storing a reference to the first element and a length. You’ll use this kind of slice for all sorts of other collections. We’ll discuss these collections in From 88c3e558feb5d7e9d81e294a217e47611de0f124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sun, 29 Sep 2024 11:01:12 +0100 Subject: [PATCH 554/720] Mention move of individual struct fields --- src/ch05-01-defining-structs.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index c5db4dc74d..1cf57d1db9 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -147,14 +147,18 @@ the struct’s definition. Note that the struct update syntax uses `=` like an assignment; this is because it moves the data, just as we saw in the [“Variables and Data Interacting with -Move”][move] section. In this example, we can no longer use -`user1` as a whole after creating `user2` because the `String` in the -`username` field of `user1` was moved into `user2`. If we had given `user2` new -`String` values for both `email` and `username`, and thus only used the -`active` and `sign_in_count` values from `user1`, then `user1` would still be -valid after creating `user2`. Both `active` and `sign_in_count` are types that -implement the `Copy` trait, so the behavior we discussed in the [“Stack-Only -Data: Copy”][copy] section would apply. +Move”][move] section. However, the fields are moved +individually, and the original struct is not invalidated if it contains +reference the data that wasn't moved. + +In Listing 5-7, we can no longer use `user1.username` because it was moved into +`user2.username`. However, we can continue to use `user1.email` normally. If we +had given `user2` new `String` values for both `email` and `username`, and thus +only used the `active` and `sign_in_count` values from `user1`, then +`user1.username` would still be valid after creating `user2`. Both `active` and +`sign_in_count` are types that implement the `Copy` trait, so the behavior we +discussed in the [“Stack-Only Data: Copy”][copy] section would +apply. ### Using Tuple Structs Without Named Fields to Create Different Types From 019a8d76e04dce674a0b2fe55ee3c63bcc87cb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sun, 29 Sep 2024 11:42:52 +0100 Subject: [PATCH 555/720] Consider mentioning the syntax to destructure a tuple struct --- .../no-listing-01-tuple-structs/src/main.rs | 4 ++++ src/ch05-01-defining-structs.md | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs b/listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs index 0d993162bf..ca0c2aa1cd 100644 --- a/listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs +++ b/listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs @@ -4,4 +4,8 @@ struct Point(i32, i32, i32); fn main() { let black = Color(0, 0, 0); let origin = Point(0, 0, 0); + + let Color(r, g, b) = black; + + assert_eq!(r, 0); } diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index c5db4dc74d..841de4ecd2 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -184,6 +184,14 @@ values. Otherwise, tuple struct instances are similar to tuples in that you can destructure them into their individual pieces, and you can use a `.` followed by the index to access an individual value. +When destructuring tuple structs, you must mention the type of the instance +being destructured. For example, the line below would not compile when used in +the previous listing: + +```rust + let (r, g, b) = black; +``` + ### Unit-Like Structs Without Any Fields You can also define structs that don’t have any fields! These are called From dc67ffe78fa66144702dfa08c546ebd15762bf3e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 30 Sep 2024 15:27:52 -0600 Subject: [PATCH 556/720] Add a short discussion of assignment and ownership in ch. 04 Add a short new section showing how assignment to a mutable variable causes an existing *owned* binding to be freed immediately. Create a new code sample and a new diagram to illustrate the behavior. Fixes #4001. --- dot/trpl04-05.dot | 85 +++++---- dot/trpl04-06.dot | 29 ++- dot/trpl04-07.dot | 41 +++++ .../Cargo.lock | 6 + .../Cargo.toml | 6 + .../src/main.rs | 8 + src/ch04-01-what-is-ownership.md | 31 ++++ src/ch04-02-references-and-borrowing.md | 6 +- src/ch04-03-slices.md | 6 +- src/img/trpl04-05.svg | 160 +++++++++-------- src/img/trpl04-06.svg | 166 ++++++++---------- src/img/trpl04-07.svg | 115 ++++++++++++ 12 files changed, 432 insertions(+), 227 deletions(-) create mode 100644 dot/trpl04-07.dot create mode 100644 listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/Cargo.lock create mode 100644 listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/Cargo.toml create mode 100644 listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/src/main.rs create mode 100644 src/img/trpl04-07.svg diff --git a/dot/trpl04-05.dot b/dot/trpl04-05.dot index ca1f7e06e9..f83ab815e0 100644 --- a/dot/trpl04-05.dot +++ b/dot/trpl04-05.dot @@ -1,32 +1,55 @@ digraph { - rankdir=LR; - overlap=false; - dpi=300.0; - node [shape="plaintext"]; - - table0[label=< - - - -
s
namevalue
ptr
>]; - table1[label=< - - - - - -
s1
namevalue
ptr
len5
capacity5
>]; - table2[label=< - - - - - - -
indexvalue
0h
1e
2l
3l
4o
>]; - - edge[tailclip="false"]; - table1:pointer:c -> table2:pointee; - table0:borrower:c -> table1:borrowee; -} - + rankdir = LR; + overlap = false; + newrank = true; + dpi = 300.0; + splines = false; + clusterrank = "local"; + node [shape = "plaintext";]; + + subgraph cluster_stack { + peripheries = 0; + rank = "same"; + + // Just to have the right height! + a [label = < + + + + + +
a
0
1
2
3
>;style = invis;]; + + s [label = < + + + + + +
s
namevalue
ptr
len4
capacity4
>;]; + } + + subgraph cluster_heap { + peripheries = 0; + rank = "same"; + + hello [label = < + + + + + + +
indexvalue
0h
1e
2l
3l
4o
>;]; + + ahoy [label = < + + + + + +
indexvalue
0a
1h
2o
3y
>;]; + } + + s -> ahoy [tailport = "pointer:c"; headport = "pointee"; tailclip = false;]; +} \ No newline at end of file diff --git a/dot/trpl04-06.dot b/dot/trpl04-06.dot index a23f179a77..ca1f7e06e9 100644 --- a/dot/trpl04-06.dot +++ b/dot/trpl04-06.dot @@ -5,37 +5,28 @@ digraph { node [shape="plaintext"]; table0[label=< - + - - +
world
s
namevalue
ptr
len5
ptr
>]; - - table3[label=< - + table1[label=<
s
+ - - - + + +
s1
namevalue
ptr
len11
capacity11
ptr
len5
capacity5
>]; - table4[label=< + table2[label=<
- - - - - -
indexvalue
0h
1e
2l
3l
4o
5
6w
7o
8r
9l
10d
>]; - edge[tailclip="false"]; - table0:pointer2:c -> table4:pointee2; - table3:pointer:c -> table4:pointee; + table1:pointer:c -> table2:pointee; + table0:borrower:c -> table1:borrowee; } diff --git a/dot/trpl04-07.dot b/dot/trpl04-07.dot new file mode 100644 index 0000000000..a23f179a77 --- /dev/null +++ b/dot/trpl04-07.dot @@ -0,0 +1,41 @@ +digraph { + rankdir=LR; + overlap=false; + dpi=300.0; + node [shape="plaintext"]; + + table0[label=< + + + + +
world
namevalue
ptr
len5
>]; + + table3[label=< + + + + + +
s
namevalue
ptr
len11
capacity11
>]; + table4[label=< + + + + + + + + + + + + +
indexvalue
0h
1e
2l
3l
4o
5
6w
7o
8r
9l
10d
>]; + + + edge[tailclip="false"]; + table0:pointer2:c -> table4:pointee2; + table3:pointer:c -> table4:pointee; +} + diff --git a/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/Cargo.lock b/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/Cargo.lock new file mode 100644 index 0000000000..2aa4918e5d --- /dev/null +++ b/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ownership" +version = "0.1.0" + diff --git a/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/Cargo.toml b/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/Cargo.toml new file mode 100644 index 0000000000..e8847526dc --- /dev/null +++ b/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "ownership" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/src/main.rs b/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/src/main.rs new file mode 100644 index 0000000000..b2d0846c11 --- /dev/null +++ b/listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/src/main.rs @@ -0,0 +1,8 @@ +fn main() { + // ANCHOR: here + let mut s = String::from("hello"); + s = String::from("ahoy"); + + println!("{s}, world!"); + // ANCHOR_END: here +} diff --git a/src/ch04-01-what-is-ownership.md b/src/ch04-01-what-is-ownership.md index b8f14fd49e..5ef7b5f97f 100644 --- a/src/ch04-01-what-is-ownership.md +++ b/src/ch04-01-what-is-ownership.md @@ -356,6 +356,37 @@ In addition, there’s a design choice that’s implied by this: Rust will never automatically create “deep” copies of your data. Therefore, any *automatic* copying can be assumed to be inexpensive in terms of runtime performance. +#### Scope and Assignment + +The inverse of this is true for the relationship between scoping, ownership, and +memory being freed via the `drop` function as well. When you assign a completely +new value to an existing variable, Rust will call `drop` and free the original +value’s memory immediately. Consider this code, for example: + +```rust +{{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-04b-replacement-drop/src/main.rs:here}} +``` + +We initially declare a variable `s` and bind it to a `String` with the value +`"hello"`. Then we immediately create a new `String` with the value `"ahoy"` and +assign it to `s`. At this point, nothing is referring to the original value on +the heap at all. + +One table s representing the string value on the stack, pointing to
+the second piece of string data (ahoy) on the heap, with the original string
+data (hello) grayed out because it cannot be accessed anymore. + +Figure 4-5: Representation in memory after the initial +value has been replaced in its entirety. + +The original string thus immediately goes out of scope. Rust will run the `drop` +function on it and its memory will be freed right away. When we print the value +at the end, it will be `"ahoy, world!"`. + diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 04dd601c7d..055001571a 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -24,13 +24,13 @@ First, notice that all the tuple code in the variable declaration and the function return value is gone. Second, note that we pass `&s1` into `calculate_length` and, in its definition, we take `&String` rather than `String`. These ampersands represent *references*, and they allow you to refer -to some value without taking ownership of it. Figure 4-5 depicts this concept. +to some value without taking ownership of it. Figure 4-6 depicts this concept. Three tables: the table for s contains only a pointer to the table
 for s1. The table for s1 contains the stack data for s1 and points to the
-string data on the heap. +string data on the heap." src="img/trpl04-06.svg" class="center" /> -Figure 4-5: A diagram of `&String s` pointing at `String +Figure 4-6: A diagram of `&String s` pointing at `String s1` > Note: The opposite of referencing by using `&` is *dereferencing*, which is diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 69fb35f82d..d01d905021 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -119,15 +119,15 @@ corresponds to `ending_index` minus `starting_index`. So, in the case of `let world = &s[6..11];`, `world` would be a slice that contains a pointer to the byte at index 6 of `s` with a length value of `5`. -Figure 4-6 shows this in a diagram. +Figure 4-7 shows this in a diagram. Three tables: a table representing the stack data of s, which points
 to the byte at index 0 in a table of the string data "hello world" on
 the heap. The third table rep-resents the stack data of the slice world, which
 has a length value of 5 and points to byte 6 of the heap data table. +src="img/trpl04-07.svg" class="center" style="width: 50%;" /> -Figure 4-6: String slice referring to part of a +Figure 4-7: String slice referring to part of a `String` With Rust’s `..` range syntax, if you want to start at index 0, you can drop diff --git a/src/img/trpl04-05.svg b/src/img/trpl04-05.svg index b4bf2ebee8..dfe9746efd 100644 --- a/src/img/trpl04-05.svg +++ b/src/img/trpl04-05.svg @@ -1,87 +1,99 @@ - - + - -%3 - - - -table0 - -s - -name - -value - -ptr - + viewBox="0.00 0.00 1104.00 1408.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + + + +cluster_stack - - -table1 - -s1 - -name - -value - -ptr - - -len - -5 - -capacity - -5 + +cluster_heap - - -table0:c->table1:borrowee - - + + + +s + +s + +name + +value + +ptr + + +len + +4 + +capacity + +4 - - -table2 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o + + +ahoy + +index + +value + +0 + +a + +1 + +h + +2 + +o + +3 + +y - + -table1:c->table2:pointee - - +s:c->ahoy:pointee + + + + + +hello + + +index + +value + +0 + +h + +1 + +e + +2 + +l + +3 + +l + +4 + +o diff --git a/src/img/trpl04-06.svg b/src/img/trpl04-06.svg index e64415fe43..b4bf2ebee8 100644 --- a/src/img/trpl04-06.svg +++ b/src/img/trpl04-06.svg @@ -5,111 +5,83 @@ --> - + viewBox="0.00 0.00 1500.00 650.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + %3 - + table0 - -world - -name - -value - -ptr - - -len - -5 + +s + +name + +value + +ptr + - - -table4 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o - -5 - - - -6 - -w - -7 - -o - -8 - -r - -9 - -l - -10 - -d - - - -table0:c->table4:pointee2 - - - - + -table3 - -s - -name - -value - -ptr - - -len - -11 - -capacity - -11 +table1 + +s1 + +name + +value + +ptr + + +len + +5 + +capacity + +5 - + -table3:c->table4:pointee - - +table0:c->table1:borrowee + + + + + +table2 + +index + +value + +0 + +h + +1 + +e + +2 + +l + +3 + +l + +4 + +o + + + +table1:c->table2:pointee + + diff --git a/src/img/trpl04-07.svg b/src/img/trpl04-07.svg new file mode 100644 index 0000000000..e64415fe43 --- /dev/null +++ b/src/img/trpl04-07.svg @@ -0,0 +1,115 @@ + + + + + + +%3 + + + +table0 + +world + +name + +value + +ptr + + +len + +5 + + + +table4 + +index + +value + +0 + +h + +1 + +e + +2 + +l + +3 + +l + +4 + +o + +5 + + + +6 + +w + +7 + +o + +8 + +r + +9 + +l + +10 + +d + + + +table0:c->table4:pointee2 + + + + + +table3 + +s + +name + +value + +ptr + + +len + +11 + +capacity + +11 + + + +table3:c->table4:pointee + + + + + From 81c42b5c543a1e7882995d10c481ac744fd2af98 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 1 Oct 2024 09:41:37 -0600 Subject: [PATCH 557/720] Simplify dot file for Figure 4-5 Get rid of things which are not contributing meaningfully to the resulting SVG output. --- dot/trpl04-05.dot | 31 ++------- src/img/trpl04-05.svg | 144 ++++++++++++++++++++---------------------- 2 files changed, 77 insertions(+), 98 deletions(-) diff --git a/dot/trpl04-05.dot b/dot/trpl04-05.dot index f83ab815e0..ccdad725aa 100644 --- a/dot/trpl04-05.dot +++ b/dot/trpl04-05.dot @@ -1,33 +1,16 @@ digraph { rankdir = LR; overlap = false; - newrank = true; dpi = 300.0; - splines = false; - clusterrank = "local"; node [shape = "plaintext";]; - subgraph cluster_stack { - peripheries = 0; - rank = "same"; - - // Just to have the right height! - a [label = < - - - - - -
a
0
1
2
3
>;style = invis;]; - - s [label = < - - - - - -
s
namevalue
ptr
len4
capacity4
>;]; - } + s [label = < + + + + + +
s
namevalue
ptr
len4
capacity4
>;]; subgraph cluster_heap { peripheries = 0; diff --git a/src/img/trpl04-05.svg b/src/img/trpl04-05.svg index dfe9746efd..f3c6e8a82b 100644 --- a/src/img/trpl04-05.svg +++ b/src/img/trpl04-05.svg @@ -5,95 +5,91 @@ --> - - + viewBox="0.00 0.00 1038.00 1342.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + + -cluster_stack - - cluster_heap - - + s - -s - -name - -value - -ptr - - -len - -4 - -capacity - -4 + +s + +name + +value + +ptr + + +len + +4 + +capacity + +4 - + ahoy - -index - -value - -0 - -a - -1 - -h - -2 - -o - -3 - -y + +index + +value + +0 + +a + +1 + +h + +2 + +o + +3 + +y s:c->ahoy:pointee - - + + - + hello - - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o + + +index + +value + +0 + +h + +1 + +e + +2 + +l + +3 + +l + +4 + +o From aca71b65a1bd0ac33b68723eed9bf9e35f5cd611 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 1 Oct 2024 09:48:54 -0600 Subject: [PATCH 558/720] Ch. 17: correct a missing word --- src/ch17-01-futures-and-syntax.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 8197b8e6c0..c595ded829 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -55,9 +55,9 @@ crates. for `trpl` because it is good and widely used. In some cases, `trpl` also renames or wraps the original APIs to let us stay -focused on the details relevant to chapter. If you want to understand what the -crate does, we encourage you to check out [its source code][crate-source]. You -will be able to see what crate each re-export comes from, and we have left +focused on the details relevant to this chapter. If you want to understand what +the crate does, we encourage you to check out [its source code][crate-source]. +You will be able to see what crate each re-export comes from, and we have left extensive comments explaining what the crate does. Go ahead and add the `trpl` crate to your `hello-async` project: From 8df8d8ecb6894d57a7482da47af8fac912d10995 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 1 Oct 2024 11:35:39 -0400 Subject: [PATCH 559/720] Be more explicit about creating a new project --- src/ch17-01-futures-and-syntax.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index c595ded829..ed2386d642 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -60,9 +60,12 @@ the crate does, we encourage you to check out [its source code][crate-source]. You will be able to see what crate each re-export comes from, and we have left extensive comments explaining what the crate does. -Go ahead and add the `trpl` crate to your `hello-async` project: +Create a new binary project named `hello-async` and add the `trpl` crate as a +dependency: ```console +$ cargo new hello-async +$ cd hello-async $ cargo add trpl ``` From e8e0c6beba433498b011123a2dd2c6a28026604a Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 1 Oct 2024 11:37:26 -0400 Subject: [PATCH 560/720] Introduce the listing more explicitly --- src/ch17-01-futures-and-syntax.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index ed2386d642..16349d943a 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -74,6 +74,9 @@ program. We will build a little command line tool which fetches two web pages, pulls the `` element from each, and prints out the title of whichever finishes that whole process first. +Let's start by writing a function that takes one page URL as a parameter, makes +a request to it, and returns the text of the title element: + <Listing number="17-1" file-name="src/main.rs" caption="Defining an async function to get the title element from an HTML page"> ```rust From f7276278082ff279b69581ebbe0704fad4f8f481 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 11:45:13 -0400 Subject: [PATCH 561/720] There is no name argument, but there is a url parameter --- src/ch17-01-futures-and-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 16349d943a..4a7a59ff96 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -184,7 +184,7 @@ Let’s walk through each part of the transformed version: above. That value matches the `Output` type in the return type. This is just like other blocks you have seen. * The new function body is an `async move` block because of how it uses the - `name` argument. (We will talk about `async` vs. `async move` much more later + `url` parameter. (We will talk about `async` vs. `async move` much more later in the chapter.) * The new version of the function has a kind of lifetime we have not seen before in the output type: `'_`. Because the function returns a `Future` which refers From a37e1a73c111b3cfee40a63f2586ffafe0b737fa Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 11:47:16 -0400 Subject: [PATCH 562/720] Rust not allowing main to be async isn't due to the first part of the sentence Change from "so" to "and" to avoid that implication. --- src/ch17-01-futures-and-syntax.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 4a7a59ff96..9467c7532e 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -210,8 +210,8 @@ account for whether the page had a `<title>`. </Listing> Unfortunately, this does not compile. The only place we can use the `await` -keyword is in async functions or blocks, so Rust will not let us mark `main` as -`async`. +keyword is in async functions or blocks, and Rust will not let us mark the +special `main` function as `async`. <!-- manual-regeneration cd listings/ch17-async-await/listing-17-03 From 2f8e266749b1540f15b069be2905301b0818960c Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 11:49:44 -0400 Subject: [PATCH 563/720] Clarify which reason we're talking about and what Rust programs have runtimes --- src/ch17-01-futures-and-syntax.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 9467c7532e..394a3c378b 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -227,11 +227,12 @@ error[E0752]: `main` function is not allowed to be `async` | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` ``` -The reason is that async code needs a *runtime*: a Rust crate which manages the -details of executing asynchronous code. A program's `main` function can -initialize a runtime, but it is not a runtime itself. (We will see more about -why this is a bit later.) Every async program in Rust has at least one place -where it sets up a runtime and executes the futures. +The reason `main` can't be marked `async` is that async code needs a *runtime*: +a Rust crate which manages the details of executing asynchronous code. A +program's `main` function can *initialize* a runtime, but it is not a runtime +*itself*. (We will see more about why this is a bit later.) Every Rust program +that executes async code has at least one place where it sets up a runtime and +executes the futures. Most languages which support async bundle a runtime with the language. Rust does not. Instead, there are many different async runtimes available, each of which From e4e5a4b0160a5e19bc25994a207db186f9f51d42 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 11:54:18 -0400 Subject: [PATCH 564/720] We haven't added 2 calls yet; remove some text that's jumping ahead --- src/ch17-01-futures-and-syntax.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 394a3c378b..0e6b35f762 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -273,10 +273,8 @@ When we run this, we get the behavior we might have expected initially: ``` Phew: we finally have some working async code! This now compiles, and we can run -it. Pick a couple URLs and run the command line tool. You may discover that some -sites are reliably faster than others, while in other cases which site “wins” -varies from run to run. Let’s briefly turn our attention back to how futures -work. +it. Before we add code to race two sites against each other, let’s briefly turn +our attention back to how futures work. Each *await point*—that is, every place where the code uses the `await` keyword—represents a place where control gets handed back to the runtime. To From 9fca5aa6f45519981eb776a74a0b550aedbdca2a Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 11:54:55 -0400 Subject: [PATCH 565/720] Add a bit more detail about why we'd want a state machine enum --- src/ch17-01-futures-and-syntax.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 0e6b35f762..3684451360 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -281,7 +281,8 @@ keyword—represents a place where control gets handed back to the runtime. To make that work, Rust needs to keep track of the state involved in the async block, so that the runtime can kick off some other work and then come back when it is ready to try advancing this one again. This is an invisible state machine, -as if you wrote something like this: +as if you wrote an enum like this to save the current state at each `await` +point: ```rust {{#rustdoc_include ../listings/ch17-async-await/no-listing-state-machine/src/lib.rs:enum}} From 01f089aa2bf6b6f4502b4225db7d1faea1924a9f Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 11:56:23 -0400 Subject: [PATCH 566/720] Clarify writing what would be tedious, and what changes later would be made --- src/ch17-01-futures-and-syntax.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 3684451360..4aed657e4d 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -288,12 +288,13 @@ point: {{#rustdoc_include ../listings/ch17-async-await/no-listing-state-machine/src/lib.rs:enum}} ``` -Writing that out by hand would be tedious and error-prone, especially when -making changes to code later. Instead, the Rust compiler creates and manages the -state machine data structures for async code automatically. If you’re wondering: -yep, the normal borrowing and ownership rules around data structures all apply. -Happily, the compiler also handles checking those for us, and has good error -messages. We will work through a few of those later in the chapter! +Writing the code to transition between each state by hand would be tedious and +error-prone, especially when adding more functionality and more states to the +code later. Instead, the Rust compiler creates and manages the state machine +data structures for async code automatically. If you’re wondering: yep, the +normal borrowing and ownership rules around data structures all apply. Happily, +the compiler also handles checking those for us, and has good error messages. +We will work through a few of those later in the chapter! Ultimately, something has to execute that state machine. That something is a runtime. (This is why you may sometimes come across references to *executors* From 502adbf52087c5cdccb9302ef404b1e924461deb Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 12:03:52 -0400 Subject: [PATCH 567/720] Be clearer about where we're using trpl::run and what it's running --- src/ch17-01-futures-and-syntax.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 4aed657e4d..f29237f195 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -304,9 +304,9 @@ executing the async code.) Now we can understand why the compiler stopped us from making `main` itself an async function back in Listing 17-3. If `main` were an async function, something else would need to manage the state machine for whatever future `main` returned, -but main is the starting point for the program! Instead, we use the `trpl::run` -function, which sets up a runtime and runs the future returned by `page_title` -until it returns `Ready`. +but `main` is the starting point for the program! Instead, we call the +`trpl::run` function in `main`, which sets up a runtime and runs the future +returned by the `async` block until it returns `Ready`. > Note: some runtimes provide macros to make it so you *can* write an async main > function. Those macros rewrite `async fn main() { ... }` to be a normal `fn From 9ad373ff7b51f49f6a3773e54600fb4932ab670c Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 12:04:33 -0400 Subject: [PATCH 568/720] Correct function name and pronoun number --- src/ch17-01-futures-and-syntax.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index f29237f195..2124b69000 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -314,8 +314,8 @@ returned by the `async` block until it returns `Ready`. > function which runs a future to completion the way `trpl::run` does. Let’s put these pieces together and see how we can write concurrent code, by -calling `page_title_for` with two different URLs passed in from the command line -and racing it. +calling `page_title` with two different URLs passed in from the command line +and racing them. <Listing number="17-5" caption="" file-name="src/main.rs"> From a25f57614ec65a99232101815f214c34c09bb5c9 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 12:06:08 -0400 Subject: [PATCH 569/720] This sounds like 1 call with 2 URLs but it's 2 calls with 1 URL each --- src/ch17-01-futures-and-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 2124b69000..b920963f0e 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -327,7 +327,7 @@ and racing them. </Listing> -In Listing 17-5, we begin by calling `page_title` with both of the user-supplied +In Listing 17-5, we begin by calling `page_title` for each of the user-supplied URLs. We save the futures produced by calling `page_title` as `title_fut_1` and `title_fut_2`. Remember, these don’t do anything yet, because futures are lazy, and we have not yet awaited them. Then we pass the futures to `trpl::race`, From 15f353c1efe09a08b296ab5a256a1c5baa236d35 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 12:07:50 -0400 Subject: [PATCH 570/720] Add a trailing comma on the last variant --- src/ch17-01-futures-and-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index b920963f0e..fc8ae2c0da 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -349,7 +349,7 @@ other”. ```rust enum Either<A, B> { Left(A), - Right(B) + Right(B), } ``` From d34446d51f7230914252e45706a8028f02fa4f36 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 12:08:59 -0400 Subject: [PATCH 571/720] Correct another instance of an old function name --- src/ch17-01-futures-and-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index fc8ae2c0da..9ecdc3437a 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -358,7 +358,7 @@ that future’s output, and `Right` with the second future argument’s output i *that* one finishes first. This matches the order the arguments appear when calling the function: the first argument is to the left of the second argument. -We also update `page_title_for` to return the same URL passed in. That way, if +We also update `page_title` to return the same URL passed in. That way, if the page which returns first does not have a `<title>` we can resolve, we can still print a meaningful message. With that information available, we wrap up by updating our `println!` output to indicate both which URL finished first and From f713c79b4bc3bdc38627d4fb86cd0234e58d5a41 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 12:11:05 -0400 Subject: [PATCH 572/720] Put back the invitation to race URLs at the end --- src/ch17-01-futures-and-syntax.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 9ecdc3437a..157fd26193 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -364,10 +364,11 @@ still print a meaningful message. With that information available, we wrap up by updating our `println!` output to indicate both which URL finished first and what the `<title>` was for the web page at that URL, if any. -You have built a small working web scraper now, which we could extend in a bunch -of different directions. More importantly, you have learned the basics of -working with futures, so we can now dig into even more of the things we can *do* -with async. +You have built a small working web scraper now! Pick a couple URLs and run the +command line tool. You may discover that some sites are reliably faster than +others, while in other cases which site “wins” varies from run to run. More +importantly, you have learned the basics of working with futures, so we can now +dig into even more of the things we can *do* with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters [iterators-lazy]: ch13-02-iterators.html From 78679a78880619e04a608cac943506cd79208364 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 12:27:10 -0400 Subject: [PATCH 573/720] Clarify why the block only borrows and remove an unneeded word --- src/ch17-02-concurrency-with-async.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index a222b851d8..c0cd4ee2c8 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -319,12 +319,13 @@ make much sense. Stopping after handling some arbitrary number of messages would make the program shut down, but we could miss messages. We need some other way to make sure that `tx` gets dropped *before* the end of the function. -Right now, the async block where we send the messages only borrows `tx`, but if -we could move `tx` into that async block, it would be dropped once that block -ends. In Chapter 13, we learned how to use the `move` keyword with closures, and -in Chapter 16, we saw that we often need to use move data into closures when -working with threads. The same basic dynamics apply to async blocks, so the -`move` keyword works with async blocks just like it does with closures. +Right now, the async block where we send the messages only borrows `tx` because +sending a message doesn't require ownership, but if we could move `tx` into +that async block, it would be dropped once that block ends. In Chapter 13, we +learned how to use the `move` keyword with closures, and in Chapter 16, we saw +that we often need to move data into closures when working with threads. The +same basic dynamics apply to async blocks, so the `move` keyword works with +async blocks just like it does with closures. In Listing 17-12, we change the async block for sending messages from a plain `async` block to an `async move` block. When we run *this* version of the code, From f01527c27164326bcd97f8b78dce67984559d9ca Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 13:15:26 -0400 Subject: [PATCH 574/720] Since -> because because none of these are time-based --- src/ch17-00-async-await.md | 2 +- src/ch17-01-futures-and-syntax.md | 12 ++++++------ src/ch17-02-concurrency-with-async.md | 2 +- src/ch17-03-more-futures.md | 2 +- src/ch17-04-streams.md | 22 +++++++++++----------- src/ch17-05-traits-for-async.md | 6 +++--- src/ch17-06-futures-tasks-threads.md | 6 +++--- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index ecd9fb14b3..2a28792819 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -36,7 +36,7 @@ happen while the network operation is still ongoing. In both of these examples, the operating system’s invisible interrupts provide a form of concurrency. That concurrency only happens at the level of a whole program, though: the operating system interrupts one program to let other -programs get work done. In many cases, since we understand our programs at a +programs get work done. In many cases, because we understand our programs at a much more granular level than the operating system does, we can spot lots of opportunities for concurrency that the operating system cannot see. diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 157fd26193..6768962fc9 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -117,7 +117,7 @@ Once we have `response_text`, we can then parse it into an instance of the type we can use to work with the HTML as a richer data structure. In particular, we can use the `select_first` method to find the first instance of a given CSS selector. By passing the string `"title"`, we will get the first `<title>` -element in the document, if there is one. Since there may not be any matching +element in the document, if there is one. Because there may not be any matching element, `select_first` returns an `Option<ElementRef>`. Finally, we use the `Option::map` method, which lets us work with the item in the `Option` if it is present, and do nothing if it is not. (We could also use a `match` expression @@ -194,11 +194,11 @@ Let’s walk through each part of the transformed version: reference which could be involved, but we *do* have to be explicit that the resulting `Future` is bound by that lifetime. -Now we can call `page_title` in `main`. To start, we will just get the title for -a single page. In Listing 17-3, we follow the same pattern we used for getting -command line arguments back in Chapter 12. Then we pass the first URL -`page_title`, and await the result. Since the value produced by the future is an -`Option<String>`, we use a `match` expression to print different messages to +Now we can call `page_title` in `main`. To start, we will just get the title +for a single page. In Listing 17-3, we follow the same pattern we used for +getting command line arguments back in Chapter 12. Then we pass the first URL +`page_title`, and await the result. Because the value produced by the future is +an `Option<String>`, we use a `match` expression to print different messages to account for whether the page had a `<title>`. <Listing number="17-3" file-name="src/main.rs" caption="Calling the `page_title` function from `main` with a user-supplied argument"> diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index c0cd4ee2c8..5e79143724 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -1,7 +1,7 @@ ## Concurrency With Async In this section, we will apply async to some of the same concurrency challenges -we tackled with threads in chapter 16. Since we already talked about a lot of +we tackled with threads in chapter 16. Because we already talked about a lot of the key ideas there, in this section we will focus on what is different between threads and futures. diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index ea9c7460ad..3d3c83fcdb 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -86,7 +86,7 @@ generated by the compiler. To make this work, we need to use *trait objects*, just as we did in [“Returning Errors from the run function”][dyn] in Chapter 12. (We will cover trait objects in detail in Chapter 18.) Using trait objects lets us treat each of the -anonymous futures produced by these types as the same type, since all of them +anonymous futures produced by these types as the same type, because all of them implement the `Future` trait. > Note: In Chapter 8, we discussed another way to include multiple types in a diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 28e8d9793f..1635044d97 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -186,7 +186,7 @@ be polled. </Listing> -However, since there are no delays between messages, this timeout does not +However, because there are no delays between messages, this timeout does not change the behavior of the program. Let’s add a variable delay to the messages we send. In `get_messages`, we use the `enumerate` iterator method with the `messages` array so that we can get the index of each item we are sending along @@ -278,7 +278,7 @@ In Listing 17-36, we start by defining a `count` in the task. (We could define it outside the task, too, but it is clearer to limit the scope of any given variable.) Then we create a an infinite loop. Each iteration of the loop asynchronously sleeps for one millisecond, increments the count, and then sends -it over the channel. Since this is all wrapped in the task created by +it over the channel. Because this is all wrapped in the task created by `spawn_task`, all of it will get cleaned up along with the runtime, including the infinite loop. @@ -318,15 +318,15 @@ for a `timeout` call. Meanwhile, the `intervals` stream has the type `impl Stream<Item = u32>`. To merge these two streams, we need to transform one of them to match the other. -In Listing 17-38, we rework with the `intervals` stream, since `messages` is +In Listing 17-38, we rework with the `intervals` stream, because `messages` is already in the basic format we want and has to handle timeout errors. First, we can use the `map` helper method to transform the `intervals` into a string. -Second, we need to match the `Timeout` from `messages`. Since we do not actually -*want* a timeout for `intervals`, though, we can just create a timeout which is -longer than the other durations we are using. Here, we create a 10-second -timeout with `Duration::from_secs(10)`. Finally, we need to make `stream` -mutable, so that the `while let` loop’s `next` calls can iterate through the -stream, and pin it so that it is safe to do so. +Second, we need to match the `Timeout` from `messages`. Because we do not +actually *want* a timeout for `intervals`, though, we can just create a timeout +which is longer than the other durations we are using. Here, we create a +10-second timeout with `Duration::from_secs(10)`. Finally, we need to make +`stream` mutable, so that the `while let` loop’s `next` calls can iterate +through the stream, and pin it so that it is safe to do so. <!-- We cannot directly test this one, because it never stops. --> @@ -365,8 +365,8 @@ Listing 17-39 shows one way to solve these last two problems. First, we use the `throttle` method on the `intervals` stream, so that it does not overwhelm the `messages` stream. Throttling is a way of limiting the rate at which a function will be called—or, in this case, how often the stream will be polled. Once every -hundred milliseconds should do, since that is in the same ballpark as how often -our messages arrive. +hundred milliseconds should do, because that is in the same ballpark as how +often our messages arrive. To limit the number of items we will accept from a stream, we can use the `take` method. We apply it to the *merged* stream, because we want to limit the final diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 91a78a7a56..a6eecf6f7b 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -195,7 +195,7 @@ those, however, `Pin` only works with *pointer types* like references (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` works with types which implement the `Deref` or `DerefMut` traits, which we covered in Chapter 15. You can think of this restriction as equivalent to only working with -pointers, though, since implementing `Deref` or `DerefMut` means your type +pointers, though, because implementing `Deref` or `DerefMut` means your type behaves like a pointer type. `Pin` is also not a pointer itself, and it does not have any behavior of its own like the ref counting of `Rc` or `Arc`. It is purely a tool the compiler can use to uphold the relevant guarantees, by @@ -410,8 +410,8 @@ the unit type `()`). `Stream` also defines a method to get those items. We call it `poll_next`, to make it clear that it polls like `Future::poll` and produces a sequence of items like `Iterator::next`. Its return type combines `Poll`with `Option`. The outer -type is `Poll`, since it has to be checked for readiness, just like a future. -The inner type is `Option`, since it needs to signal whether there are more +type is `Poll`, because it has to be checked for readiness, just like a future. +The inner type is `Option`, because it needs to signal whether there are more messages, just like an iterator. Something very similar to this will likely end up standardized as part of Rust’s diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index b54117ccc4..1d4876d2c0 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -117,9 +117,9 @@ throughout the chapter. In that future, we await those messages, just like in the other message-passing examples we have seen. To return to the examples we opened the chapter with: you could imagine running -a set of video encoding tasks using a dedicated thread, since video encoding is -compute bound, but notifying the UI that those operations are done with an async -channel. Examples of this kind of mix abound! +a set of video encoding tasks using a dedicated thread, because video encoding +is compute bound, but notifying the UI that those operations are done with an +async channel. Examples of this kind of mix abound! ## Summary From c2c083cb65f10fa7e45c39db2d34ae28952e97ca Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 13:19:30 -0400 Subject: [PATCH 575/720] Removing code style around futures; not sure what this refers to --- src/ch17-03-more-futures.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 3d3c83fcdb..b799aa30d3 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -112,8 +112,8 @@ Unfortunately, this still does not compile. In fact, we have the same basic error we did before, but we get one for both the second and third `Box::new` calls, and we also get new errors referring to the `Unpin` trait. We will come back to the `Unpin` errors in a moment. First, let’s fix the type errors on the -`Box::new` calls, by explicitly providing the type of `futures` as a trait -object (Listing 17-17). +`Box::new` calls, by explicitly annotating the type of the futures as a trait +object: <Listing number="17-17" caption="Fixing the rest of the type mismatch errors by using an explicit type declaration" file-name="src/main.rs"> From 63e7ab1ed30b53841754f2e6e1e5c00cb5c4ed45 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 13:20:32 -0400 Subject: [PATCH 576/720] Oh I see, it's the futures variable, but then I wouldn't call it a trait object --- src/ch17-03-more-futures.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index b799aa30d3..f18cca72c2 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -112,8 +112,7 @@ Unfortunately, this still does not compile. In fact, we have the same basic error we did before, but we get one for both the second and third `Box::new` calls, and we also get new errors referring to the `Unpin` trait. We will come back to the `Unpin` errors in a moment. First, let’s fix the type errors on the -`Box::new` calls, by explicitly annotating the type of the futures as a trait -object: +`Box::new` calls, by explicitly annotating the type of the `futures` variable: <Listing number="17-17" caption="Fixing the rest of the type mismatch errors by using an explicit type declaration" file-name="src/main.rs"> From b82de7ecd52325151bdb687fbafb529ab8161b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= <jpmelos@gmail.com> Date: Tue, 1 Oct 2024 19:07:52 +0100 Subject: [PATCH 577/720] Revert "Mention move of individual struct fields" This reverts commit 88c3e558feb5d7e9d81e294a217e47611de0f124. --- src/ch05-01-defining-structs.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index 1cf57d1db9..c5db4dc74d 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -147,18 +147,14 @@ the struct’s definition. Note that the struct update syntax uses `=` like an assignment; this is because it moves the data, just as we saw in the [“Variables and Data Interacting with -Move”][move]<!-- ignore --> section. However, the fields are moved -individually, and the original struct is not invalidated if it contains -reference the data that wasn't moved. - -In Listing 5-7, we can no longer use `user1.username` because it was moved into -`user2.username`. However, we can continue to use `user1.email` normally. If we -had given `user2` new `String` values for both `email` and `username`, and thus -only used the `active` and `sign_in_count` values from `user1`, then -`user1.username` would still be valid after creating `user2`. Both `active` and -`sign_in_count` are types that implement the `Copy` trait, so the behavior we -discussed in the [“Stack-Only Data: Copy”][copy]<!-- ignore --> section would -apply. +Move”][move]<!-- ignore --> section. In this example, we can no longer use +`user1` as a whole after creating `user2` because the `String` in the +`username` field of `user1` was moved into `user2`. If we had given `user2` new +`String` values for both `email` and `username`, and thus only used the +`active` and `sign_in_count` values from `user1`, then `user1` would still be +valid after creating `user2`. Both `active` and `sign_in_count` are types that +implement the `Copy` trait, so the behavior we discussed in the [“Stack-Only +Data: Copy”][copy]<!-- ignore --> section would apply. ### Using Tuple Structs Without Named Fields to Create Different Types From 26bea114edb01746afbab284fdc97330f61aa2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= <jpmelos@gmail.com> Date: Tue, 1 Oct 2024 19:13:03 +0100 Subject: [PATCH 578/720] Add note about field access after struct update syntax --- src/ch05-01-defining-structs.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index c5db4dc74d..f84785cde1 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -154,7 +154,8 @@ Move”][move]<!-- ignore --> section. In this example, we can no longer use `active` and `sign_in_count` values from `user1`, then `user1` would still be valid after creating `user2`. Both `active` and `sign_in_count` are types that implement the `Copy` trait, so the behavior we discussed in the [“Stack-Only -Data: Copy”][copy]<!-- ignore --> section would apply. +Data: Copy”][copy]<!-- ignore --> section would apply. We can still use +`user1.email` in this example, since its value was _not_ moved out. ### Using Tuple Structs Without Named Fields to Create Different Types From 204f0fc923426c20b1e1f6eb150ed2c939698b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= <jpmelos@gmail.com> Date: Tue, 1 Oct 2024 19:18:23 +0100 Subject: [PATCH 579/720] Don't run tests for this snippet --- src/ch05-01-defining-structs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index 841de4ecd2..11077f1d80 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -188,7 +188,7 @@ When destructuring tuple structs, you must mention the type of the instance being destructured. For example, the line below would not compile when used in the previous listing: -```rust +```rust,ignore let (r, g, b) = black; ``` From 2d28663328281832bed4e803d6b17bbae82d8820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= <jpmelos@gmail.com> Date: Tue, 1 Oct 2024 20:20:53 +0100 Subject: [PATCH 580/720] Convert ch05 to `<Listing>` --- src/ch05-01-defining-structs.md | 48 ++++++++++++++++----------------- src/ch05-02-example-structs.md | 24 +++++++---------- src/ch05-03-method-syntax.md | 24 ++++++++--------- 3 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index c5db4dc74d..98ef776cc8 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -13,13 +13,13 @@ grouped together. Then, inside curly brackets, we define the names and types of the pieces of data, which we call *fields*. For example, Listing 5-1 shows a struct that stores information about a user account. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-1" file-name="src/main.rs" caption="A `User` struct definition"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-01/src/main.rs:here}} ``` -<span class="caption">Listing 5-1: A `User` struct definition</span> +</Listing> To use a struct after we’ve defined it, we create an *instance* of that struct by specifying concrete values for each of the fields. We create an instance by @@ -31,14 +31,13 @@ struct definition is like a general template for the type, and instances fill in that template with particular data to create values of the type. For example, we can declare a particular user as shown in Listing 5-2. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-2" file-name="src/main.rs" caption="Creating an instance of the `User` struct"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-02/src/main.rs:here}} ``` -<span class="caption">Listing 5-2: Creating an instance of the `User` -struct</span> +</Listing> To get a specific value from a struct, we use dot notation. For example, to access this user’s email address, we use `user1.email`. If the instance is @@ -46,14 +45,13 @@ mutable, we can change a value by using the dot notation and assigning into a particular field. Listing 5-3 shows how to change the value in the `email` field of a mutable `User` instance. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-3" file-name="src/main.rs" caption="Changing the value in the `email` field of a `User` instance"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-03/src/main.rs:here}} ``` -<span class="caption">Listing 5-3: Changing the value in the `email` field of a -`User` instance</span> +</Listing> Note that the entire instance must be mutable; Rust doesn’t allow us to mark only certain fields as mutable. As with any expression, we can construct a new @@ -64,14 +62,13 @@ Listing 5-4 shows a `build_user` function that returns a `User` instance with the given email and username. The `active` field gets the value of `true`, and the `sign_in_count` gets a value of `1`. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-4" file-name="src/main.rs" caption="A `build_user` function that takes an email and username and returns a `User` instance"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-04/src/main.rs:here}} ``` -<span class="caption">Listing 5-4: A `build_user` function that takes an email -and username and returns a `User` instance</span> +</Listing> It makes sense to name the function parameters with the same name as the struct fields, but having to repeat the `email` and `username` field names and @@ -88,15 +85,13 @@ Listing 5-4, we can use the *field init shorthand* syntax to rewrite `build_user` so it behaves exactly the same but doesn’t have the repetition of `username` and `email`, as shown in Listing 5-5. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-5" file-name="src/main.rs" caption="A `build_user` function that uses field init shorthand because the `username` and `email` parameters have the same name as struct fields"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-05/src/main.rs:here}} ``` -<span class="caption">Listing 5-5: A `build_user` function that uses field init -shorthand because the `username` and `email` parameters have the same name as -struct fields</span> +</Listing> Here, we’re creating a new instance of the `User` struct, which has a field named `email`. We want to set the `email` field’s value to the value in the @@ -114,28 +109,25 @@ First, in Listing 5-6 we show how to create a new `User` instance in `user2` regularly, without the update syntax. We set a new value for `email` but otherwise use the same values from `user1` that we created in Listing 5-2. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-6" file-name="src/main.rs" caption="Creating a new `User` instance using all but one of the values from `user1`"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-06/src/main.rs:here}} ``` -<span class="caption">Listing 5-6: Creating a new `User` instance using all but one of -the values from `user1`</span> +</Listing> Using struct update syntax, we can achieve the same effect with less code, as shown in Listing 5-7. The syntax `..` specifies that the remaining fields not explicitly set should have the same value as the fields in the given instance. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-7" file-name="src/main.rs" caption="Using struct update syntax to set a new `email` value for a `User` instance but to use the rest of the values from `user1`"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-07/src/main.rs:here}} ``` -<span class="caption">Listing 5-7: Using struct update syntax to set a new -`email` value for a `User` instance but to use the rest of the values from -`user1`</span> +</Listing> The code in Listing 5-7 also creates an instance in `user2` that has a different value for `email` but has the same values for the `username`, @@ -169,12 +161,14 @@ To define a tuple struct, start with the `struct` keyword and the struct name followed by the types in the tuple. For example, here we define and use two tuple structs named `Color` and `Point`: -<span class="filename">Filename: src/main.rs</span> +<Listing file-name="src/main.rs"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs}} ``` +</Listing> + Note that the `black` and `origin` values are different types because they’re instances of different tuple structs. Each struct you define is its own type, even though the fields within the struct might have the same types. For @@ -194,12 +188,14 @@ have any data that you want to store in the type itself. We’ll discuss traits in Chapter 10. Here’s an example of declaring and instantiating a unit struct named `AlwaysEqual`: -<span class="filename">Filename: src/main.rs</span> +<Listing file-name="src/main.rs"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/no-listing-04-unit-like-structs/src/main.rs}} ``` +</Listing> + To define `AlwaysEqual`, we use the `struct` keyword, the name we want, and then a semicolon. No need for curly brackets or parentheses! Then we can get an instance of `AlwaysEqual` in the `subject` variable in a similar way: using the @@ -223,7 +219,7 @@ implement them on any type, including unit-like structs. > is valid for as long as the struct is. Let’s say you try to store a reference > in a struct without specifying lifetimes, like the following; this won’t work: > -> <span class="filename">Filename: src/main.rs</span> +> <Listing file-name="src/main.rs"> > > <!-- CAN'T EXTRACT SEE https://github.com/rust-lang/mdBook/issues/1127 --> > @@ -245,6 +241,8 @@ implement them on any type, including unit-like structs. > } > ``` > +> </Listing> +> > The compiler will complain that it needs lifetime specifiers: > > ```console diff --git a/src/ch05-02-example-structs.md b/src/ch05-02-example-structs.md index 1e7c9f7e9b..392f1bd3bd 100644 --- a/src/ch05-02-example-structs.md +++ b/src/ch05-02-example-structs.md @@ -9,14 +9,13 @@ the width and height of a rectangle specified in pixels and calculate the area of the rectangle. Listing 5-8 shows a short program with one way of doing exactly that in our project’s *src/main.rs*. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-8" file-name="src/main.rs" caption="Calculating the area of a rectangle specified by separate width and height variables"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-08/src/main.rs:all}} ``` -<span class="caption">Listing 5-8: Calculating the area of a rectangle -specified by separate width and height variables</span> +</Listing> Now, run this program using `cargo run`: @@ -45,14 +44,13 @@ of Chapter 3: by using tuples. Listing 5-9 shows another version of our program that uses tuples. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-9" file-name="src/main.rs" caption="Specifying the width and height of the rectangle with a tuple"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-09/src/main.rs}} ``` -<span class="caption">Listing 5-9: Specifying the width and height of the -rectangle with a tuple</span> +</Listing> In one way, this program is better. Tuples let us add a bit of structure, and we’re now passing just one argument. But in another way, this version is less @@ -72,13 +70,13 @@ We use structs to add meaning by labeling the data. We can transform the tuple we’re using into a struct with a name for the whole as well as names for the parts, as shown in Listing 5-10. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-10" file-name="src/main.rs" caption="Defining a `Rectangle` struct"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-10/src/main.rs}} ``` -<span class="caption">Listing 5-10: Defining a `Rectangle` struct</span> +</Listing> Here we’ve defined a struct and named it `Rectangle`. Inside the curly brackets, we defined the fields as `width` and `height`, both of which have @@ -108,14 +106,13 @@ debugging our program and see the values for all its fields. Listing 5-11 tries using the [`println!` macro][println]<!-- ignore --> as we have used in previous chapters. This won’t work, however. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-11" file-name="src/main.rs" caption="Attempting to print a `Rectangle` instance"> ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-11/src/main.rs}} ``` -<span class="caption">Listing 5-11: Attempting to print a `Rectangle` -instance</span> +</Listing> When we compile this code, we get an error with this core message: @@ -163,14 +160,13 @@ have to explicitly opt in to make that functionality available for our struct. To do that, we add the outer attribute `#[derive(Debug)]` just before the struct definition, as shown in Listing 5-12. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-12" file-name="src/main.rs" caption="Adding the attribute to derive the `Debug` trait and printing the `Rectangle` instance using debug formatting"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-12/src/main.rs}} ``` -<span class="caption">Listing 5-12: Adding the attribute to derive the `Debug` -trait and printing the `Rectangle` instance using debug formatting</span> +</Listing> Now when we run the program, we won’t get any errors, and we’ll see the following output: diff --git a/src/ch05-03-method-syntax.md b/src/ch05-03-method-syntax.md index d25e55b18c..91887210d2 100644 --- a/src/ch05-03-method-syntax.md +++ b/src/ch05-03-method-syntax.md @@ -15,14 +15,13 @@ Let’s change the `area` function that has a `Rectangle` instance as a paramete and instead make an `area` method defined on the `Rectangle` struct, as shown in Listing 5-13. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-13" file-name="src/main.rs" caption="Defining an `area` method on the `Rectangle` struct"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-13/src/main.rs}} ``` -<span class="caption">Listing 5-13: Defining an `area` method on the -`Rectangle` struct</span> +</Listing> To define the function within the context of `Rectangle`, we start an `impl` (implementation) block for `Rectangle`. Everything within this `impl` block @@ -65,12 +64,14 @@ Note that we can choose to give a method the same name as one of the struct’s fields. For example, we can define a method on `Rectangle` that is also named `width`: -<span class="filename">Filename: src/main.rs</span> +<Listing file-name="src/main.rs"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/no-listing-06-method-field-interaction/src/main.rs:here}} ``` +</Listing> + Here, we’re choosing to make the `width` method return `true` if the value in the instance’s `width` field is greater than `0` and `false` if the value is `0`: we can use a field within a method of the same name for any purpose. In @@ -141,14 +142,13 @@ within `self` (the first `Rectangle`); otherwise, it should return `false`. That is, once we’ve defined the `can_hold` method, we want to be able to write the program shown in Listing 5-14. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-14" file-name="src/main.rs" caption="Using the as-yet-unwritten `can_hold` method"> ```rust,ignore {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-14/src/main.rs}} ``` -<span class="caption">Listing 5-14: Using the as-yet-unwritten `can_hold` -method</span> +</Listing> The expected output would look like the following because both dimensions of `rect2` are smaller than the dimensions of `rect1`, but `rect3` is wider than @@ -173,14 +173,13 @@ Boolean, and the implementation will check whether the width and height of respectively. Let’s add the new `can_hold` method to the `impl` block from Listing 5-13, shown in Listing 5-15. -<span class="filename">Filename: src/main.rs</span> +<Listing number="5-15" file-name="src/main.rs" caption="Implementing the `can_hold` method on `Rectangle` that takes another `Rectangle` instance as a parameter"> ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-15/src/main.rs:here}} ``` -<span class="caption">Listing 5-15: Implementing the `can_hold` method on -`Rectangle` that takes another `Rectangle` instance as a parameter</span> +</Listing> When we run this code with the `main` function in Listing 5-14, we’ll get our desired output. Methods can take multiple parameters that we add to the @@ -226,12 +225,13 @@ Each struct is allowed to have multiple `impl` blocks. For example, Listing 5-15 is equivalent to the code shown in Listing 5-16, which has each method in its own `impl` block. +<Listing number="5-16" caption="Rewriting Listing 5-15 using multiple `impl` blocks"> + ```rust {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs:here}} ``` -<span class="caption">Listing 5-16: Rewriting Listing 5-15 using multiple `impl` -blocks</span> +</Listing> There’s no reason to separate these methods into multiple `impl` blocks here, but this is valid syntax. We’ll see a case in which multiple `impl` blocks are From db93cd0af315bba175da137b0691bdef55a4df4b Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 16:39:52 -0400 Subject: [PATCH 581/720] Caveat specificity of recv earlier, so we don't get WELL ACTUALLY poll_next --- src/ch17-04-streams.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 1635044d97..92cd9bf763 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -11,8 +11,9 @@ A sequence of items is something we have seen before, when we looked at the and the async channel receiver. The first difference is the element of time: iterators are synchronous, while the channel receiver is asynchronous. The second difference is the API. When working directly with an `Iterator`, we call -its synchronous `next` method. With a `trpl::Receiver`, we call an asynchronous -`recv` method instead, but these APIs otherwise feel very similar. +its synchronous `next` method. With the `trpl::Receiver` stream in particular, +we called an asynchronous `recv` method instead, but these APIs otherwise feel +very similar. That similarity is not a coincidence. A stream is like an asynchronous form of iteration. Whereas the `trpl::Receiver` specifically waits to receive messages, From a97d72a75389eb15216777992c71ae8060ceaea0 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 16:43:48 -0400 Subject: [PATCH 582/720] Change future tense to past tense or whatever these tenses are The needs-to-be sense made it sort of sound like the stream was something the reader needed to create. --- src/ch17-04-streams.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 92cd9bf763..6c53c50f4c 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -17,11 +17,11 @@ very similar. That similarity is not a coincidence. A stream is like an asynchronous form of iteration. Whereas the `trpl::Receiver` specifically waits to receive messages, -though, a general-purpose stream API needs to be much more general: it will just -provide the next item like `Iterator` does, but asynchronously. In fact, this is -roughly how it works in Rust, so we can actually create a stream from any +though, the general-purpose stream API is much more general: it provides the +next item like `Iterator` does, but asynchronously. The similarity between +iterators and streams in Rust means we can actually create a stream from any iterator. As with an iterator, we can work with a stream by calling its `next` -method, and then awaiting the output, as in Listing 17-30. +method and then awaiting the output, as in Listing 17-30. <Listing number="17-30" caption="Creating a stream from an iterator and printing its values" file-name="src/main.rs"> From 048717a75750869b7765d011a8993dfb2bfe7149 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 16:49:52 -0400 Subject: [PATCH 583/720] Missing period --- src/ch17-04-streams.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 6c53c50f4c..1cb54f67e4 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -34,7 +34,7 @@ method and then awaiting the output, as in Listing 17-30. We start with an array of numbers, which we convert to an iterator and then call `map` on to double all the values. Then we convert the iterator into a stream using the `trpl::stream_from_iter` function. Then we loop over the items in the -stream as they arrive with the `while let` loop +stream as they arrive with the `while let` loop. Unfortunately, when we try to run the code, it does not compile. Instead, as we can see in the output, it reports that there is no `next` method available. From b3aef45d7b71ed19827471957bba2d03a2ddc4c0 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 16:50:30 -0400 Subject: [PATCH 584/720] Stream is a trait --- src/ch17-04-streams.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 1cb54f67e4..1d1ffc31be 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -81,7 +81,7 @@ reasonably expect that to be `Stream`, but the trait we need *here* is actually the Rust community for extending one trait with another. You might be wondering why `StreamExt` instead of `Stream`, and for that matter -whether there is a `Stream` type at all. Briefly, the answer is that throughout +whether there is a `Stream` trait at all. Briefly, the answer is that throughout the Rust ecosystem, the `Stream` trait defines a low-level interface which effectively combines the `Iterator` and `Future` traits. The `StreamExt` trait supplies a higher-level set of APIs on top of `Stream`, including the `next` From 428d6deab415d82f5a8ac6a3d3bad8ef1babf14b Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 16:51:09 -0400 Subject: [PATCH 585/720] like -> similar to --- src/ch17-04-streams.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 1d1ffc31be..b79fe7d38c 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -85,9 +85,10 @@ whether there is a `Stream` trait at all. Briefly, the answer is that throughout the Rust ecosystem, the `Stream` trait defines a low-level interface which effectively combines the `Iterator` and `Future` traits. The `StreamExt` trait supplies a higher-level set of APIs on top of `Stream`, including the `next` -method and also many other utility methods like those from `Iterator`. We will -return to the `Stream` and `StreamExt` traits in a bit more detail at the end of -the chapter. For now, this is enough to let us keep moving. +method as well as other utility methods similar to those provided by the +`Iterator` trait. We will return to the `Stream` and `StreamExt` traits in a +bit more detail at the end of the chapter. For now, this is enough to let us +keep moving. All we need to do is add a `use` statement for `trpl::StreamExt`, as in Listing 17-31. From 6cd340c60eba81fc4125290c549fc3ffdd3b7404 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 16:51:39 -0400 Subject: [PATCH 586/720] 'All we need to do' makes it sound easy, but it might not be Knowing what trait to add feels hard to me sometimes. --- src/ch17-04-streams.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index b79fe7d38c..697b544764 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -90,8 +90,8 @@ method as well as other utility methods similar to those provided by the bit more detail at the end of the chapter. For now, this is enough to let us keep moving. -All we need to do is add a `use` statement for `trpl::StreamExt`, as in Listing -17-31. +The fix to the compiler error is to add a `use` statement for `trpl::StreamExt`, +as in Listing 17-31. <Listing number="17-31" caption="Successfully using an iterator as the basis for a stream" file-name="src/main.rs"> From cec24f5c349fe417019d6280be1faa3de0cd11cd Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 16:52:13 -0400 Subject: [PATCH 587/720] Be more specific than things --- src/ch17-04-streams.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 697b544764..f0b383097b 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -101,10 +101,10 @@ as in Listing 17-31. </Listing> -With all those pieces put together, things work the way we want! What is more, -now that we have `StreamExt` in scope, we can use all of its utility methods, -just like with iterators. For example, in Listing 17-32, we use the `filter` -method to filter out everything but multiples of three and five. +With all those pieces put together, this code works the way we want! What's +more, now that we have `StreamExt` in scope, we can use all of its utility +methods, just like with iterators. For example, in Listing 17-32, we use the +`filter` method to filter out everything but multiples of three and five. <Listing number="17-32" caption="Filtering a `Stream` with the `StreamExt::filter` method" file-name="src/main.rs"> @@ -120,7 +120,7 @@ do which are unique to streams. ### Composing Streams -Lots of things are naturally represented as streams: items becoming available in +Many concepts are naturally represented as streams: items becoming available in a queue, or working with more data than can fit in a computer’s memory by only pulling chunks of it from the file system at a time, or data arriving over the network over time. Because streams are futures, we can use them with any other From 79c2110983b5a8b51584e7661649422abb7fe945 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 16:56:56 -0400 Subject: [PATCH 588/720] Say more about why we're building a stream instead of WebSockets --- src/ch17-04-streams.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index f0b383097b..ed2c26acf5 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -129,11 +129,12 @@ we can batch up events to avoid triggering too many network calls, set timeouts on sequences of long-running operations, or throttle user interface events to avoid doing needless work. -Let’s start by building a little stream of messages, similar to what we might -see from a WebSocket or other real-time communication protocols. In Listing -17-33, we create a function `get_messages` which returns `impl Stream<Item = -String>`. For its implementation, we create an async channel, loop over the -first ten letters of the English alphabet, and send them across the channel. +Let’s start by building a little stream of messages, as a stand-in for a stream +of data we might see from a WebSocket or another real-time communication +protocol. In Listing 17-33, we create a function `get_messages` which returns +`impl Stream<Item = String>`. For its implementation, we create an async +channel, loop over the first ten letters of the English alphabet, and send them +across the channel. We also use a new type: `ReceiverStream`, which converts the `rx` receiver from the `trpl::channel` into a `Stream` with a `next` method. Back in `main`, we use From 9070b7fe951f4f940b00c629f263e3d45794c1e1 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 17:05:40 -0400 Subject: [PATCH 589/720] Add an explicit definition of poll so we can use it later --- src/ch17-01-futures-and-syntax.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 6768962fc9..7adff3b01c 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -16,7 +16,8 @@ The `async` keyword can be applied to blocks and functions to specify that they can be interrupted and resumed. Within an async block or async function, you can use the `await` keyword to wait for a future to become ready, called *awaiting a future*. Each place you await a future within an async block or function is a -place that async block or function may get paused and resumed. +place that async block or function may get paused and resumed. The process of +checking with a future to see if its value is available yet is called *polling*. Some other languages also use `async` and `await` keywords for async programming. If you are familiar with those languages, you may notice some From 7aa0f88cad34af9737c3b6d82a7118467f570ae9 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 17:14:08 -0400 Subject: [PATCH 590/720] Add a quick explanation of the semantics of merge --- src/ch17-04-streams.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index ed2c26acf5..b25ecbd0ea 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -299,9 +299,11 @@ indefinitely. With async, this does not block anything else, as long as there is at least one await point in each iteration through the loop. Back in our main function’s async block, we start by calling `get_intervals`. -Then we merge the `messages` and `intervals` streams with the `merge` method. -Finally, we loop over that combined stream instead of over `messages` (Listing -17-37). +Then we merge the `messages` and `intervals` streams with the `merge` method, +which combines multiple streams into one stream that produces items from any of +the source streams as soon as the items are available, without imposing any +particular ordering. Finally, we loop over that combined stream instead of over +`messages` (Listing 17-37). <Listing number="17-37" caption="Attempting to merge streams of messages and intervals" file-name="src/main.rs"> From ff5f4875a040daae4ce6b1d91fe88a9c8dbfbb9f Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 17:16:27 -0400 Subject: [PATCH 591/720] Remove an extra 'with' --- src/ch17-04-streams.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index b25ecbd0ea..dfb0016789 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -323,7 +323,7 @@ for a `timeout` call. Meanwhile, the `intervals` stream has the type `impl Stream<Item = u32>`. To merge these two streams, we need to transform one of them to match the other. -In Listing 17-38, we rework with the `intervals` stream, because `messages` is +In Listing 17-38, we rework the `intervals` stream, because `messages` is already in the basic format we want and has to handle timeout errors. First, we can use the `map` helper method to transform the `intervals` into a string. Second, we need to match the `Timeout` from `messages`. Because we do not From 796e5349ea07d2058c275ce5ad5ec5eba66c255b Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 17:19:04 -0400 Subject: [PATCH 592/720] Correct subj/verb agreement and remove a 'simply' --- src/ch17-04-streams.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index dfb0016789..74c83e8063 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -385,17 +385,17 @@ output, not just one stream or the other. </Listing> -Now when we run the program, it stop after pulling twenty items from the stream, -and the intervals do not overwhelm the messages. We also do not get `Interval: -100` or `Interval: 200` or so on, but instead simply get `Interval: 1`, -`Interval: 2`, and so on—even though we have a source stream which *can* produce -an event every millisecond. That is because the `throttle` call produces a new -stream, wrapping the original stream, so that the original stream only gets -polled at the throttle rate, not its own “native” rate. We do not have a bunch -of unhandled interval messages we are simply choosing to ignore. Instead, we -never produce those interval messages in the first place! This is the inherent -“laziness” of Rust’s futures at work again, allowing us to choose our -performance characteristics. +Now when we run the program, it stops after pulling twenty items from the +stream, and the intervals do not overwhelm the messages. We also do not get +`Interval: 100` or `Interval: 200` or so on, but instead get `Interval: 1`, +`Interval: 2`, and so on—even though we have a source stream which *can* +produce an event every millisecond. That is because the `throttle` call +produces a new stream, wrapping the original stream, so that the original +stream only gets polled at the throttle rate, not its own “native” rate. We do +not have a bunch of unhandled interval messages we are simply choosing to +ignore. Instead, we never produce those interval messages in the first place! +This is the inherent “laziness” of Rust’s futures at work again, allowing us to +choose our performance characteristics. <!-- manual-regeneration cd listings/listing-17-39 From 48379d38aac5b6e0aecf2eb2c6bfed07a36b16d4 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 17:21:41 -0400 Subject: [PATCH 593/720] Update code and output to match text --- .../listing-17-39/src/main.rs | 2 +- src/ch17-04-streams.md | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/listings/ch17-async-await/listing-17-39/src/main.rs b/listings/ch17-async-await/listing-17-39/src/main.rs index a5f51618f5..57ed7bed4a 100644 --- a/listings/ch17-async-await/listing-17-39/src/main.rs +++ b/listings/ch17-async-await/listing-17-39/src/main.rs @@ -9,7 +9,7 @@ fn main() { // ANCHOR: throttle let messages = get_messages().timeout(Duration::from_millis(200)); let intervals = get_intervals() - .map(|count| format!("Interval #{count}")) + .map(|count| format!("Interval: {count}")) .throttle(Duration::from_millis(100)) .timeout(Duration::from_secs(10)); let merged = messages.merge(intervals).take(20); diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 74c83e8063..1f1de6e2d3 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -404,26 +404,26 @@ copy and paste only the program output --> ```text -Interval #1 +Interval: 1 Message: 'a' -Interval #2 -Interval #3 +Interval: 2 +Interval: 3 Problem: Elapsed(()) -Interval #4 +Interval: 4 Message: 'b' -Interval #5 +Interval: 5 Message: 'c' -Interval #6 -Interval #7 +Interval: 6 +Interval: 7 Problem: Elapsed(()) -Interval #8 +Interval: 8 Message: 'd' -Interval #9 +Interval: 9 Message: 'e' -Interval #10 -Interval #11 +Interval: 10 +Interval: 11 Problem: Elapsed(()) -Interval #12 +Interval: 12 ``` There is one last thing we need to handle: errors! With both of these From 4647c8b3f15394f139538b502871d344d5a6e90a Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 20:35:00 -0400 Subject: [PATCH 594/720] Add trailing comma --- src/ch17-05-traits-for-async.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index a6eecf6f7b..b0851c3e7c 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -40,7 +40,7 @@ the `Poll` type: ```rust enum Poll<T> { Ready(T), - Pending + Pending, } ``` From afe43caa25c4d05ecbe066403caa47566f00d70b Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Tue, 1 Oct 2024 22:32:31 -0400 Subject: [PATCH 595/720] Use contractions more; a few tiny fixes The rest of the book's style, and No Starch's style, is more casual and uses contractions. --- src/ch17-00-async-await.md | 22 ++--- src/ch17-01-futures-and-syntax.md | 82 +++++++++--------- src/ch17-02-concurrency-with-async.md | 58 ++++++------- src/ch17-03-more-futures.md | 74 ++++++++-------- src/ch17-04-streams.md | 59 +++++++------ src/ch17-05-traits-for-async.md | 117 +++++++++++++------------- src/ch17-06-futures-tasks-threads.md | 60 ++++++------- 7 files changed, 236 insertions(+), 236 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 2a28792819..b754dc39cd 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -9,7 +9,7 @@ processes to complete. The video export will use as much CPU and GPU power as it can. If you only had one CPU core, and your operating system never paused that export until it -completed, you could not do anything else on your computer while it was running. +completed, you couldn’t do anything else on your computer while it was running. That would be a pretty frustrating experience, though. Instead, your computer’s operating system can—and does!—invisibly interrupt the export often enough to let you get other work done along the way. @@ -19,17 +19,17 @@ the CPU needs to wait on data to arrive from the network. While you can start reading the data once some of it is present, it might take a while for the rest to show up. Even once the data is all present, a video can be quite large, so it might take some time to load it all. Maybe it only takes a second or two—but -that is a very long time for a modern processor, which can do billions of +that’s a very long time for a modern processor, which can do billions of operations every second. It would be nice to be able to put the CPU to use for other work while waiting for the network call to finish—so, again, your operating system will invisibly interrupt your program so other things can happen while the network operation is still ongoing. > Note: The video export is the kind of operation which is often described as -> “CPU-bound” or “compute-bound”. It is limited by the speed of the computer’s +> “CPU-bound” or “compute-bound”. It’s limited by the speed of the computer’s > ability to process data within the *CPU* or *GPU*, and how much of that speed > it can use. The video download is the kind of operation which is often -> described as “IO-bound,” because it is limited by the speed of the computer’s +> described as “IO-bound,” because it’s limited by the speed of the computer’s > *input and output*. It can only go as fast as the data can be sent across the > network. @@ -40,7 +40,7 @@ programs get work done. In many cases, because we understand our programs at a much more granular level than the operating system does, we can spot lots of opportunities for concurrency that the operating system cannot see. -For example, if we are building a tool to manage file downloads, we should be +For example, if we’re building a tool to manage file downloads, we should be able to write our program in such a way that starting one download does not lock up the UI, and users should be able to start multiple downloads at the same time. Many operating system APIs for interacting with the network are @@ -70,7 +70,7 @@ between parallelism and concurrency. ### Parallelism and Concurrency -In the previous chapter we treated parallelism and concurrency as mostly +In the previous chapter, we treated parallelism and concurrency as mostly interchangeable. Now we need to distinguish between them more precisely, because the differences will show up as we start working. @@ -81,8 +81,8 @@ team member, or we could do a mix of both approaches. When an individual works on several different tasks before any of them is complete, this is *concurrency*. Maybe you have two different projects checked out on your computer, and when you get bored or stuck on one project, you switch -to the other. You are just one person, so you cannot make progress on both tasks -tasks at the exact same time—but you can multi-task, making progress on multiple +to the other. You’re just one person, so you can’t make progress on both tasks +at the exact same time—but you can multi-task, making progress on multiple tasks by switching between them. <figure> @@ -114,9 +114,9 @@ after the other. Likewise, you might realize that one of your own tasks depends on another of your tasks. Now your concurrent work has also become serial. Parallelism and concurrency can intersect with each other, too. If you learn -that a colleague is stuck until you finish one of your tasks, you will probably +that a colleague is stuck until you finish one of your tasks, you’ll probably focus all your efforts on that task to “unblock” your colleague. You and your -coworker are no longer able to work in parallel, and you are also no longer able +coworker are no longer able to work in parallel, and you’re also no longer able to work concurrently on your own tasks. The same basic dynamics come into play with software and hardware. On a machine @@ -128,7 +128,7 @@ also do work in parallel. One core can be doing one thing while another core does something completely unrelated, and those actually happen at the same time. -When working with async in Rust, we are always dealing with concurrency. +When working with async in Rust, we’re always dealing with concurrency. Depending on the hardware, the operating system, and the async runtime we are using—more on async runtimes shortly!—that concurrency may also use parallelism under the hood. diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 7adff3b01c..0f3145e85c 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -20,31 +20,31 @@ place that async block or function may get paused and resumed. The process of checking with a future to see if its value is available yet is called *polling*. Some other languages also use `async` and `await` keywords for async -programming. If you are familiar with those languages, you may notice some +programming. If you’re familiar with those languages, you may notice some significant differences in how Rust does things, including how it handles the -syntax. That is for good reason, as we will see! +syntax. That’s for good reason, as we’ll see! Most of the time when writing async Rust, we use the `async` and `await` keywords. Rust compiles them into equivalent code using the `Future` trait, much like it compiles `for` loops into equivalent code using the `Iterator` trait. Because Rust provides the `Future` trait, though, you can also implement it for -your own data types when you need to. Many of the functions we will see +your own data types when you need to. Many of the functions we’ll see throughout this chapter return types with their own implementations of `Future`. -We will return to the definition of the trait at the end of the chapter and dig +We’ll return to the definition of the trait at the end of the chapter and dig into more of how it works, but this is enough detail to keep us moving forward. That may all feel a bit abstract. Let’s write our first async program: a little -web scraper. We will pass in two URLs from the command line, fetch both of them +web scraper. We’ll pass in two URLs from the command line, fetch both of them concurrently, and return the result of whichever one finishes first. This -example will have a fair bit of new syntax, but don’t worry. We will explain +example will have a fair bit of new syntax, but don’t worry. We’ll explain everything you need to know as we go. ### Our First Async Program To keep this chapter focused on learning async, rather than juggling parts of the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust -Programming Language”). It re-exports all the types, traits, and functions you -will need, primarily from the [`futures`][futures-crate] and [`tokio`][tokio] +Programming Language”). It re-exports all the types, traits, and functions +you’ll need, primarily from the [`futures`][futures-crate] and [`tokio`][tokio] crates. - The `futures` crate is an official home for Rust experimentation for async @@ -53,12 +53,12 @@ crates. - Tokio is the most widely used async runtime in Rust today, especially (but not only!) for web applications. There are other great runtimes out there, and they may be more suitable for your purposes. We use Tokio under the hood - for `trpl` because it is good and widely used. + for `trpl` because it’s well-tested and widely used. In some cases, `trpl` also renames or wraps the original APIs to let us stay focused on the details relevant to this chapter. If you want to understand what the crate does, we encourage you to check out [its source code][crate-source]. -You will be able to see what crate each re-export comes from, and we have left +You’ll be able to see what crate each re-export comes from, and we’ve left extensive comments explaining what the crate does. Create a new binary project named `hello-async` and add the `trpl` crate as a @@ -71,11 +71,11 @@ $ cargo add trpl ``` Now we can use the various pieces provided by `trpl` to write our first async -program. We will build a little command line tool which fetches two web pages, +program. We’ll build a little command line tool which fetches two web pages, pulls the `<title>` element from each, and prints out the title of whichever finishes that whole process first. -Let's start by writing a function that takes one page URL as a parameter, makes +Let’s start by writing a function that takes one page URL as a parameter, makes a request to it, and returns the text of the title element: <Listing number="17-1" file-name="src/main.rs" caption="Defining an async function to get the title element from an HTML page"> @@ -100,34 +100,34 @@ is also async. We have to explicitly await both of these futures, because futures in Rust are *lazy*: they don’t do anything until you ask them to with `await`. (In fact, -Rust will show a compiler warning if you do not use a future.) This should +Rust will show a compiler warning if you don’t use a future.) This should remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. Iterators do nothing unless you call their `next` method—whether directly, or using `for` loops or methods like `map` which use `next` under the hood. With futures, the same basic idea applies: they do nothing unless you explicitly ask -them to. This laziness allows Rust to avoid running async code until it is +them to. This laziness allows Rust to avoid running async code until it’s actually needed. > Note: This is different from the behavior we saw when using `thread::spawn` in > the previous chapter, where the closure we passed to another thread started -> running immediately. It is also different from how many other languages -> approach async! But it is important for Rust. We will see why that is later. +> running immediately. It’s also different from how many other languages +> approach async! But it’s important for Rust. We’ll see why that is later. Once we have `response_text`, we can then parse it into an instance of the `Html` type using `Html::parse`. Instead of a raw string, we now have a data type we can use to work with the HTML as a richer data structure. In particular, we can use the `select_first` method to find the first instance of a given CSS -selector. By passing the string `"title"`, we will get the first `<title>` +selector. By passing the string `"title"`, we’ll get the first `<title>` element in the document, if there is one. Because there may not be any matching element, `select_first` returns an `Option<ElementRef>`. Finally, we use the -`Option::map` method, which lets us work with the item in the `Option` if it is -present, and do nothing if it is not. (We could also use a `match` expression +`Option::map` method, which lets us work with the item in the `Option` if it’s +present, and do nothing if it isn’t. (We could also use a `match` expression here, but `map` is more idiomatic.) In the body of the function we supply to `map`, we call `inner_html` on the `title_element` to get its content, which is a `String`. When all is said and done, we have an `Option<String>`. -Notice that Rust’s `await` keyword goes after the expression you are awaiting, -not before it. That is, it is a *postfix keyword*. This may be different from +Notice that Rust’s `await` keyword goes after the expression you’re awaiting, +not before it. That is, it’s a *postfix keyword*. This may be different from what you might be used to if you have used async in other languages. Rust chose this because it makes chains of methods much nicer to work with. As a result, we can change the body of `page_url_for` to chain the `trpl::get` and `text` @@ -142,7 +142,7 @@ function calls together with `await` between them, as shown in Listing 17-2: </Listing> With that, we have successfully written our first async function! Before we add -some code in `main` to call it, let’s talk a little more about what we have +some code in `main` to call it, let’s talk a little more about what we’ve written and what it means. When Rust sees a block marked with the `async` keyword, it compiles it into a @@ -185,17 +185,17 @@ Let’s walk through each part of the transformed version: above. That value matches the `Output` type in the return type. This is just like other blocks you have seen. * The new function body is an `async move` block because of how it uses the - `url` parameter. (We will talk about `async` vs. `async move` much more later + `url` parameter. (We’ll talk about `async` vs. `async move` much more later in the chapter.) -* The new version of the function has a kind of lifetime we have not seen before +* The new version of the function has a kind of lifetime we haven’t seen before in the output type: `'_`. Because the function returns a `Future` which refers to a reference—in this case, the reference from the `url` parameter—we need to - tell Rust that we mean for that reference to be included. We do not have to + tell Rust that we mean for that reference to be included. We don’t have to name the lifetime here, because Rust is smart enough to know there is only one reference which could be involved, but we *do* have to be explicit that the resulting `Future` is bound by that lifetime. -Now we can call `page_title` in `main`. To start, we will just get the title +Now we can call `page_title` in `main`. To start, we’ll just get the title for a single page. In Listing 17-3, we follow the same pattern we used for getting command line arguments back in Chapter 12. Then we pass the first URL `page_title`, and await the result. Because the value produced by the future is @@ -210,8 +210,8 @@ account for whether the page had a `<title>`. </Listing> -Unfortunately, this does not compile. The only place we can use the `await` -keyword is in async functions or blocks, and Rust will not let us mark the +Unfortunately, this doesn’t compile. The only place we can use the `await` +keyword is in async functions or blocks, and Rust won’t let us mark the special `main` function as `async`. <!-- manual-regeneration @@ -228,10 +228,10 @@ error[E0752]: `main` function is not allowed to be `async` | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` ``` -The reason `main` can't be marked `async` is that async code needs a *runtime*: +The reason `main` can’t be marked `async` is that async code needs a *runtime*: a Rust crate which manages the details of executing asynchronous code. A -program's `main` function can *initialize* a runtime, but it is not a runtime -*itself*. (We will see more about why this is a bit later.) Every Rust program +program’s `main` function can *initialize* a runtime, but it’s not a runtime +*itself*. (We’ll see more about why this is a bit later.) Every Rust program that executes async code has at least one place where it sets up a runtime and executes the futures. @@ -244,7 +244,7 @@ small amount of RAM, and no ability to do heap allocations. The crates which provide those runtimes also often supply async versions of common functionality like file or network I/O. -Here, and throughout the rest of this chapter, we will use the `run` function +Here, and throughout the rest of this chapter, we’ll use the `run` function from the `trpl` crate, which takes a future as an argument and runs it to completion. Behind the scenes, calling `run` sets up a runtime to use to run the future passed in. Once the future completes, `run` returns whatever value the @@ -253,8 +253,8 @@ future produced. We could pass the future returned by `page_title` directly to `run`. Once it completed, we would be able to match on the resulting `Option<String>`, the way we tried to do in Listing 17-3. However, for most of the examples in the chapter -(and most async code in the real world!), we will be doing more than just one -async function call, so instead we will pass an `async` block and explicitly +(and most async code in the real world!), we’ll be doing more than just one +async function call, so instead we’ll pass an `async` block and explicitly await the result of calling `page_title`, as in Listing 17-4. <Listing number="17-4" caption="Awaiting an async block with `trpl::run`" file-name="src/main.rs"> @@ -281,7 +281,7 @@ Each *await point*—that is, every place where the code uses the `await` keyword—represents a place where control gets handed back to the runtime. To make that work, Rust needs to keep track of the state involved in the async block, so that the runtime can kick off some other work and then come back when -it is ready to try advancing this one again. This is an invisible state machine, +it’s ready to try advancing this one again. This is an invisible state machine, as if you wrote an enum like this to save the current state at each `await` point: @@ -295,7 +295,7 @@ code later. Instead, the Rust compiler creates and manages the state machine data structures for async code automatically. If you’re wondering: yep, the normal borrowing and ownership rules around data structures all apply. Happily, the compiler also handles checking those for us, and has good error messages. -We will work through a few of those later in the chapter! +We’ll work through a few of those later in the chapter! Ultimately, something has to execute that state machine. That something is a runtime. (This is why you may sometimes come across references to *executors* @@ -331,17 +331,17 @@ and racing them. In Listing 17-5, we begin by calling `page_title` for each of the user-supplied URLs. We save the futures produced by calling `page_title` as `title_fut_1` and `title_fut_2`. Remember, these don’t do anything yet, because futures are lazy, -and we have not yet awaited them. Then we pass the futures to `trpl::race`, +and we haven’t yet awaited them. Then we pass the futures to `trpl::race`, which returns a value to indicate which of the futures passed to it finishes first. > Note: Under the hood, `race` is built on a more general function, `select`, > which you will encounter more often in real-world Rust code. A `select` -> function can do a lot of things that `trpl::race` function cannot, but it also +> function can do a lot of things that `trpl::race` function can’t, but it also > has some additional complexity that we can skip over for now. -Either future can legitimately “win,” so it does not make sense to return a -`Result`. Instead, `race` returns a type we have not seen before, +Either future can legitimately “win,” so it doesn’t make sense to return a +`Result`. Instead, `race` returns a type we haven’t seen before, `trpl::Either`. The `Either` type is somewhat like a `Result`, in that it has two cases. Unlike `Result`, though, there is no notion of success or failure baked into `Either`. Instead, it uses `Left` and `Right` to indicate “one or the @@ -368,7 +368,7 @@ what the `<title>` was for the web page at that URL, if any. You have built a small working web scraper now! Pick a couple URLs and run the command line tool. You may discover that some sites are reliably faster than others, while in other cases which site “wins” varies from run to run. More -importantly, you have learned the basics of working with futures, so we can now +importantly, you’ve learned the basics of working with futures, so we can now dig into even more of the things we can *do* with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 5e79143724..62f2a0bc82 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -1,8 +1,8 @@ ## Concurrency With Async -In this section, we will apply async to some of the same concurrency challenges +In this section, we’ll apply async to some of the same concurrency challenges we tackled with threads in chapter 16. Because we already talked about a lot of -the key ideas there, in this section we will focus on what is different between +the key ideas there, in this section we’ll focus on what’s different between threads and futures. In many cases, the APIs for working with concurrency using async are very @@ -31,7 +31,7 @@ As our starting point, we set up our `main` function with `trpl::run`, so that our top-level function can be async. > Note: From this point forward in the chapter, every example will include this -> exact same wrapping code with `trpl::run` in `main`, so we will often skip it +> exact same wrapping code with `trpl::run` in `main`, so we’ll often skip it > just like we do with `main`. Don’t forget to include it in your code! Then we write two loops within that block, each with a `trpl::sleep` call in it, @@ -102,8 +102,8 @@ So far, it looks like async and threads give us the same basic outcomes, just with different syntax: using `await` instead of calling `join` on the join handle, and awaiting the `sleep` calls. -The bigger difference is that we did not need to spawn another operating system -thread to do this. In fact, we do not even need to spawn a task here. Because +The bigger difference is that we didn’t need to spawn another operating system +thread to do this. In fact, we don’t even need to spawn a task here. Because async blocks compile to anonymous futures, we can put each loop in an async block and have the runtime run them both to completion using the `trpl::join` function. @@ -115,7 +115,7 @@ future whose output is a tuple with the output of each of the futures you passed in once *both* complete. Thus, in Listing 17-8, we use `trpl::join` to wait for both `fut1` and `fut2` to finish. We do *not* await `fut1` and `fut2`, but instead the new future produced by `trpl::join`. We ignore the output, because -it is just a tuple with two unit values in it. +it’s just a tuple with two unit values in it. <Listing number="17-8" caption="Using `trpl::join` to await two anonymous futures" file-name="src/main.rs"> @@ -147,7 +147,7 @@ hi number 8 from the first task! hi number 9 from the first task! ``` -Here, you will see the exact same order every time, which is very different from +Here, you’ll see the exact same order every time, which is very different from what we saw with threads. That is because the `trpl::join` function is *fair*, meaning it checks each future equally often, alternating between them, and never lets one race ahead if the other is ready. With threads, the operating system @@ -155,7 +155,7 @@ decides which thread to check and how long to let it run. With async Rust, the runtime decides which task to check. (In practice, the details get complicated because an async runtime might use operating system threads under the hood as part of how it manages concurrency, so guaranteeing fairness can be more work -for a runtime—but it is still possible!) Runtimes do not have to guarantee +for a runtime—but it’s still possible!) Runtimes don’t have to guarantee fairness for any given operation, and runtimes often offer different APIs to let you choose whether you want fairness or not. @@ -172,11 +172,11 @@ each case *before* running the code! ### Message Passing -Sharing data between futures will also be familiar: we will use message passing -again, but this with async versions of the types and functions. We will take a +Sharing data between futures will also be familiar: we’ll use message passing +again, but this with async versions of the types and functions. We’ll take a slightly different path than we did in Chapter 16, to illustrate some of the key differences between thread-based and futures-based concurrency. In Listing 17-9, -we will begin with just a single async block—*not* spawning a separate task like +we’ll begin with just a single async block—*not* spawning a separate task like we spawned a separate thread. <Listing number="17-9" caption="Creating an async channel and assigning the two halves to `tx` and `rx`" file-name="src/main.rs"> @@ -192,16 +192,16 @@ single-consumer channel API we used with threads back in Chapter 16. The async version of the API is only a little different from the thread-based version: it uses a mutable rather than an immutable receiver `rx`, and its `recv` method produces a future we need to await rather than producing the value directly. Now -we can send messages from the sender to the receiver. Notice that we do not have +we can send messages from the sender to the receiver. Notice that we don’t have to spawn a separate thread or even a task; we merely need to await the `rx.recv` call. The synchronous `Receiver::recv` method in `std::mpsc::channel` blocks until it receives a message. The `trpl::Receiver::recv` method does not, because it is async. Instead of blocking, it hands control back to the runtime until either -a message is received or the send side of the channel closes. By contrast, we do -not await the `send` call, because it does not block. It does not need to, -because the channel we are sending it into is unbounded. +a message is received or the send side of the channel closes. By contrast, we +don’t await the `send` call, because it doesn’t block. It doesn’t need to, +because the channel we’re sending it into is unbounded. > Note: Because all of this async code runs in an async block in a `trpl::run` > call, everything within it can avoid blocking. However, the code *outside* it @@ -211,7 +211,7 @@ because the channel we are sending it into is unbounded. > runtimes, `run` is actually named `block_on` for exactly this reason. Notice two things about this example: First, the message will arrive right away! -Second, although we use a future here, there is no concurrency yet. Everything +Second, although we use a future here, there’s no concurrency yet. Everything in the listing happens in sequence, just as it would if there were no futures involved. @@ -230,12 +230,12 @@ between them, as shown in Listing 17-10: In addition to sending the messages, we need to receive them. In this case, we could do that manually, by just doing `rx.recv().await` four times, because we -know how many messages are coming in. In the real world, though, we will +know how many messages are coming in. In the real world, though, we’ll generally be waiting on some *unknown* number of messages. In that case, we need to keep waiting until we determine that there are no more messages. In Listing 16-10, we used a `for` loop to process all the items received from a -synchronous channel. However, Rust does not yet have a way to write a `for` loop +synchronous channel. However, Rust doesn’t yet have a way to write a `for` loop over an *asynchronous* series of items. Instead, we need to use a new kind of loop we haven’t seen before, the `while let` conditional loop. A `while let` loop is the loop version of the `if let` construct we saw back in Chapter 6. The @@ -269,8 +269,8 @@ delay, rather than coming in with delays in between each one. Within a given async block, the order that `await` keywords appear in the code is also the order they happen when running the program. -There is only one async block in Listing 17-10, so everything in it runs -linearly. There is still no concurrency. All the `tx.send` calls happen, +There’s only one async block in Listing 17-10, so everything in it runs +linearly. There’s still no concurrency. All the `tx.send` calls happen, interspersed with all of the `trpl::sleep` calls and their associated await points. Only then does the `while let` loop get to go through any of the `await` points on the `recv` calls. @@ -280,7 +280,7 @@ each message, we need to put the `tx` and `rx` operations in their own async blocks. Then the runtime can execute each of them separately using `trpl::join`, just like in the counting example. Once again, we await the result of calling `trpl::join`, not the individual futures. If we awaited the individual futures -in sequence, we would just end up back in a sequential flow—exactly what we are +in sequence, we would just end up back in a sequential flow—exactly what we’re trying *not* to do. <!-- We cannot test this one because it never stops! --> @@ -303,24 +303,24 @@ interacts with `trpl::join`: passed to it have completed. * The `tx` future completes once it finishes sleeping after sending the last message in `vals`. -* The `rx` future will not complete until the `while let` loop ends. -* The `while let` loop will not end until awaiting `rx.recv` produces `None`. +* The `rx` future won’t complete until the `while let` loop ends. +* The `while let` loop won’t end until awaiting `rx.recv` produces `None`. * Awaiting `rx.recv` will only return `None` once the other end of the channel is closed. * The channel will only close if we call `rx.close` or when the sender side, `tx`, is dropped. -* We do not call `rx.close` anywhere, and `tx` will not be dropped until the +* We don’t call `rx.close` anywhere, and `tx` won’t be dropped until the outermost async block passed to `trpl::run` ends. -* The block cannot end because it is blocked on `trpl::join` completing, which +* The block can’t end because it is blocked on `trpl::join` completing, which takes us back to the top of this list! -We could manually close `rx` by calling `rx.close` somewhere, but that does not +We could manually close `rx` by calling `rx.close` somewhere, but that doesn’t make much sense. Stopping after handling some arbitrary number of messages would make the program shut down, but we could miss messages. We need some other way to make sure that `tx` gets dropped *before* the end of the function. Right now, the async block where we send the messages only borrows `tx` because -sending a message doesn't require ownership, but if we could move `tx` into +sending a message doesn’t require ownership, but if we could move `tx` into that async block, it would be dropped once that block ends. In Chapter 13, we learned how to use the `move` keyword with closures, and in Chapter 16, we saw that we often need to move data into closures when working with threads. The @@ -345,11 +345,11 @@ clone `tx`, creating `tx1` outside the first async block. We move `tx1` into that block just as we did before with `tx`. Then, later, we move the original `tx` into a *new* async block, where we send more messages on a slightly slower delay. We happen to put this new async block after the async block for receiving -messages, but it could go before it just as well. They key is the order of the +messages, but it could go before it just as well. The key is the order of the futures are awaited in, not the order they are created in. Both of the async blocks for sending messages need to be `async move` blocks, so -that both `tx` and `tx1` get dropped when those blocks finish. Otherwise we will +that both `tx` and `tx1` get dropped when those blocks finish. Otherwise we’ll end up back in the same infinite loop we started out in. Finally, we switch from `trpl::join` to `trpl::join3` to handle the additional future. diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index f18cca72c2..80c3b116f8 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -22,7 +22,7 @@ know the number of futures ahead of time. In real-world Rust, though, pushing futures into a collection and then waiting on some or all the futures in that collection to complete is a common pattern. -To check all the futures in some collection, we will need to iterate over and +To check all the futures in some collection, we’ll need to iterate over and join on *all* of them. The `trpl::join_all` function accepts any type which implements the `Iterator` trait, which we learned about back in Chapter 13, so it seems like just the ticket. Let’s try putting our futures in a vector, and @@ -36,7 +36,7 @@ replace `join!` with `join_all`. </Listing> -Unfortunately, this does not compile. Instead, we get this error: +Unfortunately, this doesn’t compile. Instead, we get this error: <!-- manual-regeneration cd listings/ch17-async-await/listing-17-16/ @@ -76,25 +76,25 @@ error[E0308]: mismatched types = help: consider pinning your async block and and casting it to a trait object ``` -This might be surprising. After all, none of them returns anything, so each +This might be surprising. After all, none of them return anything, so each block produces a `Future<Output = ()>`. However, `Future` is a trait, not a concrete type. The concrete types are the individual data structures generated -by the compiler for async blocks. You cannot put two different hand-written +by the compiler for async blocks. You can’t put two different hand-written structs in a `Vec`, and the same thing applies to the different structs generated by the compiler. To make this work, we need to use *trait objects*, just as we did in [“Returning -Errors from the run function”][dyn] in Chapter 12. (We will cover trait objects +Errors from the run function”][dyn] in Chapter 12. (We’ll cover trait objects in detail in Chapter 18.) Using trait objects lets us treat each of the anonymous futures produced by these types as the same type, because all of them implement the `Future` trait. > Note: In Chapter 8, we discussed another way to include multiple types in a > `Vec`: using an enum to represent each of the different types which can -> appear in the vector. We cannot do that here, though. For one thing, we have +> appear in the vector. We can’t do that here, though. For one thing, we have > no way to name the different types, because they are anonymous. For another, > the reason we reached for a vector and `join_all` in the first place was to be -> able to work with a dynamic collection of futures where we do not know what +> able to work with a dynamic collection of futures where we don’t know what > they will all be until runtime. We start by wrapping each of the futures in the `vec!` in a `Box::new`, as shown @@ -108,7 +108,7 @@ in Listing 17-16. </Listing> -Unfortunately, this still does not compile. In fact, we have the same basic +Unfortunately, this still doesn’t compile. In fact, we have the same basic error we did before, but we get one for both the second and third `Box::new` calls, and we also get new errors referring to the `Unpin` trait. We will come back to the `Unpin` errors in a moment. First, let’s fix the type errors on the @@ -204,7 +204,7 @@ For more information about an error, try `rustc --explain E0277`. That is a *lot* to digest, so let’s pull it apart. The first part of the message tell us that the first async block (`src/main.rs:8:23: 20:10`) does not implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve -it. Later in the chapter, we will dig into a few more details about `Pin` and +it. Later in the chapter, we’ll dig into a few more details about `Pin` and `Unpin`. For the moment, though, we can just follow the compiler’s advice to get unstuck! In Listing 17-18, we start by updating the type annotation for `futures`, with a `Pin` wrapping each `Box`. Second, we use `Box::pin` to pin @@ -237,9 +237,9 @@ received 'you' Phew! -There is a bit more we can explore here. For one thing, using `Pin<Box<T>>` +There’s a bit more we can explore here. For one thing, using `Pin<Box<T>>` comes with a small amount of extra overhead from putting these futures on the -heap with `Box`—and we are only doing that to get the types to line up. We don’t +heap with `Box`—and we’re only doing that to get the types to line up. We don’t actually *need* the heap allocation, after all: these futures are local to this particular function. As noted above, `Pin` is itself a wrapper type, so we can get the benefit of having a single type in the `Vec`—the original reason we @@ -311,16 +311,16 @@ interesting behavior happens in the body of the async blocks. Notice that if you flip the order of the arguments to `race`, the order of the “started” messages changes, even though the `fast` future always completes -first. That is because the implementation of this particular `race` function is -not fair. It always runs the futures passed as arguments in the order they are +first. That’s because the implementation of this particular `race` function is +not fair. It always runs the futures passed as arguments in the order they’re passed. Other implementations *are* fair, and will randomly choose which future -to poll first. Regardless of whether the implementation of race we are using is +to poll first. Regardless of whether the implementation of race we’re using is fair, though, *one* of the futures will run up to the first `await` in its body before another task can start. Recall from [Our First Async Program][async-program] that at each await point, Rust gives a runtime a chance to pause the task and switch to another one if the -future being awaited is not ready. The inverse is also true: Rust *only* pauses +future being awaited isn’t ready. The inverse is also true: Rust *only* pauses async blocks and hands control back to a runtime at an await point. Everything between await points is synchronous. @@ -329,7 +329,7 @@ that future will block any other futures from making progress. You may sometimes hear this referred to as one future *starving* other futures. In some cases, that may not be a big deal. However, if you are doing some kind of expensive setup or long-running work, or if you have a future which will keep doing some -particular task indefinitely, you will need to think about when and where to +particular task indefinitely, you’ll need to think about when and where to hand control back to the runtime. By the same token, if you have long-running blocking operations, async can be a @@ -387,13 +387,13 @@ copy just the output 'a' finished. ``` -As with our earlier example, `race` still finishes as soon as `a` is done. There -is no interleaving between the two futures, though. The `a` future does all of -its work until the `trpl::sleep` call is awaited, then the `b` future does all -of its work until its own `trpl::sleep` call is awaited, and then the `a` future -completes. To allow both futures to make progress between their slow tasks, we -need await points so we can hand control back to the runtime. That means we need -something we can await! +As with our earlier example, `race` still finishes as soon as `a` is done. +There’s no interleaving between the two futures, though. The `a` future does all +of its work until the `trpl::sleep` call is awaited, then the `b` future does +all of its work until its own `trpl::sleep` call is awaited, and then the `a` +future completes. To allow both futures to make progress between their slow +tasks, we need await points so we can hand control back to the runtime. That +means we need something we can await! We can already see this kind of handoff happening in Listing 17-23: if we removed the `trpl::sleep` at the end of the `a` future, it would complete @@ -435,7 +435,7 @@ swap back and forth each time one of them hits an await point. In this case, we have done that after every call to `slow`, but we could break up the work however makes the most sense to us. -We do not really want to *sleep* here, though: we want to make progress as fast +We don’t really want to *sleep* here, though: we want to make progress as fast as we can. We just need to hand back control to the runtime. We can do that directly, using the `yield_now` function. In Listing 17-25, we replace all those `sleep` calls with `yield_now`. @@ -456,9 +456,9 @@ example, will always sleep for at least a millisecond, even if we pass it a lot in one millisecond! You can see this for yourself by setting up a little benchmark, like the one in -Listing 17-26. (This is not an especially rigorous way to do performance +Listing 17-26. (This isn’t an especially rigorous way to do performance testing, but it suffices to show the difference here.) Here, we skip all the -status printing, pass a one-nanosecond `Duration` to `trpl::sleep`, and let +status printing, pass a one-nanosecond `Duration` to `trpl::sleep`, and let each future run by itself, with no switching between the futures. Then we run for 1,000 iterations and see how long the future using `trpl::sleep` takes compared to the future using `trpl::yield_now`. @@ -481,20 +481,22 @@ determine when it hands over control via await points. Each future therefore also has the responsibility to avoid blocking for too long. In some Rust-based embedded operating systems, this is the *only* kind of multitasking! -In real-world code, you will not usually be alternating function calls with +In real-world code, you won’t usually be alternating function calls with await points on every single line, of course. While yielding control like this -is relatively inexpensive, it is not free! In many cases, trying to break up a -compute-bound task might make it significantly slower, so sometimes it is better +is relatively inexpensive, it’s not free! In many cases, trying to break up a +compute-bound task might make it significantly slower, so sometimes it’s better for *overall* performance to let an operation block briefly. You should always measure to see what your code’s actual performance bottlenecks are. The -underlying dynamic is an important one to keep in mind if you *are* seeing a lot of work happening in serial that you expected to happen concurrently, though! +underlying dynamic is an important one to keep in mind if you *are* seeing a +lot of work happening in serial that you expected to happen concurrently, +though! ### Building Our Own Async Abstractions We can also compose futures together to create new patterns. For example, we can -build a `timeout` function with async building blocks we already have. When we -are done, the result will be another building block we could use to build up yet -further async abstractions. +build a `timeout` function with async building blocks we already have. When +we’re done, the result will be another building block we could use to build up +yet further async abstractions. Listing 17-27 shows how we would expect this `timeout` to work with a slow future. @@ -570,11 +572,11 @@ calls—one of the examples from the beginning of the chapter! In practice, you will usually work directly with `async` and `await`, and secondarily with functions and macros like `join`, `join_all`, `race`, and so -on. You will only need to reach for `pin` now and again to use them with those +on. You’ll only need to reach for `pin` now and again to use them with those APIs. -We have now seen a number of ways to work with multiple futures at the same -time. Up next, we will look at how we can work with multiple futures in a +We’ve now seen a number of ways to work with multiple futures at the same +time. Up next, we’ll look at how we can work with multiple futures in a sequence over time, with *streams*. Here are a couple more things you might want to consider first, though: diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 1f1de6e2d3..1f0ca66342 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -6,7 +6,7 @@ async channel in the [“Message Passing”][17-02-messages] earlier in the chap The async `recv` method produces a sequence of items over time. This is an instance of a much more general pattern, often called a *stream*. -A sequence of items is something we have seen before, when we looked at the +A sequence of items is something we’ve seen before, when we looked at the `Iterator` trait in Chapter 13, but there are two differences between iterators and the async channel receiver. The first difference is the element of time: iterators are synchronous, while the channel receiver is asynchronous. The @@ -15,7 +15,7 @@ its synchronous `next` method. With the `trpl::Receiver` stream in particular, we called an asynchronous `recv` method instead, but these APIs otherwise feel very similar. -That similarity is not a coincidence. A stream is like an asynchronous form of +That similarity isn’t a coincidence. A stream is like an asynchronous form of iteration. Whereas the `trpl::Receiver` specifically waits to receive messages, though, the general-purpose stream API is much more general: it provides the next item like `Iterator` does, but asynchronously. The similarity between @@ -36,7 +36,7 @@ We start with an array of numbers, which we convert to an iterator and then call using the `trpl::stream_from_iter` function. Then we loop over the items in the stream as they arrive with the `while let` loop. -Unfortunately, when we try to run the code, it does not compile. Instead, as we +Unfortunately, when we try to run the code, it doesn’t compile. Instead, as we can see in the output, it reports that there is no `next` method available. <!-- TODO: fix up the path here? --> @@ -86,7 +86,7 @@ the Rust ecosystem, the `Stream` trait defines a low-level interface which effectively combines the `Iterator` and `Future` traits. The `StreamExt` trait supplies a higher-level set of APIs on top of `Stream`, including the `next` method as well as other utility methods similar to those provided by the -`Iterator` trait. We will return to the `Stream` and `StreamExt` traits in a +`Iterator` trait. We’ll return to the `Stream` and `StreamExt` traits in a bit more detail at the end of the chapter. For now, this is enough to let us keep moving. @@ -101,7 +101,7 @@ as in Listing 17-31. </Listing> -With all those pieces put together, this code works the way we want! What's +With all those pieces put together, this code works the way we want! What’s more, now that we have `StreamExt` in scope, we can use all of its utility methods, just like with iterators. For example, in Listing 17-32, we use the `filter` method to filter out everything but multiples of three and five. @@ -114,7 +114,7 @@ methods, just like with iterators. For example, in Listing 17-32, we use the </Listing> -Of course, this is not very interesting. We could do that with normal iterators +Of course, this isn’t very interesting. We could do that with normal iterators and without any async at all. So let’s look at some of the other things we can do which are unique to streams. @@ -207,8 +207,8 @@ for 200 milliseconds, this should affect half of the messages. </Listing> To sleep between messages in the `get_messages` function without blocking, we -need to use async. However, we cannot make `get_messages` itself into an async -function, because then we would return a `Future<Output = Stream<Item = +need to use async. However, we can’t make `get_messages` itself into an async +function, because then we’d return a `Future<Output = Stream<Item = String>>` instead of just a `Stream<Item = String>>`. The caller would have to await `get_messages` itself to get access to the stream. But remember: everything in a given future happens linearly; concurrency happens *between* @@ -256,9 +256,9 @@ Problem: Elapsed(()) Message: 'j' ``` -The timeout does not prevent the messages from arriving in the end—we still get +The timeout doesn’t prevent the messages from arriving in the end—we still get all of the original messages. This is because our channel is unbounded: it can -hold as many messages as we can fit in memory. If the message does not arrive +hold as many messages as we can fit in memory. If the message doesn’t arrive before the timeout, our stream handler will account for that, but when it polls the stream again, the message may now have arrived. @@ -272,14 +272,14 @@ this stream of messages. First, let’s create another stream, which will emit an item every millisecond if we let it run directly. For simplicity, we can use the `sleep` function to send a message on a delay, and combine it with the same approach of creating a stream -from a channel we used in `get_messages`. The difference is that this time, we -are going to send back the count of intervals which has elapsed, so the return +from a channel we used in `get_messages`. The difference is that this time, +we’re going to send back the count of intervals which has elapsed, so the return type will be `impl Stream<Item = u32>`, and we can call the function `get_intervals`. In Listing 17-36, we start by defining a `count` in the task. (We could define it outside the task, too, but it is clearer to limit the scope of any given -variable.) Then we create a an infinite loop. Each iteration of the loop +variable.) Then we create an infinite loop. Each iteration of the loop asynchronously sleeps for one millisecond, increments the count, and then sends it over the channel. Because this is all wrapped in the task created by `spawn_task`, all of it will get cleaned up along with the runtime, including @@ -295,7 +295,7 @@ the infinite loop. This kind of infinite loop, which only ends when the whole runtime gets torn down, is fairly common in async Rust: many programs need to keep running -indefinitely. With async, this does not block anything else, as long as there is +indefinitely. With async, this doesn’t block anything else, as long as there is at least one await point in each iteration through the loop. Back in our main function’s async block, we start by calling `get_intervals`. @@ -316,7 +316,7 @@ particular ordering. Finally, we loop over that combined stream instead of over At this point, neither `messages` nor `intervals` needs to be pinned or mutable, because both will be combined into the single `merged` stream. However, this call to `merge` does not compile! (Neither does the `next` call in the `while -let` loop, but we will come back to that after fixing this.) The two streams +let` loop, but we’ll come back to that after fixing this.) The two streams have different types. The `messages` stream has the type `Timeout<impl Stream<Item = String>>`, where `Timeout` is the type which implements `Stream` for a `timeout` call. Meanwhile, the `intervals` stream has the type `impl @@ -326,12 +326,12 @@ them to match the other. In Listing 17-38, we rework the `intervals` stream, because `messages` is already in the basic format we want and has to handle timeout errors. First, we can use the `map` helper method to transform the `intervals` into a string. -Second, we need to match the `Timeout` from `messages`. Because we do not +Second, we need to match the `Timeout` from `messages`. Because we don’t actually *want* a timeout for `intervals`, though, we can just create a timeout which is longer than the other durations we are using. Here, we create a 10-second timeout with `Duration::from_secs(10)`. Finally, we need to make `stream` mutable, so that the `while let` loop’s `next` calls can iterate -through the stream, and pin it so that it is safe to do so. +through the stream, and pin it so that it’s safe to do so. <!-- We cannot directly test this one, because it never stops. --> @@ -343,10 +343,9 @@ through the stream, and pin it so that it is safe to do so. </Listing> - That gets us *almost* to where we need to be. Everything type checks. If you run -this, though, there will be two problems. First, it will never stop! You will -need to stop it with <span class="keystroke">ctrl-c</span>. Second, the +this, though, there will be two problems. First, it will never stop! You’ll +need to stop it with <span class="keystroke">ctrl-c</span>. Second, the messages from the English alphabet will be buried in the midst of all the interval counter messages: @@ -367,7 +366,7 @@ Interval: 43 ``` Listing 17-39 shows one way to solve these last two problems. First, we use the -`throttle` method on the `intervals` stream, so that it does not overwhelm the +`throttle` method on the `intervals` stream, so that it doesn’t overwhelm the `messages` stream. Throttling is a way of limiting the rate at which a function will be called—or, in this case, how often the stream will be polled. Once every hundred milliseconds should do, because that is in the same ballpark as how @@ -386,13 +385,13 @@ output, not just one stream or the other. </Listing> Now when we run the program, it stops after pulling twenty items from the -stream, and the intervals do not overwhelm the messages. We also do not get +stream, and the intervals don’t overwhelm the messages. We also don’t get `Interval: 100` or `Interval: 200` or so on, but instead get `Interval: 1`, `Interval: 2`, and so on—even though we have a source stream which *can* -produce an event every millisecond. That is because the `throttle` call +produce an event every millisecond. That’s because the `throttle` call produces a new stream, wrapping the original stream, so that the original -stream only gets polled at the throttle rate, not its own “native” rate. We do -not have a bunch of unhandled interval messages we are simply choosing to +stream only gets polled at the throttle rate, not its own “native” rate. We +don’t have a bunch of unhandled interval messages we’re choosing to ignore. Instead, we never produce those interval messages in the first place! This is the inherent “laziness” of Rust’s futures at work again, allowing us to choose our performance characteristics. @@ -426,12 +425,12 @@ Problem: Elapsed(()) Interval: 12 ``` -There is one last thing we need to handle: errors! With both of these +There’s one last thing we need to handle: errors! With both of these channel-based streams, the `send` calls could fail when the other side of the -channel closes—and that is just a matter of how the runtime executes the futures -which make up the stream. Up till now we have ignored this by calling `unwrap`, +channel closes—and that’s just a matter of how the runtime executes the futures +which make up the stream. Up until now we have ignored this by calling `unwrap`, but in a well-behaved app, we should explicitly handle the error, at minimum by -ending the loop so we do not try to send any more messages! Listing 17-40 shows +ending the loop so we don’t try to send any more messages! Listing 17-40 shows a simple error strategy: print the issue and then `break` from the loops. As usual, the correct way to handle a message send error will vary—just make sure you have a strategy. @@ -444,7 +443,7 @@ you have a strategy. </Listing> -Now that we have seen a bunch of async in practice, let’s take a step back and +Now that we’ve seen a bunch of async in practice, let’s take a step back and dig into a few of the details of how `Future`, `Stream`, and the other key traits which Rust uses to make async work. diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index b0851c3e7c..e7cc3b16f2 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -1,14 +1,13 @@ ## Digging Into the Traits for Async -Throughout the chapter, we have used the `Future`, `Pin`, `Unpin`, `Stream`, and -`StreamExt` traits in various ways. So far, though, we have avoided digging too +Throughout the chapter, we’ve used the `Future`, `Pin`, `Unpin`, `Stream`, and +`StreamExt` traits in various ways. So far, though, we’ve avoided digging too far into the details of how they work or how they fit together. Much of the time -when writing Rust day to day, this is fine. Sometimes, though, you will hit +when writing Rust day to day, this is fine. Sometimes, though, you’ll hit situations where understanding a few more of these details matters. In this -section, we will dig down *enough* further to help with those situations—while +section, we’ll dig down *enough* further to help with those situations—while still leaving the *really* deep dive for other documentation! - ### Future Back in [Futures and the Async Syntax][futures-syntax], we noted that `Future` @@ -26,14 +25,14 @@ pub trait Future { } ``` -That trait definition includes a bunch of new types and also some syntax we have -not seen before, so let’s walk through the definition piece by piece. +That trait definition includes a bunch of new types and also some syntax we +haven’t seen before, so let’s walk through the definition piece by piece. First, `Future`’s associated type `Output` says what the future resolves to. This is analogous to the `Item` associated type for the `Iterator` trait. Second, `Future` also has the `poll` method, which takes a special `Pin` reference for its `self` parameter and a mutable reference to a `Context` type, -and returns a `Poll<Self::Output>`. We will talk a little more about `Pin` and +and returns a `Poll<Self::Output>`. We’ll talk a little more about `Pin` and `Context` later in the section. For now, let’s focus on what the method returns, the `Poll` type: @@ -101,10 +100,10 @@ one of the main jobs for a runtime. Recall our description (in the [Counting][counting] section) of waiting on `rx.recv`. The `recv` call returns a `Future`, and awaiting it polls it. In our -initial discussion, we noted that a runtime will pause the future until it is +initial discussion, we noted that a runtime will pause the future until it’s ready with either `Some(message)` or `None` when the channel closes. With our deeper understanding of `Future` in place, and specifically `Future::poll`, we -can see how that works. The runtime knows the future is not ready when it +can see how that works. The runtime knows the future isn’t ready when it returns `Poll::Pending`. Conversely, the runtime knows the future is ready and advances it when `poll` returns `Poll::Ready(Some(message))` or `Poll::Ready(None)`. @@ -151,9 +150,9 @@ For more information about an error, try `rustc --explain E0277`. ``` When we read this error message carefully, it not only tells us that we need to -pin the values but also us why pinning is required. The `trpl::join_all` -function returns a struct called `JoinAll`. That struct in turn is generic over -a type `F`, which is constrained to implement the `Future` trait. Finally, +pin the values, but also tells us why pinning is required. The `trpl::join_all` +function returns a struct called `JoinAll`. That struct, in turn, is generic +over a type `F`, which is constrained to implement the `Future` trait. Finally, directly awaiting a Future requires that the future in question implement the `Unpin` trait. That’s a lot! But we can understand it, if we dive a little further into how the `Future` type actually works, in particular around @@ -177,29 +176,29 @@ The `cx` parameter and its `Context` type is interesting, but is beyond the scope of this chapter: you generally only need to worry about it when writing a custom `Future` implementation. -Instead, we will focus on the type for `self`. This is the first time we have +Instead, we’ll focus on the type for `self`. This is the first time we’ve seen a method where `self` has a type annotation. A type annotation for `self` is similar to type annotations for other function parameters, with two key -differences. First, when we specify the type of `self` like this, we are telling +differences. First, when we specify the type of `self` like this, we’re telling Rust what type `self` must be to call this method. Second, a type annotation on -`self` cannot be just any type. It is only allowed to be the type on which the -method is implemented, or a reference or smart pointer to that type, or a `Pin` -wrapping a reference to that type. We will see more on this syntax in Chapter -18. For now, it is enough to know that if we want to poll a future (to check +`self` can’t be just any type. It’s only allowed to be the type on which the +method is implemented, a reference or smart pointer to that type, or a `Pin` +wrapping a reference to that type. We’ll see more on this syntax in Chapter +18. For now, it’s enough to know that if we want to poll a future (to check whether it is `Pending` or `Ready(Output)`), we need a mutable reference to the type, which is wrapped in a `Pin`. -`Pin` is a wrapper type. In some ways, it is like the `Box`, `Rc`, and other -smart pointer types we saw in Chapter 15, which also wrap other types. Unlike -those, however, `Pin` only works with *pointer types* like references (`&` and -`&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` works -with types which implement the `Deref` or `DerefMut` traits, which we covered in -Chapter 15. You can think of this restriction as equivalent to only working with -pointers, though, because implementing `Deref` or `DerefMut` means your type -behaves like a pointer type. `Pin` is also not a pointer itself, and it does not -have any behavior of its own like the ref counting of `Rc` or `Arc`. It is -purely a tool the compiler can use to uphold the relevant guarantees, by -wrapping pointers in the type. +`Pin` is a wrapper type. In some ways, it’s similar to the `Box`, `Rc`, and +other smart pointer types we saw in Chapter 15, which also wrap other types. +Unlike those, however, `Pin` only works with *pointer types* such as references +(`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, +`Pin` works with types which implement the `Deref` or `DerefMut` traits, which +we covered in Chapter 15. You can think of this restriction as equivalent to +only working with pointers, though, because implementing `Deref` or `DerefMut` +means your type behaves like a pointer type. `Pin` is also not a pointer itself, +and it doesn’t have any behavior of its own like the ref counting of `Rc` or +`Arc`. It’s purely a tool the compiler can use to uphold the relevant +guarantees, by wrapping pointers in the type. Recalling that `await` is implemented in terms of calls to `poll`, this starts to explain the error message we saw above—but that was in terms of `Unpin`, not @@ -258,8 +257,8 @@ In principle, the Rust compiler could try to update every reference to an object every time it gets moved. That would potentially be a lot of performance overhead, especially given there can be a whole web of references that need updating. On the other hand, if we could make sure the data structure in -question *does not move in memory*, we do not have to update any references. -This is exactly what Rust’s borrow checker requires: you cannot move an item +question *doesn’t move in memory*, we don’t have to update any references. +This is exactly what Rust’s borrow checker requires: you can’t move an item which has any active references to it using safe code. `Pin` builds on that to give us the exact guarantee we need. When we *pin* a @@ -278,8 +277,8 @@ the `Box` pointer. Figure 17-5 illustrates this: In fact, the `Box` pointer can still move around freely. Remember: we care about making sure the data ultimately being referenced stays in its place. If a pointer moves around, but the data it points to is in the same place, as in -Figure 17-6, there is no potential problem. (How you would do this with a `Pin` -wrapping a `Box` is more than we will get into in this particular discussion, +Figure 17-6, there’s no potential problem. (How you would do this with a `Pin` +wrapping a `Box` is more than we’ll get into in this particular discussion, but it would make for a good exercise! If you look at the docs for the types as well as the `std::pin` module, you might be able to work out how you would do that.) The key is that the self-referential type itself cannot move, because it @@ -296,18 +295,18 @@ is still pinned. However, most types are perfectly safe to move around, even if they happen to be behind a `Pin` pointer. We only need to think about pinning when items have internal references. Primitive values like numbers and booleans do not have any -internal structure like that, so they are obviously safe. Neither do most types -you normally work with in Rust. A `Vec`, for example, does not have any internal +internal structure like that, so they’re obviously safe. Neither do most types +you normally work with in Rust. A `Vec`, for example, doesn’t have any internal references it needs to keep up to date this way, so you can move it around -without worrying. If you have a `Pin<Vec<String>>`, you would have to do +without worrying. If you have a `Pin<Vec<String>>`, you’d have to do everything via the safe but restrictive APIs provided by `Pin`, even though a `Vec<String>` is always safe to move if there are no other references to it. We -need a way to tell the compiler that it is actually just fine to move items +need a way to tell the compiler that it’s actually just fine to move items around in cases like these. For that, we have `Unpin`. `Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. Recall that marker traits have no functionality of their own. They exist only to -tell the compiler that it is safe to use the type which implements a given trait +tell the compiler that it’s safe to use the type which implements a given trait in a particular context. `Unpin` informs the compiler that a given type does *not* need to uphold any particular guarantees about whether the value in question can be moved. @@ -331,7 +330,7 @@ characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure </figure> This means that we can do things like replace one string with another at the -exact same location in memory as in Figure 17-8. This does not violate the `Pin` +exact same location in memory as in Figure 17-8. This doesn’t violate the `Pin` contract because `String`—like most other types in Rust—implements `Unpin`, because it has no internal references that make it unsafe to move around! @@ -345,31 +344,30 @@ because it has no internal references that make it unsafe to move around! Now we know enough to understand the errors reported for that `join_all` call from back in Listing 17-17. We originally tried to move the futures produced by -an async blocks into a `Vec<Box<dyn Future<Output = ()>>>`, but as we have seen, -those futures may have internal references, so they do not implement `Unpin`. +async blocks into a `Vec<Box<dyn Future<Output = ()>>>`, but as we’ve seen, +those futures may have internal references, so they don’t implement `Unpin`. They need to be pinned, and then we can pass the `Pin` type into the `Vec`, confident that the underlying data in the futures will *not* be moved. `Pin` and `Unpin` are mostly important for building lower-level libraries, or -when you are building a runtime itself, rather than for day to day Rust code. -When you see them, though, now you will know what to do! +when you’re building a runtime itself, rather than for day to day Rust code. +When you see them, though, now you’ll know what to do! > Note: This combination of `Pin` and `Unpin` allows a whole class of complex > types to be safe in Rust which are otherwise difficult to implement because -> they are self-referential. Types which require `Pin` show up *most* commonly +> they’re self-referential. Types which require `Pin` show up *most* commonly > in async Rust today, but you might—very rarely!—see it in other contexts, too. > -> The specifics of how `Pin` and `Unpin` work, and the rules they are required +> The specifics of how `Pin` and `Unpin` work, and the rules they’re required > to uphold, are covered extensively in the API documentation for `std::pin`, so -> if you would like to understand them more deeply, that is a great place to -> start. +> if you’d like to understand them more deeply, that’s a great place to start. > > If you want to understand how things work “under the hood” in even more > detail, the official [_Asynchronous Programming in Rust_][async-book] book has > you covered: > > - [Chapter 2: Under the Hood: Executing Futures and Tasks][under-the-hood] -> - [Chapter 4: Pinning][pinning]. +> - [Chapter 4: Pinning][pinning] ### The Stream Trait @@ -404,21 +402,21 @@ trait Stream { The `Stream` trait defines an associated type `Item` for the type of the items produced by the stream. This is like `Iterator`: there may be zero to many of -these, and unlike `Future`, where there is always a single `Output` (even if it -the unit type `()`). +these, and unlike `Future`, where there is always a single `Output` (even if +it’s the unit type `()`). `Stream` also defines a method to get those items. We call it `poll_next`, to make it clear that it polls like `Future::poll` and produces a sequence of items -like `Iterator::next`. Its return type combines `Poll`with `Option`. The outer +like `Iterator::next`. Its return type combines `Poll` with `Option`. The outer type is `Poll`, because it has to be checked for readiness, just like a future. The inner type is `Option`, because it needs to signal whether there are more messages, just like an iterator. Something very similar to this will likely end up standardized as part of Rust’s -standard library. In the meantime, it is part of the toolkit of most runtimes, +standard library. In the meantime, it’s part of the toolkit of most runtimes, so you can rely on it, and everything we cover below should generally apply! -In the example we saw in the section on streaming, though, we did not use +In the example we saw in the section on streaming, though, we didn’t use `poll_next` *or* `Stream`, but instead used `next` and `StreamExt`. We *could* work directly in terms of the `poll_next` API by hand-writing our own `Stream` state machines, of course, just as we *could* work with futures directly via @@ -442,14 +440,15 @@ in traits, since the lack thereof is the reason they do not yet have this. > fn next(&mut self) -> Next<'_, Self> where Self: Unpin; > ``` > -> That `Next` type is just a simple `struct` which implements `Future` and gives -> a way to name the lifetime of the reference to `self` with `Next<'_, Self>`, -> so that `await` can work with this! +> That `Next` type is a `struct` which implements `Future` and gives a way to +> name the lifetime of the reference to `self` with `Next<'_, Self>`, so that +> `await` can work with this method! The `StreamExt` trait is also the home of all the interesting methods available to use with streams. `StreamExt` is automatically implemented for every type -which implements `Stream`, but they are separated out so that the community can -iterate on the foundational trait distinctly from the convenience APIs. +which implements `Stream`, but these traits are defined separately so that the +community can iterate on the foundational trait distinctly from the convenience +APIs. In the version of `StreamExt` used in the `trpl` crate, the trait not only defines the `next` method, it also supplies an implementation of `next`, which diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 1d4876d2c0..7b0e7af9ab 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -1,10 +1,10 @@ ## Futures, Tasks, and Threads As we saw in the previous chapter, threads provide one approach to concurrency. -We have seen another approach to concurrency in this chapter, using async with +We’ve seen another approach to concurrency in this chapter, using async with futures and streams. You might be wondering why you would choose one or the -other. The answer is: it depends! And in many cases, it is not threads *or* -async but rather threads *and* async. +other. The answer is: it depends! And in many cases, the choice isn’t threads +*or* async but rather threads *and* async. Many operating systems have supplied threading-based concurrency models for decades now, and many programming languages have support for them as a result. @@ -12,15 +12,15 @@ However, they are not without their tradeoffs. On many operating systems, they use a fair bit of memory for each thread, and they come with some overhead for starting up and shutting down. Threads are also only an option when your operating system and hardware support them! Unlike mainstream desktop and mobile -computers, some embedded systems do not have an OS at all, so they also do not +computers, some embedded systems don’t have an OS at all, so they also don’t have threads! The async model provides a different—and ultimately complementary—set of -tradeoffs. In the async model, concurrent operations do not require their own +tradeoffs. In the async model, concurrent operations don’t require their own threads. Instead, they can run on tasks, as when we used `trpl::spawn_task` to -kick off work from a synchronous function throughout the streams section. A task -is a lot like a thread—but instead of being managed by the operating system, it -is managed by library-level code: the runtime. +kick off work from a synchronous function throughout the streams section. A +*task* is a lot like a thread—but instead of being managed by the operating +system, it’s managed by library-level code: the runtime. In the previous section, we saw that we could build a `Stream` by using an async channel and spawning an async task which we could call from synchronous code. We @@ -38,17 +38,17 @@ the `thread::spawn` and `thread::sleep` APIs from the standard library in the </Listing> If you run this, the output is identical. And notice how little changes here -from the perspective of the calling code! What is more, even though one of our +from the perspective of the calling code! What’s more, even though one of our functions spawned an async task on the runtime and the other spawned an OS thread, the resulting streams were unaffected by the differences. -However, there is a significant difference between these two approaches behave, -although we might have a hard time measuring it in this very simple example. We -could spawn hundreds of thousands or even millions of async tasks on any modern -personal computer. If we tried to do that with threads, we would literally run -out of memory! +However, there’s a significant difference between how these two approaches +behave, although we might have a hard time measuring it in this very simple +example. We could spawn hundreds of thousands or even millions of async tasks +on any modern personal computer. If we tried to do that with threads, we would +literally run out of memory! -However, there is a reason these APIs are so similar. Threads act as a boundary +However, there’s a reason these APIs are so similar. Threads act as a boundary for sets of synchronous operations; concurrency is possible *between* threads. Tasks act as a boundary for sets of *asynchronous* operations; concurrency is possible both *between* and *within* tasks. In that regard, tasks are kind of @@ -58,7 +58,7 @@ even more granular unit of concurrency, where each future may represent a tree of other futures. That is, the runtime—specifically, its executor—manages tasks, and tasks manage futures. -However, this does not mean that async tasks are always better than threads, any +However, this doesn’t mean that async tasks are always better than threads, any more than that threads are always better than tasks. On the one hand, concurrency with threads is in some ways a simpler programming @@ -66,11 +66,11 @@ model than concurrency with `async`. Threads are somewhat “fire and forget,” they have no native equivalent to a future, so they simply run to completion, without interruption except by the operating system itself. That is, they have no *intra-task concurrency* like futures can. Threads in Rust also have no -mechanisms for cancellation—a subject we have not covered in depth in this +mechanisms for cancellation—a subject we haven’t covered in depth in this chapter, but which is implicit in the fact that whenever we ended a future, its state got cleaned up correctly. -These limitations make threads harder to compose than futures. It is much more +These limitations make threads harder to compose than futures. It’s much more difficult, for example, to build something like the `timeout` we built in [“Building Our Own Async Abstractions”][combining-futures], or the `throttle` method we used with streams in [“Composing Streams”][streams]. The fact that @@ -78,15 +78,15 @@ futures are richer data structures means they *can* be composed together more naturally, as we have seen. Tasks then give *additional* control over futures, allowing you to choose where -and how to group them. And it turns out that threads and tasks often work very -well together, because tasks can (at least in some runtimes) be moved around -between threads. We have not mentioned it up until now, but under the hood the -`Runtime` we have been using, including the `spawn_blocking` and `spawn_task` -functions, is multithreaded by default! Many runtimes use an approach called -*work stealing* to transparently move tasks around between threads based on the -current utilization of the threads, with the aim of improving the overall -performance of the system. To build that actually requires threads *and* tasks, -and therefore futures. +and how to group the futures. And it turns out that threads and tasks often +work very well together, because tasks can (at least in some runtimes) be moved +around between threads. We haven’t mentioned it up until now, but under the +hood the `Runtime` we have been using, including the `spawn_blocking` and +`spawn_task` functions, is multithreaded by default! Many runtimes use an +approach called *work stealing* to transparently move tasks around between +threads based on the current utilization of the threads, with the aim of +improving the overall performance of the system. To build, that actually +requires threads *and* tasks, and therefore futures. As a default way of thinking about which to use when: @@ -96,15 +96,15 @@ As a default way of thinking about which to use when: different sources which may come in a different intervals or different rates, async is a better choice. -And if you need some mix of parallelism and concurrency, you do not have to +And if you need some mix of parallelism and concurrency, you don’t have to choose between threads and async. You can use them together freely, letting each -one serve the part it is best at. For example, Listing 17-TODO shows a fairly +one serve the part it is best at. For example, Listing 17-42 shows a fairly common example of this kind of mix in real-world Rust code. <Listing number="17-42" caption="Sending messages with blocking code in a thread and awaiting the messages in an async block" file-name="src/main.rs"> ```rust -{{#rustdoc_include ../listings/ch17-async-await/listing-17-42/src/main.rs}} +{{#rustdoc_include ../listings/ch17-async-await/listing-17-42/src/main.rs:all}} ``` </Listing> From 84eab3232cc69c4ce3508f472ac7b3c24314fbc0 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Wed, 2 Oct 2024 20:52:59 -0400 Subject: [PATCH 596/720] Be more specific about 'them' --- src/ch17-05-traits-for-async.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index e7cc3b16f2..f054de233e 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -351,7 +351,8 @@ confident that the underlying data in the futures will *not* be moved. `Pin` and `Unpin` are mostly important for building lower-level libraries, or when you’re building a runtime itself, rather than for day to day Rust code. -When you see them, though, now you’ll know what to do! +When you see these traits in error messages, though, now you’ll have a better +idea of how to fix the code! > Note: This combination of `Pin` and `Unpin` allows a whole class of complex > types to be safe in Rust which are otherwise difficult to implement because From 13e7c88811c27eaa26c90d9b23542bb5b00dbe09 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Wed, 2 Oct 2024 20:54:39 -0400 Subject: [PATCH 597/720] Clarify where the commonly used Stream definition comes from --- src/ch17-05-traits-for-async.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index f054de233e..5724103776 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -377,7 +377,8 @@ can turn our attention to the `Stream` trait. As described in the section introducing streams, streams are like asynchronous iterators. Unlike `Iterator` and `Future`, there is no definition of a `Stream` trait in the standard library as of the time of writing,<!-- TODO: verify before press time! --> but there -*is* a very common definition used throughout the ecosystem. +*is* a very common definition from the `futures` crate used throughout the +ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, so we can build up to how a `Stream` trait that merges them together might look. From From 95728278331b2e10136bcb1f830af538f66c644c Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Wed, 2 Oct 2024 21:57:52 -0400 Subject: [PATCH 598/720] Minimize the word 'like' when other words would fit --- src/ch17-00-async-await.md | 4 +- src/ch17-01-futures-and-syntax.md | 34 +++++----- src/ch17-02-concurrency-with-async.md | 10 +-- src/ch17-03-more-futures.md | 26 ++++---- src/ch17-04-streams.md | 20 +++--- src/ch17-05-traits-for-async.md | 89 ++++++++++++++------------- src/ch17-06-futures-tasks-threads.md | 18 +++--- 7 files changed, 101 insertions(+), 100 deletions(-) diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index b754dc39cd..920486d333 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -57,7 +57,7 @@ We could avoid blocking our main thread by spawning a dedicated thread to download each file. However, we would eventually find that the overhead of those threads was a problem. It would also be nicer if the call were not blocking in the first place. Last but not least, it would be better if we could write in the -same direct style we use in blocking code. Something like this: +same direct style we use in blocking code. Something similar to this: ```rust,ignore,does_not_compile let data = fetch_data_from(url).await; @@ -121,7 +121,7 @@ to work concurrently on your own tasks. The same basic dynamics come into play with software and hardware. On a machine with a single CPU core, the CPU can only do one operation at a time, but it can -still work concurrently. Using tools like threads, processes, and async, the +still work concurrently. Using tools such as threads, processes, and async, the computer can pause one activity and switch to others before eventually cycling back to that first activity again. On a machine with multiple CPU cores, it can also do work in parallel. One core can be doing one thing while another core diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 0f3145e85c..2799ff3276 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -5,12 +5,12 @@ The key elements of asynchronous programming in Rust are *futures* and Rust’s A *future* is a value which may not be ready now, but will become ready at some point in the future. (This same concept shows up in many languages, sometimes -under other names like “task” or “promise”.) Rust provides a `Future` trait as a -building block so different async operations can be implemented with different -data structures, but with a common interface. In Rust, we say that types which -implement the `Future` trait are futures. Each type which implements `Future` -holds its own information about the progress that has been made and what "ready" -means. +under other names such as “task” or “promise”.) Rust provides a `Future` trait +as a building block so different async operations can be implemented with +different data structures, but with a common interface. In Rust, we say that +types which implement the `Future` trait are futures. Each type which +implements `Future` holds its own information about the progress that has been +made and what "ready" means. The `async` keyword can be applied to blocks and functions to specify that they can be interrupted and resumed. Within an async block or async function, you can @@ -26,7 +26,7 @@ syntax. That’s for good reason, as we’ll see! Most of the time when writing async Rust, we use the `async` and `await` keywords. Rust compiles them into equivalent code using the `Future` trait, much -like it compiles `for` loops into equivalent code using the `Iterator` trait. +as it compiles `for` loops into equivalent code using the `Iterator` trait. Because Rust provides the `Future` trait, though, you can also implement it for your own data types when you need to. Many of the functions we’ll see throughout this chapter return types with their own implementations of `Future`. @@ -103,7 +103,7 @@ We have to explicitly await both of these futures, because futures in Rust are Rust will show a compiler warning if you don’t use a future.) This should remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. Iterators do nothing unless you call their `next` method—whether directly, or -using `for` loops or methods like `map` which use `next` under the hood. With +using `for` loops or methods such as `map` which use `next` under the hood. With futures, the same basic idea applies: they do nothing unless you explicitly ask them to. This laziness allows Rust to avoid running async code until it’s actually needed. @@ -152,9 +152,9 @@ whose body is an async block. Thus, an async function’s return type is the typ of the anonymous data type the compiler creates for that async block. Thus, writing `async fn` is equivalent to writing a function which returns a -*future* of the return type. When the compiler sees a function like `async fn -page_title` in Listing 17-1, it is equivalent to a non-async function defined -like this: +*future* of the return type. When the compiler sees a function definition such +as the `async fn page_title` in Listing 17-1, it’s equivalent to a non-async +function defined like this: ```rust # extern crate trpl; // required for mdbook test @@ -242,7 +242,7 @@ high-throughput web server with many CPU cores and a large amount of RAM has very different different needs than a microcontroller with a single core, a small amount of RAM, and no ability to do heap allocations. The crates which provide those runtimes also often supply async versions of common functionality -like file or network I/O. +such as file or network I/O. Here, and throughout the rest of this chapter, we’ll use the `run` function from the `trpl` crate, which takes a future as an argument and runs it to @@ -282,7 +282,7 @@ keyword—represents a place where control gets handed back to the runtime. To make that work, Rust needs to keep track of the state involved in the async block, so that the runtime can kick off some other work and then come back when it’s ready to try advancing this one again. This is an invisible state machine, -as if you wrote an enum like this to save the current state at each `await` +as if you wrote an enum in this way to save the current state at each `await` point: ```rust @@ -342,10 +342,10 @@ first. Either future can legitimately “win,” so it doesn’t make sense to return a `Result`. Instead, `race` returns a type we haven’t seen before, -`trpl::Either`. The `Either` type is somewhat like a `Result`, in that it has -two cases. Unlike `Result`, though, there is no notion of success or failure -baked into `Either`. Instead, it uses `Left` and `Right` to indicate “one or the -other”. +`trpl::Either`. The `Either` type is somewhat similar to a `Result`, in that it +has two cases. Unlike `Result`, though, there is no notion of success or +failure baked into `Either`. Instead, it uses `Left` and `Right` to indicate +“one or the other”. ```rust enum Either<A, B> { diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 62f2a0bc82..7683bf5bf4 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -32,7 +32,7 @@ that our top-level function can be async. > Note: From this point forward in the chapter, every example will include this > exact same wrapping code with `trpl::run` in `main`, so we’ll often skip it -> just like we do with `main`. Don’t forget to include it in your code! +> just as we do with `main`. Don’t forget to include it in your code! Then we write two loops within that block, each with a `trpl::sleep` call in it, which waits for half a second (500 milliseconds) before sending the next @@ -176,7 +176,7 @@ Sharing data between futures will also be familiar: we’ll use message passing again, but this with async versions of the types and functions. We’ll take a slightly different path than we did in Chapter 16, to illustrate some of the key differences between thread-based and futures-based concurrency. In Listing 17-9, -we’ll begin with just a single async block—*not* spawning a separate task like +we’ll begin with just a single async block—*not* spawning a separate task as we spawned a separate thread. <Listing number="17-9" caption="Creating an async channel and assigning the two halves to `tx` and `rx`" file-name="src/main.rs"> @@ -253,7 +253,7 @@ polling—that is, stop awaiting. The `while let` loop pulls all of this together. If the result of calling `rx.recv().await` is `Some(message)`, we get access to the message and we can -use it in the loop body, just like we could with `if let`. If the result is +use it in the loop body, just as we could with `if let`. If the result is `None`, the loop ends. Every time the loop completes, it hits the await point again, so the runtime pauses it again until another message arrives. @@ -278,7 +278,7 @@ points on the `recv` calls. To get the behavior we want, where the sleep delay happens between receiving each message, we need to put the `tx` and `rx` operations in their own async blocks. Then the runtime can execute each of them separately using `trpl::join`, -just like in the counting example. Once again, we await the result of calling +just as in the counting example. Once again, we await the result of calling `trpl::join`, not the individual futures. If we awaited the individual futures in sequence, we would just end up back in a sequential flow—exactly what we’re trying *not* to do. @@ -325,7 +325,7 @@ that async block, it would be dropped once that block ends. In Chapter 13, we learned how to use the `move` keyword with closures, and in Chapter 16, we saw that we often need to move data into closures when working with threads. The same basic dynamics apply to async blocks, so the `move` keyword works with -async blocks just like it does with closures. +async blocks just as it does with closures. In Listing 17-12, we change the async block for sending messages from a plain `async` block to an `async move` block. When we run *this* version of the code, diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 80c3b116f8..fecb73d035 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -289,8 +289,8 @@ syntax for working with them, and that is a good thing. When we “join” futures with the `join` family of functions and macros, we require *all* of them to finish before we move on. Sometimes, though, we only -need *some* future from a set to finish before we move on—kind of like racing -one future against another. +need *some* future from a set to finish before we move on—kind of similar to +racing one future against another. In Listing 17-21, we once again use `trpl::race` to run two futures, `slow` and `fast`, against each other. Each one prints a message when it starts running, @@ -449,14 +449,14 @@ directly, using the `yield_now` function. In Listing 17-25, we replace all those </Listing> This is both clearer about the actual intent and can be significantly faster -than using `sleep`, because timers like the one used by `sleep` often have +than using `sleep`, because timers such as the one used by `sleep` often have limits to how granular they can be. The version of `sleep` we are using, for example, will always sleep for at least a millisecond, even if we pass it a `Duration` of one nanosecond. Again, modern computers are *fast*: they can do a lot in one millisecond! -You can see this for yourself by setting up a little benchmark, like the one in -Listing 17-26. (This isn’t an especially rigorous way to do performance +You can see this for yourself by setting up a little benchmark, such as the one +in Listing 17-26. (This isn’t an especially rigorous way to do performance testing, but it suffices to show the difference here.) Here, we skip all the status printing, pass a one-nanosecond `Duration` to `trpl::sleep`, and let each future run by itself, with no switching between the futures. Then we run @@ -481,9 +481,9 @@ determine when it hands over control via await points. Each future therefore also has the responsibility to avoid blocking for too long. In some Rust-based embedded operating systems, this is the *only* kind of multitasking! -In real-world code, you won’t usually be alternating function calls with -await points on every single line, of course. While yielding control like this -is relatively inexpensive, it’s not free! In many cases, trying to break up a +In real-world code, you won’t usually be alternating function calls with await +points on every single line, of course. While yielding control in this way is +relatively inexpensive, it’s not free! In many cases, trying to break up a compute-bound task might make it significantly slower, so sometimes it’s better for *overall* performance to let an operation block briefly. You should always measure to see what your code’s actual performance bottlenecks are. The @@ -566,13 +566,13 @@ Failed after 2 seconds ``` Because futures compose with other futures, you can build really powerful tools -using smaller async building blocks. For example, you can use this same approach -to combine timeouts with retries, and in turn use those with things like network -calls—one of the examples from the beginning of the chapter! +using smaller async building blocks. For example, you can use this same +approach to combine timeouts with retries, and in turn use those with things +such as network calls—one of the examples from the beginning of the chapter! In practice, you will usually work directly with `async` and `await`, and -secondarily with functions and macros like `join`, `join_all`, `race`, and so -on. You’ll only need to reach for `pin` now and again to use them with those +secondarily with functions and macros such as `join`, `join_all`, `race`, and +so on. You’ll only need to reach for `pin` now and again to use them with those APIs. We’ve now seen a number of ways to work with multiple futures at the same diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 1f0ca66342..7bcc24ee4e 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -15,13 +15,13 @@ its synchronous `next` method. With the `trpl::Receiver` stream in particular, we called an asynchronous `recv` method instead, but these APIs otherwise feel very similar. -That similarity isn’t a coincidence. A stream is like an asynchronous form of -iteration. Whereas the `trpl::Receiver` specifically waits to receive messages, -though, the general-purpose stream API is much more general: it provides the -next item like `Iterator` does, but asynchronously. The similarity between -iterators and streams in Rust means we can actually create a stream from any -iterator. As with an iterator, we can work with a stream by calling its `next` -method and then awaiting the output, as in Listing 17-30. +That similarity isn’t a coincidence. A stream is similar to an asynchronous +form of iteration. Whereas the `trpl::Receiver` specifically waits to receive +messages, though, the general-purpose stream API is much more general: it +provides the next item the way `Iterator` does, but asynchronously. The +similarity between iterators and streams in Rust means we can actually create a +stream from any iterator. As with an iterator, we can work with a stream by +calling its `next` method and then awaiting the output, as in Listing 17-30. <Listing number="17-30" caption="Creating a stream from an iterator and printing its values" file-name="src/main.rs"> @@ -103,7 +103,7 @@ as in Listing 17-31. With all those pieces put together, this code works the way we want! What’s more, now that we have `StreamExt` in scope, we can use all of its utility -methods, just like with iterators. For example, in Listing 17-32, we use the +methods, just as with iterators. For example, in Listing 17-32, we use the `filter` method to filter out everything but multiples of three and five. <Listing number="17-32" caption="Filtering a `Stream` with the `StreamExt::filter` method" file-name="src/main.rs"> @@ -168,7 +168,7 @@ Message: 'j' ``` We could do this with the regular `Receiver` API, or even the regular `Iterator` -API, though. Let’s add something that requires streams, like adding a timeout +API, though. Let’s add something that requires streams: adding a timeout which applies to every item in the stream, and a delay on the items we emit. In Listing 17-34, we start by adding a timeout to the stream with the `timeout` @@ -221,7 +221,7 @@ available. Instead, we leave `get_messages` as a regular function which returns a stream, and spawn a task to handle the async `sleep` calls. -> Note: calling `spawn_task` like this works because we already set up our +> Note: calling `spawn_task` in this way works because we already set up our > runtime. Calling this particular implementation of `spawn_task` *without* > first setting up a runtime will cause a panic. Other implementations choose > different tradeoffs: they might spawn a new runtime and so avoid the panic but diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 5724103776..7cc3825886 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -43,7 +43,7 @@ enum Poll<T> { } ``` -This `Poll` type is a lot like an `Option`: it has one variant which has a value +This `Poll` type is similar to an `Option`: it has one variant which has a value (`Ready(T)`), and one which does not (`Pending`). It means something quite different, though! The `Pending` variant indicates that the future still has work to do, so the caller will need to check again later. The `Ready` variant @@ -176,17 +176,17 @@ The `cx` parameter and its `Context` type is interesting, but is beyond the scope of this chapter: you generally only need to worry about it when writing a custom `Future` implementation. -Instead, we’ll focus on the type for `self`. This is the first time we’ve -seen a method where `self` has a type annotation. A type annotation for `self` -is similar to type annotations for other function parameters, with two key -differences. First, when we specify the type of `self` like this, we’re telling -Rust what type `self` must be to call this method. Second, a type annotation on -`self` can’t be just any type. It’s only allowed to be the type on which the -method is implemented, a reference or smart pointer to that type, or a `Pin` -wrapping a reference to that type. We’ll see more on this syntax in Chapter -18. For now, it’s enough to know that if we want to poll a future (to check -whether it is `Pending` or `Ready(Output)`), we need a mutable reference to the -type, which is wrapped in a `Pin`. +Instead, we’ll focus on the type for `self`. This is the first time we’ve seen +a method where `self` has a type annotation. A type annotation for `self` is +similar to type annotations for other function parameters, with two key +differences. First, when we specify the type of `self` in this way, we’re +telling Rust what type `self` must be to call this method. Second, a type +annotation on `self` can’t be just any type. It’s only allowed to be the type +on which the method is implemented, a reference or smart pointer to that type, +or a `Pin` wrapping a reference to that type. We’ll see more on this syntax in +Chapter 18. For now, it’s enough to know that if we want to poll a future (to +check whether it is `Pending` or `Ready(Output)`), we need a mutable reference +to the type, which is wrapped in a `Pin`. `Pin` is a wrapper type. In some ways, it’s similar to the `Box`, `Rc`, and other smart pointer types we saw in Chapter 15, which also wrap other types. @@ -195,10 +195,10 @@ Unlike those, however, `Pin` only works with *pointer types* such as references `Pin` works with types which implement the `Deref` or `DerefMut` traits, which we covered in Chapter 15. You can think of this restriction as equivalent to only working with pointers, though, because implementing `Deref` or `DerefMut` -means your type behaves like a pointer type. `Pin` is also not a pointer itself, -and it doesn’t have any behavior of its own like the ref counting of `Rc` or -`Arc`. It’s purely a tool the compiler can use to uphold the relevant -guarantees, by wrapping pointers in the type. +means your type behaves similarly to a pointer type. `Pin` is also not a +pointer itself, and it doesn’t have any behavior of its own as the ref counting +of `Rc` or `Arc` does. It’s purely a tool the compiler can use to uphold the +relevant guarantees, by wrapping pointers in the type. Recalling that `await` is implemented in terms of calls to `poll`, this starts to explain the error message we saw above—but that was in terms of `Unpin`, not @@ -292,30 +292,30 @@ is still pinned. </figure> -However, most types are perfectly safe to move around, even if they happen to be -behind a `Pin` pointer. We only need to think about pinning when items have -internal references. Primitive values like numbers and booleans do not have any -internal structure like that, so they’re obviously safe. Neither do most types -you normally work with in Rust. A `Vec`, for example, doesn’t have any internal +However, most types are perfectly safe to move around, even if they happen to +be behind a `Pin` pointer. We only need to think about pinning when items have +internal references. Primitive values such as numbers and booleans don’t have +any internal references, so they’re obviously safe. Neither do most types you +normally work with in Rust. A `Vec`, for example, doesn’t have any internal references it needs to keep up to date this way, so you can move it around -without worrying. If you have a `Pin<Vec<String>>`, you’d have to do -everything via the safe but restrictive APIs provided by `Pin`, even though a +without worrying. If you have a `Pin<Vec<String>>`, you’d have to do everything +via the safe but restrictive APIs provided by `Pin`, even though a `Vec<String>` is always safe to move if there are no other references to it. We need a way to tell the compiler that it’s actually just fine to move items -around in cases like these. For that, we have `Unpin`. +around in cases such as these. For that, we have `Unpin`. -`Unpin` is a marker trait, like `Send` and `Sync`, which we saw in Chapter 16. +`Unpin` is a marker trait, as `Send` and `Sync` are, which we saw in Chapter 16. Recall that marker traits have no functionality of their own. They exist only to tell the compiler that it’s safe to use the type which implements a given trait in a particular context. `Unpin` informs the compiler that a given type does *not* need to uphold any particular guarantees about whether the value in question can be moved. -Just like `Send` and `Sync`, the compiler implements `Unpin` automatically for -all types where it can prove it is safe. Implementing `Unpin` manually is unsafe -because it requires *you* to uphold all the guarantees which make `Pin` and -`Unpin` safe yourself for a type with internal references. In practice, this is -a very rare thing to implement yourself! +Just as with `Send` and `Sync`, the compiler implements `Unpin` automatically +for all types where it can prove it is safe. Implementing `Unpin` manually is +unsafe because it requires *you* to uphold all the guarantees which make `Pin` +and `Unpin` safe yourself for a type with internal references. In practice, +this is a very rare thing to implement yourself! To make that concrete, think about a `String`: it has a length and the Unicode characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure @@ -329,7 +329,7 @@ characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure </figure> -This means that we can do things like replace one string with another at the +This means that we can do things such as replace one string with another at the exact same location in memory as in Figure 17-8. This doesn’t violate the `Pin` contract because `String`—like most other types in Rust—implements `Unpin`, because it has no internal references that make it unsafe to move around! @@ -374,11 +374,11 @@ idea of how to fix the code! Now that we have a deeper grasp on the `Future`, `Pin`, and `Unpin` traits, we can turn our attention to the `Stream` trait. As described in the section -introducing streams, streams are like asynchronous iterators. Unlike `Iterator` -and `Future`, there is no definition of a `Stream` trait in the standard library -as of the time of writing,<!-- TODO: verify before press time! --> but there -*is* a very common definition from the `futures` crate used throughout the -ecosystem. +introducing streams, streams are similar to asynchronous iterators. Unlike +`Iterator` and `Future`, there is no definition of a `Stream` trait in the +standard library as of the time of writing,<!-- TODO: verify before press time! +--> but there *is* a very common definition from the `futures` crate used +throughout the ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, so we can build up to how a `Stream` trait that merges them together might look. From @@ -403,16 +403,17 @@ trait Stream { ``` The `Stream` trait defines an associated type `Item` for the type of the items -produced by the stream. This is like `Iterator`: there may be zero to many of -these, and unlike `Future`, where there is always a single `Output` (even if -it’s the unit type `()`). +produced by the stream. This is similar to `Iterator`: there may be zero to +many of these, and unlike `Future`, where there is always a single `Output` +(even if it’s the unit type `()`). `Stream` also defines a method to get those items. We call it `poll_next`, to -make it clear that it polls like `Future::poll` and produces a sequence of items -like `Iterator::next`. Its return type combines `Poll` with `Option`. The outer -type is `Poll`, because it has to be checked for readiness, just like a future. -The inner type is `Option`, because it needs to signal whether there are more -messages, just like an iterator. +make it clear that it polls in the same way `Future::poll` does and produces a +sequence of items in the same way `Iterator::next` does. Its return type +combines `Poll` with `Option`. The outer type is `Poll`, because it has to be +checked for readiness, just as a future does. The inner type is `Option`, +because it needs to signal whether there are more messages, just as an iterator +does. Something very similar to this will likely end up standardized as part of Rust’s standard library. In the meantime, it’s part of the toolkit of most runtimes, diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 7b0e7af9ab..428eb61c9c 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -19,7 +19,7 @@ The async model provides a different—and ultimately complementary—set of tradeoffs. In the async model, concurrent operations don’t require their own threads. Instead, they can run on tasks, as when we used `trpl::spawn_task` to kick off work from a synchronous function throughout the streams section. A -*task* is a lot like a thread—but instead of being managed by the operating +*task* is similar to a thread—but instead of being managed by the operating system, it’s managed by library-level code: the runtime. In the previous section, we saw that we could build a `Stream` by using an async @@ -51,8 +51,8 @@ literally run out of memory! However, there’s a reason these APIs are so similar. Threads act as a boundary for sets of synchronous operations; concurrency is possible *between* threads. Tasks act as a boundary for sets of *asynchronous* operations; concurrency is -possible both *between* and *within* tasks. In that regard, tasks are kind of -like lightweight, runtime-managed threads with added capabilities that come from +possible both *between* and *within* tasks. In that regard, tasks are similar to +lightweight, runtime-managed threads with added capabilities that come from being managed by a runtime instead of by the operating system. Futures are an even more granular unit of concurrency, where each future may represent a tree of other futures. That is, the runtime—specifically, its executor—manages tasks, @@ -65,13 +65,13 @@ On the one hand, concurrency with threads is in some ways a simpler programming model than concurrency with `async`. Threads are somewhat “fire and forget,” they have no native equivalent to a future, so they simply run to completion, without interruption except by the operating system itself. That is, they have -no *intra-task concurrency* like futures can. Threads in Rust also have no +no *intra-task concurrency* as futures can. Threads in Rust also have no mechanisms for cancellation—a subject we haven’t covered in depth in this chapter, but which is implicit in the fact that whenever we ended a future, its state got cleaned up correctly. These limitations make threads harder to compose than futures. It’s much more -difficult, for example, to build something like the `timeout` we built in +difficult, for example, to build something similar to the `timeout` we built in [“Building Our Own Async Abstractions”][combining-futures], or the `throttle` method we used with streams in [“Composing Streams”][streams]. The fact that futures are richer data structures means they *can* be composed together more @@ -90,9 +90,9 @@ requires threads *and* tasks, and therefore futures. As a default way of thinking about which to use when: -- If the task is *very parallelizable*, like processing a bunch of data where +- If the task is *very parallelizable*, such as processing a bunch of data where each part can be processed separately, threads are a better choice. -- If the task is *very concurrent*, like handling messages from a bunch of +- If the task is *very concurrent*, such as handling messages from a bunch of different sources which may come in a different intervals or different rates, async is a better choice. @@ -112,8 +112,8 @@ common example of this kind of mix in real-world Rust code. We begin by creating an async channel. Then we spawn a thread which takes ownership of the sender side of the channel. Within the thread, we send the numbers 1 through 10, and sleep for a second in between each. Finally, we run a -future created with an async block passed to `trpl::run` just like we have -throughout the chapter. In that future, we await those messages, just like in +future created with an async block passed to `trpl::run` just as we have +throughout the chapter. In that future, we await those messages, just as in the other message-passing examples we have seen. To return to the examples we opened the chapter with: you could imagine running From fa97cab9dd12358b4843f7d01b1d0a4f423cc230 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Thu, 3 Oct 2024 21:22:12 -0400 Subject: [PATCH 599/720] Change nostarch snapshot chapter numbers to make room for the async chapter --- nostarch/chapter17.md | 1233 --------------- nostarch/chapter18.md | 2029 ++++++++++++------------ nostarch/chapter19.md | 2770 +++++++++++---------------------- nostarch/chapter20.md | 3384 ++++++++++++++++++++++------------------- nostarch/chapter21.md | 1994 ++++++++++++++++++++++++ 5 files changed, 5705 insertions(+), 5705 deletions(-) delete mode 100644 nostarch/chapter17.md create mode 100644 nostarch/chapter21.md diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md deleted file mode 100644 index 946d20a112..0000000000 --- a/nostarch/chapter17.md +++ /dev/null @@ -1,1233 +0,0 @@ -<!-- DO NOT EDIT THIS FILE. - -This file is periodically generated from the content in the `/src/` -directory, so all fixes need to be made in `/src/`. ---> - -[TOC] - -# Object-Oriented Programming Features - -Object-oriented programming (OOP) is a way of modeling programs. Objects as a -programmatic concept were introduced in the programming language Simula in the -1960s. Those objects influenced Alan Kay’s programming architecture in which -objects pass messages to each other. To describe this architecture, he coined -the term *object-oriented programming* in 1967. Many competing definitions -describe what OOP is, and by some of these definitions Rust is object oriented -but by others it is not. In this chapter, we’ll explore certain characteristics -that are commonly considered object oriented and how those characteristics -translate to idiomatic Rust. We’ll then show you how to implement an -object-oriented design pattern in Rust and discuss the trade-offs of doing so -versus implementing a solution using some of Rust’s strengths instead. - -## Characteristics of Object-Oriented Languages - -There is no consensus in the programming community about what features a -language must have to be considered object oriented. Rust is influenced by many -programming paradigms, including OOP; for example, we explored the features -that came from functional programming in Chapter 13. Arguably, OOP languages -share certain common characteristics, namely objects, encapsulation, and -inheritance. Let’s look at what each of those characteristics means and whether -Rust supports it. - -### Objects Contain Data and Behavior - -The book *Design Patterns: Elements of Reusable Object-Oriented Software* by -Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Addison-Wesley, -1994), colloquially referred to as *The Gang of Four* book, is a catalog of -object-oriented design patterns. It defines OOP in this way: - -Object-oriented programs are made up of objects. An *object* packages both data -and the procedures that operate on that data. The procedures are typically -called *methods* or *operations*. - -Using this definition, Rust is object oriented: structs and enums have data, -and `impl` blocks provide methods on structs and enums. Even though structs and -enums with methods aren’t *called* objects, they provide the same -functionality, according to the Gang of Four’s definition of objects. - -### Encapsulation That Hides Implementation Details - -Another aspect commonly associated with OOP is the idea of *encapsulation*, -which means that the implementation details of an object aren’t accessible to -code using that object. Therefore, the only way to interact with an object is -through its public API; code using the object shouldn’t be able to reach into -the object’s internals and change data or behavior directly. This enables the -programmer to change and refactor an object’s internals without needing to -change the code that uses the object. - -We discussed how to control encapsulation in Chapter 7: we can use the `pub` -keyword to decide which modules, types, functions, and methods in our code -should be public, and by default everything else is private. For example, we -can define a struct `AveragedCollection` that has a field containing a vector -of `i32` values. The struct can also have a field that contains the average of -the values in the vector, meaning the average doesn’t have to be computed on -demand whenever anyone needs it. In other words, `AveragedCollection` will -cache the calculated average for us. Listing 17-1 has the definition of the -`AveragedCollection` struct. - -Filename: src/lib.rs - -``` -pub struct AveragedCollection { - list: Vec<i32>, - average: f64, -} -``` - -Listing 17-1: An `AveragedCollection` struct that maintains a list of integers -and the average of the items in the collection - -The struct is marked `pub` so that other code can use it, but the fields within -the struct remain private. This is important in this case because we want to -ensure that whenever a value is added or removed from the list, the average is -also updated. We do this by implementing `add`, `remove`, and `average` methods -on the struct, as shown in Listing 17-2. - -Filename: src/lib.rs - -``` -impl AveragedCollection { - pub fn add(&mut self, value: i32) { - self.list.push(value); - self.update_average(); - } - - pub fn remove(&mut self) -> Option<i32> { - let result = self.list.pop(); - match result { - Some(value) => { - self.update_average(); - Some(value) - } - None => None, - } - } - - pub fn average(&self) -> f64 { - self.average - } - - fn update_average(&mut self) { - let total: i32 = self.list.iter().sum(); - self.average = total as f64 / self.list.len() as f64; - } -} -``` - -Listing 17-2: Implementations of the public methods `add`, `remove`, and -`average` on `AveragedCollection` - -The public methods `add`, `remove`, and `average` are the only ways to access -or modify data in an instance of `AveragedCollection`. When an item is added to -`list` using the `add` method or removed using the `remove` method, the -implementations of each call the private `update_average` method that handles -updating the `average` field as well. - -We leave the `list` and `average` fields private so there is no way for -external code to add or remove items to or from the `list` field directly; -otherwise, the `average` field might become out of sync when the `list` -changes. The `average` method returns the value in the `average` field, -allowing external code to read the `average` but not modify it. - -Because we’ve encapsulated the implementation details of the struct -`AveragedCollection`, we can easily change aspects, such as the data structure, -in the future. For instance, we could use a `HashSet<i32>` instead of a -`Vec<i32>` for the `list` field. As long as the signatures of the `add`, -`remove`, and `average` public methods stayed the same, code using -`AveragedCollection` wouldn’t need to change. If we made `list` public instead, -this wouldn’t necessarily be the case: `HashSet<i32>` and `Vec<i32>` have -different methods for adding and removing items, so the external code would -likely have to change if it were modifying `list` directly. - -If encapsulation is a required aspect for a language to be considered object -oriented, then Rust meets that requirement. The option to use `pub` or not for -different parts of code enables encapsulation of implementation details. - -### Inheritance as a Type System and as Code Sharing - -*Inheritance* is a mechanism whereby an object can inherit elements from -another object’s definition, thus gaining the parent object’s data and behavior -without you having to define them again. - -If a language must have inheritance to be object oriented, then Rust is not -such a language. There is no way to define a struct that inherits the parent -struct’s fields and method implementations without using a macro. - -However, if you’re used to having inheritance in your programming toolbox, you -can use other solutions in Rust, depending on your reason for reaching for -inheritance in the first place. - -You would choose inheritance for two main reasons. One is for reuse of code: -you can implement particular behavior for one type, and inheritance enables you -to reuse that implementation for a different type. You can do this in a limited -way in Rust code using default trait method implementations, which you saw in -Listing 10-14 when we added a default implementation of the `summarize` method -on the `Summary` trait. Any type implementing the `Summary` trait would have -the `summarize` method available on it without any further code. This is -similar to a parent class having an implementation of a method and an -inheriting child class also having the implementation of the method. We can -also override the default implementation of the `summarize` method when we -implement the `Summary` trait, which is similar to a child class overriding the -implementation of a method inherited from a parent class. - -The other reason to use inheritance relates to the type system: to enable a -child type to be used in the same places as the parent type. This is also -called *polymorphism*, which means that you can substitute multiple objects for -each other at runtime if they share certain characteristics. - -> ### Polymorphism -> -> To many people, polymorphism is synonymous with inheritance. But it’s -actually a more general concept that refers to code that can work with data of -multiple types. For inheritance, those types are generally subclasses. -> -> Rust instead uses generics to abstract over different possible types and -trait bounds to impose constraints on what those types must provide. This is -sometimes called *bounded parametric polymorphism*. - -Inheritance has recently fallen out of favor as a programming design solution -in many programming languages because it’s often at risk of sharing more code -than necessary. Subclasses shouldn’t always share all characteristics of their -parent class but will do so with inheritance. This can make a program’s design -less flexible. It also introduces the possibility of calling methods on -subclasses that don’t make sense or that cause errors because the methods don’t -apply to the subclass. In addition, some languages will only allow single -inheritance (meaning a subclass can only inherit from one class), further -restricting the flexibility of a program’s design. - -For these reasons, Rust takes the different approach of using trait objects -instead of inheritance. Let’s look at how trait objects enable polymorphism in -Rust. - -## Using Trait Objects That Allow for Values of Different Types - -In Chapter 8, we mentioned that one limitation of vectors is that they can -store elements of only one type. We created a workaround in Listing 8-9 where -we defined a `SpreadsheetCell` enum that had variants to hold integers, floats, -and text. This meant we could store different types of data in each cell and -still have a vector that represented a row of cells. This is a perfectly good -solution when our interchangeable items are a fixed set of types that we know -when our code is compiled. - -However, sometimes we want our library user to be able to extend the set of -types that are valid in a particular situation. To show how we might achieve -this, we’ll create an example graphical user interface (GUI) tool that iterates -through a list of items, calling a `draw` method on each one to draw it to the -screen—a common technique for GUI tools. We’ll create a library crate called -`gui` that contains the structure of a GUI library. This crate might include -some types for people to use, such as `Button` or `TextField`. In addition, -`gui` users will want to create their own types that can be drawn: for -instance, one programmer might add an `Image` and another might add a -`SelectBox`. - -We won’t implement a full-fledged GUI library for this example but will show -how the pieces would fit together. At the time of writing the library, we can’t -know and define all the types other programmers might want to create. But we do -know that `gui` needs to keep track of many values of different types, and it -needs to call a `draw` method on each of these differently typed values. It -doesn’t need to know exactly what will happen when we call the `draw` method, -just that the value will have that method available for us to call. - -To do this in a language with inheritance, we might define a class named -`Component` that has a method named `draw` on it. The other classes, such as -`Button`, `Image`, and `SelectBox`, would inherit from `Component` and thus -inherit the `draw` method. They could each override the `draw` method to define -their custom behavior, but the framework could treat all of the types as if -they were `Component` instances and call `draw` on them. But because Rust -doesn’t have inheritance, we need another way to structure the `gui` library to -allow users to extend it with new types. - -### Defining a Trait for Common Behavior - -To implement the behavior we want `gui` to have, we’ll define a trait named -`Draw` that will have one method named `draw`. Then we can define a vector that -takes a *trait object*. A trait object points to both an instance of a type -implementing our specified trait and a table used to look up trait methods on -that type at runtime. We create a trait object by specifying some sort of -pointer, such as a `&` reference or a `Box<T>` smart pointer, then the `dyn` -keyword, and then specifying the relevant trait. (We’ll talk about the reason -trait objects must use a pointer in “Dynamically Sized Types and the Sized -Trait” on page XX.) We can use trait objects in place of a generic or concrete -type. Wherever we use a trait object, Rust’s type system will ensure at compile -time that any value used in that context will implement the trait object’s -trait. Consequently, we don’t need to know all the possible types at compile -time. - -We’ve mentioned that, in Rust, we refrain from calling structs and enums -“objects” to distinguish them from other languages’ objects. In a struct or -enum, the data in the struct fields and the behavior in `impl` blocks are -separated, whereas in other languages, the data and behavior combined into one -concept is often labeled an object. However, trait objects *are* more like -objects in other languages in the sense that they combine data and behavior. -But trait objects differ from traditional objects in that we can’t add data to -a trait object. Trait objects aren’t as generally useful as objects in other -languages: their specific purpose is to allow abstraction across common -behavior. - -Listing 17-3 shows how to define a trait named `Draw` with one method named -`draw`. - -Filename: src/lib.rs - -``` -pub trait Draw { - fn draw(&self); -} -``` - -Listing 17-3: Definition of the `Draw` trait - -This syntax should look familiar from our discussions on how to define traits -in Chapter 10. Next comes some new syntax: Listing 17-4 defines a struct named -`Screen` that holds a vector named `components`. This vector is of type -`Box<dyn Draw>`, which is a trait object; it’s a stand-in for any type inside a -`Box` that implements the `Draw` trait. - -Filename: src/lib.rs - -``` -pub struct Screen { - pub components: Vec<Box<dyn Draw>>, -} -``` - -Listing 17-4: Definition of the `Screen` struct with a `components` field -holding a vector of trait objects that implement the `Draw` trait - -On the `Screen` struct, we’ll define a method named `run` that will call the -`draw` method on each of its `components`, as shown in Listing 17-5. - -Filename: src/lib.rs - -``` -impl Screen { - pub fn run(&self) { - for component in self.components.iter() { - component.draw(); - } - } -} -``` - -Listing 17-5: A `run` method on `Screen` that calls the `draw` method on each -component - -This works differently from defining a struct that uses a generic type -parameter with trait bounds. A generic type parameter can only be substituted -with one concrete type at a time, whereas trait objects allow for multiple -concrete types to fill in for the trait object at runtime. For example, we -could have defined the `Screen` struct using a generic type and a trait bound, -as in Listing 17-6. - -Filename: src/lib.rs - -``` -pub struct Screen<T: Draw> { - pub components: Vec<T>, -} - -impl<T> Screen<T> -where - T: Draw, -{ - pub fn run(&self) { - for component in self.components.iter() { - component.draw(); - } - } -} -``` - -Listing 17-6: An alternate implementation of the `Screen` struct and its `run` -method using generics and trait bounds - -This restricts us to a `Screen` instance that has a list of components all of -type `Button` or all of type `TextField`. If you’ll only ever have homogeneous -collections, using generics and trait bounds is preferable because the -definitions will be monomorphized at compile time to use the concrete types. - -On the other hand, with the method using trait objects, one `Screen` instance -can hold a `Vec<T>` that contains a `Box<Button>` as well as a -`Box<TextField>`. Let’s look at how this works, and then we’ll talk about the -runtime performance implications. - -### Implementing the Trait - -Now we’ll add some types that implement the `Draw` trait. We’ll provide the -`Button` type. Again, actually implementing a GUI library is beyond the scope -of this book, so the `draw` method won’t have any useful implementation in its -body. To imagine what the implementation might look like, a `Button` struct -might have fields for `width`, `height`, and `label`, as shown in Listing 17-7. - -Filename: src/lib.rs - -``` -pub struct Button { - pub width: u32, - pub height: u32, - pub label: String, -} - -impl Draw for Button { - fn draw(&self) { - // code to actually draw a button - } -} -``` - -Listing 17-7: A `Button` struct that implements the `Draw` trait - -The `width`, `height`, and `label` fields on `Button` will differ from the -fields on other components; for example, a `TextField` type might have those -same fields plus a `placeholder` field. Each of the types we want to draw on -the screen will implement the `Draw` trait but will use different code in the -`draw` method to define how to draw that particular type, as `Button` has here -(without the actual GUI code, as mentioned). The `Button` type, for instance, -might have an additional `impl` block containing methods related to what -happens when a user clicks the button. These kinds of methods won’t apply to -types like `TextField`. - -If someone using our library decides to implement a `SelectBox` struct that has -`width`, `height`, and `options` fields, they would implement the `Draw` trait -on the `SelectBox` type as well, as shown in Listing 17-8. - -Filename: src/main.rs - -``` -use gui::Draw; - -struct SelectBox { - width: u32, - height: u32, - options: Vec<String>, -} - -impl Draw for SelectBox { - fn draw(&self) { - // code to actually draw a select box - } -} -``` - -Listing 17-8: Another crate using `gui` and implementing the `Draw` trait on a -`SelectBox` struct - -Our library’s user can now write their `main` function to create a `Screen` -instance. To the `Screen` instance, they can add a `SelectBox` and a `Button` -by putting each in a `Box<T>` to become a trait object. They can then call the -`run` method on the `Screen` instance, which will call `draw` on each of the -components. Listing 17-9 shows this implementation. - -Filename: src/main.rs - -``` -use gui::{Button, Screen}; - -fn main() { - let screen = Screen { - components: vec![ - Box::new(SelectBox { - width: 75, - height: 10, - options: vec![ - String::from("Yes"), - String::from("Maybe"), - String::from("No"), - ], - }), - Box::new(Button { - width: 50, - height: 10, - label: String::from("OK"), - }), - ], - }; - - screen.run(); -} -``` - -Listing 17-9: Using trait objects to store values of different types that -implement the same trait - -When we wrote the library, we didn’t know that someone might add the -`SelectBox` type, but our `Screen` implementation was able to operate on the -new type and draw it because `SelectBox` implements the `Draw` trait, which -means it implements the `draw` method. - -This concept—of being concerned only with the messages a value responds to -rather than the value’s concrete type—is similar to the concept of *duck -typing* in dynamically typed languages: if it walks like a duck and quacks like -a duck, then it must be a duck! In the implementation of `run` on `Screen` in -Listing 17-5, `run` doesn’t need to know what the concrete type of each -component is. It doesn’t check whether a component is an instance of a `Button` -or a `SelectBox`, it just calls the `draw` method on the component. By -specifying `Box<dyn Draw>` as the type of the values in the `components` -vector, we’ve defined `Screen` to need values that we can call the `draw` -method on. - -The advantage of using trait objects and Rust’s type system to write code -similar to code using duck typing is that we never have to check whether a -value implements a particular method at runtime or worry about getting errors -if a value doesn’t implement a method but we call it anyway. Rust won’t compile -our code if the values don’t implement the traits that the trait objects need. - -For example, Listing 17-10 shows what happens if we try to create a `Screen` -with a `String` as a component. - -Filename: src/main.rs - -``` -use gui::Screen; - -fn main() { - let screen = Screen { - components: vec![Box::new(String::from("Hi"))], - }; - - screen.run(); -} -``` - -Listing 17-10: Attempting to use a type that doesn’t implement the trait -object’s trait - -We’ll get this error because `String` doesn’t implement the `Draw` trait: - -``` -error[E0277]: the trait bound `String: Draw` is not satisfied - --> src/main.rs:5:26 - | -5 | components: vec![Box::new(String::from("Hi"))], - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Draw` is -not implemented for `String` - | - = note: required for the cast to the object type `dyn Draw` -``` - -This error lets us know that either we’re passing something to `Screen` that we -didn’t mean to pass and so should pass a different type, or we should implement -`Draw` on `String` so that `Screen` is able to call `draw` on it. - -### Trait Objects Perform Dynamic Dispatch - -Recall in “Performance of Code Using Generics” on page XX our discussion on the -monomorphization process performed by the compiler when we use trait bounds on -generics: the compiler generates nongeneric implementations of functions and -methods for each concrete type that we use in place of a generic type -parameter. The code that results from monomorphization is doing *static -dispatch*, which is when the compiler knows what method you’re calling at -compile time. This is opposed to *dynamic dispatch*, which is when the compiler -can’t tell at compile time which method you’re calling. In dynamic dispatch -cases, the compiler emits code that at runtime will figure out which method to -call. - -When we use trait objects, Rust must use dynamic dispatch. The compiler doesn’t -know all the types that might be used with the code that’s using trait objects, -so it doesn’t know which method implemented on which type to call. Instead, at -runtime, Rust uses the pointers inside the trait object to know which method to -call. This lookup incurs a runtime cost that doesn’t occur with static -dispatch. Dynamic dispatch also prevents the compiler from choosing to inline a -method’s code, which in turn prevents some optimizations. However, we did get -extra flexibility in the code that we wrote in Listing 17-5 and were able to -support in Listing 17-9, so it’s a trade-off to consider. - -## Implementing an Object-Oriented Design Pattern - -The *state pattern* is an object-oriented design pattern. The crux of the -pattern is that we define a set of states a value can have internally. The -states are represented by a set of *state objects*, and the value’s behavior -changes based on its state. We’re going to work through an example of a blog -post struct that has a field to hold its state, which will be a state object -from the set “draft,” “review,” or “published.” - -The state objects share functionality: in Rust, of course, we use structs and -traits rather than objects and inheritance. Each state object is responsible -for its own behavior and for governing when it should change into another -state. The value that holds a state object knows nothing about the different -behavior of the states or when to transition between states. - -The advantage of using the state pattern is that, when the business -requirements of the program change, we won’t need to change the code of the -value holding the state or the code that uses the value. We’ll only need to -update the code inside one of the state objects to change its rules or perhaps -add more state objects. - -First we’re going to implement the state pattern in a more traditional -object-oriented way, then we’ll use an approach that’s a bit more natural in -Rust. Let’s dig in to incrementally implement a blog post workflow using the -state pattern. - -The final functionality will look like this: - -1. A blog post starts as an empty draft. -1. When the draft is done, a review of the post is requested. -1. When the post is approved, it gets published. -1. Only published blog posts return content to print, so unapproved posts can’t -accidentally be published. - -Any other changes attempted on a post should have no effect. For example, if we -try to approve a draft blog post before we’ve requested a review, the post -should remain an unpublished draft. - -Listing 17-11 shows this workflow in code form: this is an example usage of the -API we’ll implement in a library crate named `blog`. This won’t compile yet -because we haven’t implemented the `blog` crate. - -Filename: src/main.rs - -``` -use blog::Post; - -fn main() { - 1 let mut post = Post::new(); - - 2 post.add_text("I ate a salad for lunch today"); - 3 assert_eq!("", post.content()); - - 4 post.request_review(); - 5 assert_eq!("", post.content()); - - 6 post.approve(); - 7 assert_eq!("I ate a salad for lunch today", post.content()); -} -``` - -Listing 17-11: Code that demonstrates the desired behavior we want our `blog` -crate to have - -We want to allow the user to create a new draft blog post with `Post::new` [1]. -We want to allow text to be added to the blog post [2]. If we try to get the -post’s content immediately, before approval, we shouldn’t get any text because -the post is still a draft. We’ve added `assert_eq!` in the code for -demonstration purposes [3]. An excellent unit test for this would be to assert -that a draft blog post returns an empty string from the `content` method, but -we’re not going to write tests for this example. - -Next, we want to enable a request for a review of the post [4], and we want -`content` to return an empty string while waiting for the review [5]. When the -post receives approval [6], it should get published, meaning the text of the -post will be returned when `content` is called [7]. - -Notice that the only type we’re interacting with from the crate is the `Post` -type. This type will use the state pattern and will hold a value that will be -one of three state objects representing the various states a post can be -in—draft, review, or published. Changing from one state to another will be -managed internally within the `Post` type. The states change in response to the -methods called by our library’s users on the `Post` instance, but they don’t -have to manage the state changes directly. Also, users can’t make a mistake -with the states, such as publishing a post before it’s reviewed. - -### Defining Post and Creating a New Instance in the Draft State - -Let’s get started on the implementation of the library! We know we need a -public `Post` struct that holds some content, so we’ll start with the -definition of the struct and an associated public `new` function to create an -instance of `Post`, as shown in Listing 17-12. We’ll also make a private -`State` trait that will define the behavior that all state objects for a `Post` -must have. - -Then `Post` will hold a trait object of `Box<dyn State>` inside an `Option<T>` -in a private field named `state` to hold the state object. You’ll see why the -`Option<T>` is necessary in a bit. - -Filename: src/lib.rs - -``` -pub struct Post { - state: Option<Box<dyn State>>, - content: String, -} - -impl Post { - pub fn new() -> Post { - Post { - 1 state: Some(Box::new(Draft {})), - 2 content: String::new(), - } - } -} - -trait State {} - -struct Draft {} - -impl State for Draft {} -``` - -Listing 17-12: Definition of a `Post` struct and a `new` function that creates -a new `Post` instance, a `State` trait, and a `Draft` struct - -The `State` trait defines the behavior shared by different post states. The -state objects are `Draft`, `PendingReview`, and `Published`, and they will all -implement the `State` trait. For now, the trait doesn’t have any methods, and -we’ll start by defining just the `Draft` state because that is the state we -want a post to start in. - -When we create a new `Post`, we set its `state` field to a `Some` value that -holds a `Box` [1]. This `Box` points to a new instance of the `Draft` struct. -This ensures that whenever we create a new instance of `Post`, it will start -out as a draft. Because the `state` field of `Post` is private, there is no way -to create a `Post` in any other state! In the `Post::new` function, we set the -`content` field to a new, empty `String` [2]. - -### Storing the Text of the Post Content - -We saw in Listing 17-11 that we want to be able to call a method named -`add_text` and pass it a `&str` that is then added as the text content of the -blog post. We implement this as a method, rather than exposing the `content` -field as `pub`, so that later we can implement a method that will control how -the `content` field’s data is read. The `add_text` method is pretty -straightforward, so let’s add the implementation in Listing 17-13 to the `impl -Post` block. - -Filename: src/lib.rs - -``` -impl Post { - --snip-- - pub fn add_text(&mut self, text: &str) { - self.content.push_str(text); - } -} -``` - -Listing 17-13: Implementing the `add_text` method to add text to a post’s -`content` - -The `add_text` method takes a mutable reference to `self` because we’re -changing the `Post` instance that we’re calling `add_text` on. We then call -`push_str` on the `String` in `content` and pass the `text` argument to add to -the saved `content`. This behavior doesn’t depend on the state the post is in, -so it’s not part of the state pattern. The `add_text` method doesn’t interact -with the `state` field at all, but it is part of the behavior we want to -support. - -### Ensuring the Content of a Draft Post Is Empty - -Even after we’ve called `add_text` and added some content to our post, we still -want the `content` method to return an empty string slice because the post is -still in the draft state, as shown at [3] in Listing 17-11. For now, let’s -implement the `content` method with the simplest thing that will fulfill this -requirement: always returning an empty string slice. We’ll change this later -once we implement the ability to change a post’s state so it can be published. -So far, posts can only be in the draft state, so the post content should always -be empty. Listing 17-14 shows this placeholder implementation. - -Filename: src/lib.rs - -``` -impl Post { - --snip-- - pub fn content(&self) -> &str { - "" - } -} -``` - -Listing 17-14: Adding a placeholder implementation for the `content` method on -`Post` that always returns an empty string slice - -With this added `content` method, everything in Listing 17-11 up to the line at -[3] works as intended. - -### Requesting a Review Changes the Post’s State - -Next, we need to add functionality to request a review of a post, which should -change its state from `Draft` to `PendingReview`. Listing 17-15 shows this code. - -Filename: src/lib.rs - -``` -impl Post { - --snip-- - 1 pub fn request_review(&mut self) { - 2 if let Some(s) = self.state.take() { - 3 self.state = Some(s.request_review()) - } - } -} - -trait State { - 4 fn request_review(self: Box<Self>) -> Box<dyn State>; -} - -struct Draft {} - -impl State for Draft { - fn request_review(self: Box<Self>) -> Box<dyn State> { - 5 Box::new(PendingReview {}) - } -} - -struct PendingReview {} - -impl State for PendingReview { - fn request_review(self: Box<Self>) -> Box<dyn State> { - 6 self - } -} -``` - -Listing 17-15: Implementing `request_review` methods on `Post` and the `State` -trait - -We give `Post` a public method named `request_review` that will take a mutable -reference to `self` [1]. Then we call an internal `request_review` method on -the current state of `Post` [3], and this second `request_review` method -consumes the current state and returns a new state. - -We add the `request_review` method to the `State` trait [4]; all types that -implement the trait will now need to implement the `request_review` method. -Note that rather than having `self`, `&self`, or `&mut self` as the first -parameter of the method, we have `self: Box<Self>`. This syntax means the -method is only valid when called on a `Box` holding the type. This syntax takes -ownership of `Box<Self>`, invalidating the old state so the state value of the -`Post` can transform into a new state. - -To consume the old state, the `request_review` method needs to take ownership -of the state value. This is where the `Option` in the `state` field of `Post` -comes in: we call the `take` method to take the `Some` value out of the `state` -field and leave a `None` in its place because Rust doesn’t let us have -unpopulated fields in structs [2]. This lets us move the `state` value out of -`Post` rather than borrowing it. Then we’ll set the post’s `state` value to the -result of this operation. - -We need to set `state` to `None` temporarily rather than setting it directly -with code like `self.state = self.state.request_review();` to get ownership of -the `state` value. This ensures `Post` can’t use the old `state` value after -we’ve transformed it into a new state. - -The `request_review` method on `Draft` returns a new, boxed instance of a new -`PendingReview` struct [5], which represents the state when a post is waiting -for a review. The `PendingReview` struct also implements the `request_review` -method but doesn’t do any transformations. Rather, it returns itself [6] -because when we request a review on a post already in the `PendingReview` -state, it should stay in the `PendingReview` state. - -Now we can start seeing the advantages of the state pattern: the -`request_review` method on `Post` is the same no matter its `state` value. Each -state is responsible for its own rules. - -We’ll leave the `content` method on `Post` as is, returning an empty string -slice. We can now have a `Post` in the `PendingReview` state as well as in the -`Draft` state, but we want the same behavior in the `PendingReview` state. -Listing 17-11 now works up to the line at [5]! - -### Adding approve to Change the Behavior of content - -The `approve` method will be similar to the `request_review` method: it will -set `state` to the value that the current state says it should have when that -state is approved, as shown in Listing 17-16. - -Filename: src/lib.rs - -``` -impl Post { - --snip-- - pub fn approve(&mut self) { - if let Some(s) = self.state.take() { - self.state = Some(s.approve()) - } - } -} - -trait State { - fn request_review(self: Box<Self>) -> Box<dyn State>; - fn approve(self: Box<Self>) -> Box<dyn State>; -} - -struct Draft {} - -impl State for Draft { - --snip-- - fn approve(self: Box<Self>) -> Box<dyn State> { - 1 self - } -} - -struct PendingReview {} - -impl State for PendingReview { - --snip-- - fn approve(self: Box<Self>) -> Box<dyn State> { - 2 Box::new(Published {}) - } -} - -struct Published {} - -impl State for Published { - fn request_review(self: Box<Self>) -> Box<dyn State> { - self - } - - fn approve(self: Box<Self>) -> Box<dyn State> { - self - } -} -``` - -Listing 17-16: Implementing the `approve` method on `Post` and the `State` trait - -We add the `approve` method to the `State` trait and add a new struct that -implements `State`, the `Published` state. - -Similar to the way `request_review` on `PendingReview` works, if we call the -`approve` method on a `Draft`, it will have no effect because `approve` will -return `self` [1]. When we call `approve` on `PendingReview`, it returns a new, -boxed instance of the `Published` struct [2]. The `Published` struct implements -the `State` trait, and for both the `request_review` method and the `approve` -method, it returns itself because the post should stay in the `Published` state -in those cases. - -Now we need to update the `content` method on `Post`. We want the value -returned from `content` to depend on the current state of the `Post`, so we’re -going to have the `Post` delegate to a `content` method defined on its `state`, -as shown in Listing 17-17. - -Filename: src/lib.rs - -``` -impl Post { - --snip-- - pub fn content(&self) -> &str { - self.state.as_ref().unwrap().content(self) - } - --snip-- -} -``` - -Listing 17-17: Updating the `content` method on `Post` to delegate to a -`content` method on `State` - -Because the goal is to keep all of these rules inside the structs that -implement `State`, we call a `content` method on the value in `state` and pass -the post instance (that is, `self`) as an argument. Then we return the value -that’s returned from using the `content` method on the `state` value. - -We call the `as_ref` method on the `Option` because we want a reference to the -value inside the `Option` rather than ownership of the value. Because `state` -is an `Option<Box<dyn State>>`, when we call `as_ref`, an `Option<&Box<dyn -State>>` is returned. If we didn’t call `as_ref`, we would get an error because -we can’t move `state` out of the borrowed `&self` of the function parameter. - -We then call the `unwrap` method, which we know will never panic because we -know the methods on `Post` ensure that `state` will always contain a `Some` -value when those methods are done. This is one of the cases we talked about in -“Cases in Which You Have More Information Than the Compiler” on page XX when we -know that a `None` value is never possible, even though the compiler isn’t able -to understand that. - -At this point, when we call `content` on the `&Box<dyn State>`, deref coercion -will take effect on the `&` and the `Box` so the `content` method will -ultimately be called on the type that implements the `State` trait. That means -we need to add `content` to the `State` trait definition, and that is where -we’ll put the logic for what content to return depending on which state we -have, as shown in Listing 17-18. - -Filename: src/lib.rs - -``` -trait State { - --snip-- - fn content<'a>(&self, post: &'a Post) -> &'a str { - 1 "" - } -} - ---snip-- -struct Published {} - -impl State for Published { - --snip-- - fn content<'a>(&self, post: &'a Post) -> &'a str { - 2 &post.content - } -} -``` - -Listing 17-18: Adding the `content` method to the `State` trait - -We add a default implementation for the `content` method that returns an empty -string slice [1]. That means we don’t need to implement `content` on the -`Draft` and `PendingReview` structs. The `Published` struct will override the -`content` method and return the value in `post.content` [2]. - -Note that we need lifetime annotations on this method, as we discussed in -Chapter 10. We’re taking a reference to a `post` as an argument and returning a -reference to part of that `post`, so the lifetime of the returned reference is -related to the lifetime of the `post` argument. - -And we’re done—all of Listing 17-11 now works! We’ve implemented the state -pattern with the rules of the blog post workflow. The logic related to the -rules lives in the state objects rather than being scattered throughout `Post`. - -> ### Why Not An Enum? -> -> You may have been wondering why we didn’t use an `enum` with the different -possible post states as variants. That’s certainly a possible solution; try it -and compare the end results to see which you prefer! One disadvantage of using -an enum is that every place that checks the value of the enum will need a -`match` expression or similar to handle every possible variant. This could get -more repetitive than this trait object solution. - -### Trade-offs of the State Pattern - -We’ve shown that Rust is capable of implementing the object-oriented state -pattern to encapsulate the different kinds of behavior a post should have in -each state. The methods on `Post` know nothing about the various behaviors. The -way we organized the code, we have to look in only one place to know the -different ways a published post can behave: the implementation of the `State` -trait on the `Published` struct. - -If we were to create an alternative implementation that didn’t use the state -pattern, we might instead use `match` expressions in the methods on `Post` or -even in the `main` code that checks the state of the post and changes behavior -in those places. That would mean we would have to look in several places to -understand all the implications of a post being in the published state! This -would only increase the more states we added: each of those `match` expressions -would need another arm. - -With the state pattern, the `Post` methods and the places we use `Post` don’t -need `match` expressions, and to add a new state, we would only need to add a -new struct and implement the trait methods on that one struct. - -The implementation using the state pattern is easy to extend to add more -functionality. To see the simplicity of maintaining code that uses the state -pattern, try a few of these suggestions: - -* Add a `reject` method that changes the post’s state from `PendingReview` back -to `Draft`. -* Require two calls to `approve` before the state can be changed to `Published`. -* Allow users to add text content only when a post is in the `Draft` state. -Hint: have the state object responsible for what might change about the content -but not responsible for modifying the `Post`. - -One downside of the state pattern is that, because the states implement the -transitions between states, some of the states are coupled to each other. If we -add another state between `PendingReview` and `Published`, such as `Scheduled`, -we would have to change the code in `PendingReview` to transition to -`Scheduled` instead. It would be less work if `PendingReview` didn’t need to -change with the addition of a new state, but that would mean switching to -another design pattern. - -Another downside is that we’ve duplicated some logic. To eliminate some of the -duplication, we might try to make default implementations for the -`request_review` and `approve` methods on the `State` trait that return `self`. -However, this wouldn’t work: when using `State` as a trait object, the trait -doesn’t know what the concrete `self` will be exactly, so the return type isn’t -known at compile time. - -Other duplication includes the similar implementations of the `request_review` -and `approve` methods on `Post`. Both methods delegate to the implementation of -the same method on the value in the `state` field of `Option` and set the new -value of the `state` field to the result. If we had a lot of methods on `Post` -that followed this pattern, we might consider defining a macro to eliminate the -repetition (see “Macros” on page XX). - -By implementing the state pattern exactly as it’s defined for object-oriented -languages, we’re not taking as full advantage of Rust’s strengths as we could. -Let’s look at some changes we can make to the `blog` crate that can make -invalid states and transitions into compile-time errors. - -#### Encoding States and Behavior as Types - -We’ll show you how to rethink the state pattern to get a different set of -trade-offs. Rather than encapsulating the states and transitions completely so -outside code has no knowledge of them, we’ll encode the states into different -types. Consequently, Rust’s type checking system will prevent attempts to use -draft posts where only published posts are allowed by issuing a compiler error. - -Let’s consider the first part of `main` in Listing 17-11: - -Filename: src/main.rs - -``` -fn main() { - let mut post = Post::new(); - - post.add_text("I ate a salad for lunch today"); - assert_eq!("", post.content()); -} -``` - -We still enable the creation of new posts in the draft state using `Post::new` -and the ability to add text to the post’s content. But instead of having a -`content` method on a draft post that returns an empty string, we’ll make it so -draft posts don’t have the `content` method at all. That way, if we try to get -a draft post’s content, we’ll get a compiler error telling us the method -doesn’t exist. As a result, it will be impossible for us to accidentally -display draft post content in production because that code won’t even compile. -Listing 17-19 shows the definition of a `Post` struct and a `DraftPost` struct, -as well as methods on each. - -Filename: src/lib.rs - -``` -pub struct Post { - content: String, -} - -pub struct DraftPost { - content: String, -} - -impl Post { - 1 pub fn new() -> DraftPost { - DraftPost { - content: String::new(), - } - } - - 2 pub fn content(&self) -> &str { - &self.content - } -} - -impl DraftPost { - 3 pub fn add_text(&mut self, text: &str) { - self.content.push_str(text); - } -} -``` - -Listing 17-19: A `Post` with a `content` method and a `DraftPost` without a -`content` method - -Both the `Post` and `DraftPost` structs have a private `content` field that -stores the blog post text. The structs no longer have the `state` field because -we’re moving the encoding of the state to the types of the structs. The `Post` -struct will represent a published post, and it has a `content` method that -returns the `content` [2]. - -We still have a `Post::new` function, but instead of returning an instance of -`Post`, it returns an instance of `DraftPost` [1]. Because `content` is private -and there aren’t any functions that return `Post`, it’s not possible to create -an instance of `Post` right now. - -The `DraftPost` struct has an `add_text` method, so we can add text to -`content` as before [3], but note that `DraftPost` does not have a `content` -method defined! So now the program ensures all posts start as draft posts, and -draft posts don’t have their content available for display. Any attempt to get -around these constraints will result in a compiler error. - -#### Implementing Transitions as Transformations into Different Types - -So how do we get a published post? We want to enforce the rule that a draft -post has to be reviewed and approved before it can be published. A post in the -pending review state should still not display any content. Let’s implement -these constraints by adding another struct, `PendingReviewPost`, defining the -`request_review` method on `DraftPost` to return a `PendingReviewPost` and -defining an `approve` method on `PendingReviewPost` to return a `Post`, as -shown in Listing 17-20. - -Filename: src/lib.rs - -``` -impl DraftPost { - --snip-- - pub fn request_review(self) -> PendingReviewPost { - PendingReviewPost { - content: self.content, - } - } -} - -pub struct PendingReviewPost { - content: String, -} - -impl PendingReviewPost { - pub fn approve(self) -> Post { - Post { - content: self.content, - } - } -} -``` - -Listing 17-20: A `PendingReviewPost` that gets created by calling -`request_review` on `DraftPost` and an `approve` method that turns a -`PendingReviewPost` into a published `Post` - -The `request_review` and `approve` methods take ownership of `self`, thus -consuming the `DraftPost` and `PendingReviewPost` instances and transforming -them into a `PendingReviewPost` and a published `Post`, respectively. This way, -we won’t have any lingering `DraftPost` instances after we’ve called -`request_review` on them, and so forth. The `PendingReviewPost` struct doesn’t -have a `content` method defined on it, so attempting to read its content -results in a compiler error, as with `DraftPost`. Because the only way to get a -published `Post` instance that does have a `content` method defined is to call -the `approve` method on a `PendingReviewPost`, and the only way to get a -`PendingReviewPost` is to call the `request_review` method on a `DraftPost`, -we’ve now encoded the blog post workflow into the type system. - -But we also have to make some small changes to `main`. The `request_review` and -`approve` methods return new instances rather than modifying the struct they’re -called on, so we need to add more `let post =` shadowing assignments to save -the returned instances. We also can’t have the assertions about the draft and -pending review posts’ contents be empty strings, nor do we need them: we can’t -compile code that tries to use the content of posts in those states any longer. -The updated code in `main` is shown in Listing 17-21. - -Filename: src/main.rs - -``` -use blog::Post; - -fn main() { - let mut post = Post::new(); - - post.add_text("I ate a salad for lunch today"); - - let post = post.request_review(); - - let post = post.approve(); - - assert_eq!("I ate a salad for lunch today", post.content()); -} -``` - -Listing 17-21: Modifications to `main` to use the new implementation of the -blog post workflow - -The changes we needed to make to `main` to reassign `post` mean that this -implementation doesn’t quite follow the object-oriented state pattern anymore: -the transformations between the states are no longer encapsulated entirely -within the `Post` implementation. However, our gain is that invalid states are -now impossible because of the type system and the type checking that happens at -compile time! This ensures that certain bugs, such as display of the content of -an unpublished post, will be discovered before they make it to production. - -Try the tasks suggested at the start of this section on the `blog` crate as it -is after Listing 17-21 to see what you think about the design of this version -of the code. Note that some of the tasks might be completed already in this -design. - -We’ve seen that even though Rust is capable of implementing object-oriented -design patterns, other patterns, such as encoding state into the type system, -are also available in Rust. These patterns have different trade-offs. Although -you might be very familiar with object-oriented patterns, rethinking the -problem to take advantage of Rust’s features can provide benefits, such as -preventing some bugs at compile time. Object-oriented patterns won’t always be -the best solution in Rust due to certain features, like ownership, that -object-oriented languages don’t have. - -## Summary - -Regardless of whether you think Rust is an object-oriented language after -reading this chapter, you now know that you can use trait objects to get some -object-oriented features in Rust. Dynamic dispatch can give your code some -flexibility in exchange for a bit of runtime performance. You can use this -flexibility to implement object-oriented patterns that can help your code’s -maintainability. Rust also has other features, like ownership, that -object-oriented languages don’t have. An object-oriented pattern won’t always -be the best way to take advantage of Rust’s strengths, but it is an available -option. - -Next, we’ll look at patterns, which are another of Rust’s features that enable -lots of flexibility. We’ve looked at them briefly throughout the book but -haven’t seen their full capability yet. Let’s go! - diff --git a/nostarch/chapter18.md b/nostarch/chapter18.md index 40c7f10a1c..946d20a112 100644 --- a/nostarch/chapter18.md +++ b/nostarch/chapter18.md @@ -6,1287 +6,1228 @@ directory, so all fixes need to be made in `/src/`. [TOC] -# Patterns and Matching - -*Patterns* are a special syntax in Rust for matching against the structure of -types, both complex and simple. Using patterns in conjunction with `match` -expressions and other constructs gives you more control over a program’s -control flow. A pattern consists of some combination of the following: - -* Literals -* Destructured arrays, enums, structs, or tuples -* Variables -* Wildcards -* Placeholders - -Some example patterns include `x`, `(a, 3)`, and `Some(Color::Red)`. In the -contexts in which patterns are valid, these components describe the shape of -data. Our program then matches values against the patterns to determine whether -it has the correct shape of data to continue running a particular piece of code. +# Object-Oriented Programming Features + +Object-oriented programming (OOP) is a way of modeling programs. Objects as a +programmatic concept were introduced in the programming language Simula in the +1960s. Those objects influenced Alan Kay’s programming architecture in which +objects pass messages to each other. To describe this architecture, he coined +the term *object-oriented programming* in 1967. Many competing definitions +describe what OOP is, and by some of these definitions Rust is object oriented +but by others it is not. In this chapter, we’ll explore certain characteristics +that are commonly considered object oriented and how those characteristics +translate to idiomatic Rust. We’ll then show you how to implement an +object-oriented design pattern in Rust and discuss the trade-offs of doing so +versus implementing a solution using some of Rust’s strengths instead. + +## Characteristics of Object-Oriented Languages + +There is no consensus in the programming community about what features a +language must have to be considered object oriented. Rust is influenced by many +programming paradigms, including OOP; for example, we explored the features +that came from functional programming in Chapter 13. Arguably, OOP languages +share certain common characteristics, namely objects, encapsulation, and +inheritance. Let’s look at what each of those characteristics means and whether +Rust supports it. + +### Objects Contain Data and Behavior + +The book *Design Patterns: Elements of Reusable Object-Oriented Software* by +Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Addison-Wesley, +1994), colloquially referred to as *The Gang of Four* book, is a catalog of +object-oriented design patterns. It defines OOP in this way: + +Object-oriented programs are made up of objects. An *object* packages both data +and the procedures that operate on that data. The procedures are typically +called *methods* or *operations*. + +Using this definition, Rust is object oriented: structs and enums have data, +and `impl` blocks provide methods on structs and enums. Even though structs and +enums with methods aren’t *called* objects, they provide the same +functionality, according to the Gang of Four’s definition of objects. + +### Encapsulation That Hides Implementation Details + +Another aspect commonly associated with OOP is the idea of *encapsulation*, +which means that the implementation details of an object aren’t accessible to +code using that object. Therefore, the only way to interact with an object is +through its public API; code using the object shouldn’t be able to reach into +the object’s internals and change data or behavior directly. This enables the +programmer to change and refactor an object’s internals without needing to +change the code that uses the object. + +We discussed how to control encapsulation in Chapter 7: we can use the `pub` +keyword to decide which modules, types, functions, and methods in our code +should be public, and by default everything else is private. For example, we +can define a struct `AveragedCollection` that has a field containing a vector +of `i32` values. The struct can also have a field that contains the average of +the values in the vector, meaning the average doesn’t have to be computed on +demand whenever anyone needs it. In other words, `AveragedCollection` will +cache the calculated average for us. Listing 17-1 has the definition of the +`AveragedCollection` struct. + +Filename: src/lib.rs + +``` +pub struct AveragedCollection { + list: Vec<i32>, + average: f64, +} +``` -To use a pattern, we compare it to some value. If the pattern matches the -value, we use the value parts in our code. Recall the `match` expressions in -Chapter 6 that used patterns, such as the coin-sorting machine example. If the -value fits the shape of the pattern, we can use the named pieces. If it -doesn’t, the code associated with the pattern won’t run. +Listing 17-1: An `AveragedCollection` struct that maintains a list of integers +and the average of the items in the collection -This chapter is a reference on all things related to patterns. We’ll cover the -valid places to use patterns, the difference between refutable and irrefutable -patterns, and the different kinds of pattern syntax that you might see. By the -end of the chapter, you’ll know how to use patterns to express many concepts in -a clear way. +The struct is marked `pub` so that other code can use it, but the fields within +the struct remain private. This is important in this case because we want to +ensure that whenever a value is added or removed from the list, the average is +also updated. We do this by implementing `add`, `remove`, and `average` methods +on the struct, as shown in Listing 17-2. -## All the Places Patterns Can Be Used +Filename: src/lib.rs -Patterns pop up in a number of places in Rust, and you’ve been using them a lot -without realizing it! This section discusses all the places where patterns are -valid. +``` +impl AveragedCollection { + pub fn add(&mut self, value: i32) { + self.list.push(value); + self.update_average(); + } -### match Arms + pub fn remove(&mut self) -> Option<i32> { + let result = self.list.pop(); + match result { + Some(value) => { + self.update_average(); + Some(value) + } + None => None, + } + } -As discussed in Chapter 6, we use patterns in the arms of `match` expressions. -Formally, `match` expressions are defined as the keyword `match`, a value to -match on, and one or more match arms that consist of a pattern and an -expression to run if the value matches that arm’s pattern, like this: + pub fn average(&self) -> f64 { + self.average + } -``` -match VALUE { - PATTERN => EXPRESSION, - PATTERN => EXPRESSION, - PATTERN => EXPRESSION, + fn update_average(&mut self) { + let total: i32 = self.list.iter().sum(); + self.average = total as f64 / self.list.len() as f64; + } } ``` -For example, here’s the `match` expression from Listing 6-5 that matches on an -`Option<i32>` value in the variable `x`: - -``` -match x { - None => None, - Some(i) => Some(i + 1), +Listing 17-2: Implementations of the public methods `add`, `remove`, and +`average` on `AveragedCollection` + +The public methods `add`, `remove`, and `average` are the only ways to access +or modify data in an instance of `AveragedCollection`. When an item is added to +`list` using the `add` method or removed using the `remove` method, the +implementations of each call the private `update_average` method that handles +updating the `average` field as well. + +We leave the `list` and `average` fields private so there is no way for +external code to add or remove items to or from the `list` field directly; +otherwise, the `average` field might become out of sync when the `list` +changes. The `average` method returns the value in the `average` field, +allowing external code to read the `average` but not modify it. + +Because we’ve encapsulated the implementation details of the struct +`AveragedCollection`, we can easily change aspects, such as the data structure, +in the future. For instance, we could use a `HashSet<i32>` instead of a +`Vec<i32>` for the `list` field. As long as the signatures of the `add`, +`remove`, and `average` public methods stayed the same, code using +`AveragedCollection` wouldn’t need to change. If we made `list` public instead, +this wouldn’t necessarily be the case: `HashSet<i32>` and `Vec<i32>` have +different methods for adding and removing items, so the external code would +likely have to change if it were modifying `list` directly. + +If encapsulation is a required aspect for a language to be considered object +oriented, then Rust meets that requirement. The option to use `pub` or not for +different parts of code enables encapsulation of implementation details. + +### Inheritance as a Type System and as Code Sharing + +*Inheritance* is a mechanism whereby an object can inherit elements from +another object’s definition, thus gaining the parent object’s data and behavior +without you having to define them again. + +If a language must have inheritance to be object oriented, then Rust is not +such a language. There is no way to define a struct that inherits the parent +struct’s fields and method implementations without using a macro. + +However, if you’re used to having inheritance in your programming toolbox, you +can use other solutions in Rust, depending on your reason for reaching for +inheritance in the first place. + +You would choose inheritance for two main reasons. One is for reuse of code: +you can implement particular behavior for one type, and inheritance enables you +to reuse that implementation for a different type. You can do this in a limited +way in Rust code using default trait method implementations, which you saw in +Listing 10-14 when we added a default implementation of the `summarize` method +on the `Summary` trait. Any type implementing the `Summary` trait would have +the `summarize` method available on it without any further code. This is +similar to a parent class having an implementation of a method and an +inheriting child class also having the implementation of the method. We can +also override the default implementation of the `summarize` method when we +implement the `Summary` trait, which is similar to a child class overriding the +implementation of a method inherited from a parent class. + +The other reason to use inheritance relates to the type system: to enable a +child type to be used in the same places as the parent type. This is also +called *polymorphism*, which means that you can substitute multiple objects for +each other at runtime if they share certain characteristics. + +> ### Polymorphism +> +> To many people, polymorphism is synonymous with inheritance. But it’s +actually a more general concept that refers to code that can work with data of +multiple types. For inheritance, those types are generally subclasses. +> +> Rust instead uses generics to abstract over different possible types and +trait bounds to impose constraints on what those types must provide. This is +sometimes called *bounded parametric polymorphism*. + +Inheritance has recently fallen out of favor as a programming design solution +in many programming languages because it’s often at risk of sharing more code +than necessary. Subclasses shouldn’t always share all characteristics of their +parent class but will do so with inheritance. This can make a program’s design +less flexible. It also introduces the possibility of calling methods on +subclasses that don’t make sense or that cause errors because the methods don’t +apply to the subclass. In addition, some languages will only allow single +inheritance (meaning a subclass can only inherit from one class), further +restricting the flexibility of a program’s design. + +For these reasons, Rust takes the different approach of using trait objects +instead of inheritance. Let’s look at how trait objects enable polymorphism in +Rust. + +## Using Trait Objects That Allow for Values of Different Types + +In Chapter 8, we mentioned that one limitation of vectors is that they can +store elements of only one type. We created a workaround in Listing 8-9 where +we defined a `SpreadsheetCell` enum that had variants to hold integers, floats, +and text. This meant we could store different types of data in each cell and +still have a vector that represented a row of cells. This is a perfectly good +solution when our interchangeable items are a fixed set of types that we know +when our code is compiled. + +However, sometimes we want our library user to be able to extend the set of +types that are valid in a particular situation. To show how we might achieve +this, we’ll create an example graphical user interface (GUI) tool that iterates +through a list of items, calling a `draw` method on each one to draw it to the +screen—a common technique for GUI tools. We’ll create a library crate called +`gui` that contains the structure of a GUI library. This crate might include +some types for people to use, such as `Button` or `TextField`. In addition, +`gui` users will want to create their own types that can be drawn: for +instance, one programmer might add an `Image` and another might add a +`SelectBox`. + +We won’t implement a full-fledged GUI library for this example but will show +how the pieces would fit together. At the time of writing the library, we can’t +know and define all the types other programmers might want to create. But we do +know that `gui` needs to keep track of many values of different types, and it +needs to call a `draw` method on each of these differently typed values. It +doesn’t need to know exactly what will happen when we call the `draw` method, +just that the value will have that method available for us to call. + +To do this in a language with inheritance, we might define a class named +`Component` that has a method named `draw` on it. The other classes, such as +`Button`, `Image`, and `SelectBox`, would inherit from `Component` and thus +inherit the `draw` method. They could each override the `draw` method to define +their custom behavior, but the framework could treat all of the types as if +they were `Component` instances and call `draw` on them. But because Rust +doesn’t have inheritance, we need another way to structure the `gui` library to +allow users to extend it with new types. + +### Defining a Trait for Common Behavior + +To implement the behavior we want `gui` to have, we’ll define a trait named +`Draw` that will have one method named `draw`. Then we can define a vector that +takes a *trait object*. A trait object points to both an instance of a type +implementing our specified trait and a table used to look up trait methods on +that type at runtime. We create a trait object by specifying some sort of +pointer, such as a `&` reference or a `Box<T>` smart pointer, then the `dyn` +keyword, and then specifying the relevant trait. (We’ll talk about the reason +trait objects must use a pointer in “Dynamically Sized Types and the Sized +Trait” on page XX.) We can use trait objects in place of a generic or concrete +type. Wherever we use a trait object, Rust’s type system will ensure at compile +time that any value used in that context will implement the trait object’s +trait. Consequently, we don’t need to know all the possible types at compile +time. + +We’ve mentioned that, in Rust, we refrain from calling structs and enums +“objects” to distinguish them from other languages’ objects. In a struct or +enum, the data in the struct fields and the behavior in `impl` blocks are +separated, whereas in other languages, the data and behavior combined into one +concept is often labeled an object. However, trait objects *are* more like +objects in other languages in the sense that they combine data and behavior. +But trait objects differ from traditional objects in that we can’t add data to +a trait object. Trait objects aren’t as generally useful as objects in other +languages: their specific purpose is to allow abstraction across common +behavior. + +Listing 17-3 shows how to define a trait named `Draw` with one method named +`draw`. + +Filename: src/lib.rs + +``` +pub trait Draw { + fn draw(&self); } ``` -The patterns in this `match` expression are the `None` and `Some(i)` to the -left of each arrow. - -One requirement for `match` expressions is that they need to be *exhaustive* in -the sense that all possibilities for the value in the `match` expression must -be accounted for. One way to ensure you’ve covered every possibility is to have -a catchall pattern for the last arm: for example, a variable name matching any -value can never fail and thus covers every remaining case. - -The particular pattern `_` will match anything, but it never binds to a -variable, so it’s often used in the last match arm. The `_` pattern can be -useful when you want to ignore any value not specified, for example. We’ll -cover the `_` pattern in more detail in “Ignoring Values in a Pattern” on page -XX. - -### Conditional if let Expressions - -In Chapter 6, we discussed how to use `if let` expressions mainly as a shorter -way to write the equivalent of a `match` that only matches one case. -Optionally, `if let` can have a corresponding `else` containing code to run if -the pattern in the `if let` doesn’t match. +Listing 17-3: Definition of the `Draw` trait -Listing 18-1 shows that it’s also possible to mix and match `if let`, `else -if`, and `else if let` expressions. Doing so gives us more flexibility than a -`match` expression in which we can express only one value to compare with the -patterns. Also, Rust doesn’t require that the conditions in a series of `if -let`, `else if`, and `else if let` arms relate to each other. +This syntax should look familiar from our discussions on how to define traits +in Chapter 10. Next comes some new syntax: Listing 17-4 defines a struct named +`Screen` that holds a vector named `components`. This vector is of type +`Box<dyn Draw>`, which is a trait object; it’s a stand-in for any type inside a +`Box` that implements the `Draw` trait. -The code in Listing 18-1 determines what color to make your background based on -a series of checks for several conditions. For this example, we’ve created -variables with hardcoded values that a real program might receive from user -input. - -Filename: src/main.rs +Filename: src/lib.rs ``` -fn main() { - let favorite_color: Option<&str> = None; - let is_tuesday = false; - let age: Result<u8, _> = "34".parse(); - - 1 if let Some(color) = favorite_color { - 2 println!( - "Using your favorite, {color}, as the background" - ); - 3 } else if is_tuesday { - 4 println!("Tuesday is green day!"); - 5 } else if let Ok(age) = age { - 6 if age > 30 { - 7 println!("Using purple as the background color"); - } else { - 8 println!("Using orange as the background color"); - } - 9 } else { - 10 println!("Using blue as the background color"); - } +pub struct Screen { + pub components: Vec<Box<dyn Draw>>, } ``` -Listing 18-1: Mixing `if let`, `else if`, `else if let`, and `else` - -If the user specifies a favorite color [1], that color is used as the -background [2]. If no favorite color is specified and today is Tuesday [3], the -background color is green [4]. Otherwise, if the user specifies their age as a -string and we can parse it as a number successfully [5], the color is either -purple [7] or orange [8] depending on the value of the number [6]. If none of -these conditions apply [9], the background color is blue [10]. - -This conditional structure lets us support complex requirements. With the -hardcoded values we have here, this example will print `Using purple as the -background color`. - -You can see that `if let` can also introduce shadowed variables in the same way -that `match` arms can: the line `if let Ok(age) = age` [5] introduces a new -shadowed `age` variable that contains the value inside the `Ok` variant. This -means we need to place the `if age > 30` condition [6] within that block: we -can’t combine these two conditions into `if let Ok(age) = age && age > 30`. The -shadowed `age` we want to compare to 30 isn’t valid until the new scope starts -with the curly bracket. - -The downside of using `if let` expressions is that the compiler doesn’t check -for exhaustiveness, whereas with `match` expressions it does. If we omitted the -last `else` block [9] and therefore missed handling some cases, the compiler -would not alert us to the possible logic bug. +Listing 17-4: Definition of the `Screen` struct with a `components` field +holding a vector of trait objects that implement the `Draw` trait -### while let Conditional Loops +On the `Screen` struct, we’ll define a method named `run` that will call the +`draw` method on each of its `components`, as shown in Listing 17-5. -Similar in construction to `if let`, the `while let` conditional loop allows a -`while` loop to run for as long as a pattern continues to match. In Listing -18-2, we code a `while let` loop that uses a vector as a stack and prints the -values in the vector in the opposite order in which they were pushed. - -Filename: src/main.rs +Filename: src/lib.rs ``` -let mut stack = Vec::new(); - -stack.push(1); -stack.push(2); -stack.push(3); - -while let Some(top) = stack.pop() { - println!("{top}"); +impl Screen { + pub fn run(&self) { + for component in self.components.iter() { + component.draw(); + } + } } ``` -Listing 18-2: Using a `while let` loop to print values for as long as -`stack.pop()` returns `Some` +Listing 17-5: A `run` method on `Screen` that calls the `draw` method on each +component -This example prints `3`, `2`, and then `1`. The `pop` method takes the last -element out of the vector and returns `Some(value)`. If the vector is empty, -`pop` returns `None`. The `while` loop continues running the code in its block -as long as `pop` returns `Some`. When `pop` returns `None`, the loop stops. We -can use `while let` to pop every element off our stack. +This works differently from defining a struct that uses a generic type +parameter with trait bounds. A generic type parameter can only be substituted +with one concrete type at a time, whereas trait objects allow for multiple +concrete types to fill in for the trait object at runtime. For example, we +could have defined the `Screen` struct using a generic type and a trait bound, +as in Listing 17-6. -### for Loops - -In a `for` loop, the value that directly follows the keyword `for` is a -pattern. For example, in `for x in y`, the `x` is the pattern. Listing 18-3 -demonstrates how to use a pattern in a `for` loop to *destructure*, or break -apart, a tuple as part of the `for` loop. - -Filename: src/main.rs +Filename: src/lib.rs ``` -let v = vec!['a', 'b', 'c']; +pub struct Screen<T: Draw> { + pub components: Vec<T>, +} -for (index, value) in v.iter().enumerate() { - println!("{value} is at index {index}"); +impl<T> Screen<T> +where + T: Draw, +{ + pub fn run(&self) { + for component in self.components.iter() { + component.draw(); + } + } } ``` -Listing 18-3: Using a pattern in a `for` loop to destructure a tuple +Listing 17-6: An alternate implementation of the `Screen` struct and its `run` +method using generics and trait bounds -The code in Listing 18-3 will print the following: +This restricts us to a `Screen` instance that has a list of components all of +type `Button` or all of type `TextField`. If you’ll only ever have homogeneous +collections, using generics and trait bounds is preferable because the +definitions will be monomorphized at compile time to use the concrete types. -``` -a is at index 0 -b is at index 1 -c is at index 2 -``` +On the other hand, with the method using trait objects, one `Screen` instance +can hold a `Vec<T>` that contains a `Box<Button>` as well as a +`Box<TextField>`. Let’s look at how this works, and then we’ll talk about the +runtime performance implications. -We adapt an iterator using the `enumerate` method so it produces a value and -the index for that value, placed into a tuple. The first value produced is the -tuple `(0, 'a')`. When this value is matched to the pattern `(index, value)`, -`index` will be `0` and `value` will be `'a'`, printing the first line of the -output. +### Implementing the Trait -### let Statements +Now we’ll add some types that implement the `Draw` trait. We’ll provide the +`Button` type. Again, actually implementing a GUI library is beyond the scope +of this book, so the `draw` method won’t have any useful implementation in its +body. To imagine what the implementation might look like, a `Button` struct +might have fields for `width`, `height`, and `label`, as shown in Listing 17-7. -Prior to this chapter, we had only explicitly discussed using patterns with -`match` and `if let`, but in fact, we’ve used patterns in other places as well, -including in `let` statements. For example, consider this straightforward -variable assignment with `let`: +Filename: src/lib.rs ``` -let x = 5; -``` - -Every time you’ve used a `let` statement like this you’ve been using patterns, -although you might not have realized it! More formally, a `let` statement looks -like this: - -``` -let PATTERN = EXPRESSION; -``` - -In statements like `let x = 5;` with a variable name in the PATTERN slot, the -variable name is just a particularly simple form of a pattern. Rust compares -the expression against the pattern and assigns any names it finds. So, in the -`let x = 5;` example, `x` is a pattern that means “bind what matches here to -the variable `x`.” Because the name `x` is the whole pattern, this pattern -effectively means “bind everything to the variable `x`, whatever the value is.” - -To see the pattern-matching aspect of `let` more clearly, consider Listing -18-4, which uses a pattern with `let` to destructure a tuple. +pub struct Button { + pub width: u32, + pub height: u32, + pub label: String, +} -``` -let (x, y, z) = (1, 2, 3); +impl Draw for Button { + fn draw(&self) { + // code to actually draw a button + } +} ``` -Listing 18-4: Using a pattern to destructure a tuple and create three variables -at once +Listing 17-7: A `Button` struct that implements the `Draw` trait -Here, we match a tuple against a pattern. Rust compares the value `(1, 2, 3)` -to the pattern `(x, y, z)` and sees that the value matches the pattern, in that -it sees that the number of elements is the same in both, so Rust binds `1` to -`x`, `2` to `y`, and `3` to `z`. You can think of this tuple pattern as nesting -three individual variable patterns inside it. +The `width`, `height`, and `label` fields on `Button` will differ from the +fields on other components; for example, a `TextField` type might have those +same fields plus a `placeholder` field. Each of the types we want to draw on +the screen will implement the `Draw` trait but will use different code in the +`draw` method to define how to draw that particular type, as `Button` has here +(without the actual GUI code, as mentioned). The `Button` type, for instance, +might have an additional `impl` block containing methods related to what +happens when a user clicks the button. These kinds of methods won’t apply to +types like `TextField`. -If the number of elements in the pattern doesn’t match the number of elements -in the tuple, the overall type won’t match and we’ll get a compiler error. For -example, Listing 18-5 shows an attempt to destructure a tuple with three -elements into two variables, which won’t work. +If someone using our library decides to implement a `SelectBox` struct that has +`width`, `height`, and `options` fields, they would implement the `Draw` trait +on the `SelectBox` type as well, as shown in Listing 17-8. -``` -let (x, y) = (1, 2, 3); -``` - -Listing 18-5: Incorrectly constructing a pattern whose variables don’t match -the number of elements in the tuple - -Attempting to compile this code results in this type error: +Filename: src/main.rs ``` -error[E0308]: mismatched types - --> src/main.rs:2:9 - | -2 | let (x, y) = (1, 2, 3); - | ^^^^^^ --------- this expression has type `({integer}, {integer}, -{integer})` - | | - | expected a tuple with 3 elements, found one with 2 elements - | - = note: expected tuple `({integer}, {integer}, {integer})` - found tuple `(_, _)` -``` - -To fix the error, we could ignore one or more of the values in the tuple using -`_` or `..`, as you’ll see in “Ignoring Values in a Pattern” on page XX. If the -problem is that we have too many variables in the pattern, the solution is to -make the types match by removing variables so the number of variables equals -the number of elements in the tuple. +use gui::Draw; -### Function Parameters - -Function parameters can also be patterns. The code in Listing 18-6, which -declares a function named `foo` that takes one parameter named `x` of type -`i32`, should by now look familiar. +struct SelectBox { + width: u32, + height: u32, + options: Vec<String>, +} -``` -fn foo(x: i32) { - // code goes here +impl Draw for SelectBox { + fn draw(&self) { + // code to actually draw a select box + } } ``` -Listing 18-6: A function signature using patterns in the parameters +Listing 17-8: Another crate using `gui` and implementing the `Draw` trait on a +`SelectBox` struct -The `x` part is a pattern! As we did with `let`, we could match a tuple in a -function’s arguments to the pattern. Listing 18-7 splits the values in a tuple -as we pass it to a function. +Our library’s user can now write their `main` function to create a `Screen` +instance. To the `Screen` instance, they can add a `SelectBox` and a `Button` +by putting each in a `Box<T>` to become a trait object. They can then call the +`run` method on the `Screen` instance, which will call `draw` on each of the +components. Listing 17-9 shows this implementation. Filename: src/main.rs ``` -fn print_coordinates(&(x, y): &(i32, i32)) { - println!("Current location: ({x}, {y})"); -} +use gui::{Button, Screen}; fn main() { - let point = (3, 5); - print_coordinates(&point); + let screen = Screen { + components: vec![ + Box::new(SelectBox { + width: 75, + height: 10, + options: vec![ + String::from("Yes"), + String::from("Maybe"), + String::from("No"), + ], + }), + Box::new(Button { + width: 50, + height: 10, + label: String::from("OK"), + }), + ], + }; + + screen.run(); } ``` -Listing 18-7: A function with parameters that destructure a tuple - -This code prints `Current location: (3, 5)`. The values `&(3, 5)` match the -pattern `&(x, y)`, so `x` is the value `3` and `y` is the value `5`. - -We can also use patterns in closure parameter lists in the same way as in -function parameter lists because closures are similar to functions, as -discussed in Chapter 13. - -At this point, you’ve seen several ways to use patterns, but patterns don’t -work the same in every place we can use them. In some places, the patterns must -be irrefutable; in other circumstances, they can be refutable. We’ll discuss -these two concepts next. - -## Refutability: Whether a Pattern Might Fail to Match - -Patterns come in two forms: refutable and irrefutable. Patterns that will match -for any possible value passed are *irrefutable*. An example would be `x` in the -statement `let x = 5;` because `x` matches anything and therefore cannot fail -to match. Patterns that can fail to match for some possible value are -*refutable*. An example would be `Some(x)` in the expression `if let Some(x) = -a_value` because if the value in the `a_value` variable is `None` rather than -`Some`, the `Some(x)` pattern will not match. - -Function parameters, `let` statements, and `for` loops can only accept -irrefutable patterns because the program cannot do anything meaningful when -values don’t match. The `if let` and `while let` expressions accept refutable -and irrefutable patterns, but the compiler warns against irrefutable patterns -because, by definition, they’re intended to handle possible failure: the -functionality of a conditional is in its ability to perform differently -depending on success or failure. - -In general, you shouldn’t have to worry about the distinction between refutable -and irrefutable patterns; however, you do need to be familiar with the concept -of refutability so you can respond when you see it in an error message. In -those cases, you’ll need to change either the pattern or the construct you’re -using the pattern with, depending on the intended behavior of the code. - -Let’s look at an example of what happens when we try to use a refutable pattern -where Rust requires an irrefutable pattern and vice versa. Listing 18-8 shows a -`let` statement, but for the pattern, we’ve specified `Some(x)`, a refutable -pattern. As you might expect, this code will not compile. +Listing 17-9: Using trait objects to store values of different types that +implement the same trait -``` -let Some(x) = some_option_value; -``` +When we wrote the library, we didn’t know that someone might add the +`SelectBox` type, but our `Screen` implementation was able to operate on the +new type and draw it because `SelectBox` implements the `Draw` trait, which +means it implements the `draw` method. -Listing 18-8: Attempting to use a refutable pattern with `let` +This concept—of being concerned only with the messages a value responds to +rather than the value’s concrete type—is similar to the concept of *duck +typing* in dynamically typed languages: if it walks like a duck and quacks like +a duck, then it must be a duck! In the implementation of `run` on `Screen` in +Listing 17-5, `run` doesn’t need to know what the concrete type of each +component is. It doesn’t check whether a component is an instance of a `Button` +or a `SelectBox`, it just calls the `draw` method on the component. By +specifying `Box<dyn Draw>` as the type of the values in the `components` +vector, we’ve defined `Screen` to need values that we can call the `draw` +method on. -If `some_option_value` were a `None` value, it would fail to match the pattern -`Some(x)`, meaning the pattern is refutable. However, the `let` statement can -only accept an irrefutable pattern because there is nothing valid the code can -do with a `None` value. At compile time, Rust will complain that we’ve tried to -use a refutable pattern where an irrefutable pattern is required: +The advantage of using trait objects and Rust’s type system to write code +similar to code using duck typing is that we never have to check whether a +value implements a particular method at runtime or worry about getting errors +if a value doesn’t implement a method but we call it anyway. Rust won’t compile +our code if the values don’t implement the traits that the trait objects need. -``` -error[E0005]: refutable pattern in local binding: `None` not covered - --> src/main.rs:3:9 - | -3 | let Some(x) = some_option_value; - | ^^^^^^^ pattern `None` not covered - | - = note: `let` bindings require an "irrefutable pattern", like a `struct` or -an `enum` with only one variant - = note: for more information, visit -https://doc.rust-lang.org/book/ch18-02-refutability.html - = note: the matched value is of type `Option<i32>` -help: you might want to use `if let` to ignore the variant that isn't matched - | -3 | let x = if let Some(x) = some_option_value { x } else { todo!() }; - | ++++++++++ ++++++++++++++++++++++ -``` - -Because we didn’t cover (and couldn’t cover!) every valid value with the -pattern `Some(x)`, Rust rightfully produces a compiler error. +For example, Listing 17-10 shows what happens if we try to create a `Screen` +with a `String` as a component. -If we have a refutable pattern where an irrefutable pattern is needed, we can -fix it by changing the code that uses the pattern: instead of using `let`, we -can use `if let`. Then, if the pattern doesn’t match, the code will just skip -the code in the curly brackets, giving it a way to continue validly. Listing -18-9 shows how to fix the code in Listing 18-8. +Filename: src/main.rs ``` -if let Some(x) = some_option_value { - println!("{x}"); -} -``` +use gui::Screen; -Listing 18-9: Using `if let` and a block with refutable patterns instead of -`let` - -We’ve given the code an out! This code is perfectly valid, although it means we -cannot use an irrefutable pattern without receiving an error. If we give `if -let` a pattern that will always match, such as `x`, as shown in Listing 18-10, -the compiler will give a warning. +fn main() { + let screen = Screen { + components: vec![Box::new(String::from("Hi"))], + }; -``` -if let x = 5 { - println!("{x}"); -}; + screen.run(); +} ``` -Listing 18-10: Attempting to use an irrefutable pattern with `if let` +Listing 17-10: Attempting to use a type that doesn’t implement the trait +object’s trait -Rust complains that it doesn’t make sense to use `if let` with an irrefutable -pattern: +We’ll get this error because `String` doesn’t implement the `Draw` trait: ``` -warning: irrefutable `if let` pattern - --> src/main.rs:2:8 +error[E0277]: the trait bound `String: Draw` is not satisfied + --> src/main.rs:5:26 | -2 | if let x = 5 { - | ^^^^^^^^^ +5 | components: vec![Box::new(String::from("Hi"))], + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Draw` is +not implemented for `String` | - = note: `#[warn(irrefutable_let_patterns)]` on by default - = note: this pattern will always match, so the `if let` is -useless - = help: consider replacing the `if let` with a `let` -``` - -For this reason, match arms must use refutable patterns, except for the last -arm, which should match any remaining values with an irrefutable pattern. Rust -allows us to use an irrefutable pattern in a `match` with only one arm, but -this syntax isn’t particularly useful and could be replaced with a simpler -`let` statement. - -Now that you know where to use patterns and the difference between refutable -and irrefutable patterns, let’s cover all the syntax we can use to create -patterns. - -## Pattern Syntax - -In this section, we gather all the syntax that is valid in patterns and discuss -why and when you might want to use each one. - -### Matching Literals - -As you saw in Chapter 6, you can match patterns against literals directly. The -following code gives some examples: + = note: required for the cast to the object type `dyn Draw` +``` + +This error lets us know that either we’re passing something to `Screen` that we +didn’t mean to pass and so should pass a different type, or we should implement +`Draw` on `String` so that `Screen` is able to call `draw` on it. + +### Trait Objects Perform Dynamic Dispatch + +Recall in “Performance of Code Using Generics” on page XX our discussion on the +monomorphization process performed by the compiler when we use trait bounds on +generics: the compiler generates nongeneric implementations of functions and +methods for each concrete type that we use in place of a generic type +parameter. The code that results from monomorphization is doing *static +dispatch*, which is when the compiler knows what method you’re calling at +compile time. This is opposed to *dynamic dispatch*, which is when the compiler +can’t tell at compile time which method you’re calling. In dynamic dispatch +cases, the compiler emits code that at runtime will figure out which method to +call. + +When we use trait objects, Rust must use dynamic dispatch. The compiler doesn’t +know all the types that might be used with the code that’s using trait objects, +so it doesn’t know which method implemented on which type to call. Instead, at +runtime, Rust uses the pointers inside the trait object to know which method to +call. This lookup incurs a runtime cost that doesn’t occur with static +dispatch. Dynamic dispatch also prevents the compiler from choosing to inline a +method’s code, which in turn prevents some optimizations. However, we did get +extra flexibility in the code that we wrote in Listing 17-5 and were able to +support in Listing 17-9, so it’s a trade-off to consider. + +## Implementing an Object-Oriented Design Pattern + +The *state pattern* is an object-oriented design pattern. The crux of the +pattern is that we define a set of states a value can have internally. The +states are represented by a set of *state objects*, and the value’s behavior +changes based on its state. We’re going to work through an example of a blog +post struct that has a field to hold its state, which will be a state object +from the set “draft,” “review,” or “published.” + +The state objects share functionality: in Rust, of course, we use structs and +traits rather than objects and inheritance. Each state object is responsible +for its own behavior and for governing when it should change into another +state. The value that holds a state object knows nothing about the different +behavior of the states or when to transition between states. + +The advantage of using the state pattern is that, when the business +requirements of the program change, we won’t need to change the code of the +value holding the state or the code that uses the value. We’ll only need to +update the code inside one of the state objects to change its rules or perhaps +add more state objects. + +First we’re going to implement the state pattern in a more traditional +object-oriented way, then we’ll use an approach that’s a bit more natural in +Rust. Let’s dig in to incrementally implement a blog post workflow using the +state pattern. + +The final functionality will look like this: + +1. A blog post starts as an empty draft. +1. When the draft is done, a review of the post is requested. +1. When the post is approved, it gets published. +1. Only published blog posts return content to print, so unapproved posts can’t +accidentally be published. + +Any other changes attempted on a post should have no effect. For example, if we +try to approve a draft blog post before we’ve requested a review, the post +should remain an unpublished draft. + +Listing 17-11 shows this workflow in code form: this is an example usage of the +API we’ll implement in a library crate named `blog`. This won’t compile yet +because we haven’t implemented the `blog` crate. Filename: src/main.rs ``` -let x = 1; - -match x { - 1 => println!("one"), - 2 => println!("two"), - 3 => println!("three"), - _ => println!("anything"), -} -``` - -This code prints `one` because the value in `x` is `1`. This syntax is useful -when you want your code to take an action if it gets a particular concrete -value. - -### Matching Named Variables - -Named variables are irrefutable patterns that match any value, and we’ve used -them many times in this book. However, there is a complication when you use -named variables in `match` expressions. Because `match` starts a new scope, -variables declared as part of a pattern inside the `match` expression will -shadow those with the same name outside the `match` construct, as is the case -with all variables. In Listing 18-11, we declare a variable named `x` with the -value `Some(5)` and a variable `y` with the value `10`. We then create a -`match` expression on the value `x`. Look at the patterns in the match arms and -`println!` at the end, and try to figure out what the code will print before -running this code or reading further. +use blog::Post; -Filename: src/main.rs - -``` fn main() { - 1 let x = Some(5); - 2 let y = 10; - - match x { - 3 Some(50) => println!("Got 50"), - 4 Some(y) => println!("Matched, y = {y}"), - 5 _ => println!("Default case, x = {:?}", x), - } - - 6 println!("at the end: x = {:?}, y = {y}", x); -} -``` - -Listing 18-11: A `match` expression with an arm that introduces a shadowed -variable `y` - -Let’s walk through what happens when the `match` expression runs. The pattern -in the first match arm [3] doesn’t match the defined value of `x` [1], so the -code continues. - -The pattern in the second match arm [4] introduces a new variable named `y` -that will match any value inside a `Some` value. Because we’re in a new scope -inside the `match` expression, this is a new `y` variable, not the `y` we -declared at the beginning with the value `10` [2]. This new `y` binding will -match any value inside a `Some`, which is what we have in `x`. Therefore, this -new `y` binds to the inner value of the `Some` in `x`. That value is `5`, so -the expression for that arm executes and prints `Matched, y = 5`. - -If `x` had been a `None` value instead of `Some(5)`, the patterns in the first -two arms wouldn’t have matched, so the value would have matched to the -underscore [5]. We didn’t introduce the `x` variable in the pattern of the -underscore arm, so the `x` in the expression is still the outer `x` that hasn’t -been shadowed. In this hypothetical case, the `match` would print `Default -case, x = None`. - -When the `match` expression is done, its scope ends, and so does the scope of -the inner `y`. The last `println!` [6] produces `at the end: x = Some(5), y = -10`. - -To create a `match` expression that compares the values of the outer `x` and -`y`, rather than introducing a shadowed variable, we would need to use a match -guard conditional instead. We’ll talk about match guards in “Extra Conditionals -with Match Guards” on page XX. - -### Multiple Patterns - -In `match` expressions, you can match multiple patterns using the `|` syntax, -which is the pattern *or* operator. For example, in the following code we match -the value of `x` against the match arms, the first of which has an *or* option, -meaning if the value of `x` matches either of the values in that arm, that -arm’s code will run: - -Filename: src/main.rs - -``` -let x = 1; - -match x { - 1 | 2 => println!("one or two"), - 3 => println!("three"), - _ => println!("anything"), -} -``` - -This code prints `one or two`. + 1 let mut post = Post::new(); -### Matching Ranges of Values with ..= + 2 post.add_text("I ate a salad for lunch today"); + 3 assert_eq!("", post.content()); -The `..=` syntax allows us to match to an inclusive range of values. In the -following code, when a pattern matches any of the values within the given -range, that arm will execute: - -Filename: src/main.rs - -``` -let x = 5; + 4 post.request_review(); + 5 assert_eq!("", post.content()); -match x { - 1..=5 => println!("one through five"), - _ => println!("something else"), + 6 post.approve(); + 7 assert_eq!("I ate a salad for lunch today", post.content()); } ``` -If `x` is `1`, `2`, `3`, `4`, or `5`, the first arm will match. This syntax is -more convenient for multiple match values than using the `|` operator to -express the same idea; if we were to use `|`, we would have to specify `1 | 2 | -3 | 4 | 5`. Specifying a range is much shorter, especially if we want to match, -say, any number between 1 and 1,000! +Listing 17-11: Code that demonstrates the desired behavior we want our `blog` +crate to have -The compiler checks that the range isn’t empty at compile time, and because the -only types for which Rust can tell if a range is empty or not are `char` and -numeric values, ranges are only allowed with numeric or `char` values. - -Here is an example using ranges of `char` values: - -Filename: src/main.rs - -``` -let x = 'c'; - -match x { - 'a'..='j' => println!("early ASCII letter"), - 'k'..='z' => println!("late ASCII letter"), - _ => println!("something else"), -} -``` +We want to allow the user to create a new draft blog post with `Post::new` [1]. +We want to allow text to be added to the blog post [2]. If we try to get the +post’s content immediately, before approval, we shouldn’t get any text because +the post is still a draft. We’ve added `assert_eq!` in the code for +demonstration purposes [3]. An excellent unit test for this would be to assert +that a draft blog post returns an empty string from the `content` method, but +we’re not going to write tests for this example. -Rust can tell that `'c'` is within the first pattern’s range and prints `early -ASCII letter`. +Next, we want to enable a request for a review of the post [4], and we want +`content` to return an empty string while waiting for the review [5]. When the +post receives approval [6], it should get published, meaning the text of the +post will be returned when `content` is called [7]. -### Destructuring to Break Apart Values +Notice that the only type we’re interacting with from the crate is the `Post` +type. This type will use the state pattern and will hold a value that will be +one of three state objects representing the various states a post can be +in—draft, review, or published. Changing from one state to another will be +managed internally within the `Post` type. The states change in response to the +methods called by our library’s users on the `Post` instance, but they don’t +have to manage the state changes directly. Also, users can’t make a mistake +with the states, such as publishing a post before it’s reviewed. -We can also use patterns to destructure structs, enums, and tuples to use -different parts of these values. Let’s walk through each value. +### Defining Post and Creating a New Instance in the Draft State -#### Destructuring Structs +Let’s get started on the implementation of the library! We know we need a +public `Post` struct that holds some content, so we’ll start with the +definition of the struct and an associated public `new` function to create an +instance of `Post`, as shown in Listing 17-12. We’ll also make a private +`State` trait that will define the behavior that all state objects for a `Post` +must have. -Listing 18-12 shows a `Point` struct with two fields, `x` and `y`, that we can -break apart using a pattern with a `let` statement. +Then `Post` will hold a trait object of `Box<dyn State>` inside an `Option<T>` +in a private field named `state` to hold the state object. You’ll see why the +`Option<T>` is necessary in a bit. -Filename: src/main.rs +Filename: src/lib.rs ``` -struct Point { - x: i32, - y: i32, +pub struct Post { + state: Option<Box<dyn State>>, + content: String, } -fn main() { - let p = Point { x: 0, y: 7 }; - - let Point { x: a, y: b } = p; - assert_eq!(0, a); - assert_eq!(7, b); +impl Post { + pub fn new() -> Post { + Post { + 1 state: Some(Box::new(Draft {})), + 2 content: String::new(), + } + } } -``` - -Listing 18-12: Destructuring a struct’s fields into separate variables -This code creates the variables `a` and `b` that match the values of the `x` -and `y` fields of the `p` struct. This example shows that the names of the -variables in the pattern don’t have to match the field names of the struct. -However, it’s common to match the variable names to the field names to make it -easier to remember which variables came from which fields. Because of this -common usage, and because writing `let Point { x: x, y: y } = p;` contains a -lot of duplication, Rust has a shorthand for patterns that match struct fields: -you only need to list the name of the struct field, and the variables created -from the pattern will have the same names. Listing 18-13 behaves in the same -way as the code in Listing 18-12, but the variables created in the `let` -pattern are `x` and `y` instead of `a` and `b`. +trait State {} -Filename: src/main.rs +struct Draft {} +impl State for Draft {} ``` -struct Point { - x: i32, - y: i32, -} -fn main() { - let p = Point { x: 0, y: 7 }; - - let Point { x, y } = p; - assert_eq!(0, x); - assert_eq!(7, y); -} -``` +Listing 17-12: Definition of a `Post` struct and a `new` function that creates +a new `Post` instance, a `State` trait, and a `Draft` struct -Listing 18-13: Destructuring struct fields using struct field shorthand +The `State` trait defines the behavior shared by different post states. The +state objects are `Draft`, `PendingReview`, and `Published`, and they will all +implement the `State` trait. For now, the trait doesn’t have any methods, and +we’ll start by defining just the `Draft` state because that is the state we +want a post to start in. -This code creates the variables `x` and `y` that match the `x` and `y` fields -of the `p` variable. The outcome is that the variables `x` and `y` contain the -values from the `p` struct. +When we create a new `Post`, we set its `state` field to a `Some` value that +holds a `Box` [1]. This `Box` points to a new instance of the `Draft` struct. +This ensures that whenever we create a new instance of `Post`, it will start +out as a draft. Because the `state` field of `Post` is private, there is no way +to create a `Post` in any other state! In the `Post::new` function, we set the +`content` field to a new, empty `String` [2]. -We can also destructure with literal values as part of the struct pattern -rather than creating variables for all the fields. Doing so allows us to test -some of the fields for particular values while creating variables to -destructure the other fields. +### Storing the Text of the Post Content -In Listing 18-14, we have a `match` expression that separates `Point` values -into three cases: points that lie directly on the `x` axis (which is true when -`y = 0`), on the `y` axis (`x = 0`), or on neither axis. +We saw in Listing 17-11 that we want to be able to call a method named +`add_text` and pass it a `&str` that is then added as the text content of the +blog post. We implement this as a method, rather than exposing the `content` +field as `pub`, so that later we can implement a method that will control how +the `content` field’s data is read. The `add_text` method is pretty +straightforward, so let’s add the implementation in Listing 17-13 to the `impl +Post` block. -Filename: src/main.rs +Filename: src/lib.rs ``` -fn main() { - let p = Point { x: 0, y: 7 }; - - match p { - Point { x, y: 0 } => println!("On the x axis at {x}"), - Point { x: 0, y } => println!("On the y axis at {y}"), - Point { x, y } => { - println!("On neither axis: ({x}, {y})"); - } +impl Post { + --snip-- + pub fn add_text(&mut self, text: &str) { + self.content.push_str(text); } } ``` -Listing 18-14: Destructuring and matching literal values in one pattern +Listing 17-13: Implementing the `add_text` method to add text to a post’s +`content` -The first arm will match any point that lies on the `x` axis by specifying that -the `y` field matches if its value matches the literal `0`. The pattern still -creates an `x` variable that we can use in the code for this arm. +The `add_text` method takes a mutable reference to `self` because we’re +changing the `Post` instance that we’re calling `add_text` on. We then call +`push_str` on the `String` in `content` and pass the `text` argument to add to +the saved `content`. This behavior doesn’t depend on the state the post is in, +so it’s not part of the state pattern. The `add_text` method doesn’t interact +with the `state` field at all, but it is part of the behavior we want to +support. -Similarly, the second arm matches any point on the `y` axis by specifying that -the `x` field matches if its value is `0` and creates a variable `y` for the -value of the `y` field. The third arm doesn’t specify any literals, so it -matches any other `Point` and creates variables for both the `x` and `y` fields. +### Ensuring the Content of a Draft Post Is Empty -In this example, the value `p` matches the second arm by virtue of `x` -containing a `0`, so this code will print `On the y axis at 7`. +Even after we’ve called `add_text` and added some content to our post, we still +want the `content` method to return an empty string slice because the post is +still in the draft state, as shown at [3] in Listing 17-11. For now, let’s +implement the `content` method with the simplest thing that will fulfill this +requirement: always returning an empty string slice. We’ll change this later +once we implement the ability to change a post’s state so it can be published. +So far, posts can only be in the draft state, so the post content should always +be empty. Listing 17-14 shows this placeholder implementation. -Remember that a `match` expression stops checking arms once it has found the -first matching pattern, so even though `Point { x: 0, y: 0}` is on the `x` axis -and the `y` axis, this code would only print `On the x axis at 0`. - -#### Destructuring Enums - -We’ve destructured enums in this book (for example, Listing 6-5), but we -haven’t yet explicitly discussed that the pattern to destructure an enum -corresponds to the way the data stored within the enum is defined. As an -example, in Listing 18-15 we use the `Message` enum from Listing 6-2 and write -a `match` with patterns that will destructure each inner value. - -Filename: src/main.rs +Filename: src/lib.rs ``` -enum Message { - Quit, - Move { x: i32, y: i32 }, - Write(String), - ChangeColor(i32, i32, i32), -} - -fn main() { - 1 let msg = Message::ChangeColor(0, 160, 255); - - match msg { - 2 Message::Quit => { - println!( - "The Quit variant has no data to destructure." - ); - } - 3 Message::Move { x, y } => { - println!( - "Move in the x dir {x}, in the y dir {y}" - ); - } - 4 Message::Write(text) => { - println!("Text message: {text}"); - } - 5 Message::ChangeColor(r, g, b) => println!( - "Change color to red {r}, green {g}, and blue {b}" - ), +impl Post { + --snip-- + pub fn content(&self) -> &str { + "" } } ``` -Listing 18-15: Destructuring enum variants that hold different kinds of values - -This code will print `Change color to red 0, green 160, and blue 255`. Try -changing the value of `msg` [1] to see the code from the other arms run. +Listing 17-14: Adding a placeholder implementation for the `content` method on +`Post` that always returns an empty string slice -For enum variants without any data, like `Message::Quit` [2], we can’t -destructure the value any further. We can only match on the literal -`Message::Quit` value, and no variables are in that pattern. +With this added `content` method, everything in Listing 17-11 up to the line at +[3] works as intended. -For struct-like enum variants, such as `Message::Move` [3], we can use a -pattern similar to the pattern we specify to match structs. After the variant -name, we place curly brackets and then list the fields with variables so we -break apart the pieces to use in the code for this arm. Here we use the -shorthand form as we did in Listing 18-13. +### Requesting a Review Changes the Post’s State -For tuple-like enum variants, like `Message::Write` that holds a tuple with one -element [4] and `Message::ChangeColor` that holds a tuple with three elements -[5], the pattern is similar to the pattern we specify to match tuples. The -number of variables in the pattern must match the number of elements in the -variant we’re matching. +Next, we need to add functionality to request a review of a post, which should +change its state from `Draft` to `PendingReview`. Listing 17-15 shows this code. -#### Destructuring Nested Structs and Enums - -So far, our examples have all been matching structs or enums one level deep, -but matching can work on nested items too! For example, we can refactor the -code in Listing 18-15 to support RGB and HSV colors in the `ChangeColor` -message, as shown in Listing 18-16. - -Filename: src/main.rs +Filename: src/lib.rs ``` -enum Color { - Rgb(i32, i32, i32), - Hsv(i32, i32, i32), +impl Post { + --snip-- + 1 pub fn request_review(&mut self) { + 2 if let Some(s) = self.state.take() { + 3 self.state = Some(s.request_review()) + } + } } -enum Message { - Quit, - Move { x: i32, y: i32 }, - Write(String), - ChangeColor(Color), +trait State { + 4 fn request_review(self: Box<Self>) -> Box<dyn State>; } -fn main() { - let msg = Message::ChangeColor(Color::Hsv(0, 160, 255)); - - match msg { - Message::ChangeColor(Color::Rgb(r, g, b)) => println!( - "Change color to red {r}, green {g}, and blue {b}" - ), - Message::ChangeColor(Color::Hsv(h, s, v)) => println!( - "Change color to hue {h}, saturation {s}, value {v}" - ), - _ => (), +struct Draft {} + +impl State for Draft { + fn request_review(self: Box<Self>) -> Box<dyn State> { + 5 Box::new(PendingReview {}) } } -``` - -Listing 18-16: Matching on nested enums - -The pattern of the first arm in the `match` expression matches a -`Message::ChangeColor` enum variant that contains a `Color::Rgb` variant; then -the pattern binds to the three inner `i32` values. The pattern of the second -arm also matches a `Message::ChangeColor` enum variant, but the inner enum -matches `Color::Hsv` instead. We can specify these complex conditions in one -`match` expression, even though two enums are involved. - -#### Destructuring Structs and Tuples -We can mix, match, and nest destructuring patterns in even more complex ways. -The following example shows a complicated destructure where we nest structs and -tuples inside a tuple and destructure all the primitive values out: +struct PendingReview {} +impl State for PendingReview { + fn request_review(self: Box<Self>) -> Box<dyn State> { + 6 self + } +} ``` -let ((feet, inches), Point { x, y }) = - ((3, 10), Point { x: 3, y: -10 }); -``` - -This code lets us break complex types into their component parts so we can use -the values we’re interested in separately. -Destructuring with patterns is a convenient way to use pieces of values, such -as the value from each field in a struct, separately from each other. - -### Ignoring Values in a Pattern - -You’ve seen that it’s sometimes useful to ignore values in a pattern, such as -in the last arm of a `match`, to get a catchall that doesn’t actually do -anything but does account for all remaining possible values. There are a few -ways to ignore entire values or parts of values in a pattern: using the `_` -pattern (which you’ve seen), using the `_` pattern within another pattern, -using a name that starts with an underscore, or using `..` to ignore remaining -parts of a value. Let’s explore how and why to use each of these patterns. - -#### An Entire Value with _ - -We’ve used the underscore as a wildcard pattern that will match any value but -not bind to the value. This is especially useful as the last arm in a `match` -expression, but we can also use it in any pattern, including function -parameters, as shown in Listing 18-17. - -Filename: src/main.rs - -``` -fn foo(_: i32, y: i32) { - println!("This code only uses the y parameter: {y}"); +Listing 17-15: Implementing `request_review` methods on `Post` and the `State` +trait + +We give `Post` a public method named `request_review` that will take a mutable +reference to `self` [1]. Then we call an internal `request_review` method on +the current state of `Post` [3], and this second `request_review` method +consumes the current state and returns a new state. + +We add the `request_review` method to the `State` trait [4]; all types that +implement the trait will now need to implement the `request_review` method. +Note that rather than having `self`, `&self`, or `&mut self` as the first +parameter of the method, we have `self: Box<Self>`. This syntax means the +method is only valid when called on a `Box` holding the type. This syntax takes +ownership of `Box<Self>`, invalidating the old state so the state value of the +`Post` can transform into a new state. + +To consume the old state, the `request_review` method needs to take ownership +of the state value. This is where the `Option` in the `state` field of `Post` +comes in: we call the `take` method to take the `Some` value out of the `state` +field and leave a `None` in its place because Rust doesn’t let us have +unpopulated fields in structs [2]. This lets us move the `state` value out of +`Post` rather than borrowing it. Then we’ll set the post’s `state` value to the +result of this operation. + +We need to set `state` to `None` temporarily rather than setting it directly +with code like `self.state = self.state.request_review();` to get ownership of +the `state` value. This ensures `Post` can’t use the old `state` value after +we’ve transformed it into a new state. + +The `request_review` method on `Draft` returns a new, boxed instance of a new +`PendingReview` struct [5], which represents the state when a post is waiting +for a review. The `PendingReview` struct also implements the `request_review` +method but doesn’t do any transformations. Rather, it returns itself [6] +because when we request a review on a post already in the `PendingReview` +state, it should stay in the `PendingReview` state. + +Now we can start seeing the advantages of the state pattern: the +`request_review` method on `Post` is the same no matter its `state` value. Each +state is responsible for its own rules. + +We’ll leave the `content` method on `Post` as is, returning an empty string +slice. We can now have a `Post` in the `PendingReview` state as well as in the +`Draft` state, but we want the same behavior in the `PendingReview` state. +Listing 17-11 now works up to the line at [5]! + +### Adding approve to Change the Behavior of content + +The `approve` method will be similar to the `request_review` method: it will +set `state` to the value that the current state says it should have when that +state is approved, as shown in Listing 17-16. + +Filename: src/lib.rs + +``` +impl Post { + --snip-- + pub fn approve(&mut self) { + if let Some(s) = self.state.take() { + self.state = Some(s.approve()) + } + } } -fn main() { - foo(3, 4); +trait State { + fn request_review(self: Box<Self>) -> Box<dyn State>; + fn approve(self: Box<Self>) -> Box<dyn State>; } -``` - -Listing 18-17: Using `_` in a function signature -This code will completely ignore the value `3` passed as the first argument, -and will print `This code only uses the y parameter: 4`. +struct Draft {} -In most cases when you no longer need a particular function parameter, you -would change the signature so it doesn’t include the unused parameter. Ignoring -a function parameter can be especially useful in cases when, for example, -you’re implementing a trait when you need a certain type signature but the -function body in your implementation doesn’t need one of the parameters. You -then avoid getting a compiler warning about unused function parameters, as you -would if you used a name instead. - -#### Parts of a Value with a Nested _ +impl State for Draft { + --snip-- + fn approve(self: Box<Self>) -> Box<dyn State> { + 1 self + } +} -We can also use `_` inside another pattern to ignore just part of a value, for -example, when we want to test for only part of a value but have no use for the -other parts in the corresponding code we want to run. Listing 18-18 shows code -responsible for managing a setting’s value. The business requirements are that -the user should not be allowed to overwrite an existing customization of a -setting but can unset the setting and give it a value if it is currently unset. +struct PendingReview {} -Filename: src/main.rs +impl State for PendingReview { + --snip-- + fn approve(self: Box<Self>) -> Box<dyn State> { + 2 Box::new(Published {}) + } +} -``` -let mut setting_value = Some(5); -let new_setting_value = Some(10); +struct Published {} -match (setting_value, new_setting_value) { - (Some(_), Some(_)) => { - println!("Can't overwrite an existing customized value"); +impl State for Published { + fn request_review(self: Box<Self>) -> Box<dyn State> { + self } - _ => { - setting_value = new_setting_value; + + fn approve(self: Box<Self>) -> Box<dyn State> { + self } } - -println!("setting is {:?}", setting_value); ``` -Listing 18-18: Using an underscore within patterns that match `Some` variants -when we don’t need to use the value inside the `Some` +Listing 17-16: Implementing the `approve` method on `Post` and the `State` trait -This code will print `Can't overwrite an existing customized value` and then -`setting is Some(5)`. In the first match arm, we don’t need to match on or use -the values inside either `Some` variant, but we do need to test for the case -when `setting_value` and `new_setting_value` are the `Some` variant. In that -case, we print the reason for not changing `setting_value`, and it doesn’t get -changed. +We add the `approve` method to the `State` trait and add a new struct that +implements `State`, the `Published` state. -In all other cases (if either `setting_value` or `new_setting_value` is `None`) -expressed by the `_` pattern in the second arm, we want to allow -`new_setting_value` to become `setting_value`. +Similar to the way `request_review` on `PendingReview` works, if we call the +`approve` method on a `Draft`, it will have no effect because `approve` will +return `self` [1]. When we call `approve` on `PendingReview`, it returns a new, +boxed instance of the `Published` struct [2]. The `Published` struct implements +the `State` trait, and for both the `request_review` method and the `approve` +method, it returns itself because the post should stay in the `Published` state +in those cases. -We can also use underscores in multiple places within one pattern to ignore -particular values. Listing 18-19 shows an example of ignoring the second and -fourth values in a tuple of five items. +Now we need to update the `content` method on `Post`. We want the value +returned from `content` to depend on the current state of the `Post`, so we’re +going to have the `Post` delegate to a `content` method defined on its `state`, +as shown in Listing 17-17. -Filename: src/main.rs +Filename: src/lib.rs ``` -let numbers = (2, 4, 8, 16, 32); - -match numbers { - (first, _, third, _, fifth) => { - println!("Some numbers: {first}, {third}, {fifth}"); +impl Post { + --snip-- + pub fn content(&self) -> &str { + self.state.as_ref().unwrap().content(self) } + --snip-- } ``` -Listing 18-19: Ignoring multiple parts of a tuple +Listing 17-17: Updating the `content` method on `Post` to delegate to a +`content` method on `State` -This code will print `Some numbers: 2, 8, 32`, and the values `4` and `16` will -be ignored. +Because the goal is to keep all of these rules inside the structs that +implement `State`, we call a `content` method on the value in `state` and pass +the post instance (that is, `self`) as an argument. Then we return the value +that’s returned from using the `content` method on the `state` value. -#### An Unused Variable by Starting Its Name with _ +We call the `as_ref` method on the `Option` because we want a reference to the +value inside the `Option` rather than ownership of the value. Because `state` +is an `Option<Box<dyn State>>`, when we call `as_ref`, an `Option<&Box<dyn +State>>` is returned. If we didn’t call `as_ref`, we would get an error because +we can’t move `state` out of the borrowed `&self` of the function parameter. -If you create a variable but don’t use it anywhere, Rust will usually issue a -warning because an unused variable could be a bug. However, sometimes it’s -useful to be able to create a variable you won’t use yet, such as when you’re -prototyping or just starting a project. In this situation, you can tell Rust -not to warn you about the unused variable by starting the name of the variable -with an underscore. In Listing 18-20, we create two unused variables, but when -we compile this code, we should only get a warning about one of them. +We then call the `unwrap` method, which we know will never panic because we +know the methods on `Post` ensure that `state` will always contain a `Some` +value when those methods are done. This is one of the cases we talked about in +“Cases in Which You Have More Information Than the Compiler” on page XX when we +know that a `None` value is never possible, even though the compiler isn’t able +to understand that. -Filename: src/main.rs +At this point, when we call `content` on the `&Box<dyn State>`, deref coercion +will take effect on the `&` and the `Box` so the `content` method will +ultimately be called on the type that implements the `State` trait. That means +we need to add `content` to the `State` trait definition, and that is where +we’ll put the logic for what content to return depending on which state we +have, as shown in Listing 17-18. + +Filename: src/lib.rs ``` -fn main() { - let _x = 5; - let y = 10; +trait State { + --snip-- + fn content<'a>(&self, post: &'a Post) -> &'a str { + 1 "" + } } -``` - -Listing 18-20: Starting a variable name with an underscore to avoid getting -unused variable warnings -Here, we get a warning about not using the variable `y`, but we don’t get a -warning about not using `_x`. +--snip-- +struct Published {} -Note that there is a subtle difference between using only `_` and using a name -that starts with an underscore. The syntax `_x` still binds the value to the -variable, whereas `_` doesn’t bind at all. To show a case where this -distinction matters, Listing 18-21 will provide us with an error. - -Filename: src/main.rs - -``` -let s = Some(String::from("Hello!")); - -if let Some(_s) = s { - println!("found a string"); +impl State for Published { + --snip-- + fn content<'a>(&self, post: &'a Post) -> &'a str { + 2 &post.content + } } - -println!("{:?}", s); ``` -Listing 18-21: An unused variable starting with an underscore still binds the -value, which might take ownership of the value. - -We’ll receive an error because the `s` value will still be moved into `_s`, -which prevents us from using `s` again. However, using the underscore by itself -doesn’t ever bind to the value. Listing 18-22 will compile without any errors -because `s` doesn’t get moved into `_`. +Listing 17-18: Adding the `content` method to the `State` trait + +We add a default implementation for the `content` method that returns an empty +string slice [1]. That means we don’t need to implement `content` on the +`Draft` and `PendingReview` structs. The `Published` struct will override the +`content` method and return the value in `post.content` [2]. + +Note that we need lifetime annotations on this method, as we discussed in +Chapter 10. We’re taking a reference to a `post` as an argument and returning a +reference to part of that `post`, so the lifetime of the returned reference is +related to the lifetime of the `post` argument. + +And we’re done—all of Listing 17-11 now works! We’ve implemented the state +pattern with the rules of the blog post workflow. The logic related to the +rules lives in the state objects rather than being scattered throughout `Post`. + +> ### Why Not An Enum? +> +> You may have been wondering why we didn’t use an `enum` with the different +possible post states as variants. That’s certainly a possible solution; try it +and compare the end results to see which you prefer! One disadvantage of using +an enum is that every place that checks the value of the enum will need a +`match` expression or similar to handle every possible variant. This could get +more repetitive than this trait object solution. + +### Trade-offs of the State Pattern + +We’ve shown that Rust is capable of implementing the object-oriented state +pattern to encapsulate the different kinds of behavior a post should have in +each state. The methods on `Post` know nothing about the various behaviors. The +way we organized the code, we have to look in only one place to know the +different ways a published post can behave: the implementation of the `State` +trait on the `Published` struct. + +If we were to create an alternative implementation that didn’t use the state +pattern, we might instead use `match` expressions in the methods on `Post` or +even in the `main` code that checks the state of the post and changes behavior +in those places. That would mean we would have to look in several places to +understand all the implications of a post being in the published state! This +would only increase the more states we added: each of those `match` expressions +would need another arm. + +With the state pattern, the `Post` methods and the places we use `Post` don’t +need `match` expressions, and to add a new state, we would only need to add a +new struct and implement the trait methods on that one struct. + +The implementation using the state pattern is easy to extend to add more +functionality. To see the simplicity of maintaining code that uses the state +pattern, try a few of these suggestions: + +* Add a `reject` method that changes the post’s state from `PendingReview` back +to `Draft`. +* Require two calls to `approve` before the state can be changed to `Published`. +* Allow users to add text content only when a post is in the `Draft` state. +Hint: have the state object responsible for what might change about the content +but not responsible for modifying the `Post`. + +One downside of the state pattern is that, because the states implement the +transitions between states, some of the states are coupled to each other. If we +add another state between `PendingReview` and `Published`, such as `Scheduled`, +we would have to change the code in `PendingReview` to transition to +`Scheduled` instead. It would be less work if `PendingReview` didn’t need to +change with the addition of a new state, but that would mean switching to +another design pattern. + +Another downside is that we’ve duplicated some logic. To eliminate some of the +duplication, we might try to make default implementations for the +`request_review` and `approve` methods on the `State` trait that return `self`. +However, this wouldn’t work: when using `State` as a trait object, the trait +doesn’t know what the concrete `self` will be exactly, so the return type isn’t +known at compile time. + +Other duplication includes the similar implementations of the `request_review` +and `approve` methods on `Post`. Both methods delegate to the implementation of +the same method on the value in the `state` field of `Option` and set the new +value of the `state` field to the result. If we had a lot of methods on `Post` +that followed this pattern, we might consider defining a macro to eliminate the +repetition (see “Macros” on page XX). + +By implementing the state pattern exactly as it’s defined for object-oriented +languages, we’re not taking as full advantage of Rust’s strengths as we could. +Let’s look at some changes we can make to the `blog` crate that can make +invalid states and transitions into compile-time errors. + +#### Encoding States and Behavior as Types + +We’ll show you how to rethink the state pattern to get a different set of +trade-offs. Rather than encapsulating the states and transitions completely so +outside code has no knowledge of them, we’ll encode the states into different +types. Consequently, Rust’s type checking system will prevent attempts to use +draft posts where only published posts are allowed by issuing a compiler error. + +Let’s consider the first part of `main` in Listing 17-11: Filename: src/main.rs ``` -let s = Some(String::from("Hello!")); +fn main() { + let mut post = Post::new(); -if let Some(_) = s { - println!("found a string"); + post.add_text("I ate a salad for lunch today"); + assert_eq!("", post.content()); } - -println!("{:?}", s); ``` -Listing 18-22: Using an underscore does not bind the value. - -This code works just fine because we never bind `s` to anything; it isn’t moved. - -#### Remaining Parts of a Value with .. +We still enable the creation of new posts in the draft state using `Post::new` +and the ability to add text to the post’s content. But instead of having a +`content` method on a draft post that returns an empty string, we’ll make it so +draft posts don’t have the `content` method at all. That way, if we try to get +a draft post’s content, we’ll get a compiler error telling us the method +doesn’t exist. As a result, it will be impossible for us to accidentally +display draft post content in production because that code won’t even compile. +Listing 17-19 shows the definition of a `Post` struct and a `DraftPost` struct, +as well as methods on each. -With values that have many parts, we can use the `..` syntax to use specific -parts and ignore the rest, avoiding the need to list underscores for each -ignored value. The `..` pattern ignores any parts of a value that we haven’t -explicitly matched in the rest of the pattern. In Listing 18-23, we have a -`Point` struct that holds a coordinate in three-dimensional space. In the -`match` expression, we want to operate only on the `x` coordinate and ignore -the values in the `y` and `z` fields. - -Filename: src/main.rs +Filename: src/lib.rs ``` -struct Point { - x: i32, - y: i32, - z: i32, +pub struct Post { + content: String, } -let origin = Point { x: 0, y: 0, z: 0 }; - -match origin { - Point { x, .. } => println!("x is {x}"), +pub struct DraftPost { + content: String, } -``` - -Listing 18-23: Ignoring all fields of a `Point` except for `x` by using `..` - -We list the `x` value and then just include the `..` pattern. This is quicker -than having to list `y: _` and `z: _`, particularly when we’re working with -structs that have lots of fields in situations where only one or two fields are -relevant. - -The syntax `..` will expand to as many values as it needs to be. Listing 18-24 -shows how to use `..` with a tuple. - -Filename: src/main.rs -``` -fn main() { - let numbers = (2, 4, 8, 16, 32); - - match numbers { - (first, .., last) => { - println!("Some numbers: {first}, {last}"); +impl Post { + 1 pub fn new() -> DraftPost { + DraftPost { + content: String::new(), } } -} -``` - -Listing 18-24: Matching only the first and last values in a tuple and ignoring -all other values - -In this code, the first and last values are matched with `first` and `last`. -The `..` will match and ignore everything in the middle. - -However, using `..` must be unambiguous. If it is unclear which values are -intended for matching and which should be ignored, Rust will give us an error. -Listing 18-25 shows an example of using `..` ambiguously, so it will not -compile. -Filename: src/main.rs - -``` -fn main() { - let numbers = (2, 4, 8, 16, 32); + 2 pub fn content(&self) -> &str { + &self.content + } +} - match numbers { - (.., second, ..) => { - println!("Some numbers: {second}"); - }, +impl DraftPost { + 3 pub fn add_text(&mut self, text: &str) { + self.content.push_str(text); } } ``` -Listing 18-25: An attempt to use `..` in an ambiguous way +Listing 17-19: A `Post` with a `content` method and a `DraftPost` without a +`content` method -When we compile this example, we get this error: +Both the `Post` and `DraftPost` structs have a private `content` field that +stores the blog post text. The structs no longer have the `state` field because +we’re moving the encoding of the state to the types of the structs. The `Post` +struct will represent a published post, and it has a `content` method that +returns the `content` [2]. -``` -error: `..` can only be used once per tuple pattern - --> src/main.rs:5:22 - | -5 | (.., second, ..) => { - | -- ^^ can only be used once per tuple pattern - | | - | previously used here -``` +We still have a `Post::new` function, but instead of returning an instance of +`Post`, it returns an instance of `DraftPost` [1]. Because `content` is private +and there aren’t any functions that return `Post`, it’s not possible to create +an instance of `Post` right now. -It’s impossible for Rust to determine how many values in the tuple to ignore -before matching a value with `second` and then how many further values to -ignore thereafter. This code could mean that we want to ignore `2`, bind -`second` to `4`, and then ignore `8`, `16`, and `32`; or that we want to ignore -`2` and `4`, bind `second` to `8`, and then ignore `16` and `32`; and so forth. -The variable name `second` doesn’t mean anything special to Rust, so we get a -compiler error because using `..` in two places like this is ambiguous. +The `DraftPost` struct has an `add_text` method, so we can add text to +`content` as before [3], but note that `DraftPost` does not have a `content` +method defined! So now the program ensures all posts start as draft posts, and +draft posts don’t have their content available for display. Any attempt to get +around these constraints will result in a compiler error. -### Extra Conditionals with Match Guards +#### Implementing Transitions as Transformations into Different Types -A *match guard* is an additional `if` condition, specified after the pattern in -a `match` arm, that must also match for that arm to be chosen. Match guards are -useful for expressing more complex ideas than a pattern alone allows. +So how do we get a published post? We want to enforce the rule that a draft +post has to be reviewed and approved before it can be published. A post in the +pending review state should still not display any content. Let’s implement +these constraints by adding another struct, `PendingReviewPost`, defining the +`request_review` method on `DraftPost` to return a `PendingReviewPost` and +defining an `approve` method on `PendingReviewPost` to return a `Post`, as +shown in Listing 17-20. -The condition can use variables created in the pattern. Listing 18-26 shows a -`match` where the first arm has the pattern `Some(x)` and also has a match -guard of `if x % 2 == 0` (which will be `true` if the number is even). - -Filename: src/main.rs +Filename: src/lib.rs ``` -let num = Some(4); - -match num { - Some(x) if x % 2 == 0 => println!("The number {x} is even"), - Some(x) => println!("The number {x} is odd"), - None => (), +impl DraftPost { + --snip-- + pub fn request_review(self) -> PendingReviewPost { + PendingReviewPost { + content: self.content, + } + } } -``` - -Listing 18-26: Adding a match guard to a pattern - -This example will print `The number 4 is even`. When `num` is compared to the -pattern in the first arm, it matches because `Some(4)` matches `Some(x)`. Then -the match guard checks whether the remainder of dividing `x` by 2 is equal to -0, and because it is, the first arm is selected. -If `num` had been `Some(5)` instead, the match guard in the first arm would -have been `false` because the remainder of 5 divided by 2 is 1, which is not -equal to 0. Rust would then go to the second arm, which would match because the -second arm doesn’t have a match guard and therefore matches any `Some` variant. - -There is no way to express the `if x % 2 == 0` condition within a pattern, so -the match guard gives us the ability to express this logic. The downside of -this additional expressiveness is that the compiler doesn’t try to check for -exhaustiveness when match guard expressions are involved. - -In Listing 18-11, we mentioned that we could use match guards to solve our -pattern-shadowing problem. Recall that we created a new variable inside the -pattern in the `match` expression instead of using the variable outside the -`match`. That new variable meant we couldn’t test against the value of the -outer variable. Listing 18-27 shows how we can use a match guard to fix this -problem. - -Filename: src/main.rs - -``` -fn main() { - let x = Some(5); - let y = 10; +pub struct PendingReviewPost { + content: String, +} - match x { - Some(50) => println!("Got 50"), - Some(n) if n == y => println!("Matched, n = {n}"), - _ => println!("Default case, x = {:?}", x), +impl PendingReviewPost { + pub fn approve(self) -> Post { + Post { + content: self.content, + } } - - println!("at the end: x = {:?}, y = {y}", x); } ``` -Listing 18-27: Using a match guard to test for equality with an outer variable - -This code will now print `Default case, x = Some(5)`. The pattern in the second -match arm doesn’t introduce a new variable `y` that would shadow the outer `y`, -meaning we can use the outer `y` in the match guard. Instead of specifying the -pattern as `Some(y)`, which would have shadowed the outer `y`, we specify -`Some(n)`. This creates a new variable `n` that doesn’t shadow anything because -there is no `n` variable outside the `match`. - -The match guard `if n == y` is not a pattern and therefore doesn’t introduce -new variables. This `y` *is* the outer `y` rather than a new shadowed `y`, and -we can look for a value that has the same value as the outer `y` by comparing -`n` to `y`. - -You can also use the *or* operator `|` in a match guard to specify multiple -patterns; the match guard condition will apply to all the patterns. Listing -18-28 shows the precedence when combining a pattern that uses `|` with a match -guard. The important part of this example is that the `if y` match guard -applies to `4`, `5`, *and* `6`, even though it might look like `if y` only -applies to `6`. +Listing 17-20: A `PendingReviewPost` that gets created by calling +`request_review` on `DraftPost` and an `approve` method that turns a +`PendingReviewPost` into a published `Post` + +The `request_review` and `approve` methods take ownership of `self`, thus +consuming the `DraftPost` and `PendingReviewPost` instances and transforming +them into a `PendingReviewPost` and a published `Post`, respectively. This way, +we won’t have any lingering `DraftPost` instances after we’ve called +`request_review` on them, and so forth. The `PendingReviewPost` struct doesn’t +have a `content` method defined on it, so attempting to read its content +results in a compiler error, as with `DraftPost`. Because the only way to get a +published `Post` instance that does have a `content` method defined is to call +the `approve` method on a `PendingReviewPost`, and the only way to get a +`PendingReviewPost` is to call the `request_review` method on a `DraftPost`, +we’ve now encoded the blog post workflow into the type system. + +But we also have to make some small changes to `main`. The `request_review` and +`approve` methods return new instances rather than modifying the struct they’re +called on, so we need to add more `let post =` shadowing assignments to save +the returned instances. We also can’t have the assertions about the draft and +pending review posts’ contents be empty strings, nor do we need them: we can’t +compile code that tries to use the content of posts in those states any longer. +The updated code in `main` is shown in Listing 17-21. Filename: src/main.rs ``` -let x = 4; -let y = false; - -match x { - 4 | 5 | 6 if y => println!("yes"), - _ => println!("no"), -} -``` - -Listing 18-28: Combining multiple patterns with a match guard - -The match condition states that the arm only matches if the value of `x` is -equal to `4`, `5`, or `6` *and* if `y` is `true`. When this code runs, the -pattern of the first arm matches because `x` is `4`, but the match guard `if y` -is `false`, so the first arm is not chosen. The code moves on to the second -arm, which does match, and this program prints `no`. The reason is that the -`if` condition applies to the whole pattern `4 | 5 | 6`, not just to the last -value `6`. In other words, the precedence of a match guard in relation to a -pattern behaves like this: - -``` -(4 | 5 | 6) if y => ... -``` - -rather than this: - -``` -4 | 5 | (6 if y) => ... -``` - -After running the code, the precedence behavior is evident: if the match guard -were applied only to the final value in the list of values specified using the -`|` operator, the arm would have matched and the program would have printed -`yes`. +use blog::Post; -### @ Bindings - -The *at* operator `@` lets us create a variable that holds a value at the same -time we’re testing that value for a pattern match. In Listing 18-29, we want to -test that a `Message::Hello` `id` field is within the range `3..=7`. We also -want to bind the value to the variable `id_variable` so we can use it in the -code associated with the arm. We could name this variable `id`, the same as the -field, but for this example we’ll use a different name. +fn main() { + let mut post = Post::new(); -Filename: src/main.rs + post.add_text("I ate a salad for lunch today"); -``` -enum Message { - Hello { id: i32 }, -} + let post = post.request_review(); -let msg = Message::Hello { id: 5 }; + let post = post.approve(); -match msg { - Message::Hello { - id: id_variable @ 3..=7, - } => println!("Found an id in range: {id_variable}"), - Message::Hello { id: 10..=12 } => { - println!("Found an id in another range") - } - Message::Hello { id } => println!("Some other id: {id}"), + assert_eq!("I ate a salad for lunch today", post.content()); } ``` -Listing 18-29: Using `@` to bind to a value in a pattern while also testing it +Listing 17-21: Modifications to `main` to use the new implementation of the +blog post workflow -This example will print `Found an id in range: 5`. By specifying `id_variable -@` before the range `3..=7`, we’re capturing whatever value matched the range -while also testing that the value matched the range pattern. +The changes we needed to make to `main` to reassign `post` mean that this +implementation doesn’t quite follow the object-oriented state pattern anymore: +the transformations between the states are no longer encapsulated entirely +within the `Post` implementation. However, our gain is that invalid states are +now impossible because of the type system and the type checking that happens at +compile time! This ensures that certain bugs, such as display of the content of +an unpublished post, will be discovered before they make it to production. -In the second arm, where we only have a range specified in the pattern, the -code associated with the arm doesn’t have a variable that contains the actual -value of the `id` field. The `id` field’s value could have been 10, 11, or 12, -but the code that goes with that pattern doesn’t know which it is. The pattern -code isn’t able to use the value from the `id` field because we haven’t saved -the `id` value in a variable. +Try the tasks suggested at the start of this section on the `blog` crate as it +is after Listing 17-21 to see what you think about the design of this version +of the code. Note that some of the tasks might be completed already in this +design. -In the last arm, where we’ve specified a variable without a range, we do have -the value available to use in the arm’s code in a variable named `id`. The -reason is that we’ve used the struct field shorthand syntax. But we haven’t -applied any test to the value in the `id` field in this arm, as we did with the -first two arms: any value would match this pattern. - -Using `@` lets us test a value and save it in a variable within one pattern. +We’ve seen that even though Rust is capable of implementing object-oriented +design patterns, other patterns, such as encoding state into the type system, +are also available in Rust. These patterns have different trade-offs. Although +you might be very familiar with object-oriented patterns, rethinking the +problem to take advantage of Rust’s features can provide benefits, such as +preventing some bugs at compile time. Object-oriented patterns won’t always be +the best solution in Rust due to certain features, like ownership, that +object-oriented languages don’t have. ## Summary -Rust’s patterns are very useful in distinguishing between different kinds of -data. When used in `match` expressions, Rust ensures your patterns cover every -possible value, or your program won’t compile. Patterns in `let` statements and -function parameters make those constructs more useful, enabling the -destructuring of values into smaller parts at the same time as assigning to -variables. We can create simple or complex patterns to suit our needs. - -Next, for the penultimate chapter of the book, we’ll look at some advanced -aspects of a variety of Rust’s features. +Regardless of whether you think Rust is an object-oriented language after +reading this chapter, you now know that you can use trait objects to get some +object-oriented features in Rust. Dynamic dispatch can give your code some +flexibility in exchange for a bit of runtime performance. You can use this +flexibility to implement object-oriented patterns that can help your code’s +maintainability. Rust also has other features, like ownership, that +object-oriented languages don’t have. An object-oriented pattern won’t always +be the best way to take advantage of Rust’s strengths, but it is an available +option. + +Next, we’ll look at patterns, which are another of Rust’s features that enable +lots of flexibility. We’ve looked at them briefly throughout the book but +haven’t seen their full capability yet. Let’s go! diff --git a/nostarch/chapter19.md b/nostarch/chapter19.md index 410e7eb62d..40c7f10a1c 100644 --- a/nostarch/chapter19.md +++ b/nostarch/chapter19.md @@ -6,2291 +6,1287 @@ directory, so all fixes need to be made in `/src/`. [TOC] -# Advanced Features - -By now, you’ve learned the most commonly used parts of the Rust programming -language. Before we do one more project, in Chapter 20, we’ll look at a few -aspects of the language you might run into every once in a while, but may not -use every day. You can use this chapter as a reference for when you encounter -any unknowns. The features covered here are useful in very specific situations. -Although you might not reach for them often, we want to make sure you have a -grasp of all the features Rust has to offer. - -In this chapter, we’ll cover: - -* Unsafe Rust: how to opt out of some of Rust’s guarantees and take -responsibility for manually upholding those guarantees -* Advanced traits: associated types, default type parameters, fully qualified -syntax, supertraits, and the newtype pattern in relation to traits -* Advanced types: more about the newtype pattern, type aliases, the never type, -and dynamically sized types -* Advanced functions and closures: function pointers and returning closures -* Macros: ways to define code that defines more code at compile time - -It’s a panoply of Rust features with something for everyone! Let’s dive in! - -## Unsafe Rust - -All the code we’ve discussed so far has had Rust’s memory safety guarantees -enforced at compile time. However, Rust has a second language hidden inside it -that doesn’t enforce these memory safety guarantees: it’s called *unsafe Rust* -and works just like regular Rust, but gives us extra superpowers. - -Unsafe Rust exists because, by nature, static analysis is conservative. When -the compiler tries to determine whether or not code upholds the guarantees, -it’s better for it to reject some valid programs than to accept some invalid -programs. Although the code *might* be okay, if the Rust compiler doesn’t have -enough information to be confident, it will reject the code. In these cases, -you can use unsafe code to tell the compiler, “Trust me, I know what I’m -doing.” Be warned, however, that you use unsafe Rust at your own risk: if you -use unsafe code incorrectly, problems can occur due to memory unsafety, such as -null pointer dereferencing. - -Another reason Rust has an unsafe alter ego is that the underlying computer -hardware is inherently unsafe. If Rust didn’t let you do unsafe operations, you -couldn’t do certain tasks. Rust needs to allow you to do low-level systems -programming, such as directly interacting with the operating system or even -writing your own operating system. Working with low-level systems programming -is one of the goals of the language. Let’s explore what we can do with unsafe -Rust and how to do it. - -### Unsafe Superpowers - -To switch to unsafe Rust, use the `unsafe` keyword and then start a new block -that holds the unsafe code. You can take five actions in unsafe Rust that you -can’t in safe Rust, which we call *unsafe superpowers*. Those superpowers -include the ability to: - -1. Dereference a raw pointer -1. Call an unsafe function or method -1. Access or modify a mutable static variable -1. Implement an unsafe trait -1. Access fields of `union`s - -It’s important to understand that `unsafe` doesn’t turn off the borrow checker -or disable any of Rust’s other safety checks: if you use a reference in unsafe -code, it will still be checked. The `unsafe` keyword only gives you access to -these five features that are then not checked by the compiler for memory -safety. You’ll still get some degree of safety inside an unsafe block. - -In addition, `unsafe` does not mean the code inside the block is necessarily -dangerous or that it will definitely have memory safety problems: the intent is -that as the programmer, you’ll ensure the code inside an `unsafe` block will -access memory in a valid way. - -People are fallible and mistakes will happen, but by requiring these five -unsafe operations to be inside blocks annotated with `unsafe`, you’ll know that -any errors related to memory safety must be within an `unsafe` block. Keep -`unsafe` blocks small; you’ll be thankful later when you investigate memory -bugs. - -To isolate unsafe code as much as possible, it’s best to enclose such code -within a safe abstraction and provide a safe API, which we’ll discuss later in -the chapter when we examine unsafe functions and methods. Parts of the standard -library are implemented as safe abstractions over unsafe code that has been -audited. Wrapping unsafe code in a safe abstraction prevents uses of `unsafe` -from leaking out into all the places that you or your users might want to use -the functionality implemented with `unsafe` code, because using a safe -abstraction is safe. - -Let’s look at each of the five unsafe superpowers in turn. We’ll also look at -some abstractions that provide a safe interface to unsafe code. - -### Dereferencing a Raw Pointer - -In “Dangling References” on page XX, we mentioned that the compiler ensures -references are always valid. Unsafe Rust has two new types called *raw -pointers* that are similar to references. As with references, raw pointers can -be immutable or mutable and are written as `*const T` and `*mut T`, -respectively. The asterisk isn’t the dereference operator; it’s part of the -type name. In the context of raw pointers, *immutable* means that the pointer -can’t be directly assigned to after being dereferenced. - -Different from references and smart pointers, raw pointers: - -* Are allowed to ignore the borrowing rules by having both immutable and -mutable pointers or multiple mutable pointers to the same location -* Aren’t guaranteed to point to valid memory -* Are allowed to be null -* Don’t implement any automatic cleanup +# Patterns and Matching -By opting out of having Rust enforce these guarantees, you can give up -guaranteed safety in exchange for greater performance or the ability to -interface with another language or hardware where Rust’s guarantees don’t apply. +*Patterns* are a special syntax in Rust for matching against the structure of +types, both complex and simple. Using patterns in conjunction with `match` +expressions and other constructs gives you more control over a program’s +control flow. A pattern consists of some combination of the following: -Listing 19-1 shows how to create an immutable and a mutable raw pointer from -references. - -``` -let mut num = 5; - -let r1 = &num as *const i32; -let r2 = &mut num as *mut i32; -``` +* Literals +* Destructured arrays, enums, structs, or tuples +* Variables +* Wildcards +* Placeholders -Listing 19-1: Creating raw pointers from references +Some example patterns include `x`, `(a, 3)`, and `Some(Color::Red)`. In the +contexts in which patterns are valid, these components describe the shape of +data. Our program then matches values against the patterns to determine whether +it has the correct shape of data to continue running a particular piece of code. -Notice that we don’t include the `unsafe` keyword in this code. We can create -raw pointers in safe code; we just can’t dereference raw pointers outside an -unsafe block, as you’ll see in a bit. +To use a pattern, we compare it to some value. If the pattern matches the +value, we use the value parts in our code. Recall the `match` expressions in +Chapter 6 that used patterns, such as the coin-sorting machine example. If the +value fits the shape of the pattern, we can use the named pieces. If it +doesn’t, the code associated with the pattern won’t run. -We’ve created raw pointers by using `as` to cast an immutable and a mutable -reference into their corresponding raw pointer types. Because we created them -directly from references guaranteed to be valid, we know these particular raw -pointers are valid, but we can’t make that assumption about just any raw -pointer. +This chapter is a reference on all things related to patterns. We’ll cover the +valid places to use patterns, the difference between refutable and irrefutable +patterns, and the different kinds of pattern syntax that you might see. By the +end of the chapter, you’ll know how to use patterns to express many concepts in +a clear way. -To demonstrate this, next we’ll create a raw pointer whose validity we can’t be -so certain of. Listing 19-2 shows how to create a raw pointer to an arbitrary -location in memory. Trying to use arbitrary memory is undefined: there might be -data at that address or there might not, the compiler might optimize the code -so there is no memory access, or the program might terminate with a -segmentation fault. Usually, there is no good reason to write code like this, -but it is possible. +## All the Places Patterns Can Be Used -``` -let address = 0x012345usize; -let r = address as *const i32; -``` +Patterns pop up in a number of places in Rust, and you’ve been using them a lot +without realizing it! This section discusses all the places where patterns are +valid. -Listing 19-2: Creating a raw pointer to an arbitrary memory address +### match Arms -Recall that we can create raw pointers in safe code, but we can’t *dereference* -raw pointers and read the data being pointed to. In Listing 19-3, we use the -dereference operator `*` on a raw pointer that requires an `unsafe` block. +As discussed in Chapter 6, we use patterns in the arms of `match` expressions. +Formally, `match` expressions are defined as the keyword `match`, a value to +match on, and one or more match arms that consist of a pattern and an +expression to run if the value matches that arm’s pattern, like this: ``` -let mut num = 5; - -let r1 = &num as *const i32; -let r2 = &mut num as *mut i32; - -unsafe { - println!("r1 is: {}", *r1); - println!("r2 is: {}", *r2); +match VALUE { + PATTERN => EXPRESSION, + PATTERN => EXPRESSION, + PATTERN => EXPRESSION, } ``` -Listing 19-3: Dereferencing raw pointers within an `unsafe` block - -Creating a pointer does no harm; it’s only when we try to access the value that -it points at that we might end up dealing with an invalid value. - -Note also that in Listings 19-1 and 19-3, we created `*const i32` and `*mut -i32` raw pointers that both pointed to the same memory location, where `num` is -stored. If we instead tried to create an immutable and a mutable reference to -`num`, the code would not have compiled because Rust’s ownership rules don’t -allow a mutable reference at the same time as any immutable references. With -raw pointers, we can create a mutable pointer and an immutable pointer to the -same location and change data through the mutable pointer, potentially creating -a data race. Be careful! - -With all of these dangers, why would you ever use raw pointers? One major use -case is when interfacing with C code, as you’ll see in “Calling an Unsafe -Function or Method” on page XX. Another case is when building up safe -abstractions that the borrow checker doesn’t understand. We’ll introduce unsafe -functions and then look at an example of a safe abstraction that uses unsafe -code. - -### Calling an Unsafe Function or Method - -The second type of operation you can perform in an unsafe block is calling -unsafe functions. Unsafe functions and methods look exactly like regular -functions and methods, but they have an extra `unsafe` before the rest of the -definition. The `unsafe` keyword in this context indicates the function has -requirements we need to uphold when we call this function, because Rust can’t -guarantee we’ve met these requirements. By calling an unsafe function within an -`unsafe` block, we’re saying that we’ve read this function’s documentation and -we take responsibility for upholding the function’s contracts. - -Here is an unsafe function named `dangerous` that doesn’t do anything in its -body: - -``` -unsafe fn dangerous() {} - -unsafe { - dangerous(); -} -``` - -We must call the `dangerous` function within a separate `unsafe` block. If we -try to call `dangerous` without the `unsafe` block, we’ll get an error: - -``` -error[E0133]: call to unsafe function is unsafe and requires -unsafe function or block - --> src/main.rs:4:5 - | -4 | dangerous(); - | ^^^^^^^^^^^ call to unsafe function - | - = note: consult the function's documentation for information on -how to avoid undefined behavior -``` - -With the `unsafe` block, we’re asserting to Rust that we’ve read the function’s -documentation, we understand how to use it properly, and we’ve verified that -we’re fulfilling the contract of the function. - -Bodies of unsafe functions are effectively `unsafe` blocks, so to perform other -unsafe operations within an unsafe function, we don’t need to add another -`unsafe` block. - -#### Creating a Safe Abstraction over Unsafe Code - -Just because a function contains unsafe code doesn’t mean we need to mark the -entire function as unsafe. In fact, wrapping unsafe code in a safe function is -a common abstraction. As an example, let’s study the `split_at_mut` function -from the standard library, which requires some unsafe code. We’ll explore how -we might implement it. This safe method is defined on mutable slices: it takes -one slice and makes it two by splitting the slice at the index given as an -argument. Listing 19-4 shows how to use `split_at_mut`. - -``` -let mut v = vec![1, 2, 3, 4, 5, 6]; - -let r = &mut v[..]; - -let (a, b) = r.split_at_mut(3); +For example, here’s the `match` expression from Listing 6-5 that matches on an +`Option<i32>` value in the variable `x`: -assert_eq!(a, &mut [1, 2, 3]); -assert_eq!(b, &mut [4, 5, 6]); ``` - -Listing 19-4: Using the safe `split_at_mut` function - -We can’t implement this function using only safe Rust. An attempt might look -something like Listing 19-5, which won’t compile. For simplicity, we’ll -implement `split_at_mut` as a function rather than a method and only for slices -of `i32` values rather than for a generic type `T`. - -``` -fn split_at_mut( - values: &mut [i32], - mid: usize, -) -> (&mut [i32], &mut [i32]) { - let len = values.len(); - - assert!(mid <= len); - - (&mut values[..mid], &mut values[mid..]) +match x { + None => None, + Some(i) => Some(i + 1), } ``` -Listing 19-5: An attempted implementation of `split_at_mut` using only safe Rust - -This function first gets the total length of the slice. Then it asserts that -the index given as a parameter is within the slice by checking whether it’s -less than or equal to the length. The assertion means that if we pass an index -that is greater than the length to split the slice at, the function will panic -before it attempts to use that index. - -Then we return two mutable slices in a tuple: one from the start of the -original slice to the `mid` index and another from `mid` to the end of the -slice. - -When we try to compile the code in Listing 19-5, we’ll get an error: - -``` -error[E0499]: cannot borrow `*values` as mutable more than once at a time - --> src/main.rs:9:31 - | -2 | values: &mut [i32], - | - let's call the lifetime of this reference `'1` -... -9 | (&mut values[..mid], &mut values[mid..]) - | --------------------------^^^^^^-------- - | | | | - | | | second mutable borrow occurs here - | | first mutable borrow occurs here - | returning this value requires that `*values` is borrowed for `'1` -``` - -Rust’s borrow checker can’t understand that we’re borrowing different parts of -the slice; it only knows that we’re borrowing from the same slice twice. -Borrowing different parts of a slice is fundamentally okay because the two -slices aren’t overlapping, but Rust isn’t smart enough to know this. When we -know code is okay, but Rust doesn’t, it’s time to reach for unsafe code. - -Listing 19-6 shows how to use an `unsafe` block, a raw pointer, and some calls -to unsafe functions to make the implementation of `split_at_mut` work. - -``` -use std::slice; - -fn split_at_mut( - values: &mut [i32], - mid: usize, -) -> (&mut [i32], &mut [i32]) { - 1 let len = values.len(); - 2 let ptr = values.as_mut_ptr(); - - 3 assert!(mid <= len); - - 4 unsafe { - ( - 5 slice::from_raw_parts_mut(ptr, mid), - 6 slice::from_raw_parts_mut(ptr.add(mid), len - mid), - ) - } -} -``` +The patterns in this `match` expression are the `None` and `Some(i)` to the +left of each arrow. -Listing 19-6: Using unsafe code in the implementation of the `split_at_mut` -function - -Recall from “The Slice Type” on page XX that a slice is a pointer to some data -and the length of the slice. We use the `len` method to get the length of a -slice [1] and the `as_mut_ptr` method to access the raw pointer of a slice [2]. -In this case, because we have a mutable slice to `i32` values, `as_mut_ptr` -returns a raw pointer with the type `*mut i32`, which we’ve stored in the -variable `ptr`. - -We keep the assertion that the `mid` index is within the slice [3]. Then we get -to the unsafe code [4]: the `slice::from_raw_parts_mut` function takes a raw -pointer and a length, and it creates a slice. We use it to create a slice that -starts from `ptr` and is `mid` items long [5]. Then we call the `add` method on -`ptr` with `mid` as an argument to get a raw pointer that starts at `mid`, and -we create a slice using that pointer and the remaining number of items after -`mid` as the length [6]. - -The function `slice::from_raw_parts_mut` is unsafe because it takes a raw -pointer and must trust that this pointer is valid. The `add` method on raw -pointers is also unsafe because it must trust that the offset location is also -a valid pointer. Therefore, we had to put an `unsafe` block around our calls to -`slice::from_raw_parts_mut` and `add` so we could call them. By looking at the -code and by adding the assertion that `mid` must be less than or equal to -`len`, we can tell that all the raw pointers used within the `unsafe` block -will be valid pointers to data within the slice. This is an acceptable and -appropriate use of `unsafe`. - -Note that we don’t need to mark the resultant `split_at_mut` function as -`unsafe`, and we can call this function from safe Rust. We’ve created a safe -abstraction to the unsafe code with an implementation of the function that uses -`unsafe` code in a safe way, because it creates only valid pointers from the -data this function has access to. - -In contrast, the use of `slice::from_raw_parts_mut` in Listing 19-7 would -likely crash when the slice is used. This code takes an arbitrary memory -location and creates a slice 10,000 items long. - -``` -use std::slice; - -let address = 0x01234usize; -let r = address as *mut i32; - -let values: &[i32] = unsafe { - slice::from_raw_parts_mut(r, 10000) -}; -``` +One requirement for `match` expressions is that they need to be *exhaustive* in +the sense that all possibilities for the value in the `match` expression must +be accounted for. One way to ensure you’ve covered every possibility is to have +a catchall pattern for the last arm: for example, a variable name matching any +value can never fail and thus covers every remaining case. -Listing 19-7: Creating a slice from an arbitrary memory location +The particular pattern `_` will match anything, but it never binds to a +variable, so it’s often used in the last match arm. The `_` pattern can be +useful when you want to ignore any value not specified, for example. We’ll +cover the `_` pattern in more detail in “Ignoring Values in a Pattern” on page +XX. -We don’t own the memory at this arbitrary location, and there is no guarantee -that the slice this code creates contains valid `i32` values. Attempting to use -`values` as though it’s a valid slice results in undefined behavior. +### Conditional if let Expressions -#### Using extern Functions to Call External Code +In Chapter 6, we discussed how to use `if let` expressions mainly as a shorter +way to write the equivalent of a `match` that only matches one case. +Optionally, `if let` can have a corresponding `else` containing code to run if +the pattern in the `if let` doesn’t match. -Sometimes your Rust code might need to interact with code written in another -language. For this, Rust has the keyword `extern` that facilitates the creation -and use of a *Foreign Function Interface* *(FFI)*, which is a way for a -programming language to define functions and enable a different (foreign) -programming language to call those functions. +Listing 18-1 shows that it’s also possible to mix and match `if let`, `else +if`, and `else if let` expressions. Doing so gives us more flexibility than a +`match` expression in which we can express only one value to compare with the +patterns. Also, Rust doesn’t require that the conditions in a series of `if +let`, `else if`, and `else if let` arms relate to each other. -Listing 19-8 demonstrates how to set up an integration with the `abs` function -from the C standard library. Functions declared within `extern` blocks are -always unsafe to call from Rust code. The reason is that other languages don’t -enforce Rust’s rules and guarantees, and Rust can’t check them, so -responsibility falls on the programmer to ensure safety. +The code in Listing 18-1 determines what color to make your background based on +a series of checks for several conditions. For this example, we’ve created +variables with hardcoded values that a real program might receive from user +input. Filename: src/main.rs ``` -extern "C" { - fn abs(input: i32) -> i32; -} - fn main() { - unsafe { - println!( - "Absolute value of -3 according to C: {}", - abs(-3) + let favorite_color: Option<&str> = None; + let is_tuesday = false; + let age: Result<u8, _> = "34".parse(); + + 1 if let Some(color) = favorite_color { + 2 println!( + "Using your favorite, {color}, as the background" ); + 3 } else if is_tuesday { + 4 println!("Tuesday is green day!"); + 5 } else if let Ok(age) = age { + 6 if age > 30 { + 7 println!("Using purple as the background color"); + } else { + 8 println!("Using orange as the background color"); + } + 9 } else { + 10 println!("Using blue as the background color"); } } ``` -Listing 19-8: Declaring and calling an `extern` function defined in another -language - -Within the `extern "C"` block, we list the names and signatures of external -functions from another language we want to call. The `"C"` part defines which -*application binary interface* *(ABI)* the external function uses: the ABI -defines how to call the function at the assembly level. The `"C"` ABI is the -most common and follows the C programming language’s ABI. - -> ### Calling Rust Functions from Other Languages -> -> We can also use `extern` to create an interface that allows other languages -to call Rust functions. Instead of creating a whole `extern` block, we add the -`extern` keyword and specify the ABI to use just before the `fn` keyword for -the relevant function. We also need to add a `#[no_mangle]` annotation to tell -the Rust compiler not to mangle the name of this function. *Mangling* is when a -compiler changes the name we’ve given a function to a different name that -contains more information for other parts of the compilation process to consume -but is less human readable. Every programming language compiler mangles names -slightly differently, so for a Rust function to be nameable by other languages, -we must disable the Rust compiler’s name mangling. -> -> In the following example, we make the `call_from_c` function accessible from -C code, after it’s compiled to a shared library and linked from C: -> -> ``` -> #[no_mangle] -> pub extern "C" fn call_from_c() { -> println!("Just called a Rust function from C!"); -> } -> ``` -> -> This usage of `extern` does not require `unsafe`. - -### Accessing or Modifying a Mutable Static Variable - -In this book, we’ve not yet talked about global variables, which Rust does -support but can be problematic with Rust’s ownership rules. If two threads are -accessing the same mutable global variable, it can cause a data race. - -In Rust, global variables are called *static* variables. Listing 19-9 shows an -example declaration and use of a static variable with a string slice as a value. +Listing 18-1: Mixing `if let`, `else if`, `else if let`, and `else` -Filename: src/main.rs +If the user specifies a favorite color [1], that color is used as the +background [2]. If no favorite color is specified and today is Tuesday [3], the +background color is green [4]. Otherwise, if the user specifies their age as a +string and we can parse it as a number successfully [5], the color is either +purple [7] or orange [8] depending on the value of the number [6]. If none of +these conditions apply [9], the background color is blue [10]. -``` -static HELLO_WORLD: &str = "Hello, world!"; +This conditional structure lets us support complex requirements. With the +hardcoded values we have here, this example will print `Using purple as the +background color`. -fn main() { - println!("value is: {HELLO_WORLD}"); -} -``` +You can see that `if let` can also introduce shadowed variables in the same way +that `match` arms can: the line `if let Ok(age) = age` [5] introduces a new +shadowed `age` variable that contains the value inside the `Ok` variant. This +means we need to place the `if age > 30` condition [6] within that block: we +can’t combine these two conditions into `if let Ok(age) = age && age > 30`. The +shadowed `age` we want to compare to 30 isn’t valid until the new scope starts +with the curly bracket. -Listing 19-9: Defining and using an immutable static variable +The downside of using `if let` expressions is that the compiler doesn’t check +for exhaustiveness, whereas with `match` expressions it does. If we omitted the +last `else` block [9] and therefore missed handling some cases, the compiler +would not alert us to the possible logic bug. -Static variables are similar to constants, which we discussed in “Constants” on -page XX. The names of static variables are in `SCREAMING_SNAKE_CASE` by -convention. Static variables can only store references with the `'static` -lifetime, which means the Rust compiler can figure out the lifetime and we -aren’t required to annotate it explicitly. Accessing an immutable static -variable is safe. +### while let Conditional Loops -A subtle difference between constants and immutable static variables is that -values in a static variable have a fixed address in memory. Using the value -will always access the same data. Constants, on the other hand, are allowed to -duplicate their data whenever they’re used. Another difference is that static -variables can be mutable. Accessing and modifying mutable static variables is -*unsafe*. Listing 19-10 shows how to declare, access, and modify a mutable -static variable named `COUNTER`. +Similar in construction to `if let`, the `while let` conditional loop allows a +`while` loop to run for as long as a pattern continues to match. In Listing +18-2, we code a `while let` loop that uses a vector as a stack and prints the +values in the vector in the opposite order in which they were pushed. Filename: src/main.rs ``` -static mut COUNTER: u32 = 0; +let mut stack = Vec::new(); -fn add_to_count(inc: u32) { - unsafe { - COUNTER += inc; - } -} - -fn main() { - add_to_count(3); +stack.push(1); +stack.push(2); +stack.push(3); - unsafe { - println!("COUNTER: {COUNTER}"); - } +while let Some(top) = stack.pop() { + println!("{top}"); } ``` -Listing 19-10: Reading from or writing to a mutable static variable is unsafe. +Listing 18-2: Using a `while let` loop to print values for as long as +`stack.pop()` returns `Some` -As with regular variables, we specify mutability using the `mut` keyword. Any -code that reads or writes from `COUNTER` must be within an `unsafe` block. This -code compiles and prints `COUNTER: 3` as we would expect because it’s single -threaded. Having multiple threads access `COUNTER` would likely result in data -races. +This example prints `3`, `2`, and then `1`. The `pop` method takes the last +element out of the vector and returns `Some(value)`. If the vector is empty, +`pop` returns `None`. The `while` loop continues running the code in its block +as long as `pop` returns `Some`. When `pop` returns `None`, the loop stops. We +can use `while let` to pop every element off our stack. -With mutable data that is globally accessible, it’s difficult to ensure there -are no data races, which is why Rust considers mutable static variables to be -unsafe. Where possible, it’s preferable to use the concurrency techniques and -thread-safe smart pointers we discussed in Chapter 16 so the compiler checks -that data access from different threads is done safely. +### for Loops -### Implementing an Unsafe Trait +In a `for` loop, the value that directly follows the keyword `for` is a +pattern. For example, in `for x in y`, the `x` is the pattern. Listing 18-3 +demonstrates how to use a pattern in a `for` loop to *destructure*, or break +apart, a tuple as part of the `for` loop. -We can use `unsafe` to implement an unsafe trait. A trait is unsafe when at -least one of its methods has some invariant that the compiler can’t verify. We -declare that a trait is `unsafe` by adding the `unsafe` keyword before `trait` -and marking the implementation of the trait as `unsafe` too, as shown in -Listing 19-11. +Filename: src/main.rs ``` -unsafe trait Foo { - // methods go here -} +let v = vec!['a', 'b', 'c']; -unsafe impl Foo for i32 { - // method implementations go here +for (index, value) in v.iter().enumerate() { + println!("{value} is at index {index}"); } ``` -Listing 19-11: Defining and implementing an unsafe trait - -By using `unsafe impl`, we’re promising that we’ll uphold the invariants that -the compiler can’t verify. - -As an example, recall the `Send` and `Sync` marker traits we discussed in -“Extensible Concurrency with the Send and Sync Traits” on page XX: the compiler -implements these traits automatically if our types are composed entirely of -`Send` and `Sync` types. If we implement a type that contains a type that is -not `Send` or `Sync`, such as raw pointers, and we want to mark that type as -`Send` or `Sync`, we must use `unsafe`. Rust can’t verify that our type upholds -the guarantees that it can be safely sent across threads or accessed from -multiple threads; therefore, we need to do those checks manually and indicate -as such with `unsafe`. - -### Accessing Fields of a Union - -The final action that works only with `unsafe` is accessing fields of a union. -A `union` is similar to a `struct`, but only one declared field is used in a -particular instance at one time. Unions are primarily used to interface with -unions in C code. Accessing union fields is unsafe because Rust can’t guarantee -the type of the data currently being stored in the union instance. You can -learn more about unions in the Rust Reference at -*https://doc.rust-lang.org/reference/items/unions.html**.* +Listing 18-3: Using a pattern in a `for` loop to destructure a tuple -### When to Use Unsafe Code - -Using `unsafe` to use one of the five superpowers just discussed isn’t wrong or -even frowned upon, but it is trickier to get `unsafe` code correct because the -compiler can’t help uphold memory safety. When you have a reason to use -`unsafe` code, you can do so, and having the explicit `unsafe` annotation makes -it easier to track down the source of problems when they occur. - -## Advanced Traits - -We first covered traits in “Traits: Defining Shared Behavior” on page XX, but -we didn’t discuss the more advanced details. Now that you know more about Rust, -we can get into the nitty-gritty. - -### Associated Types - -*Associated types* connect a type placeholder with a trait such that the trait -method definitions can use these placeholder types in their signatures. The -implementor of a trait will specify the concrete type to be used instead of the -placeholder type for the particular implementation. That way, we can define a -trait that uses some types without needing to know exactly what those types are -until the trait is implemented. - -We’ve described most of the advanced features in this chapter as being rarely -needed. Associated types are somewhere in the middle: they’re used more rarely -than features explained in the rest of the book but more commonly than many of -the other features discussed in this chapter. - -One example of a trait with an associated type is the `Iterator` trait that the -standard library provides. The associated type is named `Item` and stands in -for the type of the values the type implementing the `Iterator` trait is -iterating over. The definition of the `Iterator` trait is as shown in Listing -19-12. +The code in Listing 18-3 will print the following: ``` -pub trait Iterator { - type Item; - - fn next(&mut self) -> Option<Self::Item>; -} +a is at index 0 +b is at index 1 +c is at index 2 ``` -Listing 19-12: The definition of the `Iterator` trait that has an associated -type `Item` +We adapt an iterator using the `enumerate` method so it produces a value and +the index for that value, placed into a tuple. The first value produced is the +tuple `(0, 'a')`. When this value is matched to the pattern `(index, value)`, +`index` will be `0` and `value` will be `'a'`, printing the first line of the +output. -The type `Item` is a placeholder, and the `next` method’s definition shows that -it will return values of type `Option<Self::Item>`. Implementors of the -`Iterator` trait will specify the concrete type for `Item`, and the `next` -method will return an `Option` containing a value of that concrete type. +### let Statements -Associated types might seem like a similar concept to generics, in that the -latter allow us to define a function without specifying what types it can -handle. To examine the difference between the two concepts, we’ll look at an -implementation of the `Iterator` trait on a type named `Counter` that specifies -the `Item` type is `u32`: - -Filename: src/lib.rs +Prior to this chapter, we had only explicitly discussed using patterns with +`match` and `if let`, but in fact, we’ve used patterns in other places as well, +including in `let` statements. For example, consider this straightforward +variable assignment with `let`: ``` -impl Iterator for Counter { - type Item = u32; - - fn next(&mut self) -> Option<Self::Item> { - --snip-- +let x = 5; ``` -This syntax seems comparable to that of generics. So why not just define the -`Iterator` trait with generics, as shown in Listing 19-13? +Every time you’ve used a `let` statement like this you’ve been using patterns, +although you might not have realized it! More formally, a `let` statement looks +like this: ``` -pub trait Iterator<T> { - fn next(&mut self) -> Option<T>; -} +let PATTERN = EXPRESSION; ``` -Listing 19-13: A hypothetical definition of the `Iterator` trait using generics - -The difference is that when using generics, as in Listing 19-13, we must -annotate the types in each implementation; because we can also implement -`Iterator<``String``> for Counter` or any other type, we could have multiple -implementations of `Iterator` for `Counter`. In other words, when a trait has a -generic parameter, it can be implemented for a type multiple times, changing -the concrete types of the generic type parameters each time. When we use the -`next` method on `Counter`, we would have to provide type annotations to -indicate which implementation of `Iterator` we want to use. - -With associated types, we don’t need to annotate types because we can’t -implement a trait on a type multiple times. In Listing 19-12 with the -definition that uses associated types, we can choose what the type of `Item` -will be only once because there can be only one `impl Iterator for Counter`. We -don’t have to specify that we want an iterator of `u32` values everywhere we -call `next` on `Counter`. - -Associated types also become part of the trait’s contract: implementors of the -trait must provide a type to stand in for the associated type placeholder. -Associated types often have a name that describes how the type will be used, -and documenting the associated type in the API documentation is a good practice. - -### Default Generic Type Parameters and Operator Overloading - -When we use generic type parameters, we can specify a default concrete type for -the generic type. This eliminates the need for implementors of the trait to -specify a concrete type if the default type works. You specify a default type -when declaring a generic type with the `<`PlaceholderType`=`ConcreteType`>` -syntax. - -A great example of a situation where this technique is useful is with *operator -overloading*, in which you customize the behavior of an operator (such as `+`) -in particular situations. - -Rust doesn’t allow you to create your own operators or overload arbitrary -operators. But you can overload the operations and corresponding traits listed -in `std::ops` by implementing the traits associated with the operator. For -example, in Listing 19-14 we overload the `+` operator to add two `Point` -instances together. We do this by implementing the `Add` trait on a `Point` -struct. +In statements like `let x = 5;` with a variable name in the PATTERN slot, the +variable name is just a particularly simple form of a pattern. Rust compares +the expression against the pattern and assigns any names it finds. So, in the +`let x = 5;` example, `x` is a pattern that means “bind what matches here to +the variable `x`.” Because the name `x` is the whole pattern, this pattern +effectively means “bind everything to the variable `x`, whatever the value is.” -Filename: src/main.rs +To see the pattern-matching aspect of `let` more clearly, consider Listing +18-4, which uses a pattern with `let` to destructure a tuple. ``` -use std::ops::Add; - -#[derive(Debug, Copy, Clone, PartialEq)] -struct Point { - x: i32, - y: i32, -} - -impl Add for Point { - type Output = Point; - - fn add(self, other: Point) -> Point { - Point { - x: self.x + other.x, - y: self.y + other.y, - } - } -} - -fn main() { - assert_eq!( - Point { x: 1, y: 0 } + Point { x: 2, y: 3 }, - Point { x: 3, y: 3 } - ); -} +let (x, y, z) = (1, 2, 3); ``` -Listing 19-14: Implementing the `Add` trait to overload the `+` operator for -`Point` instances +Listing 18-4: Using a pattern to destructure a tuple and create three variables +at once -The `add` method adds the `x` values of two `Point` instances and the `y` -values of two `Point` instances to create a new `Point`. The `Add` trait has an -associated type named `Output` that determines the type returned from the `add` -method. +Here, we match a tuple against a pattern. Rust compares the value `(1, 2, 3)` +to the pattern `(x, y, z)` and sees that the value matches the pattern, in that +it sees that the number of elements is the same in both, so Rust binds `1` to +`x`, `2` to `y`, and `3` to `z`. You can think of this tuple pattern as nesting +three individual variable patterns inside it. -The default generic type in this code is within the `Add` trait. Here is its -definition: +If the number of elements in the pattern doesn’t match the number of elements +in the tuple, the overall type won’t match and we’ll get a compiler error. For +example, Listing 18-5 shows an attempt to destructure a tuple with three +elements into two variables, which won’t work. ``` -trait Add<Rhs=Self> { - type Output; - - fn add(self, rhs: Rhs) -> Self::Output; -} +let (x, y) = (1, 2, 3); ``` -This code should look generally familiar: a trait with one method and an -associated type. The new part is `Rhs=Self`: this syntax is called *default -type parameters*. The `Rhs` generic type parameter (short for “right-hand -side”) defines the type of the `rhs` parameter in the `add` method. If we don’t -specify a concrete type for `Rhs` when we implement the `Add` trait, the type -of `Rhs` will default to `Self`, which will be the type we’re implementing -`Add` on. +Listing 18-5: Incorrectly constructing a pattern whose variables don’t match +the number of elements in the tuple -When we implemented `Add` for `Point`, we used the default for `Rhs` because we -wanted to add two `Point` instances. Let’s look at an example of implementing -the `Add` trait where we want to customize the `Rhs` type rather than using the -default. - -We have two structs, `Millimeters` and `Meters`, holding values in different -units. This thin wrapping of an existing type in another struct is known as the -*newtype pattern*, which we describe in more detail in “Using the Newtype -Pattern to Implement External Traits on External Types” on page XX. We want to -add values in millimeters to values in meters and have the implementation of -`Add` do the conversion correctly. We can implement `Add` for `Millimeters` -with `Meters` as the `Rhs`, as shown in Listing 19-15. - -Filename: src/lib.rs +Attempting to compile this code results in this type error: ``` -use std::ops::Add; - -struct Millimeters(u32); -struct Meters(u32); - -impl Add<Meters> for Millimeters { - type Output = Millimeters; - - fn add(self, other: Meters) -> Millimeters { - Millimeters(self.0 + (other.0 * 1000)) - } -} +error[E0308]: mismatched types + --> src/main.rs:2:9 + | +2 | let (x, y) = (1, 2, 3); + | ^^^^^^ --------- this expression has type `({integer}, {integer}, +{integer})` + | | + | expected a tuple with 3 elements, found one with 2 elements + | + = note: expected tuple `({integer}, {integer}, {integer})` + found tuple `(_, _)` ``` -Listing 19-15: Implementing the `Add` trait on `Millimeters` to add -`Millimeters` and `Meters` - -To add `Millimeters` and `Meters`, we specify `impl Add<Meters>` to set the -value of the `Rhs` type parameter instead of using the default of `Self`. - -You’ll use default type parameters in two main ways: - -1. To extend a type without breaking existing code -1. To allow customization in specific cases most users won’t need +To fix the error, we could ignore one or more of the values in the tuple using +`_` or `..`, as you’ll see in “Ignoring Values in a Pattern” on page XX. If the +problem is that we have too many variables in the pattern, the solution is to +make the types match by removing variables so the number of variables equals +the number of elements in the tuple. -The standard library’s `Add` trait is an example of the second purpose: -usually, you’ll add two like types, but the `Add` trait provides the ability to -customize beyond that. Using a default type parameter in the `Add` trait -definition means you don’t have to specify the extra parameter most of the -time. In other words, a bit of implementation boilerplate isn’t needed, making -it easier to use the trait. +### Function Parameters -The first purpose is similar to the second but in reverse: if you want to add a -type parameter to an existing trait, you can give it a default to allow -extension of the functionality of the trait without breaking the existing -implementation code. - -### Disambiguating Between Methods with the Same Name - -Nothing in Rust prevents a trait from having a method with the same name as -another trait’s method, nor does Rust prevent you from implementing both traits -on one type. It’s also possible to implement a method directly on the type with -the same name as methods from traits. - -When calling methods with the same name, you’ll need to tell Rust which one you -want to use. Consider the code in Listing 19-16 where we’ve defined two traits, -`Pilot` and `Wizard`, that both have a method called `fly`. We then implement -both traits on a type `Human` that already has a method named `fly` implemented -on it. Each `fly` method does something different. - -Filename: src/main.rs +Function parameters can also be patterns. The code in Listing 18-6, which +declares a function named `foo` that takes one parameter named `x` of type +`i32`, should by now look familiar. ``` -trait Pilot { - fn fly(&self); -} - -trait Wizard { - fn fly(&self); -} - -struct Human; - -impl Pilot for Human { - fn fly(&self) { - println!("This is your captain speaking."); - } -} - -impl Wizard for Human { - fn fly(&self) { - println!("Up!"); - } -} - -impl Human { - fn fly(&self) { - println!("*waving arms furiously*"); - } +fn foo(x: i32) { + // code goes here } ``` -Listing 19-16: Two traits are defined to have a `fly` method and are -implemented on the `Human` type, and a `fly` method is implemented on `Human` -directly. +Listing 18-6: A function signature using patterns in the parameters -When we call `fly` on an instance of `Human`, the compiler defaults to calling -the method that is directly implemented on the type, as shown in Listing 19-17. +The `x` part is a pattern! As we did with `let`, we could match a tuple in a +function’s arguments to the pattern. Listing 18-7 splits the values in a tuple +as we pass it to a function. Filename: src/main.rs ``` -fn main() { - let person = Human; - person.fly(); +fn print_coordinates(&(x, y): &(i32, i32)) { + println!("Current location: ({x}, {y})"); } -``` - -Listing 19-17: Calling `fly` on an instance of `Human` -Running this code will print `*waving arms furiously*`, showing that Rust -called the `fly` method implemented on `Human` directly. - -To call the `fly` methods from either the `Pilot` trait or the `Wizard` trait, -we need to use more explicit syntax to specify which `fly` method we mean. -Listing 19-18 demonstrates this syntax. - -Filename: src/main.rs - -``` fn main() { - let person = Human; - Pilot::fly(&person); - Wizard::fly(&person); - person.fly(); + let point = (3, 5); + print_coordinates(&point); } ``` -Listing 19-18: Specifying which trait’s `fly` method we want to call +Listing 18-7: A function with parameters that destructure a tuple -Specifying the trait name before the method name clarifies to Rust which -implementation of `fly` we want to call. We could also write -`Human::fly(&person)`, which is equivalent to the `person.fly()` that we used -in Listing 19-18, but this is a bit longer to write if we don’t need to -disambiguate. +This code prints `Current location: (3, 5)`. The values `&(3, 5)` match the +pattern `&(x, y)`, so `x` is the value `3` and `y` is the value `5`. -Running this code prints the following: +We can also use patterns in closure parameter lists in the same way as in +function parameter lists because closures are similar to functions, as +discussed in Chapter 13. -``` -This is your captain speaking. -Up! -*waving arms furiously* -``` +At this point, you’ve seen several ways to use patterns, but patterns don’t +work the same in every place we can use them. In some places, the patterns must +be irrefutable; in other circumstances, they can be refutable. We’ll discuss +these two concepts next. -Because the `fly` method takes a `self` parameter, if we had two *types* that -both implement one *trait*, Rust could figure out which implementation of a -trait to use based on the type of `self`. +## Refutability: Whether a Pattern Might Fail to Match -However, associated functions that are not methods don’t have a `self` -parameter. When there are multiple types or traits that define non-method -functions with the same function name, Rust doesn’t always know which type you -mean unless you use fully qualified syntax. For example, in Listing 19-19 we -create a trait for an animal shelter that wants to name all baby dogs Spot. We -make an `Animal` trait with an associated non-method function `baby_name`. The -`Animal` trait is implemented for the struct `Dog`, on which we also provide an -associated non-method function `baby_name` directly. +Patterns come in two forms: refutable and irrefutable. Patterns that will match +for any possible value passed are *irrefutable*. An example would be `x` in the +statement `let x = 5;` because `x` matches anything and therefore cannot fail +to match. Patterns that can fail to match for some possible value are +*refutable*. An example would be `Some(x)` in the expression `if let Some(x) = +a_value` because if the value in the `a_value` variable is `None` rather than +`Some`, the `Some(x)` pattern will not match. -Filename: src/main.rs +Function parameters, `let` statements, and `for` loops can only accept +irrefutable patterns because the program cannot do anything meaningful when +values don’t match. The `if let` and `while let` expressions accept refutable +and irrefutable patterns, but the compiler warns against irrefutable patterns +because, by definition, they’re intended to handle possible failure: the +functionality of a conditional is in its ability to perform differently +depending on success or failure. -``` -trait Animal { - fn baby_name() -> String; -} - -struct Dog; - -impl Dog { - fn baby_name() -> String { - String::from("Spot") - } -} +In general, you shouldn’t have to worry about the distinction between refutable +and irrefutable patterns; however, you do need to be familiar with the concept +of refutability so you can respond when you see it in an error message. In +those cases, you’ll need to change either the pattern or the construct you’re +using the pattern with, depending on the intended behavior of the code. -impl Animal for Dog { - fn baby_name() -> String { - String::from("puppy") - } -} +Let’s look at an example of what happens when we try to use a refutable pattern +where Rust requires an irrefutable pattern and vice versa. Listing 18-8 shows a +`let` statement, but for the pattern, we’ve specified `Some(x)`, a refutable +pattern. As you might expect, this code will not compile. -fn main() { - println!("A baby dog is called a {}", Dog::baby_name()); -} ``` - -Listing 19-19: A trait with an associated function and a type with an -associated function of the same name that also implements the trait - -We implement the code for naming all puppies Spot in the `baby_name` associated -function that is defined on `Dog`. The `Dog` type also implements the trait -`Animal`, which describes characteristics that all animals have. Baby dogs are -called puppies, and that is expressed in the implementation of the `Animal` -trait on `Dog` in the `baby_name` function associated with the `Animal` trait. - -In `main`, we call the `Dog::baby_name` function, which calls the associated -function defined on `Dog` directly. This code prints the following: - -``` -A baby dog is called a Spot +let Some(x) = some_option_value; ``` -This output isn’t what we wanted. We want to call the `baby_name` function that -is part of the `Animal` trait that we implemented on `Dog` so the code prints -`A baby dog is called a puppy`. The technique of specifying the trait name that -we used in Listing 19-18 doesn’t help here; if we change `main` to the code in -Listing 19-20, we’ll get a compilation error. +Listing 18-8: Attempting to use a refutable pattern with `let` -Filename: src/main.rs +If `some_option_value` were a `None` value, it would fail to match the pattern +`Some(x)`, meaning the pattern is refutable. However, the `let` statement can +only accept an irrefutable pattern because there is nothing valid the code can +do with a `None` value. At compile time, Rust will complain that we’ve tried to +use a refutable pattern where an irrefutable pattern is required: ``` -fn main() { - println!("A baby dog is called a {}", Animal::baby_name()); -} +error[E0005]: refutable pattern in local binding: `None` not covered + --> src/main.rs:3:9 + | +3 | let Some(x) = some_option_value; + | ^^^^^^^ pattern `None` not covered + | + = note: `let` bindings require an "irrefutable pattern", like a `struct` or +an `enum` with only one variant + = note: for more information, visit +https://doc.rust-lang.org/book/ch18-02-refutability.html + = note: the matched value is of type `Option<i32>` +help: you might want to use `if let` to ignore the variant that isn't matched + | +3 | let x = if let Some(x) = some_option_value { x } else { todo!() }; + | ++++++++++ ++++++++++++++++++++++ ``` -Listing 19-20: Attempting to call the `baby_name` function from the `Animal` -trait, but Rust doesn’t know which implementation to use +Because we didn’t cover (and couldn’t cover!) every valid value with the +pattern `Some(x)`, Rust rightfully produces a compiler error. -Because `Animal::baby_name` doesn’t have a `self` parameter, and there could be -other types that implement the `Animal` trait, Rust can’t figure out which -implementation of `Animal::baby_name` we want. We’ll get this compiler error: +If we have a refutable pattern where an irrefutable pattern is needed, we can +fix it by changing the code that uses the pattern: instead of using `let`, we +can use `if let`. Then, if the pattern doesn’t match, the code will just skip +the code in the curly brackets, giving it a way to continue validly. Listing +18-9 shows how to fix the code in Listing 18-8. ``` -error[E0283]: type annotations needed - --> src/main.rs:20:43 - | -20 | println!("A baby dog is called a {}", Animal::baby_name()); - | ^^^^^^^^^^^^^^^^^ cannot infer -type - | - = note: cannot satisfy `_: Animal` -``` - -To disambiguate and tell Rust that we want to use the implementation of -`Animal` for `Dog` as opposed to the implementation of `Animal` for some other -type, we need to use fully qualified syntax. Listing 19-21 demonstrates how to -use fully qualified syntax. - -Filename: src/main.rs - -``` -fn main() { - println!( - "A baby dog is called a {}", - <Dog as Animal>::baby_name() - ); +if let Some(x) = some_option_value { + println!("{x}"); } ``` -Listing 19-21: Using fully qualified syntax to specify that we want to call the -`baby_name` function from the `Animal` trait as implemented on `Dog` +Listing 18-9: Using `if let` and a block with refutable patterns instead of +`let` -We’re providing Rust with a type annotation within the angle brackets, which -indicates we want to call the `baby_name` method from the `Animal` trait as -implemented on `Dog` by saying that we want to treat the `Dog` type as an -`Animal` for this function call. This code will now print what we want: +We’ve given the code an out! This code is perfectly valid, although it means we +cannot use an irrefutable pattern without receiving an error. If we give `if +let` a pattern that will always match, such as `x`, as shown in Listing 18-10, +the compiler will give a warning. ``` -A baby dog is called a puppy +if let x = 5 { + println!("{x}"); +}; ``` -In general, fully qualified syntax is defined as follows: +Listing 18-10: Attempting to use an irrefutable pattern with `if let` + +Rust complains that it doesn’t make sense to use `if let` with an irrefutable +pattern: ``` -<Type as Trait>::function(receiver_if_method, next_arg, ...); +warning: irrefutable `if let` pattern + --> src/main.rs:2:8 + | +2 | if let x = 5 { + | ^^^^^^^^^ + | + = note: `#[warn(irrefutable_let_patterns)]` on by default + = note: this pattern will always match, so the `if let` is +useless + = help: consider replacing the `if let` with a `let` ``` -For associated functions that aren’t methods, there would not be a `receiver`: -there would only be the list of other arguments. You could use fully qualified -syntax everywhere that you call functions or methods. However, you’re allowed -to omit any part of this syntax that Rust can figure out from other information -in the program. You only need to use this more verbose syntax in cases where -there are multiple implementations that use the same name and Rust needs help -to identify which implementation you want to call. +For this reason, match arms must use refutable patterns, except for the last +arm, which should match any remaining values with an irrefutable pattern. Rust +allows us to use an irrefutable pattern in a `match` with only one arm, but +this syntax isn’t particularly useful and could be replaced with a simpler +`let` statement. -### Using Supertraits +Now that you know where to use patterns and the difference between refutable +and irrefutable patterns, let’s cover all the syntax we can use to create +patterns. -Sometimes you might write a trait definition that depends on another trait: for -a type to implement the first trait, you want to require that type to also -implement the second trait. You would do this so that your trait definition can -make use of the associated items of the second trait. The trait your trait -definition is relying on is called a *supertrait* of your trait. +## Pattern Syntax -For example, let’s say we want to make an `OutlinePrint` trait with an -`outline_print` method that will print a given value formatted so that it’s -framed in asterisks. That is, given a `Point` struct that implements the -standard library trait `Display` to result in `(x, y)`, when we call -`outline_print` on a `Point` instance that has `1` for `x` and `3` for `y`, it -should print the following: +In this section, we gather all the syntax that is valid in patterns and discuss +why and when you might want to use each one. -``` -********** -* * -* (1, 3) * -* * -********** -``` +### Matching Literals -In the implementation of the `outline_print` method, we want to use the -`Display` trait’s functionality. Therefore, we need to specify that the -`OutlinePrint` trait will work only for types that also implement `Display` and -provide the functionality that `OutlinePrint` needs. We can do that in the -trait definition by specifying `OutlinePrint: Display`. This technique is -similar to adding a trait bound to the trait. Listing 19-22 shows an -implementation of the `OutlinePrint` trait. +As you saw in Chapter 6, you can match patterns against literals directly. The +following code gives some examples: Filename: src/main.rs ``` -use std::fmt; +let x = 1; -trait OutlinePrint: fmt::Display { - fn outline_print(&self) { - let output = self.to_string(); - let len = output.len(); - println!("{}", "*".repeat(len + 4)); - println!("*{}*", " ".repeat(len + 2)); - println!("* {} *", output); - println!("*{}*", " ".repeat(len + 2)); - println!("{}", "*".repeat(len + 4)); - } +match x { + 1 => println!("one"), + 2 => println!("two"), + 3 => println!("three"), + _ => println!("anything"), } ``` -Listing 19-22: Implementing the `OutlinePrint` trait that requires the -functionality from `Display` +This code prints `one` because the value in `x` is `1`. This syntax is useful +when you want your code to take an action if it gets a particular concrete +value. -Because we’ve specified that `OutlinePrint` requires the `Display` trait, we -can use the `to_string` function that is automatically implemented for any type -that implements `Display`. If we tried to use `to_string` without adding a -colon and specifying the `Display` trait after the trait name, we’d get an -error saying that no method named `to_string` was found for the type `&Self` in -the current scope. +### Matching Named Variables -Let’s see what happens when we try to implement `OutlinePrint` on a type that -doesn’t implement `Display`, such as the `Point` struct: +Named variables are irrefutable patterns that match any value, and we’ve used +them many times in this book. However, there is a complication when you use +named variables in `match` expressions. Because `match` starts a new scope, +variables declared as part of a pattern inside the `match` expression will +shadow those with the same name outside the `match` construct, as is the case +with all variables. In Listing 18-11, we declare a variable named `x` with the +value `Some(5)` and a variable `y` with the value `10`. We then create a +`match` expression on the value `x`. Look at the patterns in the match arms and +`println!` at the end, and try to figure out what the code will print before +running this code or reading further. Filename: src/main.rs ``` -struct Point { - x: i32, - y: i32, -} - -impl OutlinePrint for Point {} -``` +fn main() { + 1 let x = Some(5); + 2 let y = 10; -We get an error saying that `Display` is required but not implemented: + match x { + 3 Some(50) => println!("Got 50"), + 4 Some(y) => println!("Matched, y = {y}"), + 5 _ => println!("Default case, x = {:?}", x), + } -``` -error[E0277]: `Point` doesn't implement `std::fmt::Display` - --> src/main.rs:20:6 - | -20 | impl OutlinePrint for Point {} - | ^^^^^^^^^^^^ `Point` cannot be formatted with the default formatter - | - = help: the trait `std::fmt::Display` is not implemented for `Point` - = note: in format strings you may be able to use `{:?}` (or {:#?} for -pretty-print) instead -note: required by a bound in `OutlinePrint` - --> src/main.rs:3:21 - | -3 | trait OutlinePrint: fmt::Display { - | ^^^^^^^^^^^^ required by this bound in `OutlinePrint` + 6 println!("at the end: x = {:?}, y = {y}", x); +} ``` -To fix this, we implement `Display` on `Point` and satisfy the constraint that -`OutlinePrint` requires, like so: +Listing 18-11: A `match` expression with an arm that introduces a shadowed +variable `y` -Filename: src/main.rs +Let’s walk through what happens when the `match` expression runs. The pattern +in the first match arm [3] doesn’t match the defined value of `x` [1], so the +code continues. -``` -use std::fmt; +The pattern in the second match arm [4] introduces a new variable named `y` +that will match any value inside a `Some` value. Because we’re in a new scope +inside the `match` expression, this is a new `y` variable, not the `y` we +declared at the beginning with the value `10` [2]. This new `y` binding will +match any value inside a `Some`, which is what we have in `x`. Therefore, this +new `y` binds to the inner value of the `Some` in `x`. That value is `5`, so +the expression for that arm executes and prints `Matched, y = 5`. -impl fmt::Display for Point { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({}, {})", self.x, self.y) - } -} -``` +If `x` had been a `None` value instead of `Some(5)`, the patterns in the first +two arms wouldn’t have matched, so the value would have matched to the +underscore [5]. We didn’t introduce the `x` variable in the pattern of the +underscore arm, so the `x` in the expression is still the outer `x` that hasn’t +been shadowed. In this hypothetical case, the `match` would print `Default +case, x = None`. -Then, implementing the `OutlinePrint` trait on `Point` will compile -successfully, and we can call `outline_print` on a `Point` instance to display -it within an outline of asterisks. +When the `match` expression is done, its scope ends, and so does the scope of +the inner `y`. The last `println!` [6] produces `at the end: x = Some(5), y = +10`. -### Using the Newtype Pattern to Implement External Traits +To create a `match` expression that compares the values of the outer `x` and +`y`, rather than introducing a shadowed variable, we would need to use a match +guard conditional instead. We’ll talk about match guards in “Extra Conditionals +with Match Guards” on page XX. -In “Implementing a Trait on a Type” on page XX, we mentioned the orphan rule -that states we’re only allowed to implement a trait on a type if either the -trait or the type, or both, are local to our crate. It’s possible to get around -this restriction using the *newtype pattern*, which involves creating a new -type in a tuple struct. (We covered tuple structs in “Using Tuple Structs -Without Named Fields to Create Different Types” on page XX.) The tuple struct -will have one field and be a thin wrapper around the type for which we want to -implement a trait. Then the wrapper type is local to our crate, and we can -implement the trait on the wrapper. *Newtype* is a term that originates from -the Haskell programming language. There is no runtime performance penalty for -using this pattern, and the wrapper type is elided at compile time. +### Multiple Patterns -As an example, let’s say we want to implement `Display` on `Vec<T>`, which the -orphan rule prevents us from doing directly because the `Display` trait and the -`Vec<T>` type are defined outside our crate. We can make a `Wrapper` struct -that holds an instance of `Vec<T>`; then we can implement `Display` on -`Wrapper` and use the `Vec<T>` value, as shown in Listing 19-23. +In `match` expressions, you can match multiple patterns using the `|` syntax, +which is the pattern *or* operator. For example, in the following code we match +the value of `x` against the match arms, the first of which has an *or* option, +meaning if the value of `x` matches either of the values in that arm, that +arm’s code will run: Filename: src/main.rs ``` -use std::fmt; - -struct Wrapper(Vec<String>); - -impl fmt::Display for Wrapper { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{}]", self.0.join(", ")) - } -} +let x = 1; -fn main() { - let w = Wrapper(vec![ - String::from("hello"), - String::from("world"), - ]); - println!("w = {w}"); +match x { + 1 | 2 => println!("one or two"), + 3 => println!("three"), + _ => println!("anything"), } ``` -Listing 19-23: Creating a `Wrapper` type around `Vec<String>` to implement -`Display` - -The implementation of `Display` uses `self.0` to access the inner `Vec<T>` -because `Wrapper` is a tuple struct and `Vec<T>` is the item at index 0 in the -tuple. Then we can use the functionality of the `Display` type on `Wrapper`. - -The downside of using this technique is that `Wrapper` is a new type, so it -doesn’t have the methods of the value it’s holding. We would have to implement -all the methods of `Vec<T>` directly on `Wrapper` such that the methods -delegate to `self.0`, which would allow us to treat `Wrapper` exactly like a -`Vec<T>`. If we wanted the new type to have every method the inner type has, -implementing the `Deref` trait on the `Wrapper` to return the inner type would -be a solution (we discussed implementing the `Deref` trait in “Treating Smart -Pointers Like Regular References with Deref” on page XX). If we didn’t want the -`Wrapper` type to have all the methods of the inner type—for example, to -restrict the `Wrapper` type’s behavior—we would have to implement just the -methods we do want manually. - -This newtype pattern is also useful even when traits are not involved. Let’s -switch focus and look at some advanced ways to interact with Rust’s type system. - -## Advanced Types - -The Rust type system has some features that we’ve so far mentioned but haven’t -yet discussed. We’ll start by discussing newtypes in general as we examine why -newtypes are useful as types. Then we’ll move on to type aliases, a feature -similar to newtypes but with slightly different semantics. We’ll also discuss -the `!` type and dynamically sized types. +This code prints `one or two`. -### Using the Newtype Pattern for Type Safety and Abstraction +### Matching Ranges of Values with ..= -> Note: This section assumes you’ve read the earlier section “Using the Newtype -Pattern to Implement External Traits” on page XX. +The `..=` syntax allows us to match to an inclusive range of values. In the +following code, when a pattern matches any of the values within the given +range, that arm will execute: -The newtype pattern is also useful for tasks beyond those we’ve discussed so -far, including statically enforcing that values are never confused and -indicating the units of a value. You saw an example of using newtypes to -indicate units in Listing 19-15: recall that the `Millimeters` and `Meters` -structs wrapped `u32` values in a newtype. If we wrote a function with a -parameter of type `Millimeters`, we wouldn’t be able to compile a program that -accidentally tried to call that function with a value of type `Meters` or a -plain `u32`. - -We can also use the newtype pattern to abstract away some implementation -details of a type: the new type can expose a public API that is different from -the API of the private inner type. - -Newtypes can also hide internal implementation. For example, we could provide a -`People` type to wrap a `HashMap<i32, String>` that stores a person’s ID -associated with their name. Code using `People` would only interact with the -public API we provide, such as a method to add a name string to the `People` -collection; that code wouldn’t need to know that we assign an `i32` ID to names -internally. The newtype pattern is a lightweight way to achieve encapsulation -to hide implementation details, which we discussed in “Encapsulation That Hides -Implementation Details” on page XX. - -### Creating Type Synonyms with Type Aliases - -Rust provides the ability to declare a *type alias* to give an existing type -another name. For this we use the `type` keyword. For example, we can create -the alias `Kilometers` to `i32` like so: - -``` -type Kilometers = i32; -``` - -Now the alias `Kilometers` is a *synonym* for `i32`; unlike the `Millimeters` -and `Meters` types we created in Listing 19-15, `Kilometers` is not a separate, -new type. Values that have the type `Kilometers` will be treated the same as -values of type `i32`: +Filename: src/main.rs ``` -type Kilometers = i32; +let x = 5; -let x: i32 = 5; -let y: Kilometers = 5; - -println!("x + y = {}", x + y); +match x { + 1..=5 => println!("one through five"), + _ => println!("something else"), +} ``` -Because `Kilometers` and `i32` are the same type, we can add values of both -types and we can pass `Kilometers` values to functions that take `i32` -parameters. However, using this method, we don’t get the type-checking benefits -that we get from the newtype pattern discussed earlier. In other words, if we -mix up `Kilometers` and `i32` values somewhere, the compiler will not give us -an error. +If `x` is `1`, `2`, `3`, `4`, or `5`, the first arm will match. This syntax is +more convenient for multiple match values than using the `|` operator to +express the same idea; if we were to use `|`, we would have to specify `1 | 2 | +3 | 4 | 5`. Specifying a range is much shorter, especially if we want to match, +say, any number between 1 and 1,000! -The main use case for type synonyms is to reduce repetition. For example, we -might have a lengthy type like this: +The compiler checks that the range isn’t empty at compile time, and because the +only types for which Rust can tell if a range is empty or not are `char` and +numeric values, ranges are only allowed with numeric or `char` values. -``` -Box<dyn Fn() + Send + 'static> -``` +Here is an example using ranges of `char` values: -Writing this lengthy type in function signatures and as type annotations all -over the code can be tiresome and error prone. Imagine having a project full of -code like that in Listing 19-24. +Filename: src/main.rs ``` -let f: Box<dyn Fn() + Send + 'static> = Box::new(|| { - println!("hi"); -}); +let x = 'c'; -fn takes_long_type(f: Box<dyn Fn() + Send + 'static>) { - --snip-- +match x { + 'a'..='j' => println!("early ASCII letter"), + 'k'..='z' => println!("late ASCII letter"), + _ => println!("something else"), } - -fn returns_long_type() -> Box<dyn Fn() + Send + 'static> { - --snip-- -} -``` - -Listing 19-24: Using a long type in many places - -A type alias makes this code more manageable by reducing the repetition. In -Listing 19-25, we’ve introduced an alias named `Thunk` for the verbose type and -can replace all uses of the type with the shorter alias `Thunk`. - ``` -type Thunk = Box<dyn Fn() + Send + 'static>; -let f: Thunk = Box::new(|| println!("hi")); +Rust can tell that `'c'` is within the first pattern’s range and prints `early +ASCII letter`. -fn takes_long_type(f: Thunk) { - --snip-- -} +### Destructuring to Break Apart Values -fn returns_long_type() -> Thunk { - --snip-- -} -``` +We can also use patterns to destructure structs, enums, and tuples to use +different parts of these values. Let’s walk through each value. -Listing 19-25: Introducing a type alias `Thunk` to reduce repetition +#### Destructuring Structs -This code is much easier to read and write! Choosing a meaningful name for a -type alias can help communicate your intent as well (*thunk* is a word for code -to be evaluated at a later time, so it’s an appropriate name for a closure that -gets stored). +Listing 18-12 shows a `Point` struct with two fields, `x` and `y`, that we can +break apart using a pattern with a `let` statement. -Type aliases are also commonly used with the `Result<T, E>` type for reducing -repetition. Consider the `std::io` module in the standard library. I/O -operations often return a `Result<T, E>` to handle situations when operations -fail to work. This library has a `std::io::Error` struct that represents all -possible I/O errors. Many of the functions in `std::io` will be returning -`Result<T, E>` where the `E` is `std::io::Error`, such as these functions in -the `Write` trait: +Filename: src/main.rs ``` -use std::fmt; -use std::io::Error; +struct Point { + x: i32, + y: i32, +} -pub trait Write { - fn write(&mut self, buf: &[u8]) -> Result<usize, Error>; - fn flush(&mut self) -> Result<(), Error>; +fn main() { + let p = Point { x: 0, y: 7 }; - fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>; - fn write_fmt( - &mut self, - fmt: fmt::Arguments, - ) -> Result<(), Error>; + let Point { x: a, y: b } = p; + assert_eq!(0, a); + assert_eq!(7, b); } ``` -The `Result<..., Error>` is repeated a lot. As such, `std::io` has this type -alias declaration: +Listing 18-12: Destructuring a struct’s fields into separate variables -``` -type Result<T> = std::result::Result<T, std::io::Error>; -``` +This code creates the variables `a` and `b` that match the values of the `x` +and `y` fields of the `p` struct. This example shows that the names of the +variables in the pattern don’t have to match the field names of the struct. +However, it’s common to match the variable names to the field names to make it +easier to remember which variables came from which fields. Because of this +common usage, and because writing `let Point { x: x, y: y } = p;` contains a +lot of duplication, Rust has a shorthand for patterns that match struct fields: +you only need to list the name of the struct field, and the variables created +from the pattern will have the same names. Listing 18-13 behaves in the same +way as the code in Listing 18-12, but the variables created in the `let` +pattern are `x` and `y` instead of `a` and `b`. -Because this declaration is in the `std::io` module, we can use the fully -qualified alias `std::io::Result<T>`; that is, a `Result<T, E>` with the `E` -filled in as `std::io::Error`. The `Write` trait function signatures end up -looking like this: +Filename: src/main.rs ``` -pub trait Write { - fn write(&mut self, buf: &[u8]) -> Result<usize>; - fn flush(&mut self) -> Result<()>; - - fn write_all(&mut self, buf: &[u8]) -> Result<()>; - fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()>; +struct Point { + x: i32, + y: i32, } -``` -The type alias helps in two ways: it makes code easier to write *and* it gives -us a consistent interface across all of `std::io`. Because it’s an alias, it’s -just another `Result<T, E>`, which means we can use any methods that work on -`Result<T, E>` with it, as well as special syntax like the `?` operator. - -### The Never Type That Never Returns - -Rust has a special type named `!` that’s known in type theory lingo as the -*empty type* because it has no values. We prefer to call it the *never type* -because it stands in the place of the return type when a function will never -return. Here is an example: +fn main() { + let p = Point { x: 0, y: 7 }; -``` -fn bar() -> ! { - --snip-- + let Point { x, y } = p; + assert_eq!(0, x); + assert_eq!(7, y); } ``` -This code is read as “the function `bar` returns never.” Functions that return -never are called *diverging functions*. We can’t create values of the type `!`, -so `bar` can never possibly return. +Listing 18-13: Destructuring struct fields using struct field shorthand -But what use is a type you can never create values for? Recall the code from -Listing 2-5, part of the number-guessing game; we’ve reproduced a bit of it -here in Listing 19-26. +This code creates the variables `x` and `y` that match the `x` and `y` fields +of the `p` variable. The outcome is that the variables `x` and `y` contain the +values from the `p` struct. -``` -let guess: u32 = match guess.trim().parse() { - Ok(num) => num, - Err(_) => continue, -}; -``` +We can also destructure with literal values as part of the struct pattern +rather than creating variables for all the fields. Doing so allows us to test +some of the fields for particular values while creating variables to +destructure the other fields. -Listing 19-26: A `match` with an arm that ends in `continue` +In Listing 18-14, we have a `match` expression that separates `Point` values +into three cases: points that lie directly on the `x` axis (which is true when +`y = 0`), on the `y` axis (`x = 0`), or on neither axis. -At the time, we skipped over some details in this code. In “The match Control -Flow Construct” on page XX, we discussed that `match` arms must all return the -same type. So, for example, the following code doesn’t work: +Filename: src/main.rs ``` -let guess = match guess.trim().parse() { - Ok(_) => 5, - Err(_) => "hello", -}; -``` - -The type of `guess` in this code would have to be an integer *and* a string, -and Rust requires that `guess` have only one type. So what does `continue` -return? How were we allowed to return a `u32` from one arm and have another arm -that ends with `continue` in Listing 19-26? - -As you might have guessed, `continue` has a `!` value. That is, when Rust -computes the type of `guess`, it looks at both match arms, the former with a -value of `u32` and the latter with a `!` value. Because `!` can never have a -value, Rust decides that the type of `guess` is `u32`. - -The formal way of describing this behavior is that expressions of type `!` can -be coerced into any other type. We’re allowed to end this `match` arm with -`continue` because `continue` doesn’t return a value; instead, it moves control -back to the top of the loop, so in the `Err` case, we never assign a value to -`guess`. - -The never type is useful with the `panic!` macro as well. Recall the `unwrap` -function that we call on `Option<T>` values to produce a value or panic with -this definition: +fn main() { + let p = Point { x: 0, y: 7 }; -``` -impl<T> Option<T> { - pub fn unwrap(self) -> T { - match self { - Some(val) => val, - None => panic!( - "called `Option::unwrap()` on a `None` value" - ), + match p { + Point { x, y: 0 } => println!("On the x axis at {x}"), + Point { x: 0, y } => println!("On the y axis at {y}"), + Point { x, y } => { + println!("On neither axis: ({x}, {y})"); } } } ``` -In this code, the same thing happens as in the `match` in Listing 19-26: Rust -sees that `val` has the type `T` and `panic!` has the type `!`, so the result -of the overall `match` expression is `T`. This code works because `panic!` -doesn’t produce a value; it ends the program. In the `None` case, we won’t be -returning a value from `unwrap`, so this code is valid. +Listing 18-14: Destructuring and matching literal values in one pattern -One final expression that has the type `!` is a `loop`: +The first arm will match any point that lies on the `x` axis by specifying that +the `y` field matches if its value matches the literal `0`. The pattern still +creates an `x` variable that we can use in the code for this arm. -``` -print!("forever "); +Similarly, the second arm matches any point on the `y` axis by specifying that +the `x` field matches if its value is `0` and creates a variable `y` for the +value of the `y` field. The third arm doesn’t specify any literals, so it +matches any other `Point` and creates variables for both the `x` and `y` fields. -loop { - print!("and ever "); -} -``` +In this example, the value `p` matches the second arm by virtue of `x` +containing a `0`, so this code will print `On the y axis at 7`. -Here, the loop never ends, so `!` is the value of the expression. However, this -wouldn’t be true if we included a `break`, because the loop would terminate -when it got to the `break`. - -### Dynamically Sized Types and the Sized Trait - -Rust needs to know certain details about its types, such as how much space to -allocate for a value of a particular type. This leaves one corner of its type -system a little confusing at first: the concept of *dynamically sized types*. -Sometimes referred to as *DSTs* or *unsized types*, these types let us write -code using values whose size we can know only at runtime. - -Let’s dig into the details of a dynamically sized type called `str`, which -we’ve been using throughout the book. That’s right, not `&str`, but `str` on -its own, is a DST. We can’t know how long the string is until runtime, meaning -we can’t create a variable of type `str`, nor can we take an argument of type -`str`. Consider the following code, which does not work: - -``` -let s1: str = "Hello there!"; -let s2: str = "How's it going?"; -``` - -Rust needs to know how much memory to allocate for any value of a particular -type, and all values of a type must use the same amount of memory. If Rust -allowed us to write this code, these two `str` values would need to take up the -same amount of space. But they have different lengths: `s1` needs 12 bytes of -storage and `s2` needs 15. This is why it’s not possible to create a variable -holding a dynamically sized type. - -So what do we do? In this case, you already know the answer: we make the types -of `s1` and `s2` a `&str` rather than a `str`. Recall from “String Slices” on -page XX that the slice data structure just stores the starting position and the -length of the slice. So, although a `&T` is a single value that stores the -memory address of where the `T` is located, a `&str` is *two* values: the -address of the `str` and its length. As such, we can know the size of a `&str` -value at compile time: it’s twice the length of a `usize`. That is, we always -know the size of a `&str`, no matter how long the string it refers to is. In -general, this is the way in which dynamically sized types are used in Rust: -they have an extra bit of metadata that stores the size of the dynamic -information. The golden rule of dynamically sized types is that we must always -put values of dynamically sized types behind a pointer of some kind. - -We can combine `str` with all kinds of pointers: for example, `Box<str>` or -`Rc<str>`. In fact, you’ve seen this before but with a different dynamically -sized type: traits. Every trait is a dynamically sized type we can refer to by -using the name of the trait. In “Using Trait Objects That Allow for Values of -Different Types” on page XX, we mentioned that to use traits as trait objects, -we must put them behind a pointer, such as `&dyn Trait` or `Box<dyn Trait>` -(`Rc<dyn Trait>` would work too). - -To work with DSTs, Rust provides the `Sized` trait to determine whether or not -a type’s size is known at compile time. This trait is automatically implemented -for everything whose size is known at compile time. In addition, Rust -implicitly adds a bound on `Sized` to every generic function. That is, a -generic function definition like this: - -``` -fn generic<T>(t: T) { - --snip-- -} -``` +Remember that a `match` expression stops checking arms once it has found the +first matching pattern, so even though `Point { x: 0, y: 0}` is on the `x` axis +and the `y` axis, this code would only print `On the x axis at 0`. + +#### Destructuring Enums + +We’ve destructured enums in this book (for example, Listing 6-5), but we +haven’t yet explicitly discussed that the pattern to destructure an enum +corresponds to the way the data stored within the enum is defined. As an +example, in Listing 18-15 we use the `Message` enum from Listing 6-2 and write +a `match` with patterns that will destructure each inner value. -is actually treated as though we had written this: +Filename: src/main.rs ``` -fn generic<T: Sized>(t: T) { - --snip-- +enum Message { + Quit, + Move { x: i32, y: i32 }, + Write(String), + ChangeColor(i32, i32, i32), } -``` -By default, generic functions will work only on types that have a known size at -compile time. However, you can use the following special syntax to relax this -restriction: +fn main() { + 1 let msg = Message::ChangeColor(0, 160, 255); -``` -fn generic<T: ?Sized>(t: &T) { - --snip-- + match msg { + 2 Message::Quit => { + println!( + "The Quit variant has no data to destructure." + ); + } + 3 Message::Move { x, y } => { + println!( + "Move in the x dir {x}, in the y dir {y}" + ); + } + 4 Message::Write(text) => { + println!("Text message: {text}"); + } + 5 Message::ChangeColor(r, g, b) => println!( + "Change color to red {r}, green {g}, and blue {b}" + ), + } } ``` -A trait bound on `?Sized` means “`T` may or may not be `Sized`” and this -notation overrides the default that generic types must have a known size at -compile time. The `?Trait` syntax with this meaning is only available for -`Sized`, not any other traits. - -Also note that we switched the type of the `t` parameter from `T` to `&T`. -Because the type might not be `Sized`, we need to use it behind some kind of -pointer. In this case, we’ve chosen a reference. +Listing 18-15: Destructuring enum variants that hold different kinds of values -Next, we’ll talk about functions and closures! +This code will print `Change color to red 0, green 160, and blue 255`. Try +changing the value of `msg` [1] to see the code from the other arms run. -## Advanced Functions and Closures +For enum variants without any data, like `Message::Quit` [2], we can’t +destructure the value any further. We can only match on the literal +`Message::Quit` value, and no variables are in that pattern. -This section explores some advanced features related to functions and closures, -including function pointers and returning closures. +For struct-like enum variants, such as `Message::Move` [3], we can use a +pattern similar to the pattern we specify to match structs. After the variant +name, we place curly brackets and then list the fields with variables so we +break apart the pieces to use in the code for this arm. Here we use the +shorthand form as we did in Listing 18-13. -### Function Pointers +For tuple-like enum variants, like `Message::Write` that holds a tuple with one +element [4] and `Message::ChangeColor` that holds a tuple with three elements +[5], the pattern is similar to the pattern we specify to match tuples. The +number of variables in the pattern must match the number of elements in the +variant we’re matching. -We’ve talked about how to pass closures to functions; you can also pass regular -functions to functions! This technique is useful when you want to pass a -function you’ve already defined rather than defining a new closure. Functions -coerce to the type `fn` (with a lowercase *f*), not to be confused with the -`Fn` closure trait. The `fn` type is called a *function pointer*. Passing -functions with function pointers will allow you to use functions as arguments -to other functions. +#### Destructuring Nested Structs and Enums -The syntax for specifying that a parameter is a function pointer is similar to -that of closures, as shown in Listing 19-27, where we’ve defined a function -`add_one` that adds 1 to its parameter. The function `do_twice` takes two -parameters: a function pointer to any function that takes an `i32` parameter -and returns an `i32`, and one `i32 value`. The `do_twice` function calls the -function `f` twice, passing it the `arg` value, then adds the two function call -results together. The `main` function calls `do_twice` with the arguments -`add_one` and `5`. +So far, our examples have all been matching structs or enums one level deep, +but matching can work on nested items too! For example, we can refactor the +code in Listing 18-15 to support RGB and HSV colors in the `ChangeColor` +message, as shown in Listing 18-16. Filename: src/main.rs ``` -fn add_one(x: i32) -> i32 { - x + 1 +enum Color { + Rgb(i32, i32, i32), + Hsv(i32, i32, i32), } -fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 { - f(arg) + f(arg) +enum Message { + Quit, + Move { x: i32, y: i32 }, + Write(String), + ChangeColor(Color), } fn main() { - let answer = do_twice(add_one, 5); - - println!("The answer is: {answer}"); + let msg = Message::ChangeColor(Color::Hsv(0, 160, 255)); + + match msg { + Message::ChangeColor(Color::Rgb(r, g, b)) => println!( + "Change color to red {r}, green {g}, and blue {b}" + ), + Message::ChangeColor(Color::Hsv(h, s, v)) => println!( + "Change color to hue {h}, saturation {s}, value {v}" + ), + _ => (), + } } ``` -Listing 19-27: Using the `fn` type to accept a function pointer as an argument - -This code prints `The answer is: 12`. We specify that the parameter `f` in -`do_twice` is an `fn` that takes one parameter of type `i32` and returns an -`i32`. We can then call `f` in the body of `do_twice`. In `main`, we can pass -the function name `add_one` as the first argument to `do_twice`. +Listing 18-16: Matching on nested enums -Unlike closures, `fn` is a type rather than a trait, so we specify `fn` as the -parameter type directly rather than declaring a generic type parameter with one -of the `Fn` traits as a trait bound. +The pattern of the first arm in the `match` expression matches a +`Message::ChangeColor` enum variant that contains a `Color::Rgb` variant; then +the pattern binds to the three inner `i32` values. The pattern of the second +arm also matches a `Message::ChangeColor` enum variant, but the inner enum +matches `Color::Hsv` instead. We can specify these complex conditions in one +`match` expression, even though two enums are involved. -Function pointers implement all three of the closure traits (`Fn`, `FnMut`, and -`FnOnce`), meaning you can always pass a function pointer as an argument for a -function that expects a closure. It’s best to write functions using a generic -type and one of the closure traits so your functions can accept either -functions or closures. +#### Destructuring Structs and Tuples -That said, one example of where you would want to only accept `fn` and not -closures is when interfacing with external code that doesn’t have closures: C -functions can accept functions as arguments, but C doesn’t have closures. - -As an example of where you could use either a closure defined inline or a named -function, let’s look at a use of the `map` method provided by the `Iterator` -trait in the standard library. To use the `map` function to turn a vector of -numbers into a vector of strings, we could use a closure, like this: +We can mix, match, and nest destructuring patterns in even more complex ways. +The following example shows a complicated destructure where we nest structs and +tuples inside a tuple and destructure all the primitive values out: ``` -let list_of_numbers = vec![1, 2, 3]; -let list_of_strings: Vec<String> = list_of_numbers - .iter() - .map(|i| i.to_string()) - .collect(); +let ((feet, inches), Point { x, y }) = + ((3, 10), Point { x: 3, y: -10 }); ``` -Or we could name a function as the argument to `map` instead of the closure, -like this: +This code lets us break complex types into their component parts so we can use +the values we’re interested in separately. -``` -let list_of_numbers = vec![1, 2, 3]; -let list_of_strings: Vec<String> = list_of_numbers - .iter() - .map(ToString::to_string) - .collect(); -``` +Destructuring with patterns is a convenient way to use pieces of values, such +as the value from each field in a struct, separately from each other. + +### Ignoring Values in a Pattern -Note that we must use the fully qualified syntax that we talked about in -“Advanced Traits” on page XX because there are multiple functions available -named `to_string`. +You’ve seen that it’s sometimes useful to ignore values in a pattern, such as +in the last arm of a `match`, to get a catchall that doesn’t actually do +anything but does account for all remaining possible values. There are a few +ways to ignore entire values or parts of values in a pattern: using the `_` +pattern (which you’ve seen), using the `_` pattern within another pattern, +using a name that starts with an underscore, or using `..` to ignore remaining +parts of a value. Let’s explore how and why to use each of these patterns. -Here, we’re using the `to_string` function defined in the `ToString` trait, -which the standard library has implemented for any type that implements -`Display`. +#### An Entire Value with _ -Recall from “Enum Values” on page XX that the name of each enum variant that we -define also becomes an initializer function. We can use these initializer -functions as function pointers that implement the closure traits, which means -we can specify the initializer functions as arguments for methods that take -closures, like so: +We’ve used the underscore as a wildcard pattern that will match any value but +not bind to the value. This is especially useful as the last arm in a `match` +expression, but we can also use it in any pattern, including function +parameters, as shown in Listing 18-17. + +Filename: src/main.rs ``` -enum Status { - Value(u32), - Stop, +fn foo(_: i32, y: i32) { + println!("This code only uses the y parameter: {y}"); } -let list_of_statuses: Vec<Status> = (0u32..20) - .map(Status::Value) - .collect(); +fn main() { + foo(3, 4); +} ``` -Here, we create `Status::Value` instances using each `u32` value in the range -that `map` is called on by using the initializer function of `Status::Value`. -Some people prefer this style and some people prefer to use closures. They -compile to the same code, so use whichever style is clearer to you. +Listing 18-17: Using `_` in a function signature -### Returning Closures +This code will completely ignore the value `3` passed as the first argument, +and will print `This code only uses the y parameter: 4`. -Closures are represented by traits, which means you can’t return closures -directly. In most cases where you might want to return a trait, you can instead -use the concrete type that implements the trait as the return value of the -function. However, you can’t do that with closures because they don’t have a -concrete type that is returnable; you’re not allowed to use the function -pointer `fn` as a return type, for example. +In most cases when you no longer need a particular function parameter, you +would change the signature so it doesn’t include the unused parameter. Ignoring +a function parameter can be especially useful in cases when, for example, +you’re implementing a trait when you need a certain type signature but the +function body in your implementation doesn’t need one of the parameters. You +then avoid getting a compiler warning about unused function parameters, as you +would if you used a name instead. -The following code tries to return a closure directly, but it won’t compile: +#### Parts of a Value with a Nested _ -``` -fn returns_closure() -> dyn Fn(i32) -> i32 { - |x| x + 1 -} -``` +We can also use `_` inside another pattern to ignore just part of a value, for +example, when we want to test for only part of a value but have no use for the +other parts in the corresponding code we want to run. Listing 18-18 shows code +responsible for managing a setting’s value. The business requirements are that +the user should not be allowed to overwrite an existing customization of a +setting but can unset the setting and give it a value if it is currently unset. -The compiler error is as follows: +Filename: src/main.rs ``` -error[E0746]: return type cannot have an unboxed trait object - --> src/lib.rs:1:25 - | -1 | fn returns_closure() -> dyn Fn(i32) -> i32 { - | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at -compile-time - | - = note: for information on `impl Trait`, see -<https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that- -implement-traits> -help: use `impl Fn(i32) -> i32` as the return type, as all return paths are of -type `[closure@src/lib.rs:2:5: 2:14]`, which implements `Fn(i32) -> i32` - | -1 | fn returns_closure() -> impl Fn(i32) -> i32 { - | ~~~~~~~~~~~~~~~~~~~ -``` +let mut setting_value = Some(5); +let new_setting_value = Some(10); -The error references the `Sized` trait again! Rust doesn’t know how much space -it will need to store the closure. We saw a solution to this problem earlier. -We can use a trait object: - -``` -fn returns_closure() -> Box<dyn Fn(i32) -> i32> { - Box::new(|x| x + 1) +match (setting_value, new_setting_value) { + (Some(_), Some(_)) => { + println!("Can't overwrite an existing customized value"); + } + _ => { + setting_value = new_setting_value; + } } -``` - -This code will compile just fine. For more about trait objects, refer to “Using -Trait Objects That Allow for Values of Different Types” on page XX. -Next, let’s look at macros! - -## Macros +println!("setting is {:?}", setting_value); +``` -We’ve used macros like `println!` throughout this book, but we haven’t fully -explored what a macro is and how it works. The term *macro* refers to a family -of features in Rust: *declarative* macros with `macro_rules!` and three kinds -of *procedural* macros: +Listing 18-18: Using an underscore within patterns that match `Some` variants +when we don’t need to use the value inside the `Some` -* Custom `#[derive]` macros that specify code added with the `derive` attribute -used on structs and enums -* Attribute-like macros that define custom attributes usable on any item -* Function-like macros that look like function calls but operate on the tokens -specified as their argument +This code will print `Can't overwrite an existing customized value` and then +`setting is Some(5)`. In the first match arm, we don’t need to match on or use +the values inside either `Some` variant, but we do need to test for the case +when `setting_value` and `new_setting_value` are the `Some` variant. In that +case, we print the reason for not changing `setting_value`, and it doesn’t get +changed. -We’ll talk about each of these in turn, but first, let’s look at why we even -need macros when we already have functions. +In all other cases (if either `setting_value` or `new_setting_value` is `None`) +expressed by the `_` pattern in the second arm, we want to allow +`new_setting_value` to become `setting_value`. -### The Difference Between Macros and Functions +We can also use underscores in multiple places within one pattern to ignore +particular values. Listing 18-19 shows an example of ignoring the second and +fourth values in a tuple of five items. -Fundamentally, macros are a way of writing code that writes other code, which -is known as *metaprogramming*. In Appendix C, we discuss the `derive` -attribute, which generates an implementation of various traits for you. We’ve -also used the `println!` and `vec!` macros throughout the book. All of these -macros *expand* to produce more code than the code you’ve written manually. +Filename: src/main.rs -Metaprogramming is useful for reducing the amount of code you have to write and -maintain, which is also one of the roles of functions. However, macros have -some additional powers that functions don’t have. +``` +let numbers = (2, 4, 8, 16, 32); -A function signature must declare the number and type of parameters the -function has. Macros, on the other hand, can take a variable number of -parameters: we can call `println!("hello")` with one argument or -`println!("hello {}", name)` with two arguments. Also, macros are expanded -before the compiler interprets the meaning of the code, so a macro can, for -example, implement a trait on a given type. A function can’t, because it gets -called at runtime and a trait needs to be implemented at compile time. +match numbers { + (first, _, third, _, fifth) => { + println!("Some numbers: {first}, {third}, {fifth}"); + } +} +``` -The downside to implementing a macro instead of a function is that macro -definitions are more complex than function definitions because you’re writing -Rust code that writes Rust code. Due to this indirection, macro definitions are -generally more difficult to read, understand, and maintain than function -definitions. +Listing 18-19: Ignoring multiple parts of a tuple -Another important difference between macros and functions is that you must -define macros or bring them into scope *before* you call them in a file, as -opposed to functions you can define anywhere and call anywhere. +This code will print `Some numbers: 2, 8, 32`, and the values `4` and `16` will +be ignored. -### Declarative Macros with macro_rules! for General Metaprogramming +#### An Unused Variable by Starting Its Name with _ -The most widely used form of macros in Rust is the *declarative macro*. These -are also sometimes referred to as “macros by example,” “`macro_rules!` macros,” -or just plain “macros.” At their core, declarative macros allow you to write -something similar to a Rust `match` expression. As discussed in Chapter 6, -`match` expressions are control structures that take an expression, compare the -resultant value of the expression to patterns, and then run the code associated -with the matching pattern. Macros also compare a value to patterns that are -associated with particular code: in this situation, the value is the literal -Rust source code passed to the macro; the patterns are compared with the -structure of that source code; and the code associated with each pattern, when -matched, replaces the code passed to the macro. This all happens during -compilation. +If you create a variable but don’t use it anywhere, Rust will usually issue a +warning because an unused variable could be a bug. However, sometimes it’s +useful to be able to create a variable you won’t use yet, such as when you’re +prototyping or just starting a project. In this situation, you can tell Rust +not to warn you about the unused variable by starting the name of the variable +with an underscore. In Listing 18-20, we create two unused variables, but when +we compile this code, we should only get a warning about one of them. -To define a macro, you use the `macro_rules!` construct. Let’s explore how to -use `macro_rules!` by looking at how the `vec!` macro is defined. Chapter 8 -covered how we can use the `vec!` macro to create a new vector with particular -values. For example, the following macro creates a new vector containing three -integers: +Filename: src/main.rs ``` -let v: Vec<u32> = vec![1, 2, 3]; +fn main() { + let _x = 5; + let y = 10; +} ``` -We could also use the `vec!` macro to make a vector of two integers or a vector -of five string slices. We wouldn’t be able to use a function to do the same -because we wouldn’t know the number or type of values up front. +Listing 18-20: Starting a variable name with an underscore to avoid getting +unused variable warnings -Listing 19-28 shows a slightly simplified definition of the `vec!` macro. +Here, we get a warning about not using the variable `y`, but we don’t get a +warning about not using `_x`. -Filename: src/lib.rs +Note that there is a subtle difference between using only `_` and using a name +that starts with an underscore. The syntax `_x` still binds the value to the +variable, whereas `_` doesn’t bind at all. To show a case where this +distinction matters, Listing 18-21 will provide us with an error. -``` -1 #[macro_export] -2 macro_rules! vec { - 3 ( $( $x:expr ),* ) => { - { - let mut temp_vec = Vec::new(); - 4 $( - 5 temp_vec.push(6 $x); - )* - 7 temp_vec - } - }; -} -``` +Filename: src/main.rs -Listing 19-28: A simplified version of the `vec!` macro definition - -> Note: The actual definition of the `vec!` macro in the standard library -includes code to pre-allocate the correct amount of memory up front. That code -is an optimization that we don’t include here, to make the example simpler. - -The `#[macro_export]` annotation [1] indicates that this macro should be made -available whenever the crate in which the macro is defined is brought into -scope. Without this annotation, the macro can’t be brought into scope. - -We then start the macro definition with `macro_rules!` and the name of the -macro we’re defining *without* the exclamation mark [2]. The name, in this case -`vec`, is followed by curly brackets denoting the body of the macro definition. - -The structure in the `vec!` body is similar to the structure of a `match` -expression. Here we have one arm with the pattern `( $( $x:expr ),* )`, -followed by `=>` and the block of code associated with this pattern [3]. If the -pattern matches, the associated block of code will be emitted. Given that this -is the only pattern in this macro, there is only one valid way to match; any -other pattern will result in an error. More complex macros will have more than -one arm. - -Valid pattern syntax in macro definitions is different from the pattern syntax -covered in Chapter 18 because macro patterns are matched against Rust code -structure rather than values. Let’s walk through what the pattern pieces in -Listing 19-28 mean; for the full macro pattern syntax, see the Rust Reference -at *https://doc.rust-lang.org/reference/macros-by-example.html*. - -First we use a set of parentheses to encompass the whole pattern. We use a -dollar sign (`$`) to declare a variable in the macro system that will contain -the Rust code matching the pattern. The dollar sign makes it clear this is a -macro variable as opposed to a regular Rust variable. Next comes a set of -parentheses that captures values that match the pattern within the parentheses -for use in the replacement code. Within `$()` is `$x:expr`, which matches any -Rust expression and gives the expression the name `$x`. - -The comma following `$()` indicates that a literal comma separator character -could optionally appear after the code that matches the code in `$()`. The `*` -specifies that the pattern matches zero or more of whatever precedes the `*`. - -When we call this macro with `vec![1, 2, 3];`, the `$x` pattern matches three -times with the three expressions `1`, `2`, and `3`. - -Now let’s look at the pattern in the body of the code associated with this arm: -`temp_vec.push()` [5] within `$()* at [4] and [7] is generated for each part -that matches `$()` in the pattern zero or more times depending on how many -times the pattern matches. The `$x` [6] is replaced with each expression -matched. When we call this macro with `vec![1, 2, 3];`, the code generated that -replaces this macro call will be the following: - -``` -{ - let mut temp_vec = Vec::new(); - temp_vec.push(1); - temp_vec.push(2); - temp_vec.push(3); - temp_vec -} ``` +let s = Some(String::from("Hello!")); -We’ve defined a macro that can take any number of arguments of any type and can -generate code to create a vector containing the specified elements. - -To learn more about how to write macros, consult the online documentation or -other resources, such as “The Little Book of Rust Macros” at -*https://veykril.github.io/tlborm* started by Daniel Keep and continued by -Lukas Wirth. +if let Some(_s) = s { + println!("found a string"); +} -### Procedural Macros for Generating Code from Attributes +println!("{:?}", s); +``` -The second form of macros is the procedural macro, which acts more like a -function (and is a type of procedure). *Procedural macros* accept some code as -an input, operate on that code, and produce some code as an output rather than -matching against patterns and replacing the code with other code as declarative -macros do. The three kinds of procedural macros are custom `derive`, -attribute-like, and function-like, and all work in a similar fashion. +Listing 18-21: An unused variable starting with an underscore still binds the +value, which might take ownership of the value. -When creating procedural macros, the definitions must reside in their own crate -with a special crate type. This is for complex technical reasons that we hope -to eliminate in the future. In Listing 19-29, we show how to define a -procedural macro, where `some_attribute` is a placeholder for using a specific -macro variety. +We’ll receive an error because the `s` value will still be moved into `_s`, +which prevents us from using `s` again. However, using the underscore by itself +doesn’t ever bind to the value. Listing 18-22 will compile without any errors +because `s` doesn’t get moved into `_`. -Filename: src/lib.rs +Filename: src/main.rs ``` -use proc_macro::TokenStream; +let s = Some(String::from("Hello!")); -#[some_attribute] -pub fn some_name(input: TokenStream) -> TokenStream { +if let Some(_) = s { + println!("found a string"); } -``` -Listing 19-29: An example of defining a procedural macro +println!("{:?}", s); +``` -The function that defines a procedural macro takes a `TokenStream` as an input -and produces a `TokenStream` as an output. The `TokenStream` type is defined by -the `proc_macro` crate that is included with Rust and represents a sequence of -tokens. This is the core of the macro: the source code that the macro is -operating on makes up the input `TokenStream`, and the code the macro produces -is the output `TokenStream`. The function also has an attribute attached to it -that specifies which kind of procedural macro we’re creating. We can have -multiple kinds of procedural macros in the same crate. +Listing 18-22: Using an underscore does not bind the value. -Let’s look at the different kinds of procedural macros. We’ll start with a -custom `derive` macro and then explain the small dissimilarities that make the -other forms different. +This code works just fine because we never bind `s` to anything; it isn’t moved. -### How to Write a Custom derive Macro +#### Remaining Parts of a Value with .. -Let’s create a crate named `hello_macro` that defines a trait named -`HelloMacro` with one associated function named `hello_macro`. Rather than -making our users implement the `HelloMacro` trait for each of their types, -we’ll provide a procedural macro so users can annotate their type with -`#[derive(HelloMacro)]` to get a default implementation of the `hello_macro` -function. The default implementation will print `Hello, Macro! My name is` -TypeName`!` where TypeName is the name of the type on which this trait has been -defined. In other words, we’ll write a crate that enables another programmer to -write code like Listing 19-30 using our crate. +With values that have many parts, we can use the `..` syntax to use specific +parts and ignore the rest, avoiding the need to list underscores for each +ignored value. The `..` pattern ignores any parts of a value that we haven’t +explicitly matched in the rest of the pattern. In Listing 18-23, we have a +`Point` struct that holds a coordinate in three-dimensional space. In the +`match` expression, we want to operate only on the `x` coordinate and ignore +the values in the `y` and `z` fields. Filename: src/main.rs ``` -use hello_macro::HelloMacro; -use hello_macro_derive::HelloMacro; +struct Point { + x: i32, + y: i32, + z: i32, +} -#[derive(HelloMacro)] -struct Pancakes; +let origin = Point { x: 0, y: 0, z: 0 }; -fn main() { - Pancakes::hello_macro(); +match origin { + Point { x, .. } => println!("x is {x}"), } ``` -Listing 19-30: The code a user of our crate will be able to write when using -our procedural macro +Listing 18-23: Ignoring all fields of a `Point` except for `x` by using `..` -This code will print `Hello, Macro! My name is Pancakes!` when we’re done. The -first step is to make a new library crate, like this: +We list the `x` value and then just include the `..` pattern. This is quicker +than having to list `y: _` and `z: _`, particularly when we’re working with +structs that have lots of fields in situations where only one or two fields are +relevant. -``` -$ cargo new hello_macro --lib -``` +The syntax `..` will expand to as many values as it needs to be. Listing 18-24 +shows how to use `..` with a tuple. -Next, we’ll define the `HelloMacro` trait and its associated function: - -Filename: src/lib.rs +Filename: src/main.rs ``` -pub trait HelloMacro { - fn hello_macro(); +fn main() { + let numbers = (2, 4, 8, 16, 32); + + match numbers { + (first, .., last) => { + println!("Some numbers: {first}, {last}"); + } + } } ``` -We have a trait and its function. At this point, our crate user could implement -the trait to achieve the desired functionality, like so: +Listing 18-24: Matching only the first and last values in a tuple and ignoring +all other values -``` -use hello_macro::HelloMacro; +In this code, the first and last values are matched with `first` and `last`. +The `..` will match and ignore everything in the middle. -struct Pancakes; +However, using `..` must be unambiguous. If it is unclear which values are +intended for matching and which should be ignored, Rust will give us an error. +Listing 18-25 shows an example of using `..` ambiguously, so it will not +compile. -impl HelloMacro for Pancakes { - fn hello_macro() { - println!("Hello, Macro! My name is Pancakes!"); - } -} +Filename: src/main.rs +``` fn main() { - Pancakes::hello_macro(); + let numbers = (2, 4, 8, 16, 32); + + match numbers { + (.., second, ..) => { + println!("Some numbers: {second}"); + }, + } } ``` -However, they would need to write the implementation block for each type they -wanted to use with `hello_macro`; we want to spare them from having to do this -work. - -Additionally, we can’t yet provide the `hello_macro` function with default -implementation that will print the name of the type the trait is implemented -on: Rust doesn’t have reflection capabilities, so it can’t look up the type’s -name at runtime. We need a macro to generate code at compile time. +Listing 18-25: An attempt to use `..` in an ambiguous way -The next step is to define the procedural macro. At the time of this writing, -procedural macros need to be in their own crate. Eventually, this restriction -might be lifted. The convention for structuring crates and macro crates is as -follows: for a crate named foo, a custom `derive` procedural macro crate is -called foo`_derive`. Let’s start a new crate called `hello_macro_derive` inside -our `hello_macro` project: +When we compile this example, we get this error: ``` -$ cargo new hello_macro_derive --lib +error: `..` can only be used once per tuple pattern + --> src/main.rs:5:22 + | +5 | (.., second, ..) => { + | -- ^^ can only be used once per tuple pattern + | | + | previously used here ``` -Our two crates are tightly related, so we create the procedural macro crate -within the directory of our `hello_macro` crate. If we change the trait -definition in `hello_macro`, we’ll have to change the implementation of the -procedural macro in `hello_macro_derive` as well. The two crates will need to -be published separately, and programmers using these crates will need to add -both as dependencies and bring them both into scope. We could instead have the -`hello_macro` crate use `hello_macro_derive` as a dependency and re-export the -procedural macro code. However, the way we’ve structured the project makes it -possible for programmers to use `hello_macro` even if they don’t want the -`derive` functionality. +It’s impossible for Rust to determine how many values in the tuple to ignore +before matching a value with `second` and then how many further values to +ignore thereafter. This code could mean that we want to ignore `2`, bind +`second` to `4`, and then ignore `8`, `16`, and `32`; or that we want to ignore +`2` and `4`, bind `second` to `8`, and then ignore `16` and `32`; and so forth. +The variable name `second` doesn’t mean anything special to Rust, so we get a +compiler error because using `..` in two places like this is ambiguous. + +### Extra Conditionals with Match Guards + +A *match guard* is an additional `if` condition, specified after the pattern in +a `match` arm, that must also match for that arm to be chosen. Match guards are +useful for expressing more complex ideas than a pattern alone allows. -We need to declare the `hello_macro_derive` crate as a procedural macro crate. -We’ll also need functionality from the `syn` and `quote` crates, as you’ll see -in a moment, so we need to add them as dependencies. Add the following to the -*Cargo.toml* file for `hello_macro_derive`: +The condition can use variables created in the pattern. Listing 18-26 shows a +`match` where the first arm has the pattern `Some(x)` and also has a match +guard of `if x % 2 == 0` (which will be `true` if the number is even). -Filename: hello_macro_derive/Cargo.toml +Filename: src/main.rs ``` -[lib] -proc-macro = true +let num = Some(4); -[dependencies] -syn = "1.0" -quote = "1.0" +match num { + Some(x) if x % 2 == 0 => println!("The number {x} is even"), + Some(x) => println!("The number {x} is odd"), + None => (), +} ``` -To start defining the procedural macro, place the code in Listing 19-31 into -your *src/lib.rs* file for the `hello_macro_derive` crate. Note that this code -won’t compile until we add a definition for the `impl_hello_macro` function. +Listing 18-26: Adding a match guard to a pattern -Filename: hello_macro_derive/src/lib.rs +This example will print `The number 4 is even`. When `num` is compared to the +pattern in the first arm, it matches because `Some(4)` matches `Some(x)`. Then +the match guard checks whether the remainder of dividing `x` by 2 is equal to +0, and because it is, the first arm is selected. -``` -use proc_macro::TokenStream; -use quote::quote; -use syn; +If `num` had been `Some(5)` instead, the match guard in the first arm would +have been `false` because the remainder of 5 divided by 2 is 1, which is not +equal to 0. Rust would then go to the second arm, which would match because the +second arm doesn’t have a match guard and therefore matches any `Some` variant. -#[proc_macro_derive(HelloMacro)] -pub fn hello_macro_derive(input: TokenStream) -> TokenStream { - // Construct a representation of Rust code as a syntax tree - // that we can manipulate - let ast = syn::parse(input).unwrap(); +There is no way to express the `if x % 2 == 0` condition within a pattern, so +the match guard gives us the ability to express this logic. The downside of +this additional expressiveness is that the compiler doesn’t try to check for +exhaustiveness when match guard expressions are involved. - // Build the trait implementation - impl_hello_macro(&ast) -} -``` +In Listing 18-11, we mentioned that we could use match guards to solve our +pattern-shadowing problem. Recall that we created a new variable inside the +pattern in the `match` expression instead of using the variable outside the +`match`. That new variable meant we couldn’t test against the value of the +outer variable. Listing 18-27 shows how we can use a match guard to fix this +problem. -Listing 19-31: Code that most procedural macro crates will require in order to -process Rust code - -Notice that we’ve split the code into the `hello_macro_derive` function, which -is responsible for parsing the `TokenStream`, and the `impl_hello_macro` -function, which is responsible for transforming the syntax tree: this makes -writing a procedural macro more convenient. The code in the outer function -(`hello_macro_derive` in this case) will be the same for almost every -procedural macro crate you see or create. The code you specify in the body of -the inner function (`impl_hello_macro` in this case) will be different -depending on your procedural macro’s purpose. - -We’ve introduced three new crates: `proc_macro`, `syn` (available from -*https://crates.io/crates/syn*), and `quote` (available from -*https://crates.io/crates/quote*). The `proc_macro` crate comes with Rust, so -we didn’t need to add that to the dependencies in *Cargo.toml*. The -`proc_macro` crate is the compiler’s API that allows us to read and manipulate -Rust code from our code. - -The `syn` crate parses Rust code from a string into a data structure that we -can perform operations on. The `quote` crate turns `syn` data structures back -into Rust code. These crates make it much simpler to parse any sort of Rust -code we might want to handle: writing a full parser for Rust code is no simple -task. - -The `hello_macro_derive` function will be called when a user of our library -specifies `#[derive(HelloMacro)]` on a type. This is possible because we’ve -annotated the `hello_macro_derive` function here with `proc_macro_derive` and -specified the name `HelloMacro`, which matches our trait name; this is the -convention most procedural macros follow. - -The `hello_macro_derive` function first converts the `input` from a -`TokenStream` to a data structure that we can then interpret and perform -operations on. This is where `syn` comes into play. The `parse` function in -`syn` takes a `TokenStream` and returns a `DeriveInput` struct representing the -parsed Rust code. Listing 19-32 shows the relevant parts of the `DeriveInput` -struct we get from parsing the `struct Pancakes;` string. - -``` -DeriveInput { - --snip-- - - ident: Ident { - ident: "Pancakes", - span: #0 bytes(95..103) - }, - data: Struct( - DataStruct { - struct_token: Struct, - fields: Unit, - semi_token: Some( - Semi - ) - } - ) -} -``` +Filename: src/main.rs -Listing 19-32: The `DeriveInput` instance we get when parsing the code that has -the macro’s attribute in Listing 19-30 - -The fields of this struct show that the Rust code we’ve parsed is a unit struct -with the `ident` (*identifier*, meaning the name) of `Pancakes`. There are more -fields on this struct for describing all sorts of Rust code; check the `syn` -documentation for `DeriveInput` at -*https://docs.rs/syn/1.0/syn/struct.DeriveInput.html* for more information. - -Soon we’ll define the `impl_hello_macro` function, which is where we’ll build -the new Rust code we want to include. But before we do, note that the output -for our `derive` macro is also a `TokenStream`. The returned `TokenStream` is -added to the code that our crate users write, so when they compile their crate, -they’ll get the extra functionality that we provide in the modified -`TokenStream`. - -You might have noticed that we’re calling `unwrap` to cause the -`hello_macro_derive` function to panic if the call to the `syn::parse` function -fails here. It’s necessary for our procedural macro to panic on errors because -`proc_macro_derive` functions must return `TokenStream` rather than `Result` to -conform to the procedural macro API. We’ve simplified this example by using -`unwrap`; in production code, you should provide more specific error messages -about what went wrong by using `panic!` or `expect`. - -Now that we have the code to turn the annotated Rust code from a `TokenStream` -into a `DeriveInput` instance, let’s generate the code that implements the -`HelloMacro` trait on the annotated type, as shown in Listing 19-33. - -Filename: hello_macro_derive/src/lib.rs - -``` -fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream { - let name = &ast.ident; - let gen = quote! { - impl HelloMacro for #name { - fn hello_macro() { - println!( - "Hello, Macro! My name is {}!", - stringify!(#name) - ); - } - } - }; - gen.into() -} ``` +fn main() { + let x = Some(5); + let y = 10; -Listing 19-33: Implementing the `HelloMacro` trait using the parsed Rust code + match x { + Some(50) => println!("Got 50"), + Some(n) if n == y => println!("Matched, n = {n}"), + _ => println!("Default case, x = {:?}", x), + } -We get an `Ident` struct instance containing the name (identifier) of the -annotated type using `ast.ident`. The struct in Listing 19-32 shows that when -we run the `impl_hello_macro` function on the code in Listing 19-30, the -`ident` we get will have the `ident` field with a value of `"Pancakes"`. Thus -the `name` variable in Listing 19-33 will contain an `Ident` struct instance -that, when printed, will be the string `"Pancakes"`, the name of the struct in -Listing 19-30. + println!("at the end: x = {:?}, y = {y}", x); +} +``` -The `quote!` macro lets us define the Rust code that we want to return. The -compiler expects something different to the direct result of the `quote!` -macro’s execution, so we need to convert it to a `TokenStream`. We do this by -calling the `into` method, which consumes this intermediate representation and -returns a value of the required `TokenStream` type. +Listing 18-27: Using a match guard to test for equality with an outer variable -The `quote!` macro also provides some very cool templating mechanics: we can -enter `#name`, and `quote!` will replace it with the value in the variable -`name`. You can even do some repetition similar to the way regular macros work. -Check out the `quote` crate’s docs at *https://docs.rs/quote* for a thorough -introduction. +This code will now print `Default case, x = Some(5)`. The pattern in the second +match arm doesn’t introduce a new variable `y` that would shadow the outer `y`, +meaning we can use the outer `y` in the match guard. Instead of specifying the +pattern as `Some(y)`, which would have shadowed the outer `y`, we specify +`Some(n)`. This creates a new variable `n` that doesn’t shadow anything because +there is no `n` variable outside the `match`. -We want our procedural macro to generate an implementation of our `HelloMacro` -trait for the type the user annotated, which we can get by using `#name`. The -trait implementation has the one function `hello_macro`, whose body contains -the functionality we want to provide: printing `Hello, Macro! My name is` and -then the name of the annotated type. +The match guard `if n == y` is not a pattern and therefore doesn’t introduce +new variables. This `y` *is* the outer `y` rather than a new shadowed `y`, and +we can look for a value that has the same value as the outer `y` by comparing +`n` to `y`. -The `stringify!` macro used here is built into Rust. It takes a Rust -expression, such as `1 + 2`, and at compile time turns the expression into a -string literal, such as `"1 + 2"`. This is different from `format!` or -`println!`, macros which evaluate the expression and then turn the result into -a `String`. There is a possibility that the `#name` input might be an -expression to print literally, so we use `stringify!`. Using `stringify!` also -saves an allocation by converting `#name` to a string literal at compile time. +You can also use the *or* operator `|` in a match guard to specify multiple +patterns; the match guard condition will apply to all the patterns. Listing +18-28 shows the precedence when combining a pattern that uses `|` with a match +guard. The important part of this example is that the `if y` match guard +applies to `4`, `5`, *and* `6`, even though it might look like `if y` only +applies to `6`. -At this point, `cargo build` should complete successfully in both `hello_macro` -and `hello_macro_derive`. Let’s hook up these crates to the code in Listing -19-30 to see the procedural macro in action! Create a new binary project in -your *projects* directory using `cargo new pancakes`. We need to add -`hello_macro` and `hello_macro_derive` as dependencies in the `pancakes` -crate’s *Cargo.toml*. If you’re publishing your versions of `hello_macro` and -`hello_macro_derive` to *https://crates.io*, they would be regular -dependencies; if not, you can specify them as `path` dependencies as follows: +Filename: src/main.rs ``` -[dependencies] -hello_macro = { path = "../hello_macro" } -hello_macro_derive = { path = "../hello_macro/hello_macro_derive" } -``` +let x = 4; +let y = false; -Put the code in Listing 19-30 into *src/main.rs*, and run `cargo run`: it -should print `Hello, Macro! My name is Pancakes!` The implementation of the -`HelloMacro` trait from the procedural macro was included without the -`pancakes` crate needing to implement it; the `#[derive(HelloMacro)]` added the -trait implementation. - -Next, let’s explore how the other kinds of procedural macros differ from custom -`derive` macros. +match x { + 4 | 5 | 6 if y => println!("yes"), + _ => println!("no"), +} +``` -### Attribute-like Macros +Listing 18-28: Combining multiple patterns with a match guard -Attribute-like macros are similar to custom `derive` macros, but instead of -generating code for the `derive` attribute, they allow you to create new -attributes. They’re also more flexible: `derive` only works for structs and -enums; attributes can be applied to other items as well, such as functions. -Here’s an example of using an attribute-like macro. Say you have an attribute -named `route` that annotates functions when using a web application framework: +The match condition states that the arm only matches if the value of `x` is +equal to `4`, `5`, or `6` *and* if `y` is `true`. When this code runs, the +pattern of the first arm matches because `x` is `4`, but the match guard `if y` +is `false`, so the first arm is not chosen. The code moves on to the second +arm, which does match, and this program prints `no`. The reason is that the +`if` condition applies to the whole pattern `4 | 5 | 6`, not just to the last +value `6`. In other words, the precedence of a match guard in relation to a +pattern behaves like this: ``` -#[route(GET, "/")] -fn index() { +(4 | 5 | 6) if y => ... ``` -This `#[route]` attribute would be defined by the framework as a procedural -macro. The signature of the macro definition function would look like this: +rather than this: ``` -#[proc_macro_attribute] -pub fn route( - attr: TokenStream, - item: TokenStream -) -> TokenStream { +4 | 5 | (6 if y) => ... ``` -Here, we have two parameters of type `TokenStream`. The first is for the -contents of the attribute: the `GET, "/"` part. The second is the body of the -item the attribute is attached to: in this case, `fn index() {}` and the rest -of the function’s body. +After running the code, the precedence behavior is evident: if the match guard +were applied only to the final value in the list of values specified using the +`|` operator, the arm would have matched and the program would have printed +`yes`. -Other than that, attribute-like macros work the same way as custom `derive` -macros: you create a crate with the `proc-macro` crate type and implement a -function that generates the code you want! +### @ Bindings -### Function-like Macros +The *at* operator `@` lets us create a variable that holds a value at the same +time we’re testing that value for a pattern match. In Listing 18-29, we want to +test that a `Message::Hello` `id` field is within the range `3..=7`. We also +want to bind the value to the variable `id_variable` so we can use it in the +code associated with the arm. We could name this variable `id`, the same as the +field, but for this example we’ll use a different name. -Function-like macros define macros that look like function calls. Similarly to -`macro_rules!` macros, they’re more flexible than functions; for example, they -can take an unknown number of arguments. However, `macro_rules!` macros can -only be defined using the match-like syntax we discussed in “Declarative Macros -with macro_rules! for General Metaprogramming” on page XX. Function-like macros -take a `TokenStream` parameter, and their definition manipulates that -`TokenStream` using Rust code as the other two types of procedural macros do. -An example of a function-like macro is an `sql!` macro that might be called -like so: +Filename: src/main.rs ``` -let sql = sql!(SELECT * FROM posts WHERE id=1); -``` +enum Message { + Hello { id: i32 }, +} -This macro would parse the SQL statement inside it and check that it’s -syntactically correct, which is much more complex processing than a -`macro_rules!` macro can do. The `sql!` macro would be defined like this: +let msg = Message::Hello { id: 5 }; +match msg { + Message::Hello { + id: id_variable @ 3..=7, + } => println!("Found an id in range: {id_variable}"), + Message::Hello { id: 10..=12 } => { + println!("Found an id in another range") + } + Message::Hello { id } => println!("Some other id: {id}"), +} ``` -#[proc_macro] -pub fn sql(input: TokenStream) -> TokenStream { -``` -This definition is similar to the custom `derive` macro’s signature: we receive -the tokens that are inside the parentheses and return the code we wanted to -generate. +Listing 18-29: Using `@` to bind to a value in a pattern while also testing it + +This example will print `Found an id in range: 5`. By specifying `id_variable +@` before the range `3..=7`, we’re capturing whatever value matched the range +while also testing that the value matched the range pattern. + +In the second arm, where we only have a range specified in the pattern, the +code associated with the arm doesn’t have a variable that contains the actual +value of the `id` field. The `id` field’s value could have been 10, 11, or 12, +but the code that goes with that pattern doesn’t know which it is. The pattern +code isn’t able to use the value from the `id` field because we haven’t saved +the `id` value in a variable. + +In the last arm, where we’ve specified a variable without a range, we do have +the value available to use in the arm’s code in a variable named `id`. The +reason is that we’ve used the struct field shorthand syntax. But we haven’t +applied any test to the value in the `id` field in this arm, as we did with the +first two arms: any value would match this pattern. + +Using `@` lets us test a value and save it in a variable within one pattern. ## Summary -Whew! Now you have some Rust features in your toolbox that you likely won’t use -often, but you’ll know they’re available in very particular circumstances. -We’ve introduced several complex topics so that when you encounter them in -error message suggestions or in other people’s code, you’ll be able to -recognize these concepts and syntax. Use this chapter as a reference to guide -you to solutions. +Rust’s patterns are very useful in distinguishing between different kinds of +data. When used in `match` expressions, Rust ensures your patterns cover every +possible value, or your program won’t compile. Patterns in `let` statements and +function parameters make those constructs more useful, enabling the +destructuring of values into smaller parts at the same time as assigning to +variables. We can create simple or complex patterns to suit our needs. -Next, we’ll put everything we’ve discussed throughout the book into practice -and do one more project! +Next, for the penultimate chapter of the book, we’ll look at some advanced +aspects of a variety of Rust’s features. diff --git a/nostarch/chapter20.md b/nostarch/chapter20.md index 9d4e22cd77..410e7eb62d 100644 --- a/nostarch/chapter20.md +++ b/nostarch/chapter20.md @@ -6,1989 +6,2291 @@ directory, so all fixes need to be made in `/src/`. [TOC] -# Final Project: Building a Multithreaded Web Server +# Advanced Features + +By now, you’ve learned the most commonly used parts of the Rust programming +language. Before we do one more project, in Chapter 20, we’ll look at a few +aspects of the language you might run into every once in a while, but may not +use every day. You can use this chapter as a reference for when you encounter +any unknowns. The features covered here are useful in very specific situations. +Although you might not reach for them often, we want to make sure you have a +grasp of all the features Rust has to offer. + +In this chapter, we’ll cover: + +* Unsafe Rust: how to opt out of some of Rust’s guarantees and take +responsibility for manually upholding those guarantees +* Advanced traits: associated types, default type parameters, fully qualified +syntax, supertraits, and the newtype pattern in relation to traits +* Advanced types: more about the newtype pattern, type aliases, the never type, +and dynamically sized types +* Advanced functions and closures: function pointers and returning closures +* Macros: ways to define code that defines more code at compile time + +It’s a panoply of Rust features with something for everyone! Let’s dive in! + +## Unsafe Rust + +All the code we’ve discussed so far has had Rust’s memory safety guarantees +enforced at compile time. However, Rust has a second language hidden inside it +that doesn’t enforce these memory safety guarantees: it’s called *unsafe Rust* +and works just like regular Rust, but gives us extra superpowers. + +Unsafe Rust exists because, by nature, static analysis is conservative. When +the compiler tries to determine whether or not code upholds the guarantees, +it’s better for it to reject some valid programs than to accept some invalid +programs. Although the code *might* be okay, if the Rust compiler doesn’t have +enough information to be confident, it will reject the code. In these cases, +you can use unsafe code to tell the compiler, “Trust me, I know what I’m +doing.” Be warned, however, that you use unsafe Rust at your own risk: if you +use unsafe code incorrectly, problems can occur due to memory unsafety, such as +null pointer dereferencing. + +Another reason Rust has an unsafe alter ego is that the underlying computer +hardware is inherently unsafe. If Rust didn’t let you do unsafe operations, you +couldn’t do certain tasks. Rust needs to allow you to do low-level systems +programming, such as directly interacting with the operating system or even +writing your own operating system. Working with low-level systems programming +is one of the goals of the language. Let’s explore what we can do with unsafe +Rust and how to do it. + +### Unsafe Superpowers + +To switch to unsafe Rust, use the `unsafe` keyword and then start a new block +that holds the unsafe code. You can take five actions in unsafe Rust that you +can’t in safe Rust, which we call *unsafe superpowers*. Those superpowers +include the ability to: + +1. Dereference a raw pointer +1. Call an unsafe function or method +1. Access or modify a mutable static variable +1. Implement an unsafe trait +1. Access fields of `union`s + +It’s important to understand that `unsafe` doesn’t turn off the borrow checker +or disable any of Rust’s other safety checks: if you use a reference in unsafe +code, it will still be checked. The `unsafe` keyword only gives you access to +these five features that are then not checked by the compiler for memory +safety. You’ll still get some degree of safety inside an unsafe block. + +In addition, `unsafe` does not mean the code inside the block is necessarily +dangerous or that it will definitely have memory safety problems: the intent is +that as the programmer, you’ll ensure the code inside an `unsafe` block will +access memory in a valid way. + +People are fallible and mistakes will happen, but by requiring these five +unsafe operations to be inside blocks annotated with `unsafe`, you’ll know that +any errors related to memory safety must be within an `unsafe` block. Keep +`unsafe` blocks small; you’ll be thankful later when you investigate memory +bugs. + +To isolate unsafe code as much as possible, it’s best to enclose such code +within a safe abstraction and provide a safe API, which we’ll discuss later in +the chapter when we examine unsafe functions and methods. Parts of the standard +library are implemented as safe abstractions over unsafe code that has been +audited. Wrapping unsafe code in a safe abstraction prevents uses of `unsafe` +from leaking out into all the places that you or your users might want to use +the functionality implemented with `unsafe` code, because using a safe +abstraction is safe. + +Let’s look at each of the five unsafe superpowers in turn. We’ll also look at +some abstractions that provide a safe interface to unsafe code. + +### Dereferencing a Raw Pointer + +In “Dangling References” on page XX, we mentioned that the compiler ensures +references are always valid. Unsafe Rust has two new types called *raw +pointers* that are similar to references. As with references, raw pointers can +be immutable or mutable and are written as `*const T` and `*mut T`, +respectively. The asterisk isn’t the dereference operator; it’s part of the +type name. In the context of raw pointers, *immutable* means that the pointer +can’t be directly assigned to after being dereferenced. + +Different from references and smart pointers, raw pointers: + +* Are allowed to ignore the borrowing rules by having both immutable and +mutable pointers or multiple mutable pointers to the same location +* Aren’t guaranteed to point to valid memory +* Are allowed to be null +* Don’t implement any automatic cleanup -It’s been a long journey, but we’ve reached the end of the book. In this -chapter, we’ll build one more project together to demonstrate some of the -concepts we covered in the final chapters, as well as recap some earlier -lessons. +By opting out of having Rust enforce these guarantees, you can give up +guaranteed safety in exchange for greater performance or the ability to +interface with another language or hardware where Rust’s guarantees don’t apply. -For our final project, we’ll make a web server that says “hello” and looks like -Figure 20-1 in a web browser. - -Figure 20-1: Our final shared project - -Here is our plan for building the web server: - -1. Learn a bit about TCP and HTTP. -1. Listen for TCP connections on a socket. -1. Parse a small number of HTTP requests. -1. Create a proper HTTP response. -1. Improve the throughput of our server with a thread pool. - -Before we get started, we should mention one detail: the method we’ll use won’t -be the best way to build a web server with Rust. Community members have -published a number of production-ready crates available at *https://crates.io* -that provide more complete web server and thread pool implementations than -we’ll build. However, our intention in this chapter is to help you learn, not -to take the easy route. Because Rust is a systems programming language, we can -choose the level of abstraction we want to work with and can go to a lower -level than is possible or practical in other languages. We’ll therefore write -the basic HTTP server and thread pool manually so you can learn the general -ideas and techniques behind the crates you might use in the future. - -## Building a Single-Threaded Web Server +Listing 19-1 shows how to create an immutable and a mutable raw pointer from +references. + +``` +let mut num = 5; -We’ll start by getting a single-threaded web server working. Before we begin, -let’s look at a quick overview of the protocols involved in building web -servers. The details of these protocols are beyond the scope of this book, but -a brief overview will give you the information you need. +let r1 = &num as *const i32; +let r2 = &mut num as *mut i32; +``` -The two main protocols involved in web servers are *Hypertext Transfer -Protocol* *(HTTP)* and *Transmission Control Protocol* *(TCP)*. Both protocols -are *request-response* protocols, meaning a *client* initiates requests and a -*server* listens to the requests and provides a response to the client. The -contents of those requests and responses are defined by the protocols. +Listing 19-1: Creating raw pointers from references -TCP is the lower-level protocol that describes the details of how information -gets from one server to another but doesn’t specify what that information is. -HTTP builds on top of TCP by defining the contents of the requests and -responses. It’s technically possible to use HTTP with other protocols, but in -the vast majority of cases, HTTP sends its data over TCP. We’ll work with the -raw bytes of TCP and HTTP requests and responses. +Notice that we don’t include the `unsafe` keyword in this code. We can create +raw pointers in safe code; we just can’t dereference raw pointers outside an +unsafe block, as you’ll see in a bit. -### Listening to the TCP Connection +We’ve created raw pointers by using `as` to cast an immutable and a mutable +reference into their corresponding raw pointer types. Because we created them +directly from references guaranteed to be valid, we know these particular raw +pointers are valid, but we can’t make that assumption about just any raw +pointer. -Our web server needs to listen to a TCP connection, so that’s the first part -we’ll work on. The standard library offers a `std::net` module that lets us do -this. Let’s make a new project in the usual fashion: +To demonstrate this, next we’ll create a raw pointer whose validity we can’t be +so certain of. Listing 19-2 shows how to create a raw pointer to an arbitrary +location in memory. Trying to use arbitrary memory is undefined: there might be +data at that address or there might not, the compiler might optimize the code +so there is no memory access, or the program might terminate with a +segmentation fault. Usually, there is no good reason to write code like this, +but it is possible. ``` -$ cargo new hello - Created binary (application) `hello` project -$ cd hello +let address = 0x012345usize; +let r = address as *const i32; ``` -Now enter the code in Listing 20-1 in *src/main.rs* to start. This code will -listen at the local address `127.0.0.1:7878` for incoming TCP streams. When it -gets an incoming stream, it will print `Connection established!`. +Listing 19-2: Creating a raw pointer to an arbitrary memory address -Filename: src/main.rs +Recall that we can create raw pointers in safe code, but we can’t *dereference* +raw pointers and read the data being pointed to. In Listing 19-3, we use the +dereference operator `*` on a raw pointer that requires an `unsafe` block. ``` -use std::net::TcpListener; - -fn main() { - 1 let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); +let mut num = 5; - 2 for stream in listener.incoming() { - 3 let stream = stream.unwrap(); +let r1 = &num as *const i32; +let r2 = &mut num as *mut i32; - 4 println!("Connection established!"); - } +unsafe { + println!("r1 is: {}", *r1); + println!("r2 is: {}", *r2); } ``` -Listing 20-1: Listening for incoming streams and printing a message when we -receive a stream - -Using `TcpListener`, we can listen for TCP connections at the address -`127.0.0.1:7878` [1]. In the address, the section before the colon is an IP -address representing your computer (this is the same on every computer and -doesn’t represent the authors’ computer specifically), and `7878` is the port. -We’ve chosen this port for two reasons: HTTP isn’t normally accepted on this -port, so our server is unlikely to conflict with any other web server you might -have running on your machine, and 7878 is *rust* typed on a telephone. - -The `bind` function in this scenario works like the `new` function in that it -will return a new `TcpListener` instance. The function is called `bind` -because, in networking, connecting to a port to listen to is known as “binding -to a port.” - -The `bind` function returns a `Result<T, E>`, which indicates that it’s -possible for binding to fail. For example, connecting to port 80 requires -administrator privileges (non-administrators can listen only on ports higher -than 1023), so if we tried to connect to port 80 without being an -administrator, binding wouldn’t work. Binding also wouldn’t work, for example, -if we ran two instances of our program and so had two programs listening to the -same port. Because we’re writing a basic server just for learning purposes, we -won’t worry about handling these kinds of errors; instead, we use `unwrap` to -stop the program if errors happen. - -The `incoming` method on `TcpListener` returns an iterator that gives us a -sequence of streams [2] (more specifically, streams of type `TcpStream`). A -single *stream* represents an open connection between the client and the -server. A *connection* is the name for the full request and response process in -which a client connects to the server, the server generates a response, and the -server closes the connection. As such, we will read from the `TcpStream` to see -what the client sent and then write our response to the stream to send data -back to the client. Overall, this `for` loop will process each connection in -turn and produce a series of streams for us to handle. - -For now, our handling of the stream consists of calling `unwrap` to terminate -our program if the stream has any errors [3]; if there aren’t any errors, the -program prints a message [4]. We’ll add more functionality for the success case -in the next listing. The reason we might receive errors from the `incoming` -method when a client connects to the server is that we’re not actually -iterating over connections. Instead, we’re iterating over *connection -attempts*. The connection might not be successful for a number of reasons, many -of them operating system specific. For example, many operating systems have a -limit to the number of simultaneous open connections they can support; new -connection attempts beyond that number will produce an error until some of the -open connections are closed. - -Let’s try running this code! Invoke `cargo run` in the terminal and then load -*127.0.0.1:7878* in a web browser. The browser should show an error message -like “Connection reset” because the server isn’t currently sending back any -data. But when you look at your terminal, you should see several messages that -were printed when the browser connected to the server! - -``` - Running `target/debug/hello` -Connection established! -Connection established! -Connection established! -``` - -Sometimes you’ll see multiple messages printed for one browser request; the -reason might be that the browser is making a request for the page as well as a -request for other resources, like the *favicon.ico* icon that appears in the -browser tab. - -It could also be that the browser is trying to connect to the server multiple -times because the server isn’t responding with any data. When `stream` goes out -of scope and is dropped at the end of the loop, the connection is closed as -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 ctrl-C 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 - -Let’s implement the functionality to read the request from the browser! To -separate the concerns of first getting a connection and then taking some action -with the connection, we’ll start a new function for processing connections. In -this new `handle_connection` function, we’ll read data from the TCP stream and -print it so we can see the data being sent from the browser. Change the code to -look like Listing 20-2. +Listing 19-3: Dereferencing raw pointers within an `unsafe` block -Filename: src/main.rs +Creating a pointer does no harm; it’s only when we try to access the value that +it points at that we might end up dealing with an invalid value. -``` -1 use std::{ - io::{prelude::*, BufReader}, - net::{TcpListener, TcpStream}, -}; +Note also that in Listings 19-1 and 19-3, we created `*const i32` and `*mut +i32` raw pointers that both pointed to the same memory location, where `num` is +stored. If we instead tried to create an immutable and a mutable reference to +`num`, the code would not have compiled because Rust’s ownership rules don’t +allow a mutable reference at the same time as any immutable references. With +raw pointers, we can create a mutable pointer and an immutable pointer to the +same location and change data through the mutable pointer, potentially creating +a data race. Be careful! -fn main() { - let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); +With all of these dangers, why would you ever use raw pointers? One major use +case is when interfacing with C code, as you’ll see in “Calling an Unsafe +Function or Method” on page XX. Another case is when building up safe +abstractions that the borrow checker doesn’t understand. We’ll introduce unsafe +functions and then look at an example of a safe abstraction that uses unsafe +code. - for stream in listener.incoming() { - let stream = stream.unwrap(); +### Calling an Unsafe Function or Method - 2 handle_connection(stream); - } -} +The second type of operation you can perform in an unsafe block is calling +unsafe functions. Unsafe functions and methods look exactly like regular +functions and methods, but they have an extra `unsafe` before the rest of the +definition. The `unsafe` keyword in this context indicates the function has +requirements we need to uphold when we call this function, because Rust can’t +guarantee we’ve met these requirements. By calling an unsafe function within an +`unsafe` block, we’re saying that we’ve read this function’s documentation and +we take responsibility for upholding the function’s contracts. + +Here is an unsafe function named `dangerous` that doesn’t do anything in its +body: -fn handle_connection(mut stream: TcpStream) { - 3 let buf_reader = BufReader::new(&mut stream); - 4 let http_request: Vec<_> = buf_reader - 5 .lines() - 6 .map(|result| result.unwrap()) - 7 .take_while(|line| !line.is_empty()) - .collect(); - - 8 println!("Request: {:#?}", http_request); -} -``` - -Listing 20-2: Reading from the `TcpStream` and printing the data - -We bring `std::io::prelude` and `std::io::BufReader` into scope to get access -to traits and types that let us read from and write to the stream [1]. In the -`for` loop in the `main` function, instead of printing a message that says we -made a connection, we now call the new `handle_connection` function and pass -the `stream` to it [2]. - -In the `handle_connection` function, we create a new `BufReader` instance that -wraps a mutable reference to the `stream` [3]. `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 -lines in a vector by adding the `Vec<_>` type annotation [4]. - -`BufReader` implements the `std::io::BufRead` trait, which provides the `lines` -method [5]. The `lines` method returns an iterator of `Result<String, -std::io::Error>` by splitting the stream of data whenever it sees a newline -byte. To get each `String`, we map and `unwrap` each `Result` [6]. The `Result` -might be an error if the data isn’t valid UTF-8 or if there was a problem -reading from the stream. Again, a production program should handle these errors -more gracefully, but we’re choosing to stop the program in the error case for -simplicity. +``` +unsafe fn dangerous() {} -The browser signals the end of an HTTP request by sending two newline -characters in a row, so to get one request from the stream, we take lines until -we get a line that is the empty string [7]. Once we’ve collected the lines into -the vector, we’re printing them out using pretty debug formatting [8] so we can -take a look at the instructions the web browser is sending to our server. +unsafe { + dangerous(); +} +``` -Let’s try this code! Start the program and make a request in a web browser -again. Note that we’ll still get an error page in the browser, but our -program’s output in the terminal will now look similar to this: +We must call the `dangerous` function within a separate `unsafe` block. If we +try to call `dangerous` without the `unsafe` block, we’ll get an error: ``` -$ cargo run - Compiling hello v0.1.0 (file:///projects/hello) - Finished dev [unoptimized + debuginfo] target(s) in 0.42s - Running `target/debug/hello` -Request: [ - "GET / HTTP/1.1", - "Host: 127.0.0.1:7878", - "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) -Gecko/20100101 Firefox/99.0", - "Accept: -text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/* -;q=0.8", - "Accept-Language: en-US,en;q=0.5", - "Accept-Encoding: gzip, deflate, br", - "DNT: 1", - "Connection: keep-alive", - "Upgrade-Insecure-Requests: 1", - "Sec-Fetch-Dest: document", - "Sec-Fetch-Mode: navigate", - "Sec-Fetch-Site: none", - "Sec-Fetch-User: ?1", - "Cache-Control: max-age=0", -] +error[E0133]: call to unsafe function is unsafe and requires +unsafe function or block + --> src/main.rs:4:5 + | +4 | dangerous(); + | ^^^^^^^^^^^ call to unsafe function + | + = note: consult the function's documentation for information on +how to avoid undefined behavior ``` -Depending on your browser, you might get slightly different output. Now that -we’re printing the request data, we can see why we get multiple connections -from one browser request by looking at the path after `GET` in the first line -of the request. If the repeated connections are all requesting */*, we know the -browser is trying to fetch */* repeatedly because it’s not getting a response -from our program. +With the `unsafe` block, we’re asserting to Rust that we’ve read the function’s +documentation, we understand how to use it properly, and we’ve verified that +we’re fulfilling the contract of the function. -Let’s break down this request data to understand what the browser is asking of -our program. +Bodies of unsafe functions are effectively `unsafe` blocks, so to perform other +unsafe operations within an unsafe function, we don’t need to add another +`unsafe` block. -### A Closer Look at an HTTP Request +#### Creating a Safe Abstraction over Unsafe Code -HTTP is a text-based protocol, and a request takes this format: +Just because a function contains unsafe code doesn’t mean we need to mark the +entire function as unsafe. In fact, wrapping unsafe code in a safe function is +a common abstraction. As an example, let’s study the `split_at_mut` function +from the standard library, which requires some unsafe code. We’ll explore how +we might implement it. This safe method is defined on mutable slices: it takes +one slice and makes it two by splitting the slice at the index given as an +argument. Listing 19-4 shows how to use `split_at_mut`. ``` -Method Request-URI HTTP-Version CRLF -headers CRLF -message-body -``` +let mut v = vec![1, 2, 3, 4, 5, 6]; -The first line is the *request line* that holds information about what the -client is requesting. The first part of the request line indicates the *method* -being used, such as `GET` or `POST`, which describes how the client is making -this request. Our client used a `GET` request, which means it is asking for -information. +let r = &mut v[..]; -The next part of the request line is */*, which indicates the *uniform resource -identifier* *(URI)* the client is requesting: a URI is almost, but not quite, -the same as a *uniform resource locator* *(URL)*. The difference between URIs -and URLs isn’t important for our purposes in this chapter, but the HTTP spec -uses the term *URI*, so we can just mentally substitute *URL* for *URI* here. +let (a, b) = r.split_at_mut(3); -The last part is the HTTP version the client uses, and then the request line -ends in a CRLF sequence. (CRLF stands for *carriage return* and *line feed*, -which are terms from the typewriter days!) The CRLF sequence can also be -written as `\r\n`, where `\r` is a carriage return and `\n` is a line feed. The -*CRLF sequence* separates the request line from the rest of the request data. -Note that when the CRLF is printed, we see a new line start rather than `\r\n`. +assert_eq!(a, &mut [1, 2, 3]); +assert_eq!(b, &mut [4, 5, 6]); +``` -Looking at the request line data we received from running our program so far, -we see that `GET` is the method, */* is the request URI, and `HTTP/1.1` is the -version. +Listing 19-4: Using the safe `split_at_mut` function -After the request line, the remaining lines starting from `Host:` onward are -headers. `GET` requests have no body. +We can’t implement this function using only safe Rust. An attempt might look +something like Listing 19-5, which won’t compile. For simplicity, we’ll +implement `split_at_mut` as a function rather than a method and only for slices +of `i32` values rather than for a generic type `T`. -Try making a request from a different browser or asking for a different -address, such as *127.0.0.1:7878/test*, to see how the request data changes. +``` +fn split_at_mut( + values: &mut [i32], + mid: usize, +) -> (&mut [i32], &mut [i32]) { + let len = values.len(); -Now that we know what the browser is asking for, let’s send back some data! + assert!(mid <= len); -### Writing a Response + (&mut values[..mid], &mut values[mid..]) +} +``` -We’re going to implement sending data in response to a client request. -Responses have the following format: +Listing 19-5: An attempted implementation of `split_at_mut` using only safe Rust -``` -HTTP-Version Status-Code Reason-Phrase CRLF -headers CRLF -message-body -``` +This function first gets the total length of the slice. Then it asserts that +the index given as a parameter is within the slice by checking whether it’s +less than or equal to the length. The assertion means that if we pass an index +that is greater than the length to split the slice at, the function will panic +before it attempts to use that index. -The first line is a *status line* that contains the HTTP version used in the -response, a numeric status code that summarizes the result of the request, and -a reason phrase that provides a text description of the status code. After the -CRLF sequence are any headers, another CRLF sequence, and the body of the -response. +Then we return two mutable slices in a tuple: one from the start of the +original slice to the `mid` index and another from `mid` to the end of the +slice. -Here is an example response that uses HTTP version 1.1, and has a status code -of 200, an OK reason phrase, no headers, and no body: +When we try to compile the code in Listing 19-5, we’ll get an error: ``` -HTTP/1.1 200 OK\r\n\r\n +error[E0499]: cannot borrow `*values` as mutable more than once at a time + --> src/main.rs:9:31 + | +2 | values: &mut [i32], + | - let's call the lifetime of this reference `'1` +... +9 | (&mut values[..mid], &mut values[mid..]) + | --------------------------^^^^^^-------- + | | | | + | | | second mutable borrow occurs here + | | first mutable borrow occurs here + | returning this value requires that `*values` is borrowed for `'1` ``` -The status code 200 is the standard success response. The text is a tiny -successful HTTP response. Let’s write this to the stream as our response to a -successful request! From the `handle_connection` function, remove the -`println!` that was printing the request data and replace it with the code in -Listing 20-3. +Rust’s borrow checker can’t understand that we’re borrowing different parts of +the slice; it only knows that we’re borrowing from the same slice twice. +Borrowing different parts of a slice is fundamentally okay because the two +slices aren’t overlapping, but Rust isn’t smart enough to know this. When we +know code is okay, but Rust doesn’t, it’s time to reach for unsafe code. -Filename: src/main.rs +Listing 19-6 shows how to use an `unsafe` block, a raw pointer, and some calls +to unsafe functions to make the implementation of `split_at_mut` work. ``` -fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); - let http_request: Vec<_> = buf_reader - .lines() - .map(|result| result.unwrap()) - .take_while(|line| !line.is_empty()) - .collect(); +use std::slice; + +fn split_at_mut( + values: &mut [i32], + mid: usize, +) -> (&mut [i32], &mut [i32]) { + 1 let len = values.len(); + 2 let ptr = values.as_mut_ptr(); - 1 let response = "HTTP/1.1 200 OK\r\n\r\n"; + 3 assert!(mid <= len); - 2 stream.write_all(response.3 as_bytes()).unwrap(); + 4 unsafe { + ( + 5 slice::from_raw_parts_mut(ptr, mid), + 6 slice::from_raw_parts_mut(ptr.add(mid), len - mid), + ) + } } ``` -Listing 20-3: Writing a tiny successful HTTP response to the stream +Listing 19-6: Using unsafe code in the implementation of the `split_at_mut` +function + +Recall from “The Slice Type” on page XX that a slice is a pointer to some data +and the length of the slice. We use the `len` method to get the length of a +slice [1] and the `as_mut_ptr` method to access the raw pointer of a slice [2]. +In this case, because we have a mutable slice to `i32` values, `as_mut_ptr` +returns a raw pointer with the type `*mut i32`, which we’ve stored in the +variable `ptr`. + +We keep the assertion that the `mid` index is within the slice [3]. Then we get +to the unsafe code [4]: the `slice::from_raw_parts_mut` function takes a raw +pointer and a length, and it creates a slice. We use it to create a slice that +starts from `ptr` and is `mid` items long [5]. Then we call the `add` method on +`ptr` with `mid` as an argument to get a raw pointer that starts at `mid`, and +we create a slice using that pointer and the remaining number of items after +`mid` as the length [6]. + +The function `slice::from_raw_parts_mut` is unsafe because it takes a raw +pointer and must trust that this pointer is valid. The `add` method on raw +pointers is also unsafe because it must trust that the offset location is also +a valid pointer. Therefore, we had to put an `unsafe` block around our calls to +`slice::from_raw_parts_mut` and `add` so we could call them. By looking at the +code and by adding the assertion that `mid` must be less than or equal to +`len`, we can tell that all the raw pointers used within the `unsafe` block +will be valid pointers to data within the slice. This is an acceptable and +appropriate use of `unsafe`. + +Note that we don’t need to mark the resultant `split_at_mut` function as +`unsafe`, and we can call this function from safe Rust. We’ve created a safe +abstraction to the unsafe code with an implementation of the function that uses +`unsafe` code in a safe way, because it creates only valid pointers from the +data this function has access to. + +In contrast, the use of `slice::from_raw_parts_mut` in Listing 19-7 would +likely crash when the slice is used. This code takes an arbitrary memory +location and creates a slice 10,000 items long. + +``` +use std::slice; + +let address = 0x01234usize; +let r = address as *mut i32; + +let values: &[i32] = unsafe { + slice::from_raw_parts_mut(r, 10000) +}; +``` -The first new line defines the `response` variable that holds the success -message’s data [1]. Then we call `as_bytes` on our `response` to convert the -string data to bytes [3]. The `write_all` method on `stream` takes a `&[u8]` -and sends those bytes directly down the connection [2]. Because the `write_all` -operation could fail, we use `unwrap` on any error result as before. Again, in -a real application you would add error handling here. +Listing 19-7: Creating a slice from an arbitrary memory location -With these changes, let’s run our code and make a request. We’re no longer -printing any data to the terminal, so we won’t see any output other than the -output from Cargo. When you load *127.0.0.1:7878* in a web browser, you should -get a blank page instead of an error. You’ve just handcoded receiving an HTTP -request and sending a response! +We don’t own the memory at this arbitrary location, and there is no guarantee +that the slice this code creates contains valid `i32` values. Attempting to use +`values` as though it’s a valid slice results in undefined behavior. -### Returning Real HTML +#### Using extern Functions to Call External Code -Let’s implement the functionality for returning more than a blank page. Create -the new file *hello.html* in the root of your project directory, not in the -*src* directory. You can input any HTML you want; Listing 20-4 shows one -possibility. +Sometimes your Rust code might need to interact with code written in another +language. For this, Rust has the keyword `extern` that facilitates the creation +and use of a *Foreign Function Interface* *(FFI)*, which is a way for a +programming language to define functions and enable a different (foreign) +programming language to call those functions. -Filename: hello.html +Listing 19-8 demonstrates how to set up an integration with the `abs` function +from the C standard library. Functions declared within `extern` blocks are +always unsafe to call from Rust code. The reason is that other languages don’t +enforce Rust’s rules and guarantees, and Rust can’t check them, so +responsibility falls on the programmer to ensure safety. + +Filename: src/main.rs ``` -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title>Hello! - - -

Hello!

-

Hi from Rust

- - -``` +extern "C" { + fn abs(input: i32) -> i32; +} -Listing 20-4: A sample HTML file to return in a response +fn main() { + unsafe { + println!( + "Absolute value of -3 according to C: {}", + abs(-3) + ); + } +} +``` -This is a minimal HTML5 document with a heading and some text. To return this -from the server when a request is received, we’ll modify `handle_connection` as -shown in Listing 20-5 to read the HTML file, add it to the response as a body, -and send it. +Listing 19-8: Declaring and calling an `extern` function defined in another +language + +Within the `extern "C"` block, we list the names and signatures of external +functions from another language we want to call. The `"C"` part defines which +*application binary interface* *(ABI)* the external function uses: the ABI +defines how to call the function at the assembly level. The `"C"` ABI is the +most common and follows the C programming language’s ABI. + +> ### Calling Rust Functions from Other Languages +> +> We can also use `extern` to create an interface that allows other languages +to call Rust functions. Instead of creating a whole `extern` block, we add the +`extern` keyword and specify the ABI to use just before the `fn` keyword for +the relevant function. We also need to add a `#[no_mangle]` annotation to tell +the Rust compiler not to mangle the name of this function. *Mangling* is when a +compiler changes the name we’ve given a function to a different name that +contains more information for other parts of the compilation process to consume +but is less human readable. Every programming language compiler mangles names +slightly differently, so for a Rust function to be nameable by other languages, +we must disable the Rust compiler’s name mangling. +> +> In the following example, we make the `call_from_c` function accessible from +C code, after it’s compiled to a shared library and linked from C: +> +> ``` +> #[no_mangle] +> pub extern "C" fn call_from_c() { +> println!("Just called a Rust function from C!"); +> } +> ``` +> +> This usage of `extern` does not require `unsafe`. + +### Accessing or Modifying a Mutable Static Variable + +In this book, we’ve not yet talked about global variables, which Rust does +support but can be problematic with Rust’s ownership rules. If two threads are +accessing the same mutable global variable, it can cause a data race. + +In Rust, global variables are called *static* variables. Listing 19-9 shows an +example declaration and use of a static variable with a string slice as a value. Filename: src/main.rs ``` -use std::{ - 1 fs, - io::{prelude::*, BufReader}, - net::{TcpListener, TcpStream}, -}; ---snip-- - -fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); - let http_request: Vec<_> = buf_reader - .lines() - .map(|result| result.unwrap()) - .take_while(|line| !line.is_empty()) - .collect(); - - let status_line = "HTTP/1.1 200 OK"; - let contents = fs::read_to_string("hello.html").unwrap(); - let length = contents.len(); - - 2 let response = format!( - "{status_line}\r\n\ - Content-Length: {length}\r\n\r\n\ - {contents}" - ); +static HELLO_WORLD: &str = "Hello, world!"; - stream.write_all(response.as_bytes()).unwrap(); +fn main() { + println!("value is: {HELLO_WORLD}"); } ``` -Listing 20-5: Sending the contents of *hello.html* as the body of the response - -We’ve added `fs` to the `use` statement to bring the standard library’s -filesystem module into scope [1]. The code for reading the contents of a file -to a string should look familiar; we used it when we read the contents of a -file for our I/O project in Listing 12-4. +Listing 19-9: Defining and using an immutable static variable -Next, we use `format!` to add the file’s contents as the body of the success -response [2]. To ensure a valid HTTP response, we add the `Content-Length` -header which is set to the size of our response body, in this case the size of -`hello.html`. +Static variables are similar to constants, which we discussed in “Constants” on +page XX. The names of static variables are in `SCREAMING_SNAKE_CASE` by +convention. Static variables can only store references with the `'static` +lifetime, which means the Rust compiler can figure out the lifetime and we +aren’t required to annotate it explicitly. Accessing an immutable static +variable is safe. -Run this code with `cargo run` and load *127.0.0.1:7878* in your browser; you -should see your HTML rendered! +A subtle difference between constants and immutable static variables is that +values in a static variable have a fixed address in memory. Using the value +will always access the same data. Constants, on the other hand, are allowed to +duplicate their data whenever they’re used. Another difference is that static +variables can be mutable. Accessing and modifying mutable static variables is +*unsafe*. Listing 19-10 shows how to declare, access, and modify a mutable +static variable named `COUNTER`. -Currently, we’re ignoring the request data in `http_request` and just sending -back the contents of the HTML file unconditionally. That means if you try -requesting *127.0.0.1:7878/something-else* in your browser, you’ll still get -back this same HTML response. At the moment, our server is very limited and -does not do what most web servers do. We want to customize our responses -depending on the request and only send back the HTML file for a well-formed -request to */*. +Filename: src/main.rs -### Validating the Request and Selectively Responding +``` +static mut COUNTER: u32 = 0; -Right now, our web server will return the HTML in the file no matter what the -client requested. Let’s add functionality to check that the browser is -requesting */* before returning the HTML file, and return an error if the -browser requests anything else. For this we need to modify `handle_connection`, -as shown in Listing 20-6. This new code checks the content of the request -received against what we know a request for */* looks like and adds `if` and -`else` blocks to treat requests differently. +fn add_to_count(inc: u32) { + unsafe { + COUNTER += inc; + } +} -Filename: src/main.rs +fn main() { + add_to_count(3); + unsafe { + println!("COUNTER: {COUNTER}"); + } +} ``` ---snip-- -fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); - 1 let request_line = buf_reader - .lines() - .next() - .unwrap() - .unwrap(); +Listing 19-10: Reading from or writing to a mutable static variable is unsafe. - 2 if request_line == "GET / HTTP/1.1" { - let status_line = "HTTP/1.1 200 OK"; - let contents = fs::read_to_string("hello.html").unwrap(); - let length = contents.len(); +As with regular variables, we specify mutability using the `mut` keyword. Any +code that reads or writes from `COUNTER` must be within an `unsafe` block. This +code compiles and prints `COUNTER: 3` as we would expect because it’s single +threaded. Having multiple threads access `COUNTER` would likely result in data +races. - let response = format!( - "{status_line}\r\n\ - Content-Length: {length}\r\n\r\n\ - {contents}" - ); +With mutable data that is globally accessible, it’s difficult to ensure there +are no data races, which is why Rust considers mutable static variables to be +unsafe. Where possible, it’s preferable to use the concurrency techniques and +thread-safe smart pointers we discussed in Chapter 16 so the compiler checks +that data access from different threads is done safely. - stream.write_all(response.as_bytes()).unwrap(); - 3 } else { - // some other request - } +### Implementing an Unsafe Trait + +We can use `unsafe` to implement an unsafe trait. A trait is unsafe when at +least one of its methods has some invariant that the compiler can’t verify. We +declare that a trait is `unsafe` by adding the `unsafe` keyword before `trait` +and marking the implementation of the trait as `unsafe` too, as shown in +Listing 19-11. + +``` +unsafe trait Foo { + // methods go here +} + +unsafe impl Foo for i32 { + // method implementations go here } ``` -Listing 20-6: Handling requests to */* differently from other requests +Listing 19-11: Defining and implementing an unsafe trait -We’re only going to be looking at the first line of the HTTP request, so rather -than reading the entire request into a vector, we’re calling `next` to get the -first item from the iterator [1]. The first `unwrap` takes care of the `Option` -and stops the program if the iterator has no items. The second `unwrap` handles -the `Result` and has the same effect as the `unwrap` that was in the `map` -added in Listing 20-2. +By using `unsafe impl`, we’re promising that we’ll uphold the invariants that +the compiler can’t verify. -Next, we check the `request_line` to see if it equals the request line of a GET -request to the */* path [2]. If it does, the `if` block returns the contents of -our HTML file. +As an example, recall the `Send` and `Sync` marker traits we discussed in +“Extensible Concurrency with the Send and Sync Traits” on page XX: the compiler +implements these traits automatically if our types are composed entirely of +`Send` and `Sync` types. If we implement a type that contains a type that is +not `Send` or `Sync`, such as raw pointers, and we want to mark that type as +`Send` or `Sync`, we must use `unsafe`. Rust can’t verify that our type upholds +the guarantees that it can be safely sent across threads or accessed from +multiple threads; therefore, we need to do those checks manually and indicate +as such with `unsafe`. -If the `request_line` does *not* equal the GET request to the */* path, it -means we’ve received some other request. We’ll add code to the `else` block [3] -in a moment to respond to all other requests. +### Accessing Fields of a Union -Run this code now and request *127.0.0.1:7878*; you should get the HTML in -*hello.html*. If you make any other request, such as -*127.0.0.1:7878/something-else*, you’ll get a connection error like those you -saw when running the code in Listing 20-1 and Listing 20-2. +The final action that works only with `unsafe` is accessing fields of a union. +A `union` is similar to a `struct`, but only one declared field is used in a +particular instance at one time. Unions are primarily used to interface with +unions in C code. Accessing union fields is unsafe because Rust can’t guarantee +the type of the data currently being stored in the union instance. You can +learn more about unions in the Rust Reference at +*https://doc.rust-lang.org/reference/items/unions.html**.* -Now let’s add the code in Listing 20-7 to the `else` block to return a response -with the status code 404, which signals that the content for the request was -not found. We’ll also return some HTML for a page to render in the browser -indicating the response to the end user. +### When to Use Unsafe Code -Filename: src/main.rs +Using `unsafe` to use one of the five superpowers just discussed isn’t wrong or +even frowned upon, but it is trickier to get `unsafe` code correct because the +compiler can’t help uphold memory safety. When you have a reason to use +`unsafe` code, you can do so, and having the explicit `unsafe` annotation makes +it easier to track down the source of problems when they occur. -``` ---snip-- -} else { - 1 let status_line = "HTTP/1.1 404 NOT FOUND"; - 2 let contents = fs::read_to_string("404.html").unwrap(); - let length = contents.len(); +## Advanced Traits - let response = format!( - "{status_line}\r\n\ - Content-Length: {length}\r\n\r\n - {contents}" - ); +We first covered traits in “Traits: Defining Shared Behavior” on page XX, but +we didn’t discuss the more advanced details. Now that you know more about Rust, +we can get into the nitty-gritty. + +### Associated Types - stream.write_all(response.as_bytes()).unwrap(); +*Associated types* connect a type placeholder with a trait such that the trait +method definitions can use these placeholder types in their signatures. The +implementor of a trait will specify the concrete type to be used instead of the +placeholder type for the particular implementation. That way, we can define a +trait that uses some types without needing to know exactly what those types are +until the trait is implemented. + +We’ve described most of the advanced features in this chapter as being rarely +needed. Associated types are somewhere in the middle: they’re used more rarely +than features explained in the rest of the book but more commonly than many of +the other features discussed in this chapter. + +One example of a trait with an associated type is the `Iterator` trait that the +standard library provides. The associated type is named `Item` and stands in +for the type of the values the type implementing the `Iterator` trait is +iterating over. The definition of the `Iterator` trait is as shown in Listing +19-12. + +``` +pub trait Iterator { + type Item; + + fn next(&mut self) -> Option; } ``` -Listing 20-7: Responding with status code 404 and an error page if anything -other than */* was requested +Listing 19-12: The definition of the `Iterator` trait that has an associated +type `Item` -Here, our response has a status line with status code 404 and the reason phrase -`NOT FOUND` [1]. The body of the response will be the HTML in the file -*404.html* [1]. You’ll need to create a *404.html* file next to *hello.html* -for the error page; again feel free to use any HTML you want, or use the -example HTML in Listing 20-8. +The type `Item` is a placeholder, and the `next` method’s definition shows that +it will return values of type `Option`. Implementors of the +`Iterator` trait will specify the concrete type for `Item`, and the `next` +method will return an `Option` containing a value of that concrete type. -Filename: 404.html +Associated types might seem like a similar concept to generics, in that the +latter allow us to define a function without specifying what types it can +handle. To examine the difference between the two concepts, we’ll look at an +implementation of the `Iterator` trait on a type named `Counter` that specifies +the `Item` type is `u32`: + +Filename: src/lib.rs ``` - - - - - Hello! - - -

Oops!

-

Sorry, I don't know what you're asking for.

- - -``` +impl Iterator for Counter { + type Item = u32; -Listing 20-8: Sample content for the page to send back with any 404 response + fn next(&mut self) -> Option { + --snip-- +``` -With these changes, run your server again. Requesting *127.0.0.1:7878* should -return the contents of *hello.html*, and any other request, like -*127.0.0.1:7878/foo*, should return the error HTML from *404.html*. +This syntax seems comparable to that of generics. So why not just define the +`Iterator` trait with generics, as shown in Listing 19-13? -### A Touch of Refactoring +``` +pub trait Iterator { + fn next(&mut self) -> Option; +} +``` -At the moment, the `if` and `else` blocks have a lot of repetition: they’re -both reading files and writing the contents of the files to the stream. The -only differences are the status line and the filename. Let’s make the code more -concise by pulling out those differences into separate `if` and `else` lines -that will assign the values of the status line and the filename to variables; -we can then use those variables unconditionally in the code to read the file -and write the response. Listing 20-9 shows the resultant code after replacing -the large `if` and `else` blocks. +Listing 19-13: A hypothetical definition of the `Iterator` trait using generics + +The difference is that when using generics, as in Listing 19-13, we must +annotate the types in each implementation; because we can also implement +`Iterator<``String``> for Counter` or any other type, we could have multiple +implementations of `Iterator` for `Counter`. In other words, when a trait has a +generic parameter, it can be implemented for a type multiple times, changing +the concrete types of the generic type parameters each time. When we use the +`next` method on `Counter`, we would have to provide type annotations to +indicate which implementation of `Iterator` we want to use. + +With associated types, we don’t need to annotate types because we can’t +implement a trait on a type multiple times. In Listing 19-12 with the +definition that uses associated types, we can choose what the type of `Item` +will be only once because there can be only one `impl Iterator for Counter`. We +don’t have to specify that we want an iterator of `u32` values everywhere we +call `next` on `Counter`. + +Associated types also become part of the trait’s contract: implementors of the +trait must provide a type to stand in for the associated type placeholder. +Associated types often have a name that describes how the type will be used, +and documenting the associated type in the API documentation is a good practice. + +### Default Generic Type Parameters and Operator Overloading + +When we use generic type parameters, we can specify a default concrete type for +the generic type. This eliminates the need for implementors of the trait to +specify a concrete type if the default type works. You specify a default type +when declaring a generic type with the `<`PlaceholderType`=`ConcreteType`>` +syntax. + +A great example of a situation where this technique is useful is with *operator +overloading*, in which you customize the behavior of an operator (such as `+`) +in particular situations. + +Rust doesn’t allow you to create your own operators or overload arbitrary +operators. But you can overload the operations and corresponding traits listed +in `std::ops` by implementing the traits associated with the operator. For +example, in Listing 19-14 we overload the `+` operator to add two `Point` +instances together. We do this by implementing the `Add` trait on a `Point` +struct. Filename: src/main.rs ``` ---snip-- +use std::ops::Add; -fn handle_connection(mut stream: TcpStream) { - --snip-- +#[derive(Debug, Copy, Clone, PartialEq)] +struct Point { + x: i32, + y: i32, +} - let (status_line, filename) = - if request_line == "GET / HTTP/1.1" { - ("HTTP/1.1 200 OK", "hello.html") - } else { - ("HTTP/1.1 404 NOT FOUND", "404.html") - }; +impl Add for Point { + type Output = Point; - let contents = fs::read_to_string(filename).unwrap(); - let length = contents.len(); + fn add(self, other: Point) -> Point { + Point { + x: self.x + other.x, + y: self.y + other.y, + } + } +} - let response = format!( - "{status_line}\r\n\ - Content-Length: {length}\r\n\r\n\ - {contents}" +fn main() { + assert_eq!( + Point { x: 1, y: 0 } + Point { x: 2, y: 3 }, + Point { x: 3, y: 3 } ); - - stream.write_all(response.as_bytes()).unwrap(); } ``` -Listing 20-9: Refactoring the `if` and `else` blocks to contain only the code -that differs between the two cases - -Now the `if` and `else` blocks only return the appropriate values for the -status line and filename in a tuple; we then use destructuring to assign these -two values to `status_line` and `filename` using a pattern in the `let` -statement, as discussed in Chapter 18. +Listing 19-14: Implementing the `Add` trait to overload the `+` operator for +`Point` instances -The previously duplicated code is now outside the `if` and `else` blocks and -uses the `status_line` and `filename` variables. This makes it easier to see -the difference between the two cases, and it means we have only one place to -update the code if we want to change how the file reading and response writing -work. The behavior of the code in Listing 20-9 will be the same as that in -Listing 20-8. +The `add` method adds the `x` values of two `Point` instances and the `y` +values of two `Point` instances to create a new `Point`. The `Add` trait has an +associated type named `Output` that determines the type returned from the `add` +method. -Awesome! We now have a simple web server in approximately 40 lines of Rust code -that responds to one request with a page of content and responds to all other -requests with a 404 response. +The default generic type in this code is within the `Add` trait. Here is its +definition: -Currently, our server runs in a single thread, meaning it can only serve one -request at a time. Let’s examine how that can be a problem by simulating some -slow requests. Then we’ll fix it so our server can handle multiple requests at -once. +``` +trait Add { + type Output; -## Turning Our Single-Threaded Server into a Multithreaded Server + fn add(self, rhs: Rhs) -> Self::Output; +} +``` -Right now, the server will process each request in turn, meaning it won’t -process a second connection until the first is finished processing. If the -server received more and more requests, this serial execution would be less and -less optimal. If the server receives a request that takes a long time to -process, subsequent requests will have to wait until the long request is -finished, even if the new requests can be processed quickly. We’ll need to fix -this, but first we’ll look at the problem in action. +This code should look generally familiar: a trait with one method and an +associated type. The new part is `Rhs=Self`: this syntax is called *default +type parameters*. The `Rhs` generic type parameter (short for “right-hand +side”) defines the type of the `rhs` parameter in the `add` method. If we don’t +specify a concrete type for `Rhs` when we implement the `Add` trait, the type +of `Rhs` will default to `Self`, which will be the type we’re implementing +`Add` on. -### Simulating a Slow Request +When we implemented `Add` for `Point`, we used the default for `Rhs` because we +wanted to add two `Point` instances. Let’s look at an example of implementing +the `Add` trait where we want to customize the `Rhs` type rather than using the +default. -We’ll look at how a slow-processing request can affect other requests made to -our current server implementation. Listing 20-10 implements handling a request -to */sleep* with a simulated slow response that will cause the server to sleep -for five seconds before responding. +We have two structs, `Millimeters` and `Meters`, holding values in different +units. This thin wrapping of an existing type in another struct is known as the +*newtype pattern*, which we describe in more detail in “Using the Newtype +Pattern to Implement External Traits on External Types” on page XX. We want to +add values in millimeters to values in meters and have the implementation of +`Add` do the conversion correctly. We can implement `Add` for `Millimeters` +with `Meters` as the `Rhs`, as shown in Listing 19-15. -Filename: src/main.rs +Filename: src/lib.rs ``` -use std::{ - fs, - io::{prelude::*, BufReader}, - net::{TcpListener, TcpStream}, - thread, - time::Duration, -}; ---snip-- +use std::ops::Add; -fn handle_connection(mut stream: TcpStream) { - --snip-- +struct Millimeters(u32); +struct Meters(u32); - let (status_line, filename) = 1 match &request_line[..] { - 2 "GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"), - 3 "GET /sleep HTTP/1.1" => { - thread::sleep(Duration::from_secs(5)); - ("HTTP/1.1 200 OK", "hello.html") - } - 4 _ => ("HTTP/1.1 404 NOT FOUND", "404.html"), - }; +impl Add for Millimeters { + type Output = Millimeters; - --snip-- + fn add(self, other: Meters) -> Millimeters { + Millimeters(self.0 + (other.0 * 1000)) + } } ``` -Listing 20-10: Simulating a slow request by sleeping for five seconds - -We switched from `if` to `match` now that we have three cases [1]. We need to -explicitly match on a slice of `request_line` to pattern-match against the -string literal values; `match` doesn’t do automatic referencing and -dereferencing, like the equality method does. - -The first arm [2] is the same as the `if` block from Listing 20-9. The second -arm [3] matches a request to */sleep*. When that request is received, the -server will sleep for five seconds before rendering the successful HTML page. -The third arm [4] is the same as the `else` block from Listing 20-9. - -You can see how primitive our server is: real libraries would handle the -recognition of multiple requests in a much less verbose way! - -Start the server using `cargo run`. Then open two browser windows: one for -*http://127.0.0.1:7878* and the other for *http://127.0.0.1:7878/sleep*. If you -enter the */* URI a few times, as before, you’ll see it respond quickly. But if -you enter */sleep* and then load */*, you’ll see that */* waits until `sleep` -has slept for its full five seconds before loading. - -There are multiple techniques we could use to avoid requests backing up behind -a slow request; the one we’ll implement is a thread pool. - -### Improving Throughput with a Thread Pool - -A *thread pool* is a group of spawned threads that are waiting and ready to -handle a task. When the program receives a new task, it assigns one of the -threads in the pool to the task, and that thread will process the task. The -remaining threads in the pool are available to handle any other tasks that come -in while the first thread is processing. When the first thread is done -processing its task, it’s returned to the pool of idle threads, ready to handle -a new task. A thread pool allows you to process connections concurrently, -increasing the throughput of your server. - -We’ll limit the number of threads in the pool to a small number to protect us -from DoS attacks; if we had our program create a new thread for each request as -it came in, someone making 10 million requests to our server could create havoc -by using up all our server’s resources and grinding the processing of requests -to a halt. - -Rather than spawning unlimited threads, then, we’ll have a fixed number of -threads waiting in the pool. Requests that come in are sent to the pool for -processing. The pool will maintain a queue of incoming requests. Each of the -threads in the pool will pop off a request from this queue, handle the request, -and then ask the queue for another request. With this design, we can process up -to N requests concurrently, where N is the number of threads. If each thread is -responding to a long-running request, subsequent requests can still back up in -the queue, but we’ve increased the number of long-running requests we can -handle before reaching that point. - -This technique is just one of many ways to improve the throughput of a web -server. Other options you might explore are the fork/join model, the -single-threaded async I/O model, and the multithreaded async I/O model. If -you’re interested in this topic, you can read more about other solutions and -try to implement them; with a low-level language like Rust, all of these -options are possible. - -Before we begin implementing a thread pool, let’s talk about what using the -pool should look like. When you’re trying to design code, writing the client -interface first can help guide your design. Write the API of the code so it’s -structured in the way you want to call it; then implement the functionality -within that structure rather than implementing the functionality and then -designing the public API. - -Similar to how we used test-driven development in the project in Chapter 12, -we’ll use compiler-driven development here. We’ll write the code that calls the -functions we want, and then we’ll look at errors from the compiler to determine -what we should change next to get the code to work. Before we do that, however, -we’ll explore the technique we’re not going to use as a starting point. - -#### Spawning a Thread for Each Request - -First, let’s explore how our code might look if it did create a new thread for -every connection. As mentioned earlier, this isn’t our final plan due to the -problems with potentially spawning an unlimited number of threads, but it is a -starting point to get a working multithreaded server first. Then we’ll add the -thread pool as an improvement, and contrasting the two solutions will be easier. - -Listing 20-11 shows the changes to make to `main` to spawn a new thread to -handle each stream within the `for` loop. +Listing 19-15: Implementing the `Add` trait on `Millimeters` to add +`Millimeters` and `Meters` + +To add `Millimeters` and `Meters`, we specify `impl Add` to set the +value of the `Rhs` type parameter instead of using the default of `Self`. + +You’ll use default type parameters in two main ways: + +1. To extend a type without breaking existing code +1. To allow customization in specific cases most users won’t need + +The standard library’s `Add` trait is an example of the second purpose: +usually, you’ll add two like types, but the `Add` trait provides the ability to +customize beyond that. Using a default type parameter in the `Add` trait +definition means you don’t have to specify the extra parameter most of the +time. In other words, a bit of implementation boilerplate isn’t needed, making +it easier to use the trait. + +The first purpose is similar to the second but in reverse: if you want to add a +type parameter to an existing trait, you can give it a default to allow +extension of the functionality of the trait without breaking the existing +implementation code. + +### Disambiguating Between Methods with the Same Name + +Nothing in Rust prevents a trait from having a method with the same name as +another trait’s method, nor does Rust prevent you from implementing both traits +on one type. It’s also possible to implement a method directly on the type with +the same name as methods from traits. + +When calling methods with the same name, you’ll need to tell Rust which one you +want to use. Consider the code in Listing 19-16 where we’ve defined two traits, +`Pilot` and `Wizard`, that both have a method called `fly`. We then implement +both traits on a type `Human` that already has a method named `fly` implemented +on it. Each `fly` method does something different. Filename: src/main.rs ``` -fn main() { - let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); +trait Pilot { + fn fly(&self); +} - for stream in listener.incoming() { - let stream = stream.unwrap(); +trait Wizard { + fn fly(&self); +} - thread::spawn(|| { - handle_connection(stream); - }); +struct Human; + +impl Pilot for Human { + fn fly(&self) { + println!("This is your captain speaking."); } } -``` -Listing 20-11: Spawning a new thread for each stream +impl Wizard for Human { + fn fly(&self) { + println!("Up!"); + } +} -As you learned in Chapter 16, `thread::spawn` will create a new thread and then -run the code in the closure in the new thread. If you run this code and load -*/sleep* in your browser, then */* in two more browser tabs, you’ll indeed see -that the requests to */* don’t have to wait for */sleep* to finish. However, as -we mentioned, this will eventually overwhelm the system because you’d be making -new threads without any limit. +impl Human { + fn fly(&self) { + println!("*waving arms furiously*"); + } +} +``` -#### Creating a Finite Number of Threads +Listing 19-16: Two traits are defined to have a `fly` method and are +implemented on the `Human` type, and a `fly` method is implemented on `Human` +directly. -We want our thread pool to work in a similar, familiar way so that switching -from threads to a thread pool doesn’t require large changes to the code that -uses our API. Listing 20-12 shows the hypothetical interface for a `ThreadPool` -struct we want to use instead of `thread::spawn`. +When we call `fly` on an instance of `Human`, the compiler defaults to calling +the method that is directly implemented on the type, as shown in Listing 19-17. Filename: src/main.rs ``` fn main() { - let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); - 1 let pool = ThreadPool::new(4); - - for stream in listener.incoming() { - let stream = stream.unwrap(); - - 2 pool.execute(|| { - handle_connection(stream); - }); - } + let person = Human; + person.fly(); } ``` -Listing 20-12: Our ideal `ThreadPool` interface +Listing 19-17: Calling `fly` on an instance of `Human` -We use `ThreadPool::new` to create a new thread pool with a configurable number -of threads, in this case four [1]. Then, in the `for` loop, `pool.execute` has -a similar interface as `thread::spawn` in that it takes a closure the pool -should run for each stream [2]. We need to implement `pool.execute` so it takes -the closure and gives it to a thread in the pool to run. This code won’t yet -compile, but we’ll try so that the compiler can guide us in how to fix it. +Running this code will print `*waving arms furiously*`, showing that Rust +called the `fly` method implemented on `Human` directly. -#### Building ThreadPool Using Compiler-Driven Development +To call the `fly` methods from either the `Pilot` trait or the `Wizard` trait, +we need to use more explicit syntax to specify which `fly` method we mean. +Listing 19-18 demonstrates this syntax. -Make the changes in Listing 20-12 to *src/main.rs*, and then let’s use the -compiler errors from `cargo check` to drive our development. Here is the first -error we get: +Filename: src/main.rs ``` -$ cargo check - Checking hello v0.1.0 (file:///projects/hello) -error[E0433]: failed to resolve: use of undeclared type `ThreadPool` - --> src/main.rs:11:16 - | -11 | let pool = ThreadPool::new(4); - | ^^^^^^^^^^ use of undeclared type `ThreadPool` +fn main() { + let person = Human; + Pilot::fly(&person); + Wizard::fly(&person); + person.fly(); +} ``` -Great! This error tells us we need a `ThreadPool` type or module, so we’ll -build one now. Our `ThreadPool` implementation will be independent of the kind -of work our web server is doing. So let’s switch the `hello` crate from a -binary crate to a library crate to hold our `ThreadPool` implementation. After -we change to a library crate, we could also use the separate thread pool -library for any work we want to do using a thread pool, not just for serving -web requests. +Listing 19-18: Specifying which trait’s `fly` method we want to call -Create a *src/lib.rs* file that contains the following, which is the simplest -definition of a `ThreadPool` struct that we can have for now: +Specifying the trait name before the method name clarifies to Rust which +implementation of `fly` we want to call. We could also write +`Human::fly(&person)`, which is equivalent to the `person.fly()` that we used +in Listing 19-18, but this is a bit longer to write if we don’t need to +disambiguate. -Filename: src/lib.rs +Running this code prints the following: ``` -pub struct ThreadPool; +This is your captain speaking. +Up! +*waving arms furiously* ``` -Then edit the *main.rs* file to bring `ThreadPool` into scope from the library -crate by adding the following code to the top of *src/main.rs*: +Because the `fly` method takes a `self` parameter, if we had two *types* that +both implement one *trait*, Rust could figure out which implementation of a +trait to use based on the type of `self`. + +However, associated functions that are not methods don’t have a `self` +parameter. When there are multiple types or traits that define non-method +functions with the same function name, Rust doesn’t always know which type you +mean unless you use fully qualified syntax. For example, in Listing 19-19 we +create a trait for an animal shelter that wants to name all baby dogs Spot. We +make an `Animal` trait with an associated non-method function `baby_name`. The +`Animal` trait is implemented for the struct `Dog`, on which we also provide an +associated non-method function `baby_name` directly. Filename: src/main.rs ``` -use hello::ThreadPool; +trait Animal { + fn baby_name() -> String; +} + +struct Dog; + +impl Dog { + fn baby_name() -> String { + String::from("Spot") + } +} + +impl Animal for Dog { + fn baby_name() -> String { + String::from("puppy") + } +} + +fn main() { + println!("A baby dog is called a {}", Dog::baby_name()); +} ``` -This code still won’t work, but let’s check it again to get the next error that -we need to address: +Listing 19-19: A trait with an associated function and a type with an +associated function of the same name that also implements the trait + +We implement the code for naming all puppies Spot in the `baby_name` associated +function that is defined on `Dog`. The `Dog` type also implements the trait +`Animal`, which describes characteristics that all animals have. Baby dogs are +called puppies, and that is expressed in the implementation of the `Animal` +trait on `Dog` in the `baby_name` function associated with the `Animal` trait. + +In `main`, we call the `Dog::baby_name` function, which calls the associated +function defined on `Dog` directly. This code prints the following: ``` -$ cargo check - Checking hello v0.1.0 (file:///projects/hello) -error[E0599]: no function or associated item named `new` found for struct -`ThreadPool` in the current scope - --> src/main.rs:12:28 - | -12 | let pool = ThreadPool::new(4); - | ^^^ function or associated item not found in -`ThreadPool` +A baby dog is called a Spot ``` -This error indicates that next we need to create an associated function named -`new` for `ThreadPool`. We also know that `new` needs to have one parameter -that can accept `4` as an argument and should return a `ThreadPool` instance. -Let’s implement the simplest `new` function that will have those -characteristics: +This output isn’t what we wanted. We want to call the `baby_name` function that +is part of the `Animal` trait that we implemented on `Dog` so the code prints +`A baby dog is called a puppy`. The technique of specifying the trait name that +we used in Listing 19-18 doesn’t help here; if we change `main` to the code in +Listing 19-20, we’ll get a compilation error. -Filename: src/lib.rs +Filename: src/main.rs ``` -pub struct ThreadPool; - -impl ThreadPool { - pub fn new(size: usize) -> ThreadPool { - ThreadPool - } +fn main() { + println!("A baby dog is called a {}", Animal::baby_name()); } ``` -We chose `usize` as the type of the `size` parameter because we know that a -negative number of threads doesn’t make any sense. We also know we’ll use this -`4` as the number of elements in a collection of threads, which is what the -`usize` type is for, as discussed in “Integer Types” on page XX. +Listing 19-20: Attempting to call the `baby_name` function from the `Animal` +trait, but Rust doesn’t know which implementation to use -Let’s check the code again: +Because `Animal::baby_name` doesn’t have a `self` parameter, and there could be +other types that implement the `Animal` trait, Rust can’t figure out which +implementation of `Animal::baby_name` we want. We’ll get this compiler error: ``` -$ cargo check - Checking hello v0.1.0 (file:///projects/hello) -error[E0599]: no method named `execute` found for struct `ThreadPool` in the -current scope - --> src/main.rs:17:14 +error[E0283]: type annotations needed + --> src/main.rs:20:43 + | +20 | println!("A baby dog is called a {}", Animal::baby_name()); + | ^^^^^^^^^^^^^^^^^ cannot infer +type | -17 | pool.execute(|| { - | ^^^^^^^ method not found in `ThreadPool` -``` - -Now the error occurs because we don’t have an `execute` method on `ThreadPool`. -Recall from “Creating a Finite Number of Threads” on page XX that we decided -our thread pool should have an interface similar to `thread::spawn`. In -addition, we’ll implement the `execute` function so it takes the closure it’s -given and gives it to an idle thread in the pool to run. - -We’ll define the `execute` method on `ThreadPool` to take a closure as a -parameter. Recall from “Moving Captured Values Out of Closures and the Fn -Traits” on page XX that we can take closures as parameters with three different -traits: `Fn`, `FnMut`, and `FnOnce`. We need to decide which kind of closure to -use here. We know we’ll end up doing something similar to the standard library -`thread::spawn` implementation, so we can look at what bounds the signature of -`thread::spawn` has on its parameter. The documentation shows us the following: - -``` -pub fn spawn(f: F) -> JoinHandle - where - F: FnOnce() -> T, - F: Send + 'static, - T: Send + 'static, -``` - -The `F` type parameter is the one we’re concerned with here; the `T` type -parameter is related to the return value, and we’re not concerned with that. We -can see that `spawn` uses `FnOnce` as the trait bound on `F`. This is probably -what we want as well, because we’ll eventually pass the argument we get in -`execute` to `spawn`. We can be further confident that `FnOnce` is the trait we -want to use because the thread for running a request will only execute that -request’s closure one time, which matches the `Once` in `FnOnce`. - -The `F` type parameter also has the trait bound `Send` and the lifetime bound -`'static`, which are useful in our situation: we need `Send` to transfer the -closure from one thread to another and `'static` because we don’t know how long -the thread will take to execute. Let’s create an `execute` method on -`ThreadPool` that will take a generic parameter of type `F` with these bounds: + = note: cannot satisfy `_: Animal` +``` -Filename: src/lib.rs +To disambiguate and tell Rust that we want to use the implementation of +`Animal` for `Dog` as opposed to the implementation of `Animal` for some other +type, we need to use fully qualified syntax. Listing 19-21 demonstrates how to +use fully qualified syntax. + +Filename: src/main.rs ``` -impl ThreadPool { - --snip-- - pub fn execute(&self, f: F) - where - F: FnOnce() 1 + Send + 'static, - { - } +fn main() { + println!( + "A baby dog is called a {}", + ::baby_name() + ); } ``` -We still use the `()` after `FnOnce` [1] because this `FnOnce` represents a -closure that takes no parameters and returns the unit type `()`. Just like -function definitions, the return type can be omitted from the signature, but -even if we have no parameters, we still need the parentheses. +Listing 19-21: Using fully qualified syntax to specify that we want to call the +`baby_name` function from the `Animal` trait as implemented on `Dog` -Again, this is the simplest implementation of the `execute` method: it does -nothing, but we’re only trying to make our code compile. Let’s check it again: +We’re providing Rust with a type annotation within the angle brackets, which +indicates we want to call the `baby_name` method from the `Animal` trait as +implemented on `Dog` by saying that we want to treat the `Dog` type as an +`Animal` for this function call. This code will now print what we want: ``` -$ cargo check - Checking hello v0.1.0 (file:///projects/hello) - Finished dev [unoptimized + debuginfo] target(s) in 0.24s +A baby dog is called a puppy ``` -It compiles! But note that if you try `cargo run` and make a request in the -browser, you’ll see the errors in the browser that we saw at the beginning of -the chapter. Our library isn’t actually calling the closure passed to `execute` -yet! +In general, fully qualified syntax is defined as follows: -> Note: A saying you might hear about languages with strict compilers, such as -Haskell and Rust, is “if the code compiles, it works.” But this saying is not -universally true. Our project compiles, but it does absolutely nothing! If we -were building a real, complete project, this would be a good time to start -writing unit tests to check that the code compiles *and* has the behavior we -want. +``` +::function(receiver_if_method, next_arg, ...); +``` -#### Validating the Number of Threads in new +For associated functions that aren’t methods, there would not be a `receiver`: +there would only be the list of other arguments. You could use fully qualified +syntax everywhere that you call functions or methods. However, you’re allowed +to omit any part of this syntax that Rust can figure out from other information +in the program. You only need to use this more verbose syntax in cases where +there are multiple implementations that use the same name and Rust needs help +to identify which implementation you want to call. -We aren’t doing anything with the parameters to `new` and `execute`. Let’s -implement the bodies of these functions with the behavior we want. To start, -let’s think about `new`. Earlier we chose an unsigned type for the `size` -parameter because a pool with a negative number of threads makes no sense. -However, a pool with zero threads also makes no sense, yet zero is a perfectly -valid `usize`. We’ll add code to check that `size` is greater than zero before -we return a `ThreadPool` instance and have the program panic if it receives a -zero by using the `assert!` macro, as shown in Listing 20-13. +### Using Supertraits -Filename: src/lib.rs +Sometimes you might write a trait definition that depends on another trait: for +a type to implement the first trait, you want to require that type to also +implement the second trait. You would do this so that your trait definition can +make use of the associated items of the second trait. The trait your trait +definition is relying on is called a *supertrait* of your trait. +For example, let’s say we want to make an `OutlinePrint` trait with an +`outline_print` method that will print a given value formatted so that it’s +framed in asterisks. That is, given a `Point` struct that implements the +standard library trait `Display` to result in `(x, y)`, when we call +`outline_print` on a `Point` instance that has `1` for `x` and `3` for `y`, it +should print the following: + +``` +********** +* * +* (1, 3) * +* * +********** ``` -impl ThreadPool { - /// Create a new ThreadPool. - /// - /// The size is the number of threads in the pool. - /// - 1 /// # Panics - /// - /// The `new` function will panic if the size is zero. - pub fn new(size: usize) -> ThreadPool { - 2 assert!(size > 0); - ThreadPool - } +In the implementation of the `outline_print` method, we want to use the +`Display` trait’s functionality. Therefore, we need to specify that the +`OutlinePrint` trait will work only for types that also implement `Display` and +provide the functionality that `OutlinePrint` needs. We can do that in the +trait definition by specifying `OutlinePrint: Display`. This technique is +similar to adding a trait bound to the trait. Listing 19-22 shows an +implementation of the `OutlinePrint` trait. - --snip-- +Filename: src/main.rs + +``` +use std::fmt; + +trait OutlinePrint: fmt::Display { + fn outline_print(&self) { + let output = self.to_string(); + let len = output.len(); + println!("{}", "*".repeat(len + 4)); + println!("*{}*", " ".repeat(len + 2)); + println!("* {} *", output); + println!("*{}*", " ".repeat(len + 2)); + println!("{}", "*".repeat(len + 4)); + } } ``` -Listing 20-13: Implementing `ThreadPool::new` to panic if `size` is zero +Listing 19-22: Implementing the `OutlinePrint` trait that requires the +functionality from `Display` -We’ve also added some documentation for our `ThreadPool` with doc comments. -Note that we followed good documentation practices by adding a section that -calls out the situations in which our function can panic [1], as discussed in -Chapter 14. Try running `cargo doc --open` and clicking the `ThreadPool` struct -to see what the generated docs for `new` look like! +Because we’ve specified that `OutlinePrint` requires the `Display` trait, we +can use the `to_string` function that is automatically implemented for any type +that implements `Display`. If we tried to use `to_string` without adding a +colon and specifying the `Display` trait after the trait name, we’d get an +error saying that no method named `to_string` was found for the type `&Self` in +the current scope. -Instead of adding the `assert!` macro as we’ve done here [2], we could change -`new` into `build` and return a `Result` like we did with `Config::build` in -the I/O project in Listing 12-9. But we’ve decided in this case that trying to -create a thread pool without any threads should be an unrecoverable error. If -you’re feeling ambitious, try to write a function named `build` with the -following signature to compare with the `new` function: +Let’s see what happens when we try to implement `OutlinePrint` on a type that +doesn’t implement `Display`, such as the `Point` struct: + +Filename: src/main.rs ``` -pub fn build( - size: usize -) -> Result { -``` +struct Point { + x: i32, + y: i32, +} -#### Creating Space to Store the Threads +impl OutlinePrint for Point {} +``` -Now that we have a way to know we have a valid number of threads to store in -the pool, we can create those threads and store them in the `ThreadPool` struct -before returning the struct. But how do we “store” a thread? Let’s take another -look at the `thread::spawn` signature: +We get an error saying that `Display` is required but not implemented: ``` -pub fn spawn(f: F) -> JoinHandle - where - F: FnOnce() -> T, - F: Send + 'static, - T: Send + 'static, +error[E0277]: `Point` doesn't implement `std::fmt::Display` + --> src/main.rs:20:6 + | +20 | impl OutlinePrint for Point {} + | ^^^^^^^^^^^^ `Point` cannot be formatted with the default formatter + | + = help: the trait `std::fmt::Display` is not implemented for `Point` + = note: in format strings you may be able to use `{:?}` (or {:#?} for +pretty-print) instead +note: required by a bound in `OutlinePrint` + --> src/main.rs:3:21 + | +3 | trait OutlinePrint: fmt::Display { + | ^^^^^^^^^^^^ required by this bound in `OutlinePrint` ``` -The `spawn` function returns a `JoinHandle`, where `T` is the type that the -closure returns. Let’s try using `JoinHandle` too and see what happens. In our -case, the closures we’re passing to the thread pool will handle the connection -and not return anything, so `T` will be the unit type `()`. - -The code in Listing 20-14 will compile but doesn’t create any threads yet. -We’ve changed the definition of `ThreadPool` to hold a vector of -`thread::JoinHandle<()>` instances, initialized the vector with a capacity of -`size`, set up a `for` loop that will run some code to create the threads, and -returned a `ThreadPool` instance containing them. +To fix this, we implement `Display` on `Point` and satisfy the constraint that +`OutlinePrint` requires, like so: -Filename: src/lib.rs +Filename: src/main.rs ``` -1 use std::thread; +use std::fmt; -pub struct ThreadPool { - 2 threads: Vec>, +impl fmt::Display for Point { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "({}, {})", self.x, self.y) + } } +``` -impl ThreadPool { - --snip-- - pub fn new(size: usize) -> ThreadPool { - assert!(size > 0); +Then, implementing the `OutlinePrint` trait on `Point` will compile +successfully, and we can call `outline_print` on a `Point` instance to display +it within an outline of asterisks. - 3 let mut threads = Vec::with_capacity(size); +### Using the Newtype Pattern to Implement External Traits - for _ in 0..size { - // create some threads and store them in the vector - } +In “Implementing a Trait on a Type” on page XX, we mentioned the orphan rule +that states we’re only allowed to implement a trait on a type if either the +trait or the type, or both, are local to our crate. It’s possible to get around +this restriction using the *newtype pattern*, which involves creating a new +type in a tuple struct. (We covered tuple structs in “Using Tuple Structs +Without Named Fields to Create Different Types” on page XX.) The tuple struct +will have one field and be a thin wrapper around the type for which we want to +implement a trait. Then the wrapper type is local to our crate, and we can +implement the trait on the wrapper. *Newtype* is a term that originates from +the Haskell programming language. There is no runtime performance penalty for +using this pattern, and the wrapper type is elided at compile time. + +As an example, let’s say we want to implement `Display` on `Vec`, which the +orphan rule prevents us from doing directly because the `Display` trait and the +`Vec` type are defined outside our crate. We can make a `Wrapper` struct +that holds an instance of `Vec`; then we can implement `Display` on +`Wrapper` and use the `Vec` value, as shown in Listing 19-23. + +Filename: src/main.rs - ThreadPool { threads } +``` +use std::fmt; + +struct Wrapper(Vec); + +impl fmt::Display for Wrapper { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "[{}]", self.0.join(", ")) } - --snip-- +} + +fn main() { + let w = Wrapper(vec![ + String::from("hello"), + String::from("world"), + ]); + println!("w = {w}"); } ``` -Listing 20-14: Creating a vector for `ThreadPool` to hold the threads +Listing 19-23: Creating a `Wrapper` type around `Vec` to implement +`Display` -We’ve brought `std::thread` into scope in the library crate [1] because we’re -using `thread::JoinHandle` as the type of the items in the vector in -`ThreadPool` [2]. +The implementation of `Display` uses `self.0` to access the inner `Vec` +because `Wrapper` is a tuple struct and `Vec` is the item at index 0 in the +tuple. Then we can use the functionality of the `Display` type on `Wrapper`. -Once a valid size is received, our `ThreadPool` creates a new vector that can -hold `size` items [3]. The `with_capacity` function performs the same task as -`Vec::new` but with an important difference: it pre-allocates space in the -vector. Because we know we need to store `size` elements in the vector, doing -this allocation up front is slightly more efficient than using `Vec::new`, -which resizes itself as elements are inserted. +The downside of using this technique is that `Wrapper` is a new type, so it +doesn’t have the methods of the value it’s holding. We would have to implement +all the methods of `Vec` directly on `Wrapper` such that the methods +delegate to `self.0`, which would allow us to treat `Wrapper` exactly like a +`Vec`. If we wanted the new type to have every method the inner type has, +implementing the `Deref` trait on the `Wrapper` to return the inner type would +be a solution (we discussed implementing the `Deref` trait in “Treating Smart +Pointers Like Regular References with Deref” on page XX). If we didn’t want the +`Wrapper` type to have all the methods of the inner type—for example, to +restrict the `Wrapper` type’s behavior—we would have to implement just the +methods we do want manually. -When you run `cargo check` again, it should succeed. +This newtype pattern is also useful even when traits are not involved. Let’s +switch focus and look at some advanced ways to interact with Rust’s type system. -#### Sending Code from the ThreadPool to a Thread +## Advanced Types -We left a comment in the `for` loop in Listing 20-14 regarding the creation of -threads. Here, we’ll look at how we actually create threads. The standard -library provides `thread::spawn` as a way to create threads, and -`thread::spawn` expects to get some code the thread should run as soon as the -thread is created. However, in our case, we want to create the threads and have -them *wait* for code that we’ll send later. The standard library’s -implementation of threads doesn’t include any way to do that; we have to -implement it manually. +The Rust type system has some features that we’ve so far mentioned but haven’t +yet discussed. We’ll start by discussing newtypes in general as we examine why +newtypes are useful as types. Then we’ll move on to type aliases, a feature +similar to newtypes but with slightly different semantics. We’ll also discuss +the `!` type and dynamically sized types. -We’ll implement this behavior by introducing a new data structure between the -`ThreadPool` and the threads that will manage this new behavior. We’ll call -this data structure *Worker*, which is a common term in pooling -implementations. The `Worker` picks up code that needs to be run and runs the -code in its thread. +### Using the Newtype Pattern for Type Safety and Abstraction -Think of people working in the kitchen at a restaurant: the workers wait until -orders come in from customers, and then they’re responsible for taking those -orders and filling them. +> Note: This section assumes you’ve read the earlier section “Using the Newtype +Pattern to Implement External Traits” on page XX. -Instead of storing a vector of `JoinHandle<()>` instances in the thread pool, -we’ll store instances of the `Worker` struct. Each `Worker` will store a single -`JoinHandle<()>` instance. Then we’ll implement a method on `Worker` that will -take a closure of code to run and send it to the already running thread for -execution. We’ll also give each `Worker` an `id` so we can distinguish between -the different instances of `Worker` in the pool when logging or debugging. +The newtype pattern is also useful for tasks beyond those we’ve discussed so +far, including statically enforcing that values are never confused and +indicating the units of a value. You saw an example of using newtypes to +indicate units in Listing 19-15: recall that the `Millimeters` and `Meters` +structs wrapped `u32` values in a newtype. If we wrote a function with a +parameter of type `Millimeters`, we wouldn’t be able to compile a program that +accidentally tried to call that function with a value of type `Meters` or a +plain `u32`. -Here is the new process that will happen when we create a `ThreadPool`. We’ll -implement the code that sends the closure to the thread after we have `Worker` -set up in this way: +We can also use the newtype pattern to abstract away some implementation +details of a type: the new type can expose a public API that is different from +the API of the private inner type. -1. Define a `Worker` struct that holds an `id` and a `JoinHandle<()>`. -1. Change `ThreadPool` to hold a vector of `Worker` instances. -1. Define a `Worker::new` function that takes an `id` number and returns a -`Worker` instance that holds the `id` and a thread spawned with an empty -closure. -1. In `ThreadPool::new`, use the `for` loop counter to generate an `id`, create -a new `Worker` with that `id`, and store the `Worker` in the vector. +Newtypes can also hide internal implementation. For example, we could provide a +`People` type to wrap a `HashMap` that stores a person’s ID +associated with their name. Code using `People` would only interact with the +public API we provide, such as a method to add a name string to the `People` +collection; that code wouldn’t need to know that we assign an `i32` ID to names +internally. The newtype pattern is a lightweight way to achieve encapsulation +to hide implementation details, which we discussed in “Encapsulation That Hides +Implementation Details” on page XX. -If you’re up for a challenge, try implementing these changes on your own before -looking at the code in Listing 20-15. +### Creating Type Synonyms with Type Aliases -Ready? Here is Listing 20-15 with one way to make the preceding modifications. +Rust provides the ability to declare a *type alias* to give an existing type +another name. For this we use the `type` keyword. For example, we can create +the alias `Kilometers` to `i32` like so: -Filename: src/lib.rs +``` +type Kilometers = i32; +``` + +Now the alias `Kilometers` is a *synonym* for `i32`; unlike the `Millimeters` +and `Meters` types we created in Listing 19-15, `Kilometers` is not a separate, +new type. Values that have the type `Kilometers` will be treated the same as +values of type `i32`: ``` -use std::thread; +type Kilometers = i32; -pub struct ThreadPool { - 1 workers: Vec, -} +let x: i32 = 5; +let y: Kilometers = 5; -impl ThreadPool { - --snip-- - pub fn new(size: usize) -> ThreadPool { - assert!(size > 0); +println!("x + y = {}", x + y); +``` - let mut workers = Vec::with_capacity(size); +Because `Kilometers` and `i32` are the same type, we can add values of both +types and we can pass `Kilometers` values to functions that take `i32` +parameters. However, using this method, we don’t get the type-checking benefits +that we get from the newtype pattern discussed earlier. In other words, if we +mix up `Kilometers` and `i32` values somewhere, the compiler will not give us +an error. - 2 for id in 0..size { - 3 workers.push(Worker::new(id)); - } +The main use case for type synonyms is to reduce repetition. For example, we +might have a lengthy type like this: - ThreadPool { workers } - } +``` +Box +``` + +Writing this lengthy type in function signatures and as type annotations all +over the code can be tiresome and error prone. Imagine having a project full of +code like that in Listing 19-24. + +``` +let f: Box = Box::new(|| { + println!("hi"); +}); + +fn takes_long_type(f: Box) { --snip-- } -4 struct Worker { - id: usize, - thread: thread::JoinHandle<()>, +fn returns_long_type() -> Box { + --snip-- } +``` -impl Worker { - 5 fn new(id: usize) -> Worker { - 6 let thread = thread::spawn(|| {}); +Listing 19-24: Using a long type in many places + +A type alias makes this code more manageable by reducing the repetition. In +Listing 19-25, we’ve introduced an alias named `Thunk` for the verbose type and +can replace all uses of the type with the shorter alias `Thunk`. - Worker { 7 id, 8 thread } - } -} ``` +type Thunk = Box; -Listing 20-15: Modifying `ThreadPool` to hold `Worker` instances instead of -holding threads directly +let f: Thunk = Box::new(|| println!("hi")); -We’ve changed the name of the field on `ThreadPool` from `threads` to `workers` -because it’s now holding `Worker` instances instead of `JoinHandle<()>` -instances [1]. We use the counter in the `for` loop [2] as an argument to -`Worker::new`, and we store each new `Worker` in the vector named `workers` [3]. +fn takes_long_type(f: Thunk) { + --snip-- +} -External code (like our server in *src/main.rs*) doesn’t need to know the -implementation details regarding using a `Worker` struct within `ThreadPool`, -so we make the `Worker` struct [4] and its `new` function [5] private. The -`Worker::new` function uses the `id` we give it [7] and stores a -`JoinHandle<()>` instance [8] that is created by spawning a new thread using an -empty closure [6]. +fn returns_long_type() -> Thunk { + --snip-- +} +``` -> Note: If the operating system can’t create a thread because there aren’t -enough system resources, `thread::spawn` will panic. That will cause our whole -server to panic, even though the creation of some threads might succeed. For -simplicity’s sake, this behavior is fine, but in a production thread pool -implementation, you’d likely want to use `std::thread::Builder` and its `spawn` -method that returns `Result` instead. +Listing 19-25: Introducing a type alias `Thunk` to reduce repetition -This code will compile and will store the number of `Worker` instances we -specified as an argument to `ThreadPool::new`. But we’re *still* not processing -the closure that we get in `execute`. Let’s look at how to do that next. +This code is much easier to read and write! Choosing a meaningful name for a +type alias can help communicate your intent as well (*thunk* is a word for code +to be evaluated at a later time, so it’s an appropriate name for a closure that +gets stored). -#### Sending Requests to Threads via Channels +Type aliases are also commonly used with the `Result` type for reducing +repetition. Consider the `std::io` module in the standard library. I/O +operations often return a `Result` to handle situations when operations +fail to work. This library has a `std::io::Error` struct that represents all +possible I/O errors. Many of the functions in `std::io` will be returning +`Result` where the `E` is `std::io::Error`, such as these functions in +the `Write` trait: -The next problem we’ll tackle is that the closures given to `thread::spawn` do -absolutely nothing. Currently, we get the closure we want to execute in the -`execute` method. But we need to give `thread::spawn` a closure to run when we -create each `Worker` during the creation of the `ThreadPool`. +``` +use std::fmt; +use std::io::Error; -We want the `Worker` structs that we just created to fetch the code to run from -a queue held in the `ThreadPool` and send that code to its thread to run. +pub trait Write { + fn write(&mut self, buf: &[u8]) -> Result; + fn flush(&mut self) -> Result<(), Error>; -The channels we learned about in Chapter 16—a simple way to communicate between -two threads—would be perfect for this use case. We’ll use a channel to function -as the queue of jobs, and `execute` will send a job from the `ThreadPool` to -the `Worker` instances, which will send the job to its thread. Here is the plan: + fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>; + fn write_fmt( + &mut self, + fmt: fmt::Arguments, + ) -> Result<(), Error>; +} +``` -1. The `ThreadPool` will create a channel and hold on to the sender. -1. Each `Worker` will hold on to the receiver. -1. We’ll create a new `Job` struct that will hold the closures we want to send -down the channel. -1. The `execute` method will send the job it wants to execute through the -sender. -1. In its thread, the `Worker` will loop over its receiver and execute the -closures of any jobs it receives. +The `Result<..., Error>` is repeated a lot. As such, `std::io` has this type +alias declaration: -Let’s start by creating a channel in `ThreadPool::new` and holding the sender -in the `ThreadPool` instance, as shown in Listing 20-16. The `Job` struct -doesn’t hold anything for now but will be the type of item we’re sending down -the channel. +``` +type Result = std::result::Result; +``` -Filename: src/lib.rs +Because this declaration is in the `std::io` module, we can use the fully +qualified alias `std::io::Result`; that is, a `Result` with the `E` +filled in as `std::io::Error`. The `Write` trait function signatures end up +looking like this: ``` -use std::{sync::mpsc, thread}; +pub trait Write { + fn write(&mut self, buf: &[u8]) -> Result; + fn flush(&mut self) -> Result<()>; -pub struct ThreadPool { - workers: Vec, - sender: mpsc::Sender, + fn write_all(&mut self, buf: &[u8]) -> Result<()>; + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()>; } +``` -struct Job; - -impl ThreadPool { - --snip-- - pub fn new(size: usize) -> ThreadPool { - assert!(size > 0); - - 1 let (sender, receiver) = mpsc::channel(); +The type alias helps in two ways: it makes code easier to write *and* it gives +us a consistent interface across all of `std::io`. Because it’s an alias, it’s +just another `Result`, which means we can use any methods that work on +`Result` with it, as well as special syntax like the `?` operator. - let mut workers = Vec::with_capacity(size); +### The Never Type That Never Returns - for id in 0..size { - workers.push(Worker::new(id)); - } +Rust has a special type named `!` that’s known in type theory lingo as the +*empty type* because it has no values. We prefer to call it the *never type* +because it stands in the place of the return type when a function will never +return. Here is an example: - ThreadPool { workers, 2 sender } - } +``` +fn bar() -> ! { --snip-- } ``` -Listing 20-16: Modifying `ThreadPool` to store the sender of a channel that -transmits `Job` instances +This code is read as “the function `bar` returns never.” Functions that return +never are called *diverging functions*. We can’t create values of the type `!`, +so `bar` can never possibly return. + +But what use is a type you can never create values for? Recall the code from +Listing 2-5, part of the number-guessing game; we’ve reproduced a bit of it +here in Listing 19-26. -In `ThreadPool::new`, we create our new channel [1] and have the pool hold the -sender [2]. This will successfully compile. +``` +let guess: u32 = match guess.trim().parse() { + Ok(num) => num, + Err(_) => continue, +}; +``` -Let’s try passing a receiver of the channel into each `Worker` as the thread -pool creates the channel. We know we want to use the receiver in the thread -that the `Worker` instances spawn, so we’ll reference the `receiver` parameter -in the closure. The code in Listing 20-17 won’t quite compile yet. +Listing 19-26: A `match` with an arm that ends in `continue` -Filename: src/lib.rs +At the time, we skipped over some details in this code. In “The match Control +Flow Construct” on page XX, we discussed that `match` arms must all return the +same type. So, for example, the following code doesn’t work: ``` -impl ThreadPool { - --snip-- - pub fn new(size: usize) -> ThreadPool { - assert!(size > 0); +let guess = match guess.trim().parse() { + Ok(_) => 5, + Err(_) => "hello", +}; +``` - let (sender, receiver) = mpsc::channel(); +The type of `guess` in this code would have to be an integer *and* a string, +and Rust requires that `guess` have only one type. So what does `continue` +return? How were we allowed to return a `u32` from one arm and have another arm +that ends with `continue` in Listing 19-26? - let mut workers = Vec::with_capacity(size); +As you might have guessed, `continue` has a `!` value. That is, when Rust +computes the type of `guess`, it looks at both match arms, the former with a +value of `u32` and the latter with a `!` value. Because `!` can never have a +value, Rust decides that the type of `guess` is `u32`. - for id in 0..size { - 1 workers.push(Worker::new(id, receiver)); - } +The formal way of describing this behavior is that expressions of type `!` can +be coerced into any other type. We’re allowed to end this `match` arm with +`continue` because `continue` doesn’t return a value; instead, it moves control +back to the top of the loop, so in the `Err` case, we never assign a value to +`guess`. + +The never type is useful with the `panic!` macro as well. Recall the `unwrap` +function that we call on `Option` values to produce a value or panic with +this definition: - ThreadPool { workers, sender } +``` +impl Option { + pub fn unwrap(self) -> T { + match self { + Some(val) => val, + None => panic!( + "called `Option::unwrap()` on a `None` value" + ), + } } - --snip-- } +``` ---snip-- +In this code, the same thing happens as in the `match` in Listing 19-26: Rust +sees that `val` has the type `T` and `panic!` has the type `!`, so the result +of the overall `match` expression is `T`. This code works because `panic!` +doesn’t produce a value; it ends the program. In the `None` case, we won’t be +returning a value from `unwrap`, so this code is valid. -impl Worker { - fn new(id: usize, receiver: mpsc::Receiver) -> Worker { - let thread = thread::spawn(|| { - 2 receiver; - }); +One final expression that has the type `!` is a `loop`: - Worker { id, thread } - } -} ``` +print!("forever "); -Listing 20-17: Passing the receiver to each `Worker` +loop { + print!("and ever "); +} +``` -We’ve made some small and straightforward changes: we pass the receiver into -`Worker::new` [1], and then we use it inside the closure [2]. +Here, the loop never ends, so `!` is the value of the expression. However, this +wouldn’t be true if we included a `break`, because the loop would terminate +when it got to the `break`. + +### Dynamically Sized Types and the Sized Trait + +Rust needs to know certain details about its types, such as how much space to +allocate for a value of a particular type. This leaves one corner of its type +system a little confusing at first: the concept of *dynamically sized types*. +Sometimes referred to as *DSTs* or *unsized types*, these types let us write +code using values whose size we can know only at runtime. + +Let’s dig into the details of a dynamically sized type called `str`, which +we’ve been using throughout the book. That’s right, not `&str`, but `str` on +its own, is a DST. We can’t know how long the string is until runtime, meaning +we can’t create a variable of type `str`, nor can we take an argument of type +`str`. Consider the following code, which does not work: + +``` +let s1: str = "Hello there!"; +let s2: str = "How's it going?"; +``` + +Rust needs to know how much memory to allocate for any value of a particular +type, and all values of a type must use the same amount of memory. If Rust +allowed us to write this code, these two `str` values would need to take up the +same amount of space. But they have different lengths: `s1` needs 12 bytes of +storage and `s2` needs 15. This is why it’s not possible to create a variable +holding a dynamically sized type. + +So what do we do? In this case, you already know the answer: we make the types +of `s1` and `s2` a `&str` rather than a `str`. Recall from “String Slices” on +page XX that the slice data structure just stores the starting position and the +length of the slice. So, although a `&T` is a single value that stores the +memory address of where the `T` is located, a `&str` is *two* values: the +address of the `str` and its length. As such, we can know the size of a `&str` +value at compile time: it’s twice the length of a `usize`. That is, we always +know the size of a `&str`, no matter how long the string it refers to is. In +general, this is the way in which dynamically sized types are used in Rust: +they have an extra bit of metadata that stores the size of the dynamic +information. The golden rule of dynamically sized types is that we must always +put values of dynamically sized types behind a pointer of some kind. + +We can combine `str` with all kinds of pointers: for example, `Box` or +`Rc`. In fact, you’ve seen this before but with a different dynamically +sized type: traits. Every trait is a dynamically sized type we can refer to by +using the name of the trait. In “Using Trait Objects That Allow for Values of +Different Types” on page XX, we mentioned that to use traits as trait objects, +we must put them behind a pointer, such as `&dyn Trait` or `Box` +(`Rc` would work too). + +To work with DSTs, Rust provides the `Sized` trait to determine whether or not +a type’s size is known at compile time. This trait is automatically implemented +for everything whose size is known at compile time. In addition, Rust +implicitly adds a bound on `Sized` to every generic function. That is, a +generic function definition like this: + +``` +fn generic(t: T) { + --snip-- +} +``` -When we try to check this code, we get this error: +is actually treated as though we had written this: ``` -$ cargo check - Checking hello v0.1.0 (file:///projects/hello) -error[E0382]: use of moved value: `receiver` - --> src/lib.rs:26:42 - | -21 | let (sender, receiver) = mpsc::channel(); - | -------- move occurs because `receiver` has type -`std::sync::mpsc::Receiver`, which does not implement the `Copy` trait -... -26 | workers.push(Worker::new(id, receiver)); - | ^^^^^^^^ value moved here, in -previous iteration of loop -``` - -The code is trying to pass `receiver` to multiple `Worker` instances. This -won’t work, as you’ll recall from Chapter 16: the channel implementation that -Rust provides is multiple *producer*, single *consumer*. This means we can’t -just clone the consuming end of the channel to fix this code. We also don’t -want to send a message multiple times to multiple consumers; we want one list -of messages with multiple `Worker` instances such that each message gets -processed once. - -Additionally, taking a job off the channel queue involves mutating the -`receiver`, so the threads need a safe way to share and modify `receiver`; -otherwise, we might get race conditions (as covered in Chapter 16). - -Recall the thread-safe smart pointers discussed in Chapter 16: to share -ownership across multiple threads and allow the threads to mutate the value, we -need to use `Arc>`. The `Arc` type will let multiple `Worker` -instances own the receiver, and `Mutex` will ensure that only one `Worker` gets -a job from the receiver at a time. Listing 20-18 shows the changes we need to -make. +fn generic(t: T) { + --snip-- +} +``` -Filename: src/lib.rs +By default, generic functions will work only on types that have a known size at +compile time. However, you can use the following special syntax to relax this +restriction: ``` -use std::{ - sync::{mpsc, Arc, Mutex}, - thread, -}; ---snip-- - -impl ThreadPool { +fn generic(t: &T) { --snip-- - pub fn new(size: usize) -> ThreadPool { - assert!(size > 0); +} +``` - let (sender, receiver) = mpsc::channel(); +A trait bound on `?Sized` means “`T` may or may not be `Sized`” and this +notation overrides the default that generic types must have a known size at +compile time. The `?Trait` syntax with this meaning is only available for +`Sized`, not any other traits. - 1 let receiver = Arc::new(Mutex::new(receiver)); +Also note that we switched the type of the `t` parameter from `T` to `&T`. +Because the type might not be `Sized`, we need to use it behind some kind of +pointer. In this case, we’ve chosen a reference. - let mut workers = Vec::with_capacity(size); +Next, we’ll talk about functions and closures! - for id in 0..size { - workers.push( - Worker::new(id, Arc::clone(& 2 receiver)) - ); - } +## Advanced Functions and Closures - ThreadPool { workers, sender } - } +This section explores some advanced features related to functions and closures, +including function pointers and returning closures. - --snip-- +### Function Pointers + +We’ve talked about how to pass closures to functions; you can also pass regular +functions to functions! This technique is useful when you want to pass a +function you’ve already defined rather than defining a new closure. Functions +coerce to the type `fn` (with a lowercase *f*), not to be confused with the +`Fn` closure trait. The `fn` type is called a *function pointer*. Passing +functions with function pointers will allow you to use functions as arguments +to other functions. + +The syntax for specifying that a parameter is a function pointer is similar to +that of closures, as shown in Listing 19-27, where we’ve defined a function +`add_one` that adds 1 to its parameter. The function `do_twice` takes two +parameters: a function pointer to any function that takes an `i32` parameter +and returns an `i32`, and one `i32 value`. The `do_twice` function calls the +function `f` twice, passing it the `arg` value, then adds the two function call +results together. The `main` function calls `do_twice` with the arguments +`add_one` and `5`. + +Filename: src/main.rs + +``` +fn add_one(x: i32) -> i32 { + x + 1 } ---snip-- +fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 { + f(arg) + f(arg) +} -impl Worker { - fn new( - id: usize, - receiver: Arc>>, - ) -> Worker { - --snip-- - } +fn main() { + let answer = do_twice(add_one, 5); + + println!("The answer is: {answer}"); } ``` -Listing 20-18: Sharing the receiver among the `Worker` instances using `Arc` -and `Mutex` +Listing 19-27: Using the `fn` type to accept a function pointer as an argument -In `ThreadPool::new`, we put the receiver in an `Arc` and a `Mutex` [1]. For -each new `Worker`, we clone the `Arc` to bump the reference count so the -`Worker` instances can share ownership of the receiver [2]. +This code prints `The answer is: 12`. We specify that the parameter `f` in +`do_twice` is an `fn` that takes one parameter of type `i32` and returns an +`i32`. We can then call `f` in the body of `do_twice`. In `main`, we can pass +the function name `add_one` as the first argument to `do_twice`. -With these changes, the code compiles! We’re getting there! +Unlike closures, `fn` is a type rather than a trait, so we specify `fn` as the +parameter type directly rather than declaring a generic type parameter with one +of the `Fn` traits as a trait bound. -#### Implementing the execute Method +Function pointers implement all three of the closure traits (`Fn`, `FnMut`, and +`FnOnce`), meaning you can always pass a function pointer as an argument for a +function that expects a closure. It’s best to write functions using a generic +type and one of the closure traits so your functions can accept either +functions or closures. -Let’s finally implement the `execute` method on `ThreadPool`. We’ll also change -`Job` from a struct to a type alias for a trait object that holds the type of -closure that `execute` receives. As discussed in “Creating Type Synonyms with -Type Aliases” on page XX, type aliases allow us to make long types shorter for -ease of use. Look at Listing 20-19. +That said, one example of where you would want to only accept `fn` and not +closures is when interfacing with external code that doesn’t have closures: C +functions can accept functions as arguments, but C doesn’t have closures. -Filename: src/lib.rs +As an example of where you could use either a closure defined inline or a named +function, let’s look at a use of the `map` method provided by the `Iterator` +trait in the standard library. To use the `map` function to turn a vector of +numbers into a vector of strings, we could use a closure, like this: ``` ---snip-- +let list_of_numbers = vec![1, 2, 3]; +let list_of_strings: Vec = list_of_numbers + .iter() + .map(|i| i.to_string()) + .collect(); +``` -type Job = Box; +Or we could name a function as the argument to `map` instead of the closure, +like this: -impl ThreadPool { - --snip-- +``` +let list_of_numbers = vec![1, 2, 3]; +let list_of_strings: Vec = list_of_numbers + .iter() + .map(ToString::to_string) + .collect(); +``` - pub fn execute(&self, f: F) - where - F: FnOnce() + Send + 'static, - { - 1 let job = Box::new(f); +Note that we must use the fully qualified syntax that we talked about in +“Advanced Traits” on page XX because there are multiple functions available +named `to_string`. - 2 self.sender.send(job).unwrap(); - } +Here, we’re using the `to_string` function defined in the `ToString` trait, +which the standard library has implemented for any type that implements +`Display`. + +Recall from “Enum Values” on page XX that the name of each enum variant that we +define also becomes an initializer function. We can use these initializer +functions as function pointers that implement the closure traits, which means +we can specify the initializer functions as arguments for methods that take +closures, like so: + +``` +enum Status { + Value(u32), + Stop, } ---snip-- +let list_of_statuses: Vec = (0u32..20) + .map(Status::Value) + .collect(); ``` -Listing 20-19: Creating a `Job` type alias for a `Box` that holds each closure -and then sending the job down the channel +Here, we create `Status::Value` instances using each `u32` value in the range +that `map` is called on by using the initializer function of `Status::Value`. +Some people prefer this style and some people prefer to use closures. They +compile to the same code, so use whichever style is clearer to you. -After creating a new `Job` instance using the closure we get in `execute` [1], -we send that job down the sending end of the channel [2]. We’re calling -`unwrap` on `send` for the case that sending fails. This might happen if, for -example, we stop all our threads from executing, meaning the receiving end has -stopped receiving new messages. At the moment, we can’t stop our threads from -executing: our threads continue executing as long as the pool exists. The -reason we use `unwrap` is that we know the failure case won’t happen, but the -compiler doesn’t know that. +### Returning Closures -But we’re not quite done yet! In the `Worker`, our closure being passed to -`thread::spawn` still only *references* the receiving end of the channel. -Instead, we need the closure to loop forever, asking the receiving end of the -channel for a job and running the job when it gets one. Let’s make the change -shown in Listing 20-20 to `Worker::new`. +Closures are represented by traits, which means you can’t return closures +directly. In most cases where you might want to return a trait, you can instead +use the concrete type that implements the trait as the return value of the +function. However, you can’t do that with closures because they don’t have a +concrete type that is returnable; you’re not allowed to use the function +pointer `fn` as a return type, for example. -Filename: src/lib.rs +The following code tries to return a closure directly, but it won’t compile: ``` ---snip-- +fn returns_closure() -> dyn Fn(i32) -> i32 { + |x| x + 1 +} +``` -impl Worker { - fn new( - id: usize, - receiver: Arc>>, - ) -> Worker { - let thread = thread::spawn(move || loop { - let job = receiver - 1 .lock() - 2 .unwrap() - 3 .recv() - 4 .unwrap(); +The compiler error is as follows: - println!("Worker {id} got a job; executing."); +``` +error[E0746]: return type cannot have an unboxed trait object + --> src/lib.rs:1:25 + | +1 | fn returns_closure() -> dyn Fn(i32) -> i32 { + | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at +compile-time + | + = note: for information on `impl Trait`, see + +help: use `impl Fn(i32) -> i32` as the return type, as all return paths are of +type `[closure@src/lib.rs:2:5: 2:14]`, which implements `Fn(i32) -> i32` + | +1 | fn returns_closure() -> impl Fn(i32) -> i32 { + | ~~~~~~~~~~~~~~~~~~~ +``` - job(); - }); +The error references the `Sized` trait again! Rust doesn’t know how much space +it will need to store the closure. We saw a solution to this problem earlier. +We can use a trait object: - Worker { id, thread } - } +``` +fn returns_closure() -> Box i32> { + Box::new(|x| x + 1) } ``` -Listing 20-20: Receiving and executing the jobs in the `Worker` instance’s -thread +This code will compile just fine. For more about trait objects, refer to “Using +Trait Objects That Allow for Values of Different Types” on page XX. -Here, we first call `lock` on the `receiver` to acquire the mutex [1], and then -we call `unwrap` to panic on any errors [2]. Acquiring a lock might fail if the -mutex is in a *poisoned* state, which can happen if some other thread panicked -while holding the lock rather than releasing the lock. In this situation, -calling `unwrap` to have this thread panic is the correct action to take. Feel -free to change this `unwrap` to an `expect` with an error message that is -meaningful to you. +Next, let’s look at macros! -If we get the lock on the mutex, we call `recv` to receive a `Job` from the -channel [3]. A final `unwrap` moves past any errors here as well [4], which -might occur if the thread holding the sender has shut down, similar to how the -`send` method returns `Err` if the receiver shuts down. +## Macros -The call to `recv` blocks, so if there is no job yet, the current thread will -wait until a job becomes available. The `Mutex` ensures that only one -`Worker` thread at a time is trying to request a job. +We’ve used macros like `println!` throughout this book, but we haven’t fully +explored what a macro is and how it works. The term *macro* refers to a family +of features in Rust: *declarative* macros with `macro_rules!` and three kinds +of *procedural* macros: -Our thread pool is now in a working state! Give it a `cargo run` and make some -requests: +* Custom `#[derive]` macros that specify code added with the `derive` attribute +used on structs and enums +* Attribute-like macros that define custom attributes usable on any item +* Function-like macros that look like function calls but operate on the tokens +specified as their argument -``` -$ cargo run - Compiling hello v0.1.0 (file:///projects/hello) -warning: field is never read: `workers` - --> src/lib.rs:7:5 - | -7 | workers: Vec, - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(dead_code)]` on by default +We’ll talk about each of these in turn, but first, let’s look at why we even +need macros when we already have functions. -warning: field is never read: `id` - --> src/lib.rs:48:5 - | -48 | id: usize, - | ^^^^^^^^^ +### The Difference Between Macros and Functions -warning: field is never read: `thread` - --> src/lib.rs:49:5 - | -49 | thread: thread::JoinHandle<()>, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -warning: `hello` (lib) generated 3 warnings - Finished dev [unoptimized + debuginfo] target(s) in 1.40s - Running `target/debug/hello` -Worker 0 got a job; executing. -Worker 2 got a job; executing. -Worker 1 got a job; executing. -Worker 3 got a job; executing. -Worker 0 got a job; executing. -Worker 2 got a job; executing. -Worker 1 got a job; executing. -Worker 3 got a job; executing. -Worker 0 got a job; executing. -Worker 2 got a job; executing. -``` - -Success! We now have a thread pool that executes connections asynchronously. -There are never more than four threads created, so our system won’t get -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 -might load one at a time in five-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. - -After learning about the `while let` loop in Chapter 18, you might be wondering -why we didn’t write the `Worker` thread code as shown in Listing 20-21. +Fundamentally, macros are a way of writing code that writes other code, which +is known as *metaprogramming*. In Appendix C, we discuss the `derive` +attribute, which generates an implementation of various traits for you. We’ve +also used the `println!` and `vec!` macros throughout the book. All of these +macros *expand* to produce more code than the code you’ve written manually. -Filename: src/lib.rs +Metaprogramming is useful for reducing the amount of code you have to write and +maintain, which is also one of the roles of functions. However, macros have +some additional powers that functions don’t have. -``` ---snip-- +A function signature must declare the number and type of parameters the +function has. Macros, on the other hand, can take a variable number of +parameters: we can call `println!("hello")` with one argument or +`println!("hello {}", name)` with two arguments. Also, macros are expanded +before the compiler interprets the meaning of the code, so a macro can, for +example, implement a trait on a given type. A function can’t, because it gets +called at runtime and a trait needs to be implemented at compile time. -impl Worker { - fn new( - id: usize, - receiver: Arc>>, - ) -> Worker { - let thread = thread::spawn(move || { - while let Ok(job) = receiver.lock().unwrap().recv() { - println!("Worker {id} got a job; executing."); +The downside to implementing a macro instead of a function is that macro +definitions are more complex than function definitions because you’re writing +Rust code that writes Rust code. Due to this indirection, macro definitions are +generally more difficult to read, understand, and maintain than function +definitions. - job(); - } - }); +Another important difference between macros and functions is that you must +define macros or bring them into scope *before* you call them in a file, as +opposed to functions you can define anywhere and call anywhere. - Worker { id, thread } - } -} +### Declarative Macros with macro_rules! for General Metaprogramming + +The most widely used form of macros in Rust is the *declarative macro*. These +are also sometimes referred to as “macros by example,” “`macro_rules!` macros,” +or just plain “macros.” At their core, declarative macros allow you to write +something similar to a Rust `match` expression. As discussed in Chapter 6, +`match` expressions are control structures that take an expression, compare the +resultant value of the expression to patterns, and then run the code associated +with the matching pattern. Macros also compare a value to patterns that are +associated with particular code: in this situation, the value is the literal +Rust source code passed to the macro; the patterns are compared with the +structure of that source code; and the code associated with each pattern, when +matched, replaces the code passed to the macro. This all happens during +compilation. + +To define a macro, you use the `macro_rules!` construct. Let’s explore how to +use `macro_rules!` by looking at how the `vec!` macro is defined. Chapter 8 +covered how we can use the `vec!` macro to create a new vector with particular +values. For example, the following macro creates a new vector containing three +integers: + +``` +let v: Vec = vec![1, 2, 3]; ``` -Listing 20-21: An alternative implementation of `Worker::new` using `while let` +We could also use the `vec!` macro to make a vector of two integers or a vector +of five string slices. We wouldn’t be able to use a function to do the same +because we wouldn’t know the number or type of values up front. -This code compiles and runs but doesn’t result in the desired threading -behavior: a slow request will still cause other requests to wait to be -processed. The reason is somewhat subtle: the `Mutex` struct has no public -`unlock` method because the ownership of the lock is based on the lifetime of -the `MutexGuard` within the `LockResult>` that the `lock` -method returns. At compile time, the borrow checker can then enforce the rule -that a resource guarded by a `Mutex` cannot be accessed unless we hold the -lock. However, this implementation can also result in the lock being held -longer than intended if we aren’t mindful of the lifetime of the -`MutexGuard`. +Listing 19-28 shows a slightly simplified definition of the `vec!` macro. -The code in Listing 20-20 that uses `let job = -receiver.lock().unwrap().recv().unwrap();` works because with `let`, any -temporary values used in the expression on the right-hand side of the equal -sign are immediately dropped when the `let` statement ends. However, `while -let` (and `if let` and `match`) does not drop temporary values until the end of -the associated block. In Listing 20-21, the lock remains held for the duration -of the call to `job()`, meaning other `Worker` instances cannot receive jobs. +Filename: src/lib.rs -## Graceful Shutdown and Cleanup +``` +1 #[macro_export] +2 macro_rules! vec { + 3 ( $( $x:expr ),* ) => { + { + let mut temp_vec = Vec::new(); + 4 $( + 5 temp_vec.push(6 $x); + )* + 7 temp_vec + } + }; +} +``` + +Listing 19-28: A simplified version of the `vec!` macro definition + +> Note: The actual definition of the `vec!` macro in the standard library +includes code to pre-allocate the correct amount of memory up front. That code +is an optimization that we don’t include here, to make the example simpler. + +The `#[macro_export]` annotation [1] indicates that this macro should be made +available whenever the crate in which the macro is defined is brought into +scope. Without this annotation, the macro can’t be brought into scope. + +We then start the macro definition with `macro_rules!` and the name of the +macro we’re defining *without* the exclamation mark [2]. The name, in this case +`vec`, is followed by curly brackets denoting the body of the macro definition. + +The structure in the `vec!` body is similar to the structure of a `match` +expression. Here we have one arm with the pattern `( $( $x:expr ),* )`, +followed by `=>` and the block of code associated with this pattern [3]. If the +pattern matches, the associated block of code will be emitted. Given that this +is the only pattern in this macro, there is only one valid way to match; any +other pattern will result in an error. More complex macros will have more than +one arm. + +Valid pattern syntax in macro definitions is different from the pattern syntax +covered in Chapter 18 because macro patterns are matched against Rust code +structure rather than values. Let’s walk through what the pattern pieces in +Listing 19-28 mean; for the full macro pattern syntax, see the Rust Reference +at *https://doc.rust-lang.org/reference/macros-by-example.html*. + +First we use a set of parentheses to encompass the whole pattern. We use a +dollar sign (`$`) to declare a variable in the macro system that will contain +the Rust code matching the pattern. The dollar sign makes it clear this is a +macro variable as opposed to a regular Rust variable. Next comes a set of +parentheses that captures values that match the pattern within the parentheses +for use in the replacement code. Within `$()` is `$x:expr`, which matches any +Rust expression and gives the expression the name `$x`. + +The comma following `$()` indicates that a literal comma separator character +could optionally appear after the code that matches the code in `$()`. The `*` +specifies that the pattern matches zero or more of whatever precedes the `*`. + +When we call this macro with `vec![1, 2, 3];`, the `$x` pattern matches three +times with the three expressions `1`, `2`, and `3`. + +Now let’s look at the pattern in the body of the code associated with this arm: +`temp_vec.push()` [5] within `$()* at [4] and [7] is generated for each part +that matches `$()` in the pattern zero or more times depending on how many +times the pattern matches. The `$x` [6] is replaced with each expression +matched. When we call this macro with `vec![1, 2, 3];`, the code generated that +replaces this macro call will be the following: + +``` +{ + let mut temp_vec = Vec::new(); + temp_vec.push(1); + temp_vec.push(2); + temp_vec.push(3); + temp_vec +} +``` + +We’ve defined a macro that can take any number of arguments of any type and can +generate code to create a vector containing the specified elements. -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 ctrl-C 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. +To learn more about how to write macros, consult the online documentation or +other resources, such as “The Little Book of Rust Macros” at +*https://veykril.github.io/tlborm* started by Daniel Keep and continued by +Lukas Wirth. -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 -closing. Then we’ll implement a way to tell the threads they should stop -accepting new requests and shut down. To see this code in action, we’ll modify -our server to accept only two requests before gracefully shutting down its -thread pool. +### Procedural Macros for Generating Code from Attributes -### Implementing the Drop Trait on ThreadPool +The second form of macros is the procedural macro, which acts more like a +function (and is a type of procedure). *Procedural macros* accept some code as +an input, operate on that code, and produce some code as an output rather than +matching against patterns and replacing the code with other code as declarative +macros do. The three kinds of procedural macros are custom `derive`, +attribute-like, and function-like, and all work in a similar fashion. -Let’s start with implementing `Drop` on our thread pool. When the pool is -dropped, our threads should all join to make sure they finish their work. -Listing 20-22 shows a first attempt at a `Drop` implementation; this code won’t -quite work yet. +When creating procedural macros, the definitions must reside in their own crate +with a special crate type. This is for complex technical reasons that we hope +to eliminate in the future. In Listing 19-29, we show how to define a +procedural macro, where `some_attribute` is a placeholder for using a specific +macro variety. Filename: src/lib.rs ``` -impl Drop for ThreadPool { - fn drop(&mut self) { - 1 for worker in &mut self.workers { - 2 println!("Shutting down worker {}", worker.id); +use proc_macro::TokenStream; - 3 worker.thread.join().unwrap(); - } - } +#[some_attribute] +pub fn some_name(input: TokenStream) -> TokenStream { } ``` -Listing 20-22: Joining each thread when the thread pool goes out of scope - -First we loop through each of the thread pool `workers` [1]. We use `&mut` for -this because `self` is a mutable reference, and we also need to be able to -mutate `worker`. For each `worker`, we print a message saying that this -particular `Worker` instance is shutting down [2], and then we call `join` on -that `Worker` instance’s thread [3]. If the call to `join` fails, we use -`unwrap` to make Rust panic and go into an ungraceful shutdown. +Listing 19-29: An example of defining a procedural macro -Here is the error we get when we compile this code: +The function that defines a procedural macro takes a `TokenStream` as an input +and produces a `TokenStream` as an output. The `TokenStream` type is defined by +the `proc_macro` crate that is included with Rust and represents a sequence of +tokens. This is the core of the macro: the source code that the macro is +operating on makes up the input `TokenStream`, and the code the macro produces +is the output `TokenStream`. The function also has an attribute attached to it +that specifies which kind of procedural macro we’re creating. We can have +multiple kinds of procedural macros in the same crate. -``` -error[E0507]: cannot move out of `worker.thread` which is behind a mutable -reference - --> src/lib.rs:52:13 - | -52 | worker.thread.join().unwrap(); - | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this -method call - | | - | move occurs because `worker.thread` has type -`JoinHandle<()>`, which does not implement the `Copy` trait - | -note: this function takes ownership of the receiver `self`, which moves -`worker.thread` -``` +Let’s look at the different kinds of procedural macros. We’ll start with a +custom `derive` macro and then explain the small dissimilarities that make the +other forms different. -The error tells us we can’t call `join` because we only have a mutable borrow -of each `worker` and `join` takes ownership of its argument. To solve this -issue, we need to move the thread out of the `Worker` instance that owns -`thread` so `join` can consume the thread. We did this in Listing 17-15: if -`Worker` holds an `Option>` instead, we can call the -`take` method on the `Option` to move the value out of the `Some` variant and -leave a `None` variant in its place. In other words, a `Worker` that is running -will have a `Some` variant in `thread`, and when we want to clean up a -`Worker`, we’ll replace `Some` with `None` so the `Worker` doesn’t have a -thread to run. +### How to Write a Custom derive Macro -So we know we want to update the definition of `Worker` like this: +Let’s create a crate named `hello_macro` that defines a trait named +`HelloMacro` with one associated function named `hello_macro`. Rather than +making our users implement the `HelloMacro` trait for each of their types, +we’ll provide a procedural macro so users can annotate their type with +`#[derive(HelloMacro)]` to get a default implementation of the `hello_macro` +function. The default implementation will print `Hello, Macro! My name is` +TypeName`!` where TypeName is the name of the type on which this trait has been +defined. In other words, we’ll write a crate that enables another programmer to +write code like Listing 19-30 using our crate. -Filename: src/lib.rs +Filename: src/main.rs ``` -struct Worker { - id: usize, - thread: Option>, +use hello_macro::HelloMacro; +use hello_macro_derive::HelloMacro; + +#[derive(HelloMacro)] +struct Pancakes; + +fn main() { + Pancakes::hello_macro(); } ``` -Now let’s lean on the compiler to find the other places that need to change. -Checking this code, we get two errors: +Listing 19-30: The code a user of our crate will be able to write when using +our procedural macro -``` -error[E0599]: no method named `join` found for enum `Option` in the current -scope - --> src/lib.rs:52:27 - | -52 | worker.thread.join().unwrap(); - | ^^^^ method not found in -`Option>` +This code will print `Hello, Macro! My name is Pancakes!` when we’re done. The +first step is to make a new library crate, like this: -error[E0308]: mismatched types - --> src/lib.rs:72:22 - | -72 | Worker { id, thread } - | ^^^^^^ expected enum `Option`, found struct -`JoinHandle` - | - = note: expected enum `Option>` - found struct `JoinHandle<_>` -help: try wrapping the expression in `Some` - | -72 | Worker { id, thread: Some(thread) } - | +++++++++++++ + +``` +$ cargo new hello_macro --lib ``` -Let’s address the second error, which points to the code at the end of -`Worker::new`; we need to wrap the `thread` value in `Some` when we create a -new `Worker`. Make the following changes to fix this error: +Next, we’ll define the `HelloMacro` trait and its associated function: Filename: src/lib.rs ``` -impl Worker { - fn new( - id: usize, - receiver: Arc>>, - ) -> Worker { - --snip-- - - Worker { - id, - thread: Some(thread), - } - } +pub trait HelloMacro { + fn hello_macro(); } ``` -The first error is in our `Drop` implementation. We mentioned earlier that we -intended to call `take` on the `Option` value to move `thread` out of `worker`. -The following changes will do so: - -Filename: src/lib.rs +We have a trait and its function. At this point, our crate user could implement +the trait to achieve the desired functionality, like so: ``` -impl Drop for ThreadPool { - fn drop(&mut self) { - for worker in &mut self.workers { - println!("Shutting down worker {}", worker.id); +use hello_macro::HelloMacro; - 1 if let Some(thread) = worker.thread.take() { - 2 thread.join().unwrap(); - } - } +struct Pancakes; + +impl HelloMacro for Pancakes { + fn hello_macro() { + println!("Hello, Macro! My name is Pancakes!"); } } + +fn main() { + Pancakes::hello_macro(); +} ``` -As discussed in Chapter 17, the `take` method on `Option` takes the `Some` -variant out and leaves `None` in its place. We’re using `if let` to destructure -the `Some` and get the thread [1]; then we call `join` on the thread [2]. If a -`Worker` instance’s thread is already `None`, we know that `Worker` has already -had its thread cleaned up, so nothing happens in that case. +However, they would need to write the implementation block for each type they +wanted to use with `hello_macro`; we want to spare them from having to do this +work. -### Signaling to the Threads to Stop Listening for Jobs +Additionally, we can’t yet provide the `hello_macro` function with default +implementation that will print the name of the type the trait is implemented +on: Rust doesn’t have reflection capabilities, so it can’t look up the type’s +name at runtime. We need a macro to generate code at compile time. -With all the changes we’ve made, our code compiles without any warnings. -However, the bad news is that this code doesn’t function the way we want it to -yet. The key is the logic in the closures run by the threads of the `Worker` -instances: at the moment, we call `join`, but that won’t shut down the threads, -because they `loop` forever looking for jobs. If we try to drop our -`ThreadPool` with our current implementation of `drop`, the main thread will -block forever, waiting for the first thread to finish. +The next step is to define the procedural macro. At the time of this writing, +procedural macros need to be in their own crate. Eventually, this restriction +might be lifted. The convention for structuring crates and macro crates is as +follows: for a crate named foo, a custom `derive` procedural macro crate is +called foo`_derive`. Let’s start a new crate called `hello_macro_derive` inside +our `hello_macro` project: -To fix this problem, we’ll need a change in the `ThreadPool` `drop` -implementation and then a change in the `Worker` loop. +``` +$ cargo new hello_macro_derive --lib +``` -First we’ll change the `ThreadPool` `drop` implementation to explicitly drop -the `sender` before waiting for the threads to finish. Listing 20-23 shows the -changes to `ThreadPool` to explicitly drop `sender`. We use the same `Option` -and `take` technique as we did with the thread to be able to move `sender` out -of `ThreadPool`. +Our two crates are tightly related, so we create the procedural macro crate +within the directory of our `hello_macro` crate. If we change the trait +definition in `hello_macro`, we’ll have to change the implementation of the +procedural macro in `hello_macro_derive` as well. The two crates will need to +be published separately, and programmers using these crates will need to add +both as dependencies and bring them both into scope. We could instead have the +`hello_macro` crate use `hello_macro_derive` as a dependency and re-export the +procedural macro code. However, the way we’ve structured the project makes it +possible for programmers to use `hello_macro` even if they don’t want the +`derive` functionality. -Filename: src/lib.rs +We need to declare the `hello_macro_derive` crate as a procedural macro crate. +We’ll also need functionality from the `syn` and `quote` crates, as you’ll see +in a moment, so we need to add them as dependencies. Add the following to the +*Cargo.toml* file for `hello_macro_derive`: + +Filename: hello_macro_derive/Cargo.toml ``` -pub struct ThreadPool { - workers: Vec, - sender: Option>, -} ---snip-- -impl ThreadPool { - pub fn new(size: usize) -> ThreadPool { - --snip-- +[lib] +proc-macro = true - ThreadPool { - workers, - sender: Some(sender), - } - } +[dependencies] +syn = "1.0" +quote = "1.0" +``` - pub fn execute(&self, f: F) - where - F: FnOnce() + Send + 'static, - { - let job = Box::new(f); - - self.sender - .as_ref() - .unwrap() - .send(job) - .unwrap(); - } +To start defining the procedural macro, place the code in Listing 19-31 into +your *src/lib.rs* file for the `hello_macro_derive` crate. Note that this code +won’t compile until we add a definition for the `impl_hello_macro` function. + +Filename: hello_macro_derive/src/lib.rs + +``` +use proc_macro::TokenStream; +use quote::quote; +use syn; + +#[proc_macro_derive(HelloMacro)] +pub fn hello_macro_derive(input: TokenStream) -> TokenStream { + // Construct a representation of Rust code as a syntax tree + // that we can manipulate + let ast = syn::parse(input).unwrap(); + + // Build the trait implementation + impl_hello_macro(&ast) } +``` -impl Drop for ThreadPool { - fn drop(&mut self) { - 1 drop(self.sender.take()); +Listing 19-31: Code that most procedural macro crates will require in order to +process Rust code + +Notice that we’ve split the code into the `hello_macro_derive` function, which +is responsible for parsing the `TokenStream`, and the `impl_hello_macro` +function, which is responsible for transforming the syntax tree: this makes +writing a procedural macro more convenient. The code in the outer function +(`hello_macro_derive` in this case) will be the same for almost every +procedural macro crate you see or create. The code you specify in the body of +the inner function (`impl_hello_macro` in this case) will be different +depending on your procedural macro’s purpose. + +We’ve introduced three new crates: `proc_macro`, `syn` (available from +*https://crates.io/crates/syn*), and `quote` (available from +*https://crates.io/crates/quote*). The `proc_macro` crate comes with Rust, so +we didn’t need to add that to the dependencies in *Cargo.toml*. The +`proc_macro` crate is the compiler’s API that allows us to read and manipulate +Rust code from our code. + +The `syn` crate parses Rust code from a string into a data structure that we +can perform operations on. The `quote` crate turns `syn` data structures back +into Rust code. These crates make it much simpler to parse any sort of Rust +code we might want to handle: writing a full parser for Rust code is no simple +task. + +The `hello_macro_derive` function will be called when a user of our library +specifies `#[derive(HelloMacro)]` on a type. This is possible because we’ve +annotated the `hello_macro_derive` function here with `proc_macro_derive` and +specified the name `HelloMacro`, which matches our trait name; this is the +convention most procedural macros follow. + +The `hello_macro_derive` function first converts the `input` from a +`TokenStream` to a data structure that we can then interpret and perform +operations on. This is where `syn` comes into play. The `parse` function in +`syn` takes a `TokenStream` and returns a `DeriveInput` struct representing the +parsed Rust code. Listing 19-32 shows the relevant parts of the `DeriveInput` +struct we get from parsing the `struct Pancakes;` string. + +``` +DeriveInput { + --snip-- - for worker in &mut self.workers { - println!("Shutting down worker {}", worker.id); + ident: Ident { + ident: "Pancakes", + span: #0 bytes(95..103) + }, + data: Struct( + DataStruct { + struct_token: Struct, + fields: Unit, + semi_token: Some( + Semi + ) + } + ) +} +``` - if let Some(thread) = worker.thread.take() { - thread.join().unwrap(); +Listing 19-32: The `DeriveInput` instance we get when parsing the code that has +the macro’s attribute in Listing 19-30 + +The fields of this struct show that the Rust code we’ve parsed is a unit struct +with the `ident` (*identifier*, meaning the name) of `Pancakes`. There are more +fields on this struct for describing all sorts of Rust code; check the `syn` +documentation for `DeriveInput` at +*https://docs.rs/syn/1.0/syn/struct.DeriveInput.html* for more information. + +Soon we’ll define the `impl_hello_macro` function, which is where we’ll build +the new Rust code we want to include. But before we do, note that the output +for our `derive` macro is also a `TokenStream`. The returned `TokenStream` is +added to the code that our crate users write, so when they compile their crate, +they’ll get the extra functionality that we provide in the modified +`TokenStream`. + +You might have noticed that we’re calling `unwrap` to cause the +`hello_macro_derive` function to panic if the call to the `syn::parse` function +fails here. It’s necessary for our procedural macro to panic on errors because +`proc_macro_derive` functions must return `TokenStream` rather than `Result` to +conform to the procedural macro API. We’ve simplified this example by using +`unwrap`; in production code, you should provide more specific error messages +about what went wrong by using `panic!` or `expect`. + +Now that we have the code to turn the annotated Rust code from a `TokenStream` +into a `DeriveInput` instance, let’s generate the code that implements the +`HelloMacro` trait on the annotated type, as shown in Listing 19-33. + +Filename: hello_macro_derive/src/lib.rs + +``` +fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream { + let name = &ast.ident; + let gen = quote! { + impl HelloMacro for #name { + fn hello_macro() { + println!( + "Hello, Macro! My name is {}!", + stringify!(#name) + ); } } - } + }; + gen.into() } ``` -Listing 20-23: Explicitly dropping `sender` before joining the `Worker` threads +Listing 19-33: Implementing the `HelloMacro` trait using the parsed Rust code -Dropping `sender` [1] closes the channel, which indicates no more messages will -be sent. When that happens, all the calls to `recv` that the `Worker` instances -do in the infinite loop will return an error. In Listing 20-24, we change the -`Worker` loop to gracefully exit the loop in that case, which means the threads -will finish when the `ThreadPool` `drop` implementation calls `join` on them. +We get an `Ident` struct instance containing the name (identifier) of the +annotated type using `ast.ident`. The struct in Listing 19-32 shows that when +we run the `impl_hello_macro` function on the code in Listing 19-30, the +`ident` we get will have the `ident` field with a value of `"Pancakes"`. Thus +the `name` variable in Listing 19-33 will contain an `Ident` struct instance +that, when printed, will be the string `"Pancakes"`, the name of the struct in +Listing 19-30. -Filename: src/lib.rs +The `quote!` macro lets us define the Rust code that we want to return. The +compiler expects something different to the direct result of the `quote!` +macro’s execution, so we need to convert it to a `TokenStream`. We do this by +calling the `into` method, which consumes this intermediate representation and +returns a value of the required `TokenStream` type. + +The `quote!` macro also provides some very cool templating mechanics: we can +enter `#name`, and `quote!` will replace it with the value in the variable +`name`. You can even do some repetition similar to the way regular macros work. +Check out the `quote` crate’s docs at *https://docs.rs/quote* for a thorough +introduction. + +We want our procedural macro to generate an implementation of our `HelloMacro` +trait for the type the user annotated, which we can get by using `#name`. The +trait implementation has the one function `hello_macro`, whose body contains +the functionality we want to provide: printing `Hello, Macro! My name is` and +then the name of the annotated type. + +The `stringify!` macro used here is built into Rust. It takes a Rust +expression, such as `1 + 2`, and at compile time turns the expression into a +string literal, such as `"1 + 2"`. This is different from `format!` or +`println!`, macros which evaluate the expression and then turn the result into +a `String`. There is a possibility that the `#name` input might be an +expression to print literally, so we use `stringify!`. Using `stringify!` also +saves an allocation by converting `#name` to a string literal at compile time. + +At this point, `cargo build` should complete successfully in both `hello_macro` +and `hello_macro_derive`. Let’s hook up these crates to the code in Listing +19-30 to see the procedural macro in action! Create a new binary project in +your *projects* directory using `cargo new pancakes`. We need to add +`hello_macro` and `hello_macro_derive` as dependencies in the `pancakes` +crate’s *Cargo.toml*. If you’re publishing your versions of `hello_macro` and +`hello_macro_derive` to *https://crates.io*, they would be regular +dependencies; if not, you can specify them as `path` dependencies as follows: ``` -impl Worker { - fn new( - id: usize, - receiver: Arc>>, - ) -> Worker { - let thread = thread::spawn(move || loop { - let message = receiver.lock().unwrap().recv(); - - match message { - Ok(job) => { - println!( - "Worker {id} got a job; executing." - ); - - job(); - } - Err(_) => { - println!( - "Worker {id} shutting down." - ); - break; - } - } - }); +[dependencies] +hello_macro = { path = "../hello_macro" } +hello_macro_derive = { path = "../hello_macro/hello_macro_derive" } +``` - Worker { - id, - thread: Some(thread), - } - } -} +Put the code in Listing 19-30 into *src/main.rs*, and run `cargo run`: it +should print `Hello, Macro! My name is Pancakes!` The implementation of the +`HelloMacro` trait from the procedural macro was included without the +`pancakes` crate needing to implement it; the `#[derive(HelloMacro)]` added the +trait implementation. + +Next, let’s explore how the other kinds of procedural macros differ from custom +`derive` macros. + +### Attribute-like Macros + +Attribute-like macros are similar to custom `derive` macros, but instead of +generating code for the `derive` attribute, they allow you to create new +attributes. They’re also more flexible: `derive` only works for structs and +enums; attributes can be applied to other items as well, such as functions. +Here’s an example of using an attribute-like macro. Say you have an attribute +named `route` that annotates functions when using a web application framework: + +``` +#[route(GET, "/")] +fn index() { ``` -Listing 20-24: Explicitly breaking out of the loop when `recv` returns an error +This `#[route]` attribute would be defined by the framework as a procedural +macro. The signature of the macro definition function would look like this: -To see this code in action, let’s modify `main` to accept only two requests -before gracefully shutting down the server, as shown in Listing 20-25. +``` +#[proc_macro_attribute] +pub fn route( + attr: TokenStream, + item: TokenStream +) -> TokenStream { +``` -Filename: src/main.rs +Here, we have two parameters of type `TokenStream`. The first is for the +contents of the attribute: the `GET, "/"` part. The second is the body of the +item the attribute is attached to: in this case, `fn index() {}` and the rest +of the function’s body. + +Other than that, attribute-like macros work the same way as custom `derive` +macros: you create a crate with the `proc-macro` crate type and implement a +function that generates the code you want! + +### Function-like Macros + +Function-like macros define macros that look like function calls. Similarly to +`macro_rules!` macros, they’re more flexible than functions; for example, they +can take an unknown number of arguments. However, `macro_rules!` macros can +only be defined using the match-like syntax we discussed in “Declarative Macros +with macro_rules! for General Metaprogramming” on page XX. Function-like macros +take a `TokenStream` parameter, and their definition manipulates that +`TokenStream` using Rust code as the other two types of procedural macros do. +An example of a function-like macro is an `sql!` macro that might be called +like so: ``` -fn main() { - let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); - let pool = ThreadPool::new(4); +let sql = sql!(SELECT * FROM posts WHERE id=1); +``` - for stream in listener.incoming().take(2) { - let stream = stream.unwrap(); +This macro would parse the SQL statement inside it and check that it’s +syntactically correct, which is much more complex processing than a +`macro_rules!` macro can do. The `sql!` macro would be defined like this: - pool.execute(|| { - handle_connection(stream); - }); - } +``` +#[proc_macro] +pub fn sql(input: TokenStream) -> TokenStream { +``` - println!("Shutting down."); -} -``` - -Listing 20-25: Shutting down the server after serving two requests by exiting -the loop - -You wouldn’t want a real-world web server to shut down after serving only two -requests. This code just demonstrates that the graceful shutdown and cleanup is -in working order. - -The `take` method is defined in the `Iterator` trait and limits the iteration -to the first two items at most. The `ThreadPool` will go out of scope at the -end of `main`, and the `drop` implementation will run. - -Start the server with `cargo run`, and make three requests. The third request -should error, and in your terminal you should see output similar to this: - -``` -$ cargo run - Compiling hello v0.1.0 (file:///projects/hello) - Finished dev [unoptimized + debuginfo] target(s) in 1.0s - Running `target/debug/hello` -Worker 0 got a job; executing. -Shutting down. -Shutting down worker 0 -Worker 3 got a job; executing. -Worker 1 disconnected; shutting down. -Worker 2 disconnected; shutting down. -Worker 3 disconnected; shutting down. -Worker 0 disconnected; shutting down. -Shutting down worker 1 -Shutting down worker 2 -Shutting down worker 3 -``` - -You might see a different ordering of `Worker` IDs and messages printed. We can -see how this code works from the messages: `Worker` instances 0 and 3 got the -first two requests. The server stopped accepting connections after the second -connection, and the `Drop` implementation on `ThreadPool` starts executing -before `Worker` 3 even starts its job. Dropping the `sender` disconnects all -the `Worker` instances and tells them to shut down. The `Worker` instances each -print a message when they disconnect, and then the thread pool calls `join` to -wait for each `Worker` thread to finish. - -Notice one interesting aspect of this particular execution: the `ThreadPool` -dropped the `sender`, and before any `Worker` received an error, we tried to -join `Worker` 0. `Worker` 0 had not yet gotten an error from `recv`, so the -main thread blocked, waiting for `Worker` 0 to finish. In the meantime, -`Worker` 3 received a job and then all threads received an error. When `Worker` -0 finished, the main thread waited for the rest of the `Worker` instances to -finish. At that point, they had all exited their loops and stopped. - -Congrats! We’ve now completed our project; we have a basic web server that uses -a thread pool to respond asynchronously. We’re able to perform a graceful -shutdown of the server, which cleans up all the threads in the pool. See -*https://www.nostarch.com/Rust2021* to download the full code for this chapter -for reference. - -We could do more here! If you want to continue enhancing this project, here are -some ideas: - -* Add more documentation to `ThreadPool` and its public methods. -* Add tests of the library’s functionality. -* Change calls to `unwrap` to more robust error handling. -* Use `ThreadPool` to perform some task other than serving web requests. -* Find a thread pool crate on *https://crates.io* and implement a similar web -server using the crate instead. Then compare its API and robustness to the -thread pool we implemented. +This definition is similar to the custom `derive` macro’s signature: we receive +the tokens that are inside the parentheses and return the code we wanted to +generate. ## Summary -Well done! You’ve made it to the end of the book! We want to thank you for -joining us on this tour of Rust. You’re now ready to implement your own Rust -projects and help with other people’s projects. Keep in mind that there is a -welcoming community of other Rustaceans who would love to help you with any -challenges you encounter on your Rust journey. +Whew! Now you have some Rust features in your toolbox that you likely won’t use +often, but you’ll know they’re available in very particular circumstances. +We’ve introduced several complex topics so that when you encounter them in +error message suggestions or in other people’s code, you’ll be able to +recognize these concepts and syntax. Use this chapter as a reference to guide +you to solutions. + +Next, we’ll put everything we’ve discussed throughout the book into practice +and do one more project! diff --git a/nostarch/chapter21.md b/nostarch/chapter21.md new file mode 100644 index 0000000000..9d4e22cd77 --- /dev/null +++ b/nostarch/chapter21.md @@ -0,0 +1,1994 @@ + + +[TOC] + +# Final Project: Building a Multithreaded Web Server + +It’s been a long journey, but we’ve reached the end of the book. In this +chapter, we’ll build one more project together to demonstrate some of the +concepts we covered in the final chapters, as well as recap some earlier +lessons. + +For our final project, we’ll make a web server that says “hello” and looks like +Figure 20-1 in a web browser. + +Figure 20-1: Our final shared project + +Here is our plan for building the web server: + +1. Learn a bit about TCP and HTTP. +1. Listen for TCP connections on a socket. +1. Parse a small number of HTTP requests. +1. Create a proper HTTP response. +1. Improve the throughput of our server with a thread pool. + +Before we get started, we should mention one detail: the method we’ll use won’t +be the best way to build a web server with Rust. Community members have +published a number of production-ready crates available at *https://crates.io* +that provide more complete web server and thread pool implementations than +we’ll build. However, our intention in this chapter is to help you learn, not +to take the easy route. Because Rust is a systems programming language, we can +choose the level of abstraction we want to work with and can go to a lower +level than is possible or practical in other languages. We’ll therefore write +the basic HTTP server and thread pool manually so you can learn the general +ideas and techniques behind the crates you might use in the future. + +## Building a Single-Threaded Web Server + +We’ll start by getting a single-threaded web server working. Before we begin, +let’s look at a quick overview of the protocols involved in building web +servers. The details of these protocols are beyond the scope of this book, but +a brief overview will give you the information you need. + +The two main protocols involved in web servers are *Hypertext Transfer +Protocol* *(HTTP)* and *Transmission Control Protocol* *(TCP)*. Both protocols +are *request-response* protocols, meaning a *client* initiates requests and a +*server* listens to the requests and provides a response to the client. The +contents of those requests and responses are defined by the protocols. + +TCP is the lower-level protocol that describes the details of how information +gets from one server to another but doesn’t specify what that information is. +HTTP builds on top of TCP by defining the contents of the requests and +responses. It’s technically possible to use HTTP with other protocols, but in +the vast majority of cases, HTTP sends its data over TCP. We’ll work with the +raw bytes of TCP and HTTP requests and responses. + +### Listening to the TCP Connection + +Our web server needs to listen to a TCP connection, so that’s the first part +we’ll work on. The standard library offers a `std::net` module that lets us do +this. Let’s make a new project in the usual fashion: + +``` +$ cargo new hello + Created binary (application) `hello` project +$ cd hello +``` + +Now enter the code in Listing 20-1 in *src/main.rs* to start. This code will +listen at the local address `127.0.0.1:7878` for incoming TCP streams. When it +gets an incoming stream, it will print `Connection established!`. + +Filename: src/main.rs + +``` +use std::net::TcpListener; + +fn main() { + 1 let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); + + 2 for stream in listener.incoming() { + 3 let stream = stream.unwrap(); + + 4 println!("Connection established!"); + } +} +``` + +Listing 20-1: Listening for incoming streams and printing a message when we +receive a stream + +Using `TcpListener`, we can listen for TCP connections at the address +`127.0.0.1:7878` [1]. In the address, the section before the colon is an IP +address representing your computer (this is the same on every computer and +doesn’t represent the authors’ computer specifically), and `7878` is the port. +We’ve chosen this port for two reasons: HTTP isn’t normally accepted on this +port, so our server is unlikely to conflict with any other web server you might +have running on your machine, and 7878 is *rust* typed on a telephone. + +The `bind` function in this scenario works like the `new` function in that it +will return a new `TcpListener` instance. The function is called `bind` +because, in networking, connecting to a port to listen to is known as “binding +to a port.” + +The `bind` function returns a `Result`, which indicates that it’s +possible for binding to fail. For example, connecting to port 80 requires +administrator privileges (non-administrators can listen only on ports higher +than 1023), so if we tried to connect to port 80 without being an +administrator, binding wouldn’t work. Binding also wouldn’t work, for example, +if we ran two instances of our program and so had two programs listening to the +same port. Because we’re writing a basic server just for learning purposes, we +won’t worry about handling these kinds of errors; instead, we use `unwrap` to +stop the program if errors happen. + +The `incoming` method on `TcpListener` returns an iterator that gives us a +sequence of streams [2] (more specifically, streams of type `TcpStream`). A +single *stream* represents an open connection between the client and the +server. A *connection* is the name for the full request and response process in +which a client connects to the server, the server generates a response, and the +server closes the connection. As such, we will read from the `TcpStream` to see +what the client sent and then write our response to the stream to send data +back to the client. Overall, this `for` loop will process each connection in +turn and produce a series of streams for us to handle. + +For now, our handling of the stream consists of calling `unwrap` to terminate +our program if the stream has any errors [3]; if there aren’t any errors, the +program prints a message [4]. We’ll add more functionality for the success case +in the next listing. The reason we might receive errors from the `incoming` +method when a client connects to the server is that we’re not actually +iterating over connections. Instead, we’re iterating over *connection +attempts*. The connection might not be successful for a number of reasons, many +of them operating system specific. For example, many operating systems have a +limit to the number of simultaneous open connections they can support; new +connection attempts beyond that number will produce an error until some of the +open connections are closed. + +Let’s try running this code! Invoke `cargo run` in the terminal and then load +*127.0.0.1:7878* in a web browser. The browser should show an error message +like “Connection reset” because the server isn’t currently sending back any +data. But when you look at your terminal, you should see several messages that +were printed when the browser connected to the server! + +``` + Running `target/debug/hello` +Connection established! +Connection established! +Connection established! +``` + +Sometimes you’ll see multiple messages printed for one browser request; the +reason might be that the browser is making a request for the page as well as a +request for other resources, like the *favicon.ico* icon that appears in the +browser tab. + +It could also be that the browser is trying to connect to the server multiple +times because the server isn’t responding with any data. When `stream` goes out +of scope and is dropped at the end of the loop, the connection is closed as +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 ctrl-C 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 + +Let’s implement the functionality to read the request from the browser! To +separate the concerns of first getting a connection and then taking some action +with the connection, we’ll start a new function for processing connections. In +this new `handle_connection` function, we’ll read data from the TCP stream and +print it so we can see the data being sent from the browser. Change the code to +look like Listing 20-2. + +Filename: src/main.rs + +``` +1 use std::{ + io::{prelude::*, BufReader}, + net::{TcpListener, TcpStream}, +}; + +fn main() { + let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); + + for stream in listener.incoming() { + let stream = stream.unwrap(); + + 2 handle_connection(stream); + } +} + +fn handle_connection(mut stream: TcpStream) { + 3 let buf_reader = BufReader::new(&mut stream); + 4 let http_request: Vec<_> = buf_reader + 5 .lines() + 6 .map(|result| result.unwrap()) + 7 .take_while(|line| !line.is_empty()) + .collect(); + + 8 println!("Request: {:#?}", http_request); +} +``` + +Listing 20-2: Reading from the `TcpStream` and printing the data + +We bring `std::io::prelude` and `std::io::BufReader` into scope to get access +to traits and types that let us read from and write to the stream [1]. In the +`for` loop in the `main` function, instead of printing a message that says we +made a connection, we now call the new `handle_connection` function and pass +the `stream` to it [2]. + +In the `handle_connection` function, we create a new `BufReader` instance that +wraps a mutable reference to the `stream` [3]. `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 +lines in a vector by adding the `Vec<_>` type annotation [4]. + +`BufReader` implements the `std::io::BufRead` trait, which provides the `lines` +method [5]. The `lines` method returns an iterator of `Result` by splitting the stream of data whenever it sees a newline +byte. To get each `String`, we map and `unwrap` each `Result` [6]. The `Result` +might be an error if the data isn’t valid UTF-8 or if there was a problem +reading from the stream. Again, a production program should handle these errors +more gracefully, but we’re choosing to stop the program in the error case for +simplicity. + +The browser signals the end of an HTTP request by sending two newline +characters in a row, so to get one request from the stream, we take lines until +we get a line that is the empty string [7]. Once we’ve collected the lines into +the vector, we’re printing them out using pretty debug formatting [8] so we can +take a look at the instructions the web browser is sending to our server. + +Let’s try this code! Start the program and make a request in a web browser +again. Note that we’ll still get an error page in the browser, but our +program’s output in the terminal will now look similar to this: + +``` +$ cargo run + Compiling hello v0.1.0 (file:///projects/hello) + Finished dev [unoptimized + debuginfo] target(s) in 0.42s + Running `target/debug/hello` +Request: [ + "GET / HTTP/1.1", + "Host: 127.0.0.1:7878", + "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) +Gecko/20100101 Firefox/99.0", + "Accept: +text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/* +;q=0.8", + "Accept-Language: en-US,en;q=0.5", + "Accept-Encoding: gzip, deflate, br", + "DNT: 1", + "Connection: keep-alive", + "Upgrade-Insecure-Requests: 1", + "Sec-Fetch-Dest: document", + "Sec-Fetch-Mode: navigate", + "Sec-Fetch-Site: none", + "Sec-Fetch-User: ?1", + "Cache-Control: max-age=0", +] +``` + +Depending on your browser, you might get slightly different output. Now that +we’re printing the request data, we can see why we get multiple connections +from one browser request by looking at the path after `GET` in the first line +of the request. If the repeated connections are all requesting */*, we know the +browser is trying to fetch */* repeatedly because it’s not getting a response +from our program. + +Let’s break down this request data to understand what the browser is asking of +our program. + +### A Closer Look at an HTTP Request + +HTTP is a text-based protocol, and a request takes this format: + +``` +Method Request-URI HTTP-Version CRLF +headers CRLF +message-body +``` + +The first line is the *request line* that holds information about what the +client is requesting. The first part of the request line indicates the *method* +being used, such as `GET` or `POST`, which describes how the client is making +this request. Our client used a `GET` request, which means it is asking for +information. + +The next part of the request line is */*, which indicates the *uniform resource +identifier* *(URI)* the client is requesting: a URI is almost, but not quite, +the same as a *uniform resource locator* *(URL)*. The difference between URIs +and URLs isn’t important for our purposes in this chapter, but the HTTP spec +uses the term *URI*, so we can just mentally substitute *URL* for *URI* here. + +The last part is the HTTP version the client uses, and then the request line +ends in a CRLF sequence. (CRLF stands for *carriage return* and *line feed*, +which are terms from the typewriter days!) The CRLF sequence can also be +written as `\r\n`, where `\r` is a carriage return and `\n` is a line feed. The +*CRLF sequence* separates the request line from the rest of the request data. +Note that when the CRLF is printed, we see a new line start rather than `\r\n`. + +Looking at the request line data we received from running our program so far, +we see that `GET` is the method, */* is the request URI, and `HTTP/1.1` is the +version. + +After the request line, the remaining lines starting from `Host:` onward are +headers. `GET` requests have no body. + +Try making a request from a different browser or asking for a different +address, such as *127.0.0.1:7878/test*, to see how the request data changes. + +Now that we know what the browser is asking for, let’s send back some data! + +### Writing a Response + +We’re going to implement sending data in response to a client request. +Responses have the following format: + +``` +HTTP-Version Status-Code Reason-Phrase CRLF +headers CRLF +message-body +``` + +The first line is a *status line* that contains the HTTP version used in the +response, a numeric status code that summarizes the result of the request, and +a reason phrase that provides a text description of the status code. After the +CRLF sequence are any headers, another CRLF sequence, and the body of the +response. + +Here is an example response that uses HTTP version 1.1, and has a status code +of 200, an OK reason phrase, no headers, and no body: + +``` +HTTP/1.1 200 OK\r\n\r\n +``` + +The status code 200 is the standard success response. The text is a tiny +successful HTTP response. Let’s write this to the stream as our response to a +successful request! From the `handle_connection` function, remove the +`println!` that was printing the request data and replace it with the code in +Listing 20-3. + +Filename: src/main.rs + +``` +fn handle_connection(mut stream: TcpStream) { + let buf_reader = BufReader::new(&mut stream); + let http_request: Vec<_> = buf_reader + .lines() + .map(|result| result.unwrap()) + .take_while(|line| !line.is_empty()) + .collect(); + + 1 let response = "HTTP/1.1 200 OK\r\n\r\n"; + + 2 stream.write_all(response.3 as_bytes()).unwrap(); +} +``` + +Listing 20-3: Writing a tiny successful HTTP response to the stream + +The first new line defines the `response` variable that holds the success +message’s data [1]. Then we call `as_bytes` on our `response` to convert the +string data to bytes [3]. The `write_all` method on `stream` takes a `&[u8]` +and sends those bytes directly down the connection [2]. Because the `write_all` +operation could fail, we use `unwrap` on any error result as before. Again, in +a real application you would add error handling here. + +With these changes, let’s run our code and make a request. We’re no longer +printing any data to the terminal, so we won’t see any output other than the +output from Cargo. When you load *127.0.0.1:7878* in a web browser, you should +get a blank page instead of an error. You’ve just handcoded receiving an HTTP +request and sending a response! + +### Returning Real HTML + +Let’s implement the functionality for returning more than a blank page. Create +the new file *hello.html* in the root of your project directory, not in the +*src* directory. You can input any HTML you want; Listing 20-4 shows one +possibility. + +Filename: hello.html + +``` + + + + + Hello! + + +

Hello!

+

Hi from Rust

+ + +``` + +Listing 20-4: A sample HTML file to return in a response + +This is a minimal HTML5 document with a heading and some text. To return this +from the server when a request is received, we’ll modify `handle_connection` as +shown in Listing 20-5 to read the HTML file, add it to the response as a body, +and send it. + +Filename: src/main.rs + +``` +use std::{ + 1 fs, + io::{prelude::*, BufReader}, + net::{TcpListener, TcpStream}, +}; +--snip-- + +fn handle_connection(mut stream: TcpStream) { + let buf_reader = BufReader::new(&mut stream); + let http_request: Vec<_> = buf_reader + .lines() + .map(|result| result.unwrap()) + .take_while(|line| !line.is_empty()) + .collect(); + + let status_line = "HTTP/1.1 200 OK"; + let contents = fs::read_to_string("hello.html").unwrap(); + let length = contents.len(); + + 2 let response = format!( + "{status_line}\r\n\ + Content-Length: {length}\r\n\r\n\ + {contents}" + ); + + stream.write_all(response.as_bytes()).unwrap(); +} +``` + +Listing 20-5: Sending the contents of *hello.html* as the body of the response + +We’ve added `fs` to the `use` statement to bring the standard library’s +filesystem module into scope [1]. The code for reading the contents of a file +to a string should look familiar; we used it when we read the contents of a +file for our I/O project in Listing 12-4. + +Next, we use `format!` to add the file’s contents as the body of the success +response [2]. To ensure a valid HTTP response, we add the `Content-Length` +header which is set to the size of our response body, in this case the size of +`hello.html`. + +Run this code with `cargo run` and load *127.0.0.1:7878* in your browser; you +should see your HTML rendered! + +Currently, we’re ignoring the request data in `http_request` and just sending +back the contents of the HTML file unconditionally. That means if you try +requesting *127.0.0.1:7878/something-else* in your browser, you’ll still get +back this same HTML response. At the moment, our server is very limited and +does not do what most web servers do. We want to customize our responses +depending on the request and only send back the HTML file for a well-formed +request to */*. + +### Validating the Request and Selectively Responding + +Right now, our web server will return the HTML in the file no matter what the +client requested. Let’s add functionality to check that the browser is +requesting */* before returning the HTML file, and return an error if the +browser requests anything else. For this we need to modify `handle_connection`, +as shown in Listing 20-6. This new code checks the content of the request +received against what we know a request for */* looks like and adds `if` and +`else` blocks to treat requests differently. + +Filename: src/main.rs + +``` +--snip-- + +fn handle_connection(mut stream: TcpStream) { + let buf_reader = BufReader::new(&mut stream); + 1 let request_line = buf_reader + .lines() + .next() + .unwrap() + .unwrap(); + + 2 if request_line == "GET / HTTP/1.1" { + let status_line = "HTTP/1.1 200 OK"; + let contents = fs::read_to_string("hello.html").unwrap(); + let length = contents.len(); + + let response = format!( + "{status_line}\r\n\ + Content-Length: {length}\r\n\r\n\ + {contents}" + ); + + stream.write_all(response.as_bytes()).unwrap(); + 3 } else { + // some other request + } +} +``` + +Listing 20-6: Handling requests to */* differently from other requests + +We’re only going to be looking at the first line of the HTTP request, so rather +than reading the entire request into a vector, we’re calling `next` to get the +first item from the iterator [1]. The first `unwrap` takes care of the `Option` +and stops the program if the iterator has no items. The second `unwrap` handles +the `Result` and has the same effect as the `unwrap` that was in the `map` +added in Listing 20-2. + +Next, we check the `request_line` to see if it equals the request line of a GET +request to the */* path [2]. If it does, the `if` block returns the contents of +our HTML file. + +If the `request_line` does *not* equal the GET request to the */* path, it +means we’ve received some other request. We’ll add code to the `else` block [3] +in a moment to respond to all other requests. + +Run this code now and request *127.0.0.1:7878*; you should get the HTML in +*hello.html*. If you make any other request, such as +*127.0.0.1:7878/something-else*, you’ll get a connection error like those you +saw when running the code in Listing 20-1 and Listing 20-2. + +Now let’s add the code in Listing 20-7 to the `else` block to return a response +with the status code 404, which signals that the content for the request was +not found. We’ll also return some HTML for a page to render in the browser +indicating the response to the end user. + +Filename: src/main.rs + +``` +--snip-- +} else { + 1 let status_line = "HTTP/1.1 404 NOT FOUND"; + 2 let contents = fs::read_to_string("404.html").unwrap(); + let length = contents.len(); + + let response = format!( + "{status_line}\r\n\ + Content-Length: {length}\r\n\r\n + {contents}" + ); + + stream.write_all(response.as_bytes()).unwrap(); +} +``` + +Listing 20-7: Responding with status code 404 and an error page if anything +other than */* was requested + +Here, our response has a status line with status code 404 and the reason phrase +`NOT FOUND` [1]. The body of the response will be the HTML in the file +*404.html* [1]. You’ll need to create a *404.html* file next to *hello.html* +for the error page; again feel free to use any HTML you want, or use the +example HTML in Listing 20-8. + +Filename: 404.html + +``` + + + + + Hello! + + +

Oops!

+

Sorry, I don't know what you're asking for.

+ + +``` + +Listing 20-8: Sample content for the page to send back with any 404 response + +With these changes, run your server again. Requesting *127.0.0.1:7878* should +return the contents of *hello.html*, and any other request, like +*127.0.0.1:7878/foo*, should return the error HTML from *404.html*. + +### A Touch of Refactoring + +At the moment, the `if` and `else` blocks have a lot of repetition: they’re +both reading files and writing the contents of the files to the stream. The +only differences are the status line and the filename. Let’s make the code more +concise by pulling out those differences into separate `if` and `else` lines +that will assign the values of the status line and the filename to variables; +we can then use those variables unconditionally in the code to read the file +and write the response. Listing 20-9 shows the resultant code after replacing +the large `if` and `else` blocks. + +Filename: src/main.rs + +``` +--snip-- + +fn handle_connection(mut stream: TcpStream) { + --snip-- + + let (status_line, filename) = + if request_line == "GET / HTTP/1.1" { + ("HTTP/1.1 200 OK", "hello.html") + } else { + ("HTTP/1.1 404 NOT FOUND", "404.html") + }; + + let contents = fs::read_to_string(filename).unwrap(); + let length = contents.len(); + + let response = format!( + "{status_line}\r\n\ + Content-Length: {length}\r\n\r\n\ + {contents}" + ); + + stream.write_all(response.as_bytes()).unwrap(); +} +``` + +Listing 20-9: Refactoring the `if` and `else` blocks to contain only the code +that differs between the two cases + +Now the `if` and `else` blocks only return the appropriate values for the +status line and filename in a tuple; we then use destructuring to assign these +two values to `status_line` and `filename` using a pattern in the `let` +statement, as discussed in Chapter 18. + +The previously duplicated code is now outside the `if` and `else` blocks and +uses the `status_line` and `filename` variables. This makes it easier to see +the difference between the two cases, and it means we have only one place to +update the code if we want to change how the file reading and response writing +work. The behavior of the code in Listing 20-9 will be the same as that in +Listing 20-8. + +Awesome! We now have a simple web server in approximately 40 lines of Rust code +that responds to one request with a page of content and responds to all other +requests with a 404 response. + +Currently, our server runs in a single thread, meaning it can only serve one +request at a time. Let’s examine how that can be a problem by simulating some +slow requests. Then we’ll fix it so our server can handle multiple requests at +once. + +## Turning Our Single-Threaded Server into a Multithreaded Server + +Right now, the server will process each request in turn, meaning it won’t +process a second connection until the first is finished processing. If the +server received more and more requests, this serial execution would be less and +less optimal. If the server receives a request that takes a long time to +process, subsequent requests will have to wait until the long request is +finished, even if the new requests can be processed quickly. We’ll need to fix +this, but first we’ll look at the problem in action. + +### Simulating a Slow Request + +We’ll look at how a slow-processing request can affect other requests made to +our current server implementation. Listing 20-10 implements handling a request +to */sleep* with a simulated slow response that will cause the server to sleep +for five seconds before responding. + +Filename: src/main.rs + +``` +use std::{ + fs, + io::{prelude::*, BufReader}, + net::{TcpListener, TcpStream}, + thread, + time::Duration, +}; +--snip-- + +fn handle_connection(mut stream: TcpStream) { + --snip-- + + let (status_line, filename) = 1 match &request_line[..] { + 2 "GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"), + 3 "GET /sleep HTTP/1.1" => { + thread::sleep(Duration::from_secs(5)); + ("HTTP/1.1 200 OK", "hello.html") + } + 4 _ => ("HTTP/1.1 404 NOT FOUND", "404.html"), + }; + + --snip-- +} +``` + +Listing 20-10: Simulating a slow request by sleeping for five seconds + +We switched from `if` to `match` now that we have three cases [1]. We need to +explicitly match on a slice of `request_line` to pattern-match against the +string literal values; `match` doesn’t do automatic referencing and +dereferencing, like the equality method does. + +The first arm [2] is the same as the `if` block from Listing 20-9. The second +arm [3] matches a request to */sleep*. When that request is received, the +server will sleep for five seconds before rendering the successful HTML page. +The third arm [4] is the same as the `else` block from Listing 20-9. + +You can see how primitive our server is: real libraries would handle the +recognition of multiple requests in a much less verbose way! + +Start the server using `cargo run`. Then open two browser windows: one for +*http://127.0.0.1:7878* and the other for *http://127.0.0.1:7878/sleep*. If you +enter the */* URI a few times, as before, you’ll see it respond quickly. But if +you enter */sleep* and then load */*, you’ll see that */* waits until `sleep` +has slept for its full five seconds before loading. + +There are multiple techniques we could use to avoid requests backing up behind +a slow request; the one we’ll implement is a thread pool. + +### Improving Throughput with a Thread Pool + +A *thread pool* is a group of spawned threads that are waiting and ready to +handle a task. When the program receives a new task, it assigns one of the +threads in the pool to the task, and that thread will process the task. The +remaining threads in the pool are available to handle any other tasks that come +in while the first thread is processing. When the first thread is done +processing its task, it’s returned to the pool of idle threads, ready to handle +a new task. A thread pool allows you to process connections concurrently, +increasing the throughput of your server. + +We’ll limit the number of threads in the pool to a small number to protect us +from DoS attacks; if we had our program create a new thread for each request as +it came in, someone making 10 million requests to our server could create havoc +by using up all our server’s resources and grinding the processing of requests +to a halt. + +Rather than spawning unlimited threads, then, we’ll have a fixed number of +threads waiting in the pool. Requests that come in are sent to the pool for +processing. The pool will maintain a queue of incoming requests. Each of the +threads in the pool will pop off a request from this queue, handle the request, +and then ask the queue for another request. With this design, we can process up +to N requests concurrently, where N is the number of threads. If each thread is +responding to a long-running request, subsequent requests can still back up in +the queue, but we’ve increased the number of long-running requests we can +handle before reaching that point. + +This technique is just one of many ways to improve the throughput of a web +server. Other options you might explore are the fork/join model, the +single-threaded async I/O model, and the multithreaded async I/O model. If +you’re interested in this topic, you can read more about other solutions and +try to implement them; with a low-level language like Rust, all of these +options are possible. + +Before we begin implementing a thread pool, let’s talk about what using the +pool should look like. When you’re trying to design code, writing the client +interface first can help guide your design. Write the API of the code so it’s +structured in the way you want to call it; then implement the functionality +within that structure rather than implementing the functionality and then +designing the public API. + +Similar to how we used test-driven development in the project in Chapter 12, +we’ll use compiler-driven development here. We’ll write the code that calls the +functions we want, and then we’ll look at errors from the compiler to determine +what we should change next to get the code to work. Before we do that, however, +we’ll explore the technique we’re not going to use as a starting point. + +#### Spawning a Thread for Each Request + +First, let’s explore how our code might look if it did create a new thread for +every connection. As mentioned earlier, this isn’t our final plan due to the +problems with potentially spawning an unlimited number of threads, but it is a +starting point to get a working multithreaded server first. Then we’ll add the +thread pool as an improvement, and contrasting the two solutions will be easier. + +Listing 20-11 shows the changes to make to `main` to spawn a new thread to +handle each stream within the `for` loop. + +Filename: src/main.rs + +``` +fn main() { + let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); + + for stream in listener.incoming() { + let stream = stream.unwrap(); + + thread::spawn(|| { + handle_connection(stream); + }); + } +} +``` + +Listing 20-11: Spawning a new thread for each stream + +As you learned in Chapter 16, `thread::spawn` will create a new thread and then +run the code in the closure in the new thread. If you run this code and load +*/sleep* in your browser, then */* in two more browser tabs, you’ll indeed see +that the requests to */* don’t have to wait for */sleep* to finish. However, as +we mentioned, this will eventually overwhelm the system because you’d be making +new threads without any limit. + +#### Creating a Finite Number of Threads + +We want our thread pool to work in a similar, familiar way so that switching +from threads to a thread pool doesn’t require large changes to the code that +uses our API. Listing 20-12 shows the hypothetical interface for a `ThreadPool` +struct we want to use instead of `thread::spawn`. + +Filename: src/main.rs + +``` +fn main() { + let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); + 1 let pool = ThreadPool::new(4); + + for stream in listener.incoming() { + let stream = stream.unwrap(); + + 2 pool.execute(|| { + handle_connection(stream); + }); + } +} +``` + +Listing 20-12: Our ideal `ThreadPool` interface + +We use `ThreadPool::new` to create a new thread pool with a configurable number +of threads, in this case four [1]. Then, in the `for` loop, `pool.execute` has +a similar interface as `thread::spawn` in that it takes a closure the pool +should run for each stream [2]. We need to implement `pool.execute` so it takes +the closure and gives it to a thread in the pool to run. This code won’t yet +compile, but we’ll try so that the compiler can guide us in how to fix it. + +#### Building ThreadPool Using Compiler-Driven Development + +Make the changes in Listing 20-12 to *src/main.rs*, and then let’s use the +compiler errors from `cargo check` to drive our development. Here is the first +error we get: + +``` +$ cargo check + Checking hello v0.1.0 (file:///projects/hello) +error[E0433]: failed to resolve: use of undeclared type `ThreadPool` + --> src/main.rs:11:16 + | +11 | let pool = ThreadPool::new(4); + | ^^^^^^^^^^ use of undeclared type `ThreadPool` +``` + +Great! This error tells us we need a `ThreadPool` type or module, so we’ll +build one now. Our `ThreadPool` implementation will be independent of the kind +of work our web server is doing. So let’s switch the `hello` crate from a +binary crate to a library crate to hold our `ThreadPool` implementation. After +we change to a library crate, we could also use the separate thread pool +library for any work we want to do using a thread pool, not just for serving +web requests. + +Create a *src/lib.rs* file that contains the following, which is the simplest +definition of a `ThreadPool` struct that we can have for now: + +Filename: src/lib.rs + +``` +pub struct ThreadPool; +``` + +Then edit the *main.rs* file to bring `ThreadPool` into scope from the library +crate by adding the following code to the top of *src/main.rs*: + +Filename: src/main.rs + +``` +use hello::ThreadPool; +``` + +This code still won’t work, but let’s check it again to get the next error that +we need to address: + +``` +$ cargo check + Checking hello v0.1.0 (file:///projects/hello) +error[E0599]: no function or associated item named `new` found for struct +`ThreadPool` in the current scope + --> src/main.rs:12:28 + | +12 | let pool = ThreadPool::new(4); + | ^^^ function or associated item not found in +`ThreadPool` +``` + +This error indicates that next we need to create an associated function named +`new` for `ThreadPool`. We also know that `new` needs to have one parameter +that can accept `4` as an argument and should return a `ThreadPool` instance. +Let’s implement the simplest `new` function that will have those +characteristics: + +Filename: src/lib.rs + +``` +pub struct ThreadPool; + +impl ThreadPool { + pub fn new(size: usize) -> ThreadPool { + ThreadPool + } +} +``` + +We chose `usize` as the type of the `size` parameter because we know that a +negative number of threads doesn’t make any sense. We also know we’ll use this +`4` as the number of elements in a collection of threads, which is what the +`usize` type is for, as discussed in “Integer Types” on page XX. + +Let’s check the code again: + +``` +$ cargo check + Checking hello v0.1.0 (file:///projects/hello) +error[E0599]: no method named `execute` found for struct `ThreadPool` in the +current scope + --> src/main.rs:17:14 + | +17 | pool.execute(|| { + | ^^^^^^^ method not found in `ThreadPool` +``` + +Now the error occurs because we don’t have an `execute` method on `ThreadPool`. +Recall from “Creating a Finite Number of Threads” on page XX that we decided +our thread pool should have an interface similar to `thread::spawn`. In +addition, we’ll implement the `execute` function so it takes the closure it’s +given and gives it to an idle thread in the pool to run. + +We’ll define the `execute` method on `ThreadPool` to take a closure as a +parameter. Recall from “Moving Captured Values Out of Closures and the Fn +Traits” on page XX that we can take closures as parameters with three different +traits: `Fn`, `FnMut`, and `FnOnce`. We need to decide which kind of closure to +use here. We know we’ll end up doing something similar to the standard library +`thread::spawn` implementation, so we can look at what bounds the signature of +`thread::spawn` has on its parameter. The documentation shows us the following: + +``` +pub fn spawn(f: F) -> JoinHandle + where + F: FnOnce() -> T, + F: Send + 'static, + T: Send + 'static, +``` + +The `F` type parameter is the one we’re concerned with here; the `T` type +parameter is related to the return value, and we’re not concerned with that. We +can see that `spawn` uses `FnOnce` as the trait bound on `F`. This is probably +what we want as well, because we’ll eventually pass the argument we get in +`execute` to `spawn`. We can be further confident that `FnOnce` is the trait we +want to use because the thread for running a request will only execute that +request’s closure one time, which matches the `Once` in `FnOnce`. + +The `F` type parameter also has the trait bound `Send` and the lifetime bound +`'static`, which are useful in our situation: we need `Send` to transfer the +closure from one thread to another and `'static` because we don’t know how long +the thread will take to execute. Let’s create an `execute` method on +`ThreadPool` that will take a generic parameter of type `F` with these bounds: + +Filename: src/lib.rs + +``` +impl ThreadPool { + --snip-- + pub fn execute(&self, f: F) + where + F: FnOnce() 1 + Send + 'static, + { + } +} +``` + +We still use the `()` after `FnOnce` [1] because this `FnOnce` represents a +closure that takes no parameters and returns the unit type `()`. Just like +function definitions, the return type can be omitted from the signature, but +even if we have no parameters, we still need the parentheses. + +Again, this is the simplest implementation of the `execute` method: it does +nothing, but we’re only trying to make our code compile. Let’s check it again: + +``` +$ cargo check + Checking hello v0.1.0 (file:///projects/hello) + Finished dev [unoptimized + debuginfo] target(s) in 0.24s +``` + +It compiles! But note that if you try `cargo run` and make a request in the +browser, you’ll see the errors in the browser that we saw at the beginning of +the chapter. Our library isn’t actually calling the closure passed to `execute` +yet! + +> Note: A saying you might hear about languages with strict compilers, such as +Haskell and Rust, is “if the code compiles, it works.” But this saying is not +universally true. Our project compiles, but it does absolutely nothing! If we +were building a real, complete project, this would be a good time to start +writing unit tests to check that the code compiles *and* has the behavior we +want. + +#### Validating the Number of Threads in new + +We aren’t doing anything with the parameters to `new` and `execute`. Let’s +implement the bodies of these functions with the behavior we want. To start, +let’s think about `new`. Earlier we chose an unsigned type for the `size` +parameter because a pool with a negative number of threads makes no sense. +However, a pool with zero threads also makes no sense, yet zero is a perfectly +valid `usize`. We’ll add code to check that `size` is greater than zero before +we return a `ThreadPool` instance and have the program panic if it receives a +zero by using the `assert!` macro, as shown in Listing 20-13. + +Filename: src/lib.rs + +``` +impl ThreadPool { + /// Create a new ThreadPool. + /// + /// The size is the number of threads in the pool. + /// + 1 /// # Panics + /// + /// The `new` function will panic if the size is zero. + pub fn new(size: usize) -> ThreadPool { + 2 assert!(size > 0); + + ThreadPool + } + + --snip-- +} +``` + +Listing 20-13: Implementing `ThreadPool::new` to panic if `size` is zero + +We’ve also added some documentation for our `ThreadPool` with doc comments. +Note that we followed good documentation practices by adding a section that +calls out the situations in which our function can panic [1], as discussed in +Chapter 14. Try running `cargo doc --open` and clicking the `ThreadPool` struct +to see what the generated docs for `new` look like! + +Instead of adding the `assert!` macro as we’ve done here [2], we could change +`new` into `build` and return a `Result` like we did with `Config::build` in +the I/O project in Listing 12-9. But we’ve decided in this case that trying to +create a thread pool without any threads should be an unrecoverable error. If +you’re feeling ambitious, try to write a function named `build` with the +following signature to compare with the `new` function: + +``` +pub fn build( + size: usize +) -> Result { +``` + +#### Creating Space to Store the Threads + +Now that we have a way to know we have a valid number of threads to store in +the pool, we can create those threads and store them in the `ThreadPool` struct +before returning the struct. But how do we “store” a thread? Let’s take another +look at the `thread::spawn` signature: + +``` +pub fn spawn(f: F) -> JoinHandle + where + F: FnOnce() -> T, + F: Send + 'static, + T: Send + 'static, +``` + +The `spawn` function returns a `JoinHandle`, where `T` is the type that the +closure returns. Let’s try using `JoinHandle` too and see what happens. In our +case, the closures we’re passing to the thread pool will handle the connection +and not return anything, so `T` will be the unit type `()`. + +The code in Listing 20-14 will compile but doesn’t create any threads yet. +We’ve changed the definition of `ThreadPool` to hold a vector of +`thread::JoinHandle<()>` instances, initialized the vector with a capacity of +`size`, set up a `for` loop that will run some code to create the threads, and +returned a `ThreadPool` instance containing them. + +Filename: src/lib.rs + +``` +1 use std::thread; + +pub struct ThreadPool { + 2 threads: Vec>, +} + +impl ThreadPool { + --snip-- + pub fn new(size: usize) -> ThreadPool { + assert!(size > 0); + + 3 let mut threads = Vec::with_capacity(size); + + for _ in 0..size { + // create some threads and store them in the vector + } + + ThreadPool { threads } + } + --snip-- +} +``` + +Listing 20-14: Creating a vector for `ThreadPool` to hold the threads + +We’ve brought `std::thread` into scope in the library crate [1] because we’re +using `thread::JoinHandle` as the type of the items in the vector in +`ThreadPool` [2]. + +Once a valid size is received, our `ThreadPool` creates a new vector that can +hold `size` items [3]. The `with_capacity` function performs the same task as +`Vec::new` but with an important difference: it pre-allocates space in the +vector. Because we know we need to store `size` elements in the vector, doing +this allocation up front is slightly more efficient than using `Vec::new`, +which resizes itself as elements are inserted. + +When you run `cargo check` again, it should succeed. + +#### Sending Code from the ThreadPool to a Thread + +We left a comment in the `for` loop in Listing 20-14 regarding the creation of +threads. Here, we’ll look at how we actually create threads. The standard +library provides `thread::spawn` as a way to create threads, and +`thread::spawn` expects to get some code the thread should run as soon as the +thread is created. However, in our case, we want to create the threads and have +them *wait* for code that we’ll send later. The standard library’s +implementation of threads doesn’t include any way to do that; we have to +implement it manually. + +We’ll implement this behavior by introducing a new data structure between the +`ThreadPool` and the threads that will manage this new behavior. We’ll call +this data structure *Worker*, which is a common term in pooling +implementations. The `Worker` picks up code that needs to be run and runs the +code in its thread. + +Think of people working in the kitchen at a restaurant: the workers wait until +orders come in from customers, and then they’re responsible for taking those +orders and filling them. + +Instead of storing a vector of `JoinHandle<()>` instances in the thread pool, +we’ll store instances of the `Worker` struct. Each `Worker` will store a single +`JoinHandle<()>` instance. Then we’ll implement a method on `Worker` that will +take a closure of code to run and send it to the already running thread for +execution. We’ll also give each `Worker` an `id` so we can distinguish between +the different instances of `Worker` in the pool when logging or debugging. + +Here is the new process that will happen when we create a `ThreadPool`. We’ll +implement the code that sends the closure to the thread after we have `Worker` +set up in this way: + +1. Define a `Worker` struct that holds an `id` and a `JoinHandle<()>`. +1. Change `ThreadPool` to hold a vector of `Worker` instances. +1. Define a `Worker::new` function that takes an `id` number and returns a +`Worker` instance that holds the `id` and a thread spawned with an empty +closure. +1. In `ThreadPool::new`, use the `for` loop counter to generate an `id`, create +a new `Worker` with that `id`, and store the `Worker` in the vector. + +If you’re up for a challenge, try implementing these changes on your own before +looking at the code in Listing 20-15. + +Ready? Here is Listing 20-15 with one way to make the preceding modifications. + +Filename: src/lib.rs + +``` +use std::thread; + +pub struct ThreadPool { + 1 workers: Vec, +} + +impl ThreadPool { + --snip-- + pub fn new(size: usize) -> ThreadPool { + assert!(size > 0); + + let mut workers = Vec::with_capacity(size); + + 2 for id in 0..size { + 3 workers.push(Worker::new(id)); + } + + ThreadPool { workers } + } + --snip-- +} + +4 struct Worker { + id: usize, + thread: thread::JoinHandle<()>, +} + +impl Worker { + 5 fn new(id: usize) -> Worker { + 6 let thread = thread::spawn(|| {}); + + Worker { 7 id, 8 thread } + } +} +``` + +Listing 20-15: Modifying `ThreadPool` to hold `Worker` instances instead of +holding threads directly + +We’ve changed the name of the field on `ThreadPool` from `threads` to `workers` +because it’s now holding `Worker` instances instead of `JoinHandle<()>` +instances [1]. We use the counter in the `for` loop [2] as an argument to +`Worker::new`, and we store each new `Worker` in the vector named `workers` [3]. + +External code (like our server in *src/main.rs*) doesn’t need to know the +implementation details regarding using a `Worker` struct within `ThreadPool`, +so we make the `Worker` struct [4] and its `new` function [5] private. The +`Worker::new` function uses the `id` we give it [7] and stores a +`JoinHandle<()>` instance [8] that is created by spawning a new thread using an +empty closure [6]. + +> Note: If the operating system can’t create a thread because there aren’t +enough system resources, `thread::spawn` will panic. That will cause our whole +server to panic, even though the creation of some threads might succeed. For +simplicity’s sake, this behavior is fine, but in a production thread pool +implementation, you’d likely want to use `std::thread::Builder` and its `spawn` +method that returns `Result` instead. + +This code will compile and will store the number of `Worker` instances we +specified as an argument to `ThreadPool::new`. But we’re *still* not processing +the closure that we get in `execute`. Let’s look at how to do that next. + +#### Sending Requests to Threads via Channels + +The next problem we’ll tackle is that the closures given to `thread::spawn` do +absolutely nothing. Currently, we get the closure we want to execute in the +`execute` method. But we need to give `thread::spawn` a closure to run when we +create each `Worker` during the creation of the `ThreadPool`. + +We want the `Worker` structs that we just created to fetch the code to run from +a queue held in the `ThreadPool` and send that code to its thread to run. + +The channels we learned about in Chapter 16—a simple way to communicate between +two threads—would be perfect for this use case. We’ll use a channel to function +as the queue of jobs, and `execute` will send a job from the `ThreadPool` to +the `Worker` instances, which will send the job to its thread. Here is the plan: + +1. The `ThreadPool` will create a channel and hold on to the sender. +1. Each `Worker` will hold on to the receiver. +1. We’ll create a new `Job` struct that will hold the closures we want to send +down the channel. +1. The `execute` method will send the job it wants to execute through the +sender. +1. In its thread, the `Worker` will loop over its receiver and execute the +closures of any jobs it receives. + +Let’s start by creating a channel in `ThreadPool::new` and holding the sender +in the `ThreadPool` instance, as shown in Listing 20-16. The `Job` struct +doesn’t hold anything for now but will be the type of item we’re sending down +the channel. + +Filename: src/lib.rs + +``` +use std::{sync::mpsc, thread}; + +pub struct ThreadPool { + workers: Vec, + sender: mpsc::Sender, +} + +struct Job; + +impl ThreadPool { + --snip-- + pub fn new(size: usize) -> ThreadPool { + assert!(size > 0); + + 1 let (sender, receiver) = mpsc::channel(); + + let mut workers = Vec::with_capacity(size); + + for id in 0..size { + workers.push(Worker::new(id)); + } + + ThreadPool { workers, 2 sender } + } + --snip-- +} +``` + +Listing 20-16: Modifying `ThreadPool` to store the sender of a channel that +transmits `Job` instances + +In `ThreadPool::new`, we create our new channel [1] and have the pool hold the +sender [2]. This will successfully compile. + +Let’s try passing a receiver of the channel into each `Worker` as the thread +pool creates the channel. We know we want to use the receiver in the thread +that the `Worker` instances spawn, so we’ll reference the `receiver` parameter +in the closure. The code in Listing 20-17 won’t quite compile yet. + +Filename: src/lib.rs + +``` +impl ThreadPool { + --snip-- + pub fn new(size: usize) -> ThreadPool { + assert!(size > 0); + + let (sender, receiver) = mpsc::channel(); + + let mut workers = Vec::with_capacity(size); + + for id in 0..size { + 1 workers.push(Worker::new(id, receiver)); + } + + ThreadPool { workers, sender } + } + --snip-- +} + +--snip-- + +impl Worker { + fn new(id: usize, receiver: mpsc::Receiver) -> Worker { + let thread = thread::spawn(|| { + 2 receiver; + }); + + Worker { id, thread } + } +} +``` + +Listing 20-17: Passing the receiver to each `Worker` + +We’ve made some small and straightforward changes: we pass the receiver into +`Worker::new` [1], and then we use it inside the closure [2]. + +When we try to check this code, we get this error: + +``` +$ cargo check + Checking hello v0.1.0 (file:///projects/hello) +error[E0382]: use of moved value: `receiver` + --> src/lib.rs:26:42 + | +21 | let (sender, receiver) = mpsc::channel(); + | -------- move occurs because `receiver` has type +`std::sync::mpsc::Receiver`, which does not implement the `Copy` trait +... +26 | workers.push(Worker::new(id, receiver)); + | ^^^^^^^^ value moved here, in +previous iteration of loop +``` + +The code is trying to pass `receiver` to multiple `Worker` instances. This +won’t work, as you’ll recall from Chapter 16: the channel implementation that +Rust provides is multiple *producer*, single *consumer*. This means we can’t +just clone the consuming end of the channel to fix this code. We also don’t +want to send a message multiple times to multiple consumers; we want one list +of messages with multiple `Worker` instances such that each message gets +processed once. + +Additionally, taking a job off the channel queue involves mutating the +`receiver`, so the threads need a safe way to share and modify `receiver`; +otherwise, we might get race conditions (as covered in Chapter 16). + +Recall the thread-safe smart pointers discussed in Chapter 16: to share +ownership across multiple threads and allow the threads to mutate the value, we +need to use `Arc>`. The `Arc` type will let multiple `Worker` +instances own the receiver, and `Mutex` will ensure that only one `Worker` gets +a job from the receiver at a time. Listing 20-18 shows the changes we need to +make. + +Filename: src/lib.rs + +``` +use std::{ + sync::{mpsc, Arc, Mutex}, + thread, +}; +--snip-- + +impl ThreadPool { + --snip-- + pub fn new(size: usize) -> ThreadPool { + assert!(size > 0); + + let (sender, receiver) = mpsc::channel(); + + 1 let receiver = Arc::new(Mutex::new(receiver)); + + let mut workers = Vec::with_capacity(size); + + for id in 0..size { + workers.push( + Worker::new(id, Arc::clone(& 2 receiver)) + ); + } + + ThreadPool { workers, sender } + } + + --snip-- +} + +--snip-- + +impl Worker { + fn new( + id: usize, + receiver: Arc>>, + ) -> Worker { + --snip-- + } +} +``` + +Listing 20-18: Sharing the receiver among the `Worker` instances using `Arc` +and `Mutex` + +In `ThreadPool::new`, we put the receiver in an `Arc` and a `Mutex` [1]. For +each new `Worker`, we clone the `Arc` to bump the reference count so the +`Worker` instances can share ownership of the receiver [2]. + +With these changes, the code compiles! We’re getting there! + +#### Implementing the execute Method + +Let’s finally implement the `execute` method on `ThreadPool`. We’ll also change +`Job` from a struct to a type alias for a trait object that holds the type of +closure that `execute` receives. As discussed in “Creating Type Synonyms with +Type Aliases” on page XX, type aliases allow us to make long types shorter for +ease of use. Look at Listing 20-19. + +Filename: src/lib.rs + +``` +--snip-- + +type Job = Box; + +impl ThreadPool { + --snip-- + + pub fn execute(&self, f: F) + where + F: FnOnce() + Send + 'static, + { + 1 let job = Box::new(f); + + 2 self.sender.send(job).unwrap(); + } +} + +--snip-- +``` + +Listing 20-19: Creating a `Job` type alias for a `Box` that holds each closure +and then sending the job down the channel + +After creating a new `Job` instance using the closure we get in `execute` [1], +we send that job down the sending end of the channel [2]. We’re calling +`unwrap` on `send` for the case that sending fails. This might happen if, for +example, we stop all our threads from executing, meaning the receiving end has +stopped receiving new messages. At the moment, we can’t stop our threads from +executing: our threads continue executing as long as the pool exists. The +reason we use `unwrap` is that we know the failure case won’t happen, but the +compiler doesn’t know that. + +But we’re not quite done yet! In the `Worker`, our closure being passed to +`thread::spawn` still only *references* the receiving end of the channel. +Instead, we need the closure to loop forever, asking the receiving end of the +channel for a job and running the job when it gets one. Let’s make the change +shown in Listing 20-20 to `Worker::new`. + +Filename: src/lib.rs + +``` +--snip-- + +impl Worker { + fn new( + id: usize, + receiver: Arc>>, + ) -> Worker { + let thread = thread::spawn(move || loop { + let job = receiver + 1 .lock() + 2 .unwrap() + 3 .recv() + 4 .unwrap(); + + println!("Worker {id} got a job; executing."); + + job(); + }); + + Worker { id, thread } + } +} +``` + +Listing 20-20: Receiving and executing the jobs in the `Worker` instance’s +thread + +Here, we first call `lock` on the `receiver` to acquire the mutex [1], and then +we call `unwrap` to panic on any errors [2]. Acquiring a lock might fail if the +mutex is in a *poisoned* state, which can happen if some other thread panicked +while holding the lock rather than releasing the lock. In this situation, +calling `unwrap` to have this thread panic is the correct action to take. Feel +free to change this `unwrap` to an `expect` with an error message that is +meaningful to you. + +If we get the lock on the mutex, we call `recv` to receive a `Job` from the +channel [3]. A final `unwrap` moves past any errors here as well [4], which +might occur if the thread holding the sender has shut down, similar to how the +`send` method returns `Err` if the receiver shuts down. + +The call to `recv` blocks, so if there is no job yet, the current thread will +wait until a job becomes available. The `Mutex` ensures that only one +`Worker` thread at a time is trying to request a job. + +Our thread pool is now in a working state! Give it a `cargo run` and make some +requests: + +``` +$ cargo run + Compiling hello v0.1.0 (file:///projects/hello) +warning: field is never read: `workers` + --> src/lib.rs:7:5 + | +7 | workers: Vec, + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(dead_code)]` on by default + +warning: field is never read: `id` + --> src/lib.rs:48:5 + | +48 | id: usize, + | ^^^^^^^^^ + +warning: field is never read: `thread` + --> src/lib.rs:49:5 + | +49 | thread: thread::JoinHandle<()>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: `hello` (lib) generated 3 warnings + Finished dev [unoptimized + debuginfo] target(s) in 1.40s + Running `target/debug/hello` +Worker 0 got a job; executing. +Worker 2 got a job; executing. +Worker 1 got a job; executing. +Worker 3 got a job; executing. +Worker 0 got a job; executing. +Worker 2 got a job; executing. +Worker 1 got a job; executing. +Worker 3 got a job; executing. +Worker 0 got a job; executing. +Worker 2 got a job; executing. +``` + +Success! We now have a thread pool that executes connections asynchronously. +There are never more than four threads created, so our system won’t get +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 +might load one at a time in five-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. + +After learning about the `while let` loop in Chapter 18, you might be wondering +why we didn’t write the `Worker` thread code as shown in Listing 20-21. + +Filename: src/lib.rs + +``` +--snip-- + +impl Worker { + fn new( + id: usize, + receiver: Arc>>, + ) -> Worker { + let thread = thread::spawn(move || { + while let Ok(job) = receiver.lock().unwrap().recv() { + println!("Worker {id} got a job; executing."); + + job(); + } + }); + + Worker { id, thread } + } +} +``` + +Listing 20-21: An alternative implementation of `Worker::new` using `while let` + +This code compiles and runs but doesn’t result in the desired threading +behavior: a slow request will still cause other requests to wait to be +processed. The reason is somewhat subtle: the `Mutex` struct has no public +`unlock` method because the ownership of the lock is based on the lifetime of +the `MutexGuard` within the `LockResult>` that the `lock` +method returns. At compile time, the borrow checker can then enforce the rule +that a resource guarded by a `Mutex` cannot be accessed unless we hold the +lock. However, this implementation can also result in the lock being held +longer than intended if we aren’t mindful of the lifetime of the +`MutexGuard`. + +The code in Listing 20-20 that uses `let job = +receiver.lock().unwrap().recv().unwrap();` works because with `let`, any +temporary values used in the expression on the right-hand side of the equal +sign are immediately dropped when the `let` statement ends. However, `while +let` (and `if let` and `match`) does not drop temporary values until the end of +the associated block. In Listing 20-21, the lock remains held for the duration +of the call to `job()`, meaning other `Worker` instances cannot receive jobs. + +## Graceful Shutdown and Cleanup + +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 ctrl-C 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 +closing. Then we’ll implement a way to tell the threads they should stop +accepting new requests and shut down. To see this code in action, we’ll modify +our server to accept only two requests before gracefully shutting down its +thread pool. + +### Implementing the Drop Trait on ThreadPool + +Let’s start with implementing `Drop` on our thread pool. When the pool is +dropped, our threads should all join to make sure they finish their work. +Listing 20-22 shows a first attempt at a `Drop` implementation; this code won’t +quite work yet. + +Filename: src/lib.rs + +``` +impl Drop for ThreadPool { + fn drop(&mut self) { + 1 for worker in &mut self.workers { + 2 println!("Shutting down worker {}", worker.id); + + 3 worker.thread.join().unwrap(); + } + } +} +``` + +Listing 20-22: Joining each thread when the thread pool goes out of scope + +First we loop through each of the thread pool `workers` [1]. We use `&mut` for +this because `self` is a mutable reference, and we also need to be able to +mutate `worker`. For each `worker`, we print a message saying that this +particular `Worker` instance is shutting down [2], and then we call `join` on +that `Worker` instance’s thread [3]. If the call to `join` fails, we use +`unwrap` to make Rust panic and go into an ungraceful shutdown. + +Here is the error we get when we compile this code: + +``` +error[E0507]: cannot move out of `worker.thread` which is behind a mutable +reference + --> src/lib.rs:52:13 + | +52 | worker.thread.join().unwrap(); + | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this +method call + | | + | move occurs because `worker.thread` has type +`JoinHandle<()>`, which does not implement the `Copy` trait + | +note: this function takes ownership of the receiver `self`, which moves +`worker.thread` +``` + +The error tells us we can’t call `join` because we only have a mutable borrow +of each `worker` and `join` takes ownership of its argument. To solve this +issue, we need to move the thread out of the `Worker` instance that owns +`thread` so `join` can consume the thread. We did this in Listing 17-15: if +`Worker` holds an `Option>` instead, we can call the +`take` method on the `Option` to move the value out of the `Some` variant and +leave a `None` variant in its place. In other words, a `Worker` that is running +will have a `Some` variant in `thread`, and when we want to clean up a +`Worker`, we’ll replace `Some` with `None` so the `Worker` doesn’t have a +thread to run. + +So we know we want to update the definition of `Worker` like this: + +Filename: src/lib.rs + +``` +struct Worker { + id: usize, + thread: Option>, +} +``` + +Now let’s lean on the compiler to find the other places that need to change. +Checking this code, we get two errors: + +``` +error[E0599]: no method named `join` found for enum `Option` in the current +scope + --> src/lib.rs:52:27 + | +52 | worker.thread.join().unwrap(); + | ^^^^ method not found in +`Option>` + +error[E0308]: mismatched types + --> src/lib.rs:72:22 + | +72 | Worker { id, thread } + | ^^^^^^ expected enum `Option`, found struct +`JoinHandle` + | + = note: expected enum `Option>` + found struct `JoinHandle<_>` +help: try wrapping the expression in `Some` + | +72 | Worker { id, thread: Some(thread) } + | +++++++++++++ + +``` + +Let’s address the second error, which points to the code at the end of +`Worker::new`; we need to wrap the `thread` value in `Some` when we create a +new `Worker`. Make the following changes to fix this error: + +Filename: src/lib.rs + +``` +impl Worker { + fn new( + id: usize, + receiver: Arc>>, + ) -> Worker { + --snip-- + + Worker { + id, + thread: Some(thread), + } + } +} +``` + +The first error is in our `Drop` implementation. We mentioned earlier that we +intended to call `take` on the `Option` value to move `thread` out of `worker`. +The following changes will do so: + +Filename: src/lib.rs + +``` +impl Drop for ThreadPool { + fn drop(&mut self) { + for worker in &mut self.workers { + println!("Shutting down worker {}", worker.id); + + 1 if let Some(thread) = worker.thread.take() { + 2 thread.join().unwrap(); + } + } + } +} +``` + +As discussed in Chapter 17, the `take` method on `Option` takes the `Some` +variant out and leaves `None` in its place. We’re using `if let` to destructure +the `Some` and get the thread [1]; then we call `join` on the thread [2]. If a +`Worker` instance’s thread is already `None`, we know that `Worker` has already +had its thread cleaned up, so nothing happens in that case. + +### Signaling to the Threads to Stop Listening for Jobs + +With all the changes we’ve made, our code compiles without any warnings. +However, the bad news is that this code doesn’t function the way we want it to +yet. The key is the logic in the closures run by the threads of the `Worker` +instances: at the moment, we call `join`, but that won’t shut down the threads, +because they `loop` forever looking for jobs. If we try to drop our +`ThreadPool` with our current implementation of `drop`, the main thread will +block forever, waiting for the first thread to finish. + +To fix this problem, we’ll need a change in the `ThreadPool` `drop` +implementation and then a change in the `Worker` loop. + +First we’ll change the `ThreadPool` `drop` implementation to explicitly drop +the `sender` before waiting for the threads to finish. Listing 20-23 shows the +changes to `ThreadPool` to explicitly drop `sender`. We use the same `Option` +and `take` technique as we did with the thread to be able to move `sender` out +of `ThreadPool`. + +Filename: src/lib.rs + +``` +pub struct ThreadPool { + workers: Vec, + sender: Option>, +} +--snip-- +impl ThreadPool { + pub fn new(size: usize) -> ThreadPool { + --snip-- + + ThreadPool { + workers, + sender: Some(sender), + } + } + + pub fn execute(&self, f: F) + where + F: FnOnce() + Send + 'static, + { + let job = Box::new(f); + + self.sender + .as_ref() + .unwrap() + .send(job) + .unwrap(); + } +} + +impl Drop for ThreadPool { + fn drop(&mut self) { + 1 drop(self.sender.take()); + + for worker in &mut self.workers { + println!("Shutting down worker {}", worker.id); + + if let Some(thread) = worker.thread.take() { + thread.join().unwrap(); + } + } + } +} +``` + +Listing 20-23: Explicitly dropping `sender` before joining the `Worker` threads + +Dropping `sender` [1] closes the channel, which indicates no more messages will +be sent. When that happens, all the calls to `recv` that the `Worker` instances +do in the infinite loop will return an error. In Listing 20-24, we change the +`Worker` loop to gracefully exit the loop in that case, which means the threads +will finish when the `ThreadPool` `drop` implementation calls `join` on them. + +Filename: src/lib.rs + +``` +impl Worker { + fn new( + id: usize, + receiver: Arc>>, + ) -> Worker { + let thread = thread::spawn(move || loop { + let message = receiver.lock().unwrap().recv(); + + match message { + Ok(job) => { + println!( + "Worker {id} got a job; executing." + ); + + job(); + } + Err(_) => { + println!( + "Worker {id} shutting down." + ); + break; + } + } + }); + + Worker { + id, + thread: Some(thread), + } + } +} +``` + +Listing 20-24: Explicitly breaking out of the loop when `recv` returns an error + +To see this code in action, let’s modify `main` to accept only two requests +before gracefully shutting down the server, as shown in Listing 20-25. + +Filename: src/main.rs + +``` +fn main() { + let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); + let pool = ThreadPool::new(4); + + for stream in listener.incoming().take(2) { + let stream = stream.unwrap(); + + pool.execute(|| { + handle_connection(stream); + }); + } + + println!("Shutting down."); +} +``` + +Listing 20-25: Shutting down the server after serving two requests by exiting +the loop + +You wouldn’t want a real-world web server to shut down after serving only two +requests. This code just demonstrates that the graceful shutdown and cleanup is +in working order. + +The `take` method is defined in the `Iterator` trait and limits the iteration +to the first two items at most. The `ThreadPool` will go out of scope at the +end of `main`, and the `drop` implementation will run. + +Start the server with `cargo run`, and make three requests. The third request +should error, and in your terminal you should see output similar to this: + +``` +$ cargo run + Compiling hello v0.1.0 (file:///projects/hello) + Finished dev [unoptimized + debuginfo] target(s) in 1.0s + Running `target/debug/hello` +Worker 0 got a job; executing. +Shutting down. +Shutting down worker 0 +Worker 3 got a job; executing. +Worker 1 disconnected; shutting down. +Worker 2 disconnected; shutting down. +Worker 3 disconnected; shutting down. +Worker 0 disconnected; shutting down. +Shutting down worker 1 +Shutting down worker 2 +Shutting down worker 3 +``` + +You might see a different ordering of `Worker` IDs and messages printed. We can +see how this code works from the messages: `Worker` instances 0 and 3 got the +first two requests. The server stopped accepting connections after the second +connection, and the `Drop` implementation on `ThreadPool` starts executing +before `Worker` 3 even starts its job. Dropping the `sender` disconnects all +the `Worker` instances and tells them to shut down. The `Worker` instances each +print a message when they disconnect, and then the thread pool calls `join` to +wait for each `Worker` thread to finish. + +Notice one interesting aspect of this particular execution: the `ThreadPool` +dropped the `sender`, and before any `Worker` received an error, we tried to +join `Worker` 0. `Worker` 0 had not yet gotten an error from `recv`, so the +main thread blocked, waiting for `Worker` 0 to finish. In the meantime, +`Worker` 3 received a job and then all threads received an error. When `Worker` +0 finished, the main thread waited for the rest of the `Worker` instances to +finish. At that point, they had all exited their loops and stopped. + +Congrats! We’ve now completed our project; we have a basic web server that uses +a thread pool to respond asynchronously. We’re able to perform a graceful +shutdown of the server, which cleans up all the threads in the pool. See +*https://www.nostarch.com/Rust2021* to download the full code for this chapter +for reference. + +We could do more here! If you want to continue enhancing this project, here are +some ideas: + +* Add more documentation to `ThreadPool` and its public methods. +* Add tests of the library’s functionality. +* Change calls to `unwrap` to more robust error handling. +* Use `ThreadPool` to perform some task other than serving web requests. +* Find a thread pool crate on *https://crates.io* and implement a similar web +server using the crate instead. Then compare its API and robustness to the +thread pool we implemented. + +## Summary + +Well done! You’ve made it to the end of the book! We want to thank you for +joining us on this tour of Rust. You’re now ready to implement your own Rust +projects and help with other people’s projects. Keep in mind that there is a +welcoming community of other Rustaceans who would love to help you with any +challenges you encounter on your Rust journey. + From 3b8d132adf52c624118e72b6cdd7fc32aee5d001 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 3 Oct 2024 21:24:28 -0400 Subject: [PATCH 600/720] Generated nostarch snapshot for the new async chapter --- nostarch/chapter17.md | 3157 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3157 insertions(+) create mode 100644 nostarch/chapter17.md diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md new file mode 100644 index 0000000000..57e90e6704 --- /dev/null +++ b/nostarch/chapter17.md @@ -0,0 +1,3157 @@ + + +[TOC] + +## Async and Await + +Many operations we ask the computer to do can take a while to finish. For +example, if you used a video editor to create a video of a family celebration, +exporting it could take anywhere from minutes to hours. Similarly, downloading a +video shared by someone in your family might take a long time. It would be nice +if we could do something else while we are waiting for those long-running +processes to complete. + +The video export will use as much CPU and GPU power as it can. If you only had +one CPU core, and your operating system never paused that export until it +completed, you couldn’t do anything else on your computer while it was running. +That would be a pretty frustrating experience, though. Instead, your computer’s +operating system can—and does!—invisibly interrupt the export often enough to +let you get other work done along the way. + +The file download is different. It does not take up very much CPU time. Instead, +the CPU needs to wait on data to arrive from the network. While you can start +reading the data once some of it is present, it might take a while for the rest +to show up. Even once the data is all present, a video can be quite large, so it +might take some time to load it all. Maybe it only takes a second or two—but +that’s a very long time for a modern processor, which can do billions of +operations every second. It would be nice to be able to put the CPU to use for +other work while waiting for the network call to finish—so, again, your +operating system will invisibly interrupt your program so other things can +happen while the network operation is still ongoing. + + > + > Note: The video export is the kind of operation which is often described as + > “CPU-bound” or “compute-bound”. It’s limited by the speed of the computer’s + > ability to process data within the *CPU* or *GPU*, and how much of that speed + > it can use. The video download is the kind of operation which is often + > described as “IO-bound,” because it’s limited by the speed of the computer’s + > *input and output*. It can only go as fast as the data can be sent across the + > network. + +In both of these examples, the operating system’s invisible interrupts provide a +form of concurrency. That concurrency only happens at the level of a whole +program, though: the operating system interrupts one program to let other +programs get work done. In many cases, because we understand our programs at a +much more granular level than the operating system does, we can spot lots of +opportunities for concurrency that the operating system cannot see. + +For example, if we’re building a tool to manage file downloads, we should be +able to write our program in such a way that starting one download does not lock +up the UI, and users should be able to start multiple downloads at the same +time. Many operating system APIs for interacting with the network are +*blocking*, though. That is, these APIs block the program’s progress until the +data that they are processing is completely ready. + + > + > Note: This is how *most* function calls work, if you think about it! However, + > we normally reserve the term “blocking” for function calls which interact with + > files, the network, or other resources on the computer, because those are the + > places where an individual program would benefit from the operation being + > *non*-blocking. + +We could avoid blocking our main thread by spawning a dedicated thread to +download each file. However, we would eventually find that the overhead of those +threads was a problem. It would also be nicer if the call were not blocking in +the first place. Last but not least, it would be better if we could write in the +same direct style we use in blocking code. Something similar to this: + +``` +let data = fetch_data_from(url).await; +println!("{data}"); +``` + +That is exactly what Rust’s async abstraction gives us. Before we see how this +works in practice, though, we need to take a short detour into the differences +between parallelism and concurrency. + +### Parallelism and Concurrency + +In the previous chapter, we treated parallelism and concurrency as mostly +interchangeable. Now we need to distinguish between them more precisely, because +the differences will show up as we start working. + +Consider the different ways a team could split up work on a software project. We +could assign a single individual multiple tasks, or we could assign one task per +team member, or we could do a mix of both approaches. + +When an individual works on several different tasks before any of them is +complete, this is *concurrency*. Maybe you have two different projects checked +out on your computer, and when you get bored or stuck on one project, you switch +to the other. You’re just one person, so you can’t make progress on both tasks +at the exact same time—but you can multi-task, making progress on multiple +tasks by switching between them. + +
+ +Concurrent work flow + +
Figure 17-1: A concurrent workflow, switching between Task A and Task B
+ +
+ +When you agree to split up a group of tasks between the people on the team, with +each person taking one task and working on it alone, this is *parallelism*. Each +person on the team can make progress at the exact same time. + +
+ +Concurrent work flow + +
Figure 17-2: A parallel workflow, where work happens on Task A and Task B independently
+ +
+ +With both of these situations, you might have to coordinate between different +tasks. Maybe you *thought* the task that one person was working on was totally +independent from everyone else’s work, but it actually needs something finished +by another person on the team. Some of the work could be done in parallel, but +some of it was actually *serial*: it could only happen in a series, one thing +after the other. Likewise, you might realize that one of your own tasks depends +on another of your tasks. Now your concurrent work has also become serial. + +Parallelism and concurrency can intersect with each other, too. If you learn +that a colleague is stuck until you finish one of your tasks, you’ll probably +focus all your efforts on that task to “unblock” your colleague. You and your +coworker are no longer able to work in parallel, and you’re also no longer able +to work concurrently on your own tasks. + +The same basic dynamics come into play with software and hardware. On a machine +with a single CPU core, the CPU can only do one operation at a time, but it can +still work concurrently. Using tools such as threads, processes, and async, the +computer can pause one activity and switch to others before eventually cycling +back to that first activity again. On a machine with multiple CPU cores, it can +also do work in parallel. One core can be doing one thing while another core +does something completely unrelated, and those actually happen at the same +time. + +When working with async in Rust, we’re always dealing with concurrency. +Depending on the hardware, the operating system, and the async runtime we are +using—more on async runtimes shortly!—that concurrency may also use parallelism +under the hood. + +Now, let’s dive into how async programming in Rust actually works! In the rest +of this chapter, we will: + +* see how to use Rust’s `async` and `await` syntax +* explore how to use the async model to solve some of the same challenges we + looked at in Chapter 16 +* look at how multithreading and async provide complementary solutions, which + you can even use together in many cases + +## Futures and the Async Syntax + +The key elements of asynchronous programming in Rust are *futures* and Rust’s +`async` and `await` keywords. + +A *future* is a value which may not be ready now, but will become ready at some +point in the future. (This same concept shows up in many languages, sometimes +under other names such as “task” or “promise”.) Rust provides a `Future` trait +as a building block so different async operations can be implemented with +different data structures, but with a common interface. In Rust, we say that +types which implement the `Future` trait are futures. Each type which +implements `Future` holds its own information about the progress that has been +made and what “ready” means. + +The `async` keyword can be applied to blocks and functions to specify that they +can be interrupted and resumed. Within an async block or async function, you can +use the `await` keyword to wait for a future to become ready, called *awaiting a +future*. Each place you await a future within an async block or function is a +place that async block or function may get paused and resumed. The process of +checking with a future to see if its value is available yet is called *polling*. + +Some other languages also use `async` and `await` keywords for async +programming. If you’re familiar with those languages, you may notice some +significant differences in how Rust does things, including how it handles the +syntax. That’s for good reason, as we’ll see! + +Most of the time when writing async Rust, we use the `async` and `await` +keywords. Rust compiles them into equivalent code using the `Future` trait, much +as it compiles `for` loops into equivalent code using the `Iterator` trait. +Because Rust provides the `Future` trait, though, you can also implement it for +your own data types when you need to. Many of the functions we’ll see +throughout this chapter return types with their own implementations of `Future`. +We’ll return to the definition of the trait at the end of the chapter and dig +into more of how it works, but this is enough detail to keep us moving forward. + +That may all feel a bit abstract. Let’s write our first async program: a little +web scraper. We’ll pass in two URLs from the command line, fetch both of them +concurrently, and return the result of whichever one finishes first. This +example will have a fair bit of new syntax, but don’t worry. We’ll explain +everything you need to know as we go. + +### Our First Async Program + +To keep this chapter focused on learning async, rather than juggling parts of +the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust +Programming Language”). It re-exports all the types, traits, and functions +you’ll need, primarily from the `futures` at *https://crates.io/crates/futures* and `tokio` at *https://tokio.rs* +crates. + +* The `futures` crate is an official home for Rust experimentation for async + code, and is actually where the `Future` type was originally designed. + +* Tokio is the most widely used async runtime in Rust today, especially (but + not only!) for web applications. There are other great runtimes out there, + and they may be more suitable for your purposes. We use Tokio under the hood + for `trpl` because it’s well-tested and widely used. + +In some cases, `trpl` also renames or wraps the original APIs to let us stay +focused on the details relevant to this chapter. If you want to understand what +the crate does, we encourage you to check out its source code at *https://github.com/rust-lang/book/tree/main/packages/trpl*. +You’ll be able to see what crate each re-export comes from, and we’ve left +extensive comments explaining what the crate does. + +Create a new binary project named `hello-async` and add the `trpl` crate as a +dependency: + +``` +$ cargo new hello-async +$ cd hello-async +$ cargo add trpl +``` + +Now we can use the various pieces provided by `trpl` to write our first async +program. We’ll build a little command line tool which fetches two web pages, +pulls the `` element from each, and prints out the title of whichever +finishes that whole process first. + +Let’s start by writing a function that takes one page URL as a parameter, makes +a request to it, and returns the text of the title element: + + +Filename: src/main.rs + +``` +use trpl::Html; + +async fn page_title(url: &str) -> Option<String> { + let response = trpl::get(url).await; + let response_text = response.text().await; + Html::parse(&response_text) + .select_first("title") + .map(|title_element| title_element.inner_html()) +} +``` + +Listing 17-1: Defining an async function to get the title element from an HTML page + +In Listing 17-1, we define a function named `page_title`, and we mark it with +the `async` keyword. Then we use the `trpl::get` function to fetch whatever URL +is passed in, and, and we await the response by using the `await` keyword. Then +we get the text of the response by calling its `text` method and once again +awaiting it with the `await` keyword. Both of these steps are asynchronous. For +`get`, we need to wait for the server to send back the first part of its +response, which will include HTTP headers, cookies, and so on. That part of the +response can be delivered separately from the body of the request. Especially if +the body is very large, it can take some time for it all to arrive. Thus, we +have to wait for the *entirety* of the response to arrive, so the `text` method +is also async. + +We have to explicitly await both of these futures, because futures in Rust are +*lazy*: they don’t do anything until you ask them to with `await`. (In fact, +Rust will show a compiler warning if you don’t use a future.) This should +remind you of our discussion of iterators back in Chapter 13 at *ch13-02-iterators.html*. +Iterators do nothing unless you call their `next` method—whether directly, or +using `for` loops or methods such as `map` which use `next` under the hood. With +futures, the same basic idea applies: they do nothing unless you explicitly ask +them to. This laziness allows Rust to avoid running async code until it’s +actually needed. + + > + > Note: This is different from the behavior we saw when using `thread::spawn` in + > the previous chapter, where the closure we passed to another thread started + > running immediately. It’s also different from how many other languages + > approach async! But it’s important for Rust. We’ll see why that is later. + +Once we have `response_text`, we can then parse it into an instance of the +`Html` type using `Html::parse`. Instead of a raw string, we now have a data +type we can use to work with the HTML as a richer data structure. In particular, +we can use the `select_first` method to find the first instance of a given CSS +selector. By passing the string `"title"`, we’ll get the first `<title>` +element in the document, if there is one. Because there may not be any matching +element, `select_first` returns an `Option<ElementRef>`. Finally, we use the +`Option::map` method, which lets us work with the item in the `Option` if it’s +present, and do nothing if it isn’t. (We could also use a `match` expression +here, but `map` is more idiomatic.) In the body of the function we supply to +`map`, we call `inner_html` on the `title_element` to get its content, which is +a `String`. When all is said and done, we have an `Option<String>`. + +Notice that Rust’s `await` keyword goes after the expression you’re awaiting, +not before it. That is, it’s a *postfix keyword*. This may be different from +what you might be used to if you have used async in other languages. Rust chose +this because it makes chains of methods much nicer to work with. As a result, we +can change the body of `page_url_for` to chain the `trpl::get` and `text` +function calls together with `await` between them, as shown in Listing 17-2: + + +Filename: src/main.rs + +``` + let response_text = trpl::get(url).await.text().await; +``` + +Listing 17-2: Chaining with the <code>await</code> keyword + +With that, we have successfully written our first async function! Before we add +some code in `main` to call it, let’s talk a little more about what we’ve +written and what it means. + +When Rust sees a block marked with the `async` keyword, it compiles it into a +unique, anonymous data type which implements the `Future` trait. When Rust +sees a function marked with `async`, it compiles it into a non-async function +whose body is an async block. Thus, an async function’s return type is the type +of the anonymous data type the compiler creates for that async block. + +Thus, writing `async fn` is equivalent to writing a function which returns a +*future* of the return type. When the compiler sees a function definition such +as the `async fn page_title` in Listing 17-1, it’s equivalent to a non-async +function defined like this: + +``` +use std::future::Future; +use trpl::Html; + +fn page_title(url: &str) -> impl Future<Output = Option<String>> + '_ { + async move { + let text = trpl::get(url).await.text().await; + Html::parse(&text) + .select_first("title") + .map(|title| title.inner_html()) + } +} +``` + +Let’s walk through each part of the transformed version: + +* It uses the `impl Trait` syntax we discussed back in the “Traits as + Parameters” at *ch10-02-traits.html#traits-as-parameters* section in Chapter 10. +* The returned trait is a `Future`, with an associated type of `Output`. Notice + that the `Output` type is `Option<String>`, which is the same as the the + original return type from the `async fn` version of `page_title`. +* All of the code called in the body of the original function is wrapped in an + `async move` block. Remember that blocks are expressions. This whole block is + the expression returned from the function. +* This async block produces a value with the type `Option<String>`, as described + above. That value matches the `Output` type in the return type. This is just + like other blocks you have seen. +* The new function body is an `async move` block because of how it uses the + `url` parameter. (We’ll talk about `async` vs. `async move` much more later + in the chapter.) +* The new version of the function has a kind of lifetime we haven’t seen before + in the output type: `'_`. Because the function returns a `Future` which refers + to a reference—in this case, the reference from the `url` parameter—we need to + tell Rust that we mean for that reference to be included. We don’t have to + name the lifetime here, because Rust is smart enough to know there is only one + reference which could be involved, but we *do* have to be explicit that the + resulting `Future` is bound by that lifetime. + +Now we can call `page_title` in `main`. To start, we’ll just get the title +for a single page. In Listing 17-3, we follow the same pattern we used for +getting command line arguments back in Chapter 12. Then we pass the first URL +`page_title`, and await the result. Because the value produced by the future is +an `Option<String>`, we use a `match` expression to print different messages to +account for whether the page had a `<title>`. + + +Filename: src/main.rs + +``` +async fn main() { + let args: Vec<String> = std::env::args().collect(); + let url = &args[1]; + match page_title(url).await { + Some(title) => println!("The title for {url} was {title}"), + None => println!("{url} had no title"), + } +} +``` + +Listing 17-3: Calling the <code>page_title</code> function from <code>main</code> with a user-supplied argument + +Unfortunately, this doesn’t compile. The only place we can use the `await` +keyword is in async functions or blocks, and Rust won’t let us mark the +special `main` function as `async`. + +<!-- manual-regeneration +cd listings/ch17-async-await/listing-17-03 +cargo build +copy just the compiler error +--> + +``` +error[E0752]: `main` function is not allowed to be `async` + --> src/main.rs:6:1 + | +6 | async fn main() { + | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` +``` + +The reason `main` can’t be marked `async` is that async code needs a *runtime*: +a Rust crate which manages the details of executing asynchronous code. A +program’s `main` function can *initialize* a runtime, but it’s not a runtime +*itself*. (We’ll see more about why this is a bit later.) Every Rust program +that executes async code has at least one place where it sets up a runtime and +executes the futures. + +Most languages which support async bundle a runtime with the language. Rust does +not. Instead, there are many different async runtimes available, each of which +makes different tradeoffs suitable to the use case they target. For example, a +high-throughput web server with many CPU cores and a large amount of RAM has +very different different needs than a microcontroller with a single core, a +small amount of RAM, and no ability to do heap allocations. The crates which +provide those runtimes also often supply async versions of common functionality +such as file or network I/O. + +Here, and throughout the rest of this chapter, we’ll use the `run` function +from the `trpl` crate, which takes a future as an argument and runs it to +completion. Behind the scenes, calling `run` sets up a runtime to use to run the +future passed in. Once the future completes, `run` returns whatever value the +future produced. + +We could pass the future returned by `page_title` directly to `run`. Once it +completed, we would be able to match on the resulting `Option<String>`, the way +we tried to do in Listing 17-3. However, for most of the examples in the chapter +(and most async code in the real world!), we’ll be doing more than just one +async function call, so instead we’ll pass an `async` block and explicitly +await the result of calling `page_title`, as in Listing 17-4. + + +Filename: src/main.rs + +<!-- should_panic,noplayground because mdbook does not pass args --> + +``` + trpl::run(async { + let url = &args[1]; + match page_title(url).await { + Some(title) => println!("The title for {url} was {title}"), + None => println!("{url} had no title"), + } + }) +``` + +Listing 17-4: Awaiting an async block with <code>trpl::run</code> + +When we run this, we get the behavior we might have expected initially: + +``` +$ cargo run "http://www.rust-lang.org" +The title for http://www.rust-lang.org was + Rust Programming Language +``` + +Phew: we finally have some working async code! This now compiles, and we can run +it. Before we add code to race two sites against each other, let’s briefly turn +our attention back to how futures work. + +Each *await point*—that is, every place where the code uses the `await` +keyword—represents a place where control gets handed back to the runtime. To +make that work, Rust needs to keep track of the state involved in the async +block, so that the runtime can kick off some other work and then come back when +it’s ready to try advancing this one again. This is an invisible state machine, +as if you wrote an enum in this way to save the current state at each `await` +point: + +``` +enum PageTitleFuture<'a> { + Initial { url: &'a str }, + GetAwaitPoint { url: &'a str }, + TextAwaitPoint { response: trpl::Response }, +} +``` + +Writing the code to transition between each state by hand would be tedious and +error-prone, especially when adding more functionality and more states to the +code later. Instead, the Rust compiler creates and manages the state machine +data structures for async code automatically. If you’re wondering: yep, the +normal borrowing and ownership rules around data structures all apply. Happily, +the compiler also handles checking those for us, and has good error messages. +We’ll work through a few of those later in the chapter! + +Ultimately, something has to execute that state machine. That something is a +runtime. (This is why you may sometimes come across references to *executors* +when looking into runtimes: an executor is the part of a runtime responsible for +executing the async code.) + +Now we can understand why the compiler stopped us from making `main` itself an +async function back in Listing 17-3. If `main` were an async function, something +else would need to manage the state machine for whatever future `main` returned, +but `main` is the starting point for the program! Instead, we call the +`trpl::run` function in `main`, which sets up a runtime and runs the future +returned by the `async` block until it returns `Ready`. + + > + > Note: some runtimes provide macros to make it so you *can* write an async main + > function. Those macros rewrite `async fn main() { ... }` to be a normal `fn main` which does the same thing we did by hand in Listing 17-5: call a + > function which runs a future to completion the way `trpl::run` does. + +Let’s put these pieces together and see how we can write concurrent code, by +calling `page_title` with two different URLs passed in from the command line +and racing them. + + +Filename: src/main.rs + +<!-- should_panic,noplayground because mdbook does not pass args --> + +``` +use trpl::{Either, Html}; + +fn main() { + let args: Vec<String> = std::env::args().collect(); + + trpl::run(async { + let title_fut_1 = page_title(&args[1]); + let title_fut_2 = page_title(&args[2]); + + let (url, maybe_title) = + match trpl::race(title_fut_1, title_fut_2).await { + Either::Left(left) => left, + Either::Right(right) => right, + }; + + println!("{url} returned first"); + match maybe_title { + Some(title) => println!("Its page title is: '{title}'"), + None => println!("Its title could not be parsed."), + } + }) +} + +async fn page_title(url: &str) -> (&str, Option<String>) { + let text = trpl::get(url).await.text().await; + let title = Html::parse(&text) + .select_first("title") + .map(|title| title.inner_html()); + (url, title) +} +``` + +Listing 17-5: + +In Listing 17-5, we begin by calling `page_title` for each of the user-supplied +URLs. We save the futures produced by calling `page_title` as `title_fut_1` and +`title_fut_2`. Remember, these don’t do anything yet, because futures are lazy, +and we haven’t yet awaited them. Then we pass the futures to `trpl::race`, +which returns a value to indicate which of the futures passed to it finishes +first. + + > + > Note: Under the hood, `race` is built on a more general function, `select`, + > which you will encounter more often in real-world Rust code. A `select` + > function can do a lot of things that `trpl::race` function can’t, but it also + > has some additional complexity that we can skip over for now. + +Either future can legitimately “win,” so it doesn’t make sense to return a +`Result`. Instead, `race` returns a type we haven’t seen before, +`trpl::Either`. The `Either` type is somewhat similar to a `Result`, in that it +has two cases. Unlike `Result`, though, there is no notion of success or +failure baked into `Either`. Instead, it uses `Left` and `Right` to indicate +“one or the other”. + +``` +enum Either<A, B> { + Left(A), + Right(B), +} +``` + +The `race` function returns `Left` if the first argument finishes first, with +that future’s output, and `Right` with the second future argument’s output if +*that* one finishes first. This matches the order the arguments appear when +calling the function: the first argument is to the left of the second argument. + +We also update `page_title` to return the same URL passed in. That way, if +the page which returns first does not have a `<title>` we can resolve, we can +still print a meaningful message. With that information available, we wrap up by +updating our `println!` output to indicate both which URL finished first and +what the `<title>` was for the web page at that URL, if any. + +You have built a small working web scraper now! Pick a couple URLs and run the +command line tool. You may discover that some sites are reliably faster than +others, while in other cases which site “wins” varies from run to run. More +importantly, you’ve learned the basics of working with futures, so we can now +dig into even more of the things we can *do* with async. + +<!-- TODO: map source link version to version of Rust? --> + +## Concurrency With Async + +In this section, we’ll apply async to some of the same concurrency challenges +we tackled with threads in chapter 16. Because we already talked about a lot of +the key ideas there, in this section we’ll focus on what’s different between +threads and futures. + +In many cases, the APIs for working with concurrency using async are very +similar to those for using threads. In other cases, they end up being shaped +quite differently. Even when the APIs *look* similar between threads and async, +they often have different behavior—and they nearly always have different +performance characteristics. + +### Counting + +The first task we tackled in Chapter 16 was counting up on two separate threads. +Let’s do the same using async. The `trpl` crate supplies a `spawn_task` function +which looks very similar to the `thread::spawn` API, and a `sleep` function +which is an async version of the `thread::sleep` API. We can use these together +to implement the same counting example as with threads, in Listing 17-6. + + +Filename: src/main.rs + +``` +use std::time::Duration; + +fn main() { + trpl::run(async { + trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(500)).await; + } + }); + + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(500)).await; + } + }); +} +``` + +Listing 17-6: Using <code>spawn_task</code> to count with two + +As our starting point, we set up our `main` function with `trpl::run`, so +that our top-level function can be async. + + > + > Note: From this point forward in the chapter, every example will include this + > exact same wrapping code with `trpl::run` in `main`, so we’ll often skip it + > just as we do with `main`. Don’t forget to include it in your code! + +Then we write two loops within that block, each with a `trpl::sleep` call in it, +which waits for half a second (500 milliseconds) before sending the next +message. We put one loop in the body of a `trpl::spawn_task` and the other in a +top-level `for` loop. We also add an `await` after the `sleep` calls. + +This does something similar to the thread-based implementation—including the +fact that you may see the messages appear in a different order in your own +terminal when you run it. + +<!-- Not extracting output because changes to this output aren't significant; +the changes are likely to be due to the threads running differently rather than +changes in the compiler --> + +``` +hi number 1 from the second task! +hi number 1 from the first task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +``` + +This version stops as soon as the for loop in the body of the main async block +finishes, because the task spawned by `spawn_task` is shut down when the main +function ends. If you want to run all the way to the completion of the task, you +will need to use a join handle to wait for the first task to complete. With +threads, we used the `join` method to “block” until the thread was done running. +In Listing 17-7, we can use `await` to do the same thing, because the task +handle itself is a future. Its `Output` type is a `Result`, so we also unwrap it +after awaiting it. + + +Filename: src/main.rs + +``` + let handle = trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(500)).await; + } + }); + + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(500)).await; + } + + handle.await.unwrap(); +``` + +Listing 17-7: Using <code>await</code> with a join handle to run a task to completion + +This updated version runs till *both* loops finish. + +<!-- Not extracting output because changes to this output aren't significant; +the changes are likely to be due to the threads running differently rather than +changes in the compiler --> + +``` +hi number 1 from the second task! +hi number 1 from the first task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +hi number 6 from the first task! +hi number 7 from the first task! +hi number 8 from the first task! +hi number 9 from the first task! +``` + +So far, it looks like async and threads give us the same basic outcomes, just +with different syntax: using `await` instead of calling `join` on the join +handle, and awaiting the `sleep` calls. + +The bigger difference is that we didn’t need to spawn another operating system +thread to do this. In fact, we don’t even need to spawn a task here. Because +async blocks compile to anonymous futures, we can put each loop in an async +block and have the runtime run them both to completion using the `trpl::join` +function. + +In Chapter 16, we showed how to use the `join` method on the `JoinHandle` type +returned when you call `std::thread::spawn`. The `trpl::join` function is +similar, but for futures. When you give it two futures, it produces a single new +future whose output is a tuple with the output of each of the futures you passed +in once *both* complete. Thus, in Listing 17-8, we use `trpl::join` to wait for +both `fut1` and `fut2` to finish. We do *not* await `fut1` and `fut2`, but +instead the new future produced by `trpl::join`. We ignore the output, because +it’s just a tuple with two unit values in it. + + +Filename: src/main.rs + +``` + let fut1 = async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(500)).await; + } + }; + + let fut2 = async { + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(500)).await; + } + }; + + trpl::join(fut1, fut2).await; +``` + +Listing 17-8: Using <code>trpl::join</code> to await two anonymous futures + +When we run this, we see both futures run to completion: + +<!-- Not extracting output because changes to this output aren't significant; +the changes are likely to be due to the threads running differently rather than +changes in the compiler --> + +``` +hi number 1 from the first task! +hi number 1 from the second task! +hi number 2 from the first task! +hi number 2 from the second task! +hi number 3 from the first task! +hi number 3 from the second task! +hi number 4 from the first task! +hi number 4 from the second task! +hi number 5 from the first task! +hi number 6 from the first task! +hi number 7 from the first task! +hi number 8 from the first task! +hi number 9 from the first task! +``` + +Here, you’ll see the exact same order every time, which is very different from +what we saw with threads. That is because the `trpl::join` function is *fair*, +meaning it checks each future equally often, alternating between them, and never +lets one race ahead if the other is ready. With threads, the operating system +decides which thread to check and how long to let it run. With async Rust, the +runtime decides which task to check. (In practice, the details get complicated +because an async runtime might use operating system threads under the hood as +part of how it manages concurrency, so guaranteeing fairness can be more work +for a runtime—but it’s still possible!) Runtimes don’t have to guarantee +fairness for any given operation, and runtimes often offer different APIs to let +you choose whether you want fairness or not. + +Try some of these different variations on awaiting the futures and see what they +do: + +* Remove the async block from around either or both of the loops. +* Await each async block immediately after defining it. +* Wrap only the first loop in an async block, and await the resulting future + after the body of second loop. + +For an extra challenge, see if you can figure out what the output will be in +each case *before* running the code! + +### Message Passing + +Sharing data between futures will also be familiar: we’ll use message passing +again, but this with async versions of the types and functions. We’ll take a +slightly different path than we did in Chapter 16, to illustrate some of the key +differences between thread-based and futures-based concurrency. In Listing 17-9, +we’ll begin with just a single async block—*not* spawning a separate task as +we spawned a separate thread. + + +Filename: src/main.rs + +``` + let (tx, mut rx) = trpl::channel(); + + let val = String::from("hi"); + tx.send(val).unwrap(); + + let received = rx.recv().await.unwrap(); + println!("Got: {received}"); +``` + +Listing 17-9: Creating an async channel and assigning the two halves to <code>tx</code> and <code>rx</code> + +Here, we use `trpl::channel`, an async version of the multiple-producer, +single-consumer channel API we used with threads back in Chapter 16. The async +version of the API is only a little different from the thread-based version: it +uses a mutable rather than an immutable receiver `rx`, and its `recv` method +produces a future we need to await rather than producing the value directly. Now +we can send messages from the sender to the receiver. Notice that we don’t have +to spawn a separate thread or even a task; we merely need to await the `rx.recv` +call. + +The synchronous `Receiver::recv` method in `std::mpsc::channel` blocks until +it receives a message. The `trpl::Receiver::recv` method does not, because it +is async. Instead of blocking, it hands control back to the runtime until either +a message is received or the send side of the channel closes. By contrast, we +don’t await the `send` call, because it doesn’t block. It doesn’t need to, +because the channel we’re sending it into is unbounded. + + > + > Note: Because all of this async code runs in an async block in a `trpl::run` + > call, everything within it can avoid blocking. However, the code *outside* it + > will block on the `run` function returning. That is the whole point of the + > `trpl::run` function: it lets you *choose* where to block on some set of async + > code, and thus where to transition between sync and async code. In most async + > runtimes, `run` is actually named `block_on` for exactly this reason. + +Notice two things about this example: First, the message will arrive right away! +Second, although we use a future here, there’s no concurrency yet. Everything +in the listing happens in sequence, just as it would if there were no futures +involved. + +Let’s address the first part by sending a series of messages, and sleep in +between them, as shown in Listing 17-10: + +<!-- We cannot test this one because it never stops! --> + + +Filename: src/main.rs + +``` + let (tx, mut rx) = trpl::channel(); + + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } +``` + +Listing 17-10: Sending and receiving multiple messages over the async channel and sleeping with an <code>await</code> between each message + +In addition to sending the messages, we need to receive them. In this case, we +could do that manually, by just doing `rx.recv().await` four times, because we +know how many messages are coming in. In the real world, though, we’ll +generally be waiting on some *unknown* number of messages. In that case, we need +to keep waiting until we determine that there are no more messages. + +In Listing 16-10, we used a `for` loop to process all the items received from a +synchronous channel. However, Rust doesn’t yet have a way to write a `for` loop +over an *asynchronous* series of items. Instead, we need to use a new kind of +loop we haven’t seen before, the `while let` conditional loop. A `while let` +loop is the loop version of the `if let` construct we saw back in Chapter 6. The +loop will continue executing as long as the pattern it specifies continues to +match the value. + +<!-- TODO: update text in ch. 19 to account for our having introduced this. --> + +The `rx.recv` call produces a `Future`, which we await. The runtime will pause +the `Future` until it is ready. Once a message arrives, the future will resolve +to `Some(message)`, as many times as a message arrives. When the channel closes, +regardless of whether *any* messages have arrived, the future will instead +resolve to `None` to indicate that there are no more values, and we should stop +polling—that is, stop awaiting. + +The `while let` loop pulls all of this together. If the result of calling +`rx.recv().await` is `Some(message)`, we get access to the message and we can +use it in the loop body, just as we could with `if let`. If the result is +`None`, the loop ends. Every time the loop completes, it hits the await point +again, so the runtime pauses it again until another message arrives. + +The code now successfully sends and receives all of the messages. Unfortunately, +there are still a couple problems. For one thing, the messages do not arrive at +half-second intervals. They arrive all at once, two seconds (2,000 milliseconds) +after we start the program. For another, this program also never exits! Instead, +it waits forever for new messages. You will need to shut it down using <span +class="keystroke">ctrl-c</span>. + +Let’s start by understanding why the messages all come in at once after the full +delay, rather than coming in with delays in between each one. Within a given +async block, the order that `await` keywords appear in the code is also the +order they happen when running the program. + +There’s only one async block in Listing 17-10, so everything in it runs +linearly. There’s still no concurrency. All the `tx.send` calls happen, +interspersed with all of the `trpl::sleep` calls and their associated await +points. Only then does the `while let` loop get to go through any of the `await` +points on the `recv` calls. + +To get the behavior we want, where the sleep delay happens between receiving +each message, we need to put the `tx` and `rx` operations in their own async +blocks. Then the runtime can execute each of them separately using `trpl::join`, +just as in the counting example. Once again, we await the result of calling +`trpl::join`, not the individual futures. If we awaited the individual futures +in sequence, we would just end up back in a sequential flow—exactly what we’re +trying *not* to do. + +<!-- We cannot test this one because it never stops! --> + + +Filename: src/main.rs + +``` + let tx_fut = async { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; +``` + +Listing 17-11: Separating <code>send</code> and <code>recv</code> into their own <code>async</code> blocks and awaiting the futures for those blocks + +With the updated code in Listing 17-11, the messages get printed at +500-millisecond intervals, rather than all in a rush after two seconds. + +The program still never exits, though, because of the way `while let` loop +interacts with `trpl::join`: + +* The future returned from `trpl::join` only completes once *both* futures + passed to it have completed. +* The `tx` future completes once it finishes sleeping after sending the last + message in `vals`. +* The `rx` future won’t complete until the `while let` loop ends. +* The `while let` loop won’t end until awaiting `rx.recv` produces `None`. +* Awaiting `rx.recv` will only return `None` once the other end of the channel + is closed. +* The channel will only close if we call `rx.close` or when the sender side, + `tx`, is dropped. +* We don’t call `rx.close` anywhere, and `tx` won’t be dropped until the + outermost async block passed to `trpl::run` ends. +* The block can’t end because it is blocked on `trpl::join` completing, which + takes us back to the top of this list! + +We could manually close `rx` by calling `rx.close` somewhere, but that doesn’t +make much sense. Stopping after handling some arbitrary number of messages would +make the program shut down, but we could miss messages. We need some other way +to make sure that `tx` gets dropped *before* the end of the function. + +Right now, the async block where we send the messages only borrows `tx` because +sending a message doesn’t require ownership, but if we could move `tx` into +that async block, it would be dropped once that block ends. In Chapter 13, we +learned how to use the `move` keyword with closures, and in Chapter 16, we saw +that we often need to move data into closures when working with threads. The +same basic dynamics apply to async blocks, so the `move` keyword works with +async blocks just as it does with closures. + +In Listing 17-12, we change the async block for sending messages from a plain +`async` block to an `async move` block. When we run *this* version of the code, +it shuts down gracefully after the last message is sent and received. + + +Filename: src/main.rs + +``` + let (tx, mut rx) = trpl::channel(); + + let tx_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; +``` + +Listing 17-12: A working example of sending and receiving messages between futures which correctly shuts down when complete + +This async channel is also a multiple-producer channel, so we can call `clone` +on `tx` if we want to send messages from multiple futures. In Listing 17-13, we +clone `tx`, creating `tx1` outside the first async block. We move `tx1` into +that block just as we did before with `tx`. Then, later, we move the original +`tx` into a *new* async block, where we send more messages on a slightly slower +delay. We happen to put this new async block after the async block for receiving +messages, but it could go before it just as well. The key is the order of the +futures are awaited in, not the order they are created in. + +Both of the async blocks for sending messages need to be `async move` blocks, so +that both `tx` and `tx1` get dropped when those blocks finish. Otherwise we’ll +end up back in the same infinite loop we started out in. Finally, we switch from +`trpl::join` to `trpl::join3` to handle the additional future. + + +Filename: src/main.rs + +``` + let (tx, mut rx) = trpl::channel(); + + let tx1 = tx.clone(); + let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; + + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + }; + + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(1500)).await; + } + }; + + trpl::join3(tx1_fut, tx_fut, rx_fut).await; +``` + +Listing 17-13: Using multiple producers with async blocks + +Now we see all the messages from both sending futures. Because the sending +futures use slightly different delays after sending, the messages are also +received at those different intervals. + +<!-- Not extracting output because changes to this output aren't significant; +the changes are likely to be due to the threads running differently rather than +changes in the compiler --> + +``` +received 'hi' +received 'more' +received 'from' +received 'the' +received 'messages' +received 'future' +received 'for' +received 'you' +``` + +This is a good start, but it limits us to just a handful of futures: two with +`join`, or three with `join3`. Let’s see how we might work with more futures. + +## Working With Any Number of Futures + +When we switched from using two futures to three in the previous section, we +also had to switch from using `join` to using `join3`. It would be annoying to +have to call a different function every time we changed the number of futures we +wanted to join. Happily, we have a macro form of `join` to which we can pass an +arbitrary number of arguments. It also handles awaiting the futures itself. +Thus, we could rewrite the code from Listing 17-13 to use `join!` instead of +`join3`, as in Listing 17-14: + + +Filename: src/main.rs + +``` + trpl::join!(tx1_fut, tx_fut, rx_fut); +``` + +Listing 17-14: Using <code>join!</code> to wait for multiple futures + +This is definitely a nice improvement over needing to swap between `join` and +`join3` and `join4` and so on! However, even this macro form only works when we +know the number of futures ahead of time. In real-world Rust, though, pushing +futures into a collection and then waiting on some or all the futures in that +collection to complete is a common pattern. + +To check all the futures in some collection, we’ll need to iterate over and +join on *all* of them. The `trpl::join_all` function accepts any type which +implements the `Iterator` trait, which we learned about back in Chapter 13, so +it seems like just the ticket. Let’s try putting our futures in a vector, and +replace `join!` with `join_all`. + + +``` + let futures = vec![tx1_fut, rx_fut, tx_fut]; + + trpl::join_all(futures).await; +``` + +Listing 17-15: Storing anonymous futures in a vector and calling <code>join_all</code> + +Unfortunately, this doesn’t compile. Instead, we get this error: + +<!-- manual-regeneration +cd listings/ch17-async-await/listing-17-16/ +cargo build +copy just the compiler error +--> + +``` +error[E0308]: mismatched types + --> src/main.rs:43:37 + | +8 | let tx1_fut = async move { + | _______________________- +9 | | let vals = vec![ +10 | | String::from("hi"), +11 | | String::from("from"), +... | +19 | | } +20 | | }; + | |_________- the expected `async` block +21 | +22 | let rx_fut = async { + | ______________________- +23 | | while let Some(value) = rx.recv().await { +24 | | println!("received '{value}'"); +25 | | } +26 | | }; + | |_________- the found `async` block +... +43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; + | ^^^^^^ expected `async` block, found a different `async` block + | + = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` + found `async` block `{async block@src/main.rs:22:22: 26:10}` + = note: no two async blocks, even if identical, have the same type + = help: consider pinning your async block and and casting it to a trait object +``` + +This might be surprising. After all, none of them return anything, so each +block produces a `Future<Output = ()>`. However, `Future` is a trait, not a +concrete type. The concrete types are the individual data structures generated +by the compiler for async blocks. You can’t put two different hand-written +structs in a `Vec`, and the same thing applies to the different structs +generated by the compiler. + +To make this work, we need to use *trait objects*, just as we did in “Returning +Errors from the run function” at *ch12-03-improving-error-handling-and-modularity.html* in Chapter 12. (We’ll cover trait objects +in detail in Chapter 18.) Using trait objects lets us treat each of the +anonymous futures produced by these types as the same type, because all of them +implement the `Future` trait. + + > + > Note: In Chapter 8, we discussed another way to include multiple types in a + > `Vec`: using an enum to represent each of the different types which can + > appear in the vector. We can’t do that here, though. For one thing, we have + > no way to name the different types, because they are anonymous. For another, + > the reason we reached for a vector and `join_all` in the first place was to be + > able to work with a dynamic collection of futures where we don’t know what + > they will all be until runtime. + +We start by wrapping each of the futures in the `vec!` in a `Box::new`, as shown +in Listing 17-16. + + +Filename: src/main.rs + +``` + let futures = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + + trpl::join_all(futures).await; +``` + +Listing 17-16: Trying to use <code>Box::new</code> to align the types of the futures in a <code>Vec</code> + +Unfortunately, this still doesn’t compile. In fact, we have the same basic +error we did before, but we get one for both the second and third `Box::new` +calls, and we also get new errors referring to the `Unpin` trait. We will come +back to the `Unpin` errors in a moment. First, let’s fix the type errors on the +`Box::new` calls, by explicitly annotating the type of the `futures` variable: + + +Filename: src/main.rs + +``` + let futures: Vec<Box<dyn Future<Output = ()>>> = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; +``` + +Listing 17-17: Fixing the rest of the type mismatch errors by using an explicit type declaration + +The type we had to write here is a little involved, so let’s walk through it: + +* The innermost type is the future itself. We note explicitly that the output of + the future is the unit type `()` by writing `Future<Output = ()>`. +* Then we annotate the trait with `dyn` to mark it as dynamic. +* The entire trait reference is wrapped in a `Box`. +* Finally, we state explicitly that `futures` is a `Vec` containing these items. + +That already made a big difference. Now when we run the compiler, we only have +the errors mentioning `Unpin`. Although there are three of them, notice that +each is very similar in its contents. + +<!-- manual-regeneration +cd listings/ch17-async-await/listing-17-17 +cargo build +copy *only* the errors +--> + +``` +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:24 + | +46 | trpl::join_all(futures).await; + | -------------- ^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + | | + | required by a bound introduced by this call + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` +note: required by a bound in `join_all` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 + | +102 | pub fn join_all<I>(iter: I) -> JoinAll<I::Item> + | -------- required by a bound in this function +... +105 | I::Item: Future, + | ^^^^^^ required by this bound in `join_all` + +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:9 + | +46 | trpl::join_all(futures).await; + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` +note: required by a bound in `JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll<F> + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` + +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:33 + | +46 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` +note: required by a bound in `JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll<F> + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. +``` + +That is a *lot* to digest, so let’s pull it apart. The first part of the message +tell us that the first async block (`src/main.rs:8:23: 20:10`) does not +implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve +it. Later in the chapter, we’ll dig into a few more details about `Pin` and +`Unpin`. For the moment, though, we can just follow the compiler’s advice to get +unstuck! In Listing 17-18, we start by updating the type annotation for +`futures`, with a `Pin` wrapping each `Box`. Second, we use `Box::pin` to pin +the futures themselves. + + +Filename: src/main.rs + +``` + let futures: Vec<Pin<Box<dyn Future<Output = ()>>>> = + vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; +``` + +Listing 17-18: Using <code>Pin</code> and <code>Box::pin</code> to make the <code>Vec</code> type check + +If we compile and run this, we finally get the output we hoped for: + +<!-- Not extracting output because changes to this output aren't significant; +the changes are likely to be due to the threads running differently rather than +changes in the compiler --> + +``` +received 'hi' +received 'more' +received 'from' +received 'messages' +received 'the' +received 'for' +received 'future' +received 'you' +``` + +Phew! + +There’s a bit more we can explore here. For one thing, using `Pin<Box<T>>` +comes with a small amount of extra overhead from putting these futures on the +heap with `Box`—and we’re only doing that to get the types to line up. We don’t +actually *need* the heap allocation, after all: these futures are local to this +particular function. As noted above, `Pin` is itself a wrapper type, so we can +get the benefit of having a single type in the `Vec`—the original reason we +reached for `Box`—without doing a heap allocation. We can use `Pin` directly +with each future, using the `std::pin::pin` macro. + +However, we must still be explicit about the type of the pinned reference; +otherwise Rust will still not know to interpret these as dynamic trait objects, +which is what we need them to be in the `Vec`. We therefore `pin!` each future +when we define it, and define `futures` as a `Vec` containing pinned mutable +references to the dynamic `Future` type, as in Listing 17-19. + + +Filename: src/main.rs + +``` + let tx1_fut = pin!(async move { + // --snip-- + }); + + let rx_fut = pin!(async { + // --snip-- + }); + + let tx_fut = pin!(async move { + // --snip-- + }); + + let futures: Vec<Pin<&mut dyn Future<Output = ()>>> = + vec![tx1_fut, rx_fut, tx_fut]; +``` + +Listing 17-19: Using <code>Pin</code> directly with the <code>pin!</code> macro to avoid unnecessary heap allocations + +We got this far by ignoring the fact that we might have different `Output` +types. For example, in Listing 17-20, the anonymous future for `a` implements +`Future<Output = u32>`, the anonymous future for `b` implements `Future<Output = &str>`, and the anonymous future for `c` implements `Future<Output = bool>`. + + +Filename: src/main.rs + +``` + let a = async { 1u32 }; + let b = async { "Hello!" }; + let c = async { true }; + + let (a_result, b_result, c_result) = trpl::join!(a, b, c); + println!("{a_result}, {b_result}, {c_result}"); +``` + +Listing 17-20: Three futures with distinct types + +We can use `trpl::join!` to await them, because it allows you to pass in +multiple future types and produces a tuple of those types. We *cannot* use +`trpl::join_all`, because it requires the futures passed in all to have the same +type. Remember, that error is what got us started on this adventure with `Pin`! + +This is a fundamental tradeoff: we can either deal with a dynamic number of +futures with `join_all`, as long as they all have the same type, or we can deal +with a set number of futures with the `join` functions or the `join!` macro, +even if they have different types. This is the same as working with any other +types in Rust, though. Futures are not special, even though we have some nice +syntax for working with them, and that is a good thing. + +### Racing futures + +When we “join” futures with the `join` family of functions and macros, we +require *all* of them to finish before we move on. Sometimes, though, we only +need *some* future from a set to finish before we move on—kind of similar to +racing one future against another. + +In Listing 17-21, we once again use `trpl::race` to run two futures, `slow` and +`fast`, against each other. Each one prints a message when it starts running, +pauses for some amount of time by calling and awaiting `sleep`, and then prints +another message when it finishes. Then we pass both to `trpl::race` and wait for +one of them to finish. (The outcome here won’t be too surprising: `fast` wins!) +Unlike when we used `race` back in Our First Async Program at *ch17-01-futures-and-syntax.html#our-first-async-program*, we +just ignore the `Either` instance it returns here, because all of the +interesting behavior happens in the body of the async blocks. + + +Filename: src/main.rs + +``` + let slow = async { + println!("'slow' started."); + trpl::sleep(Duration::from_millis(100)).await; + println!("'slow' finished."); + }; + + let fast = async { + println!("'fast' started."); + trpl::sleep(Duration::from_millis(50)).await; + println!("'fast' finished."); + }; + + trpl::race(slow, fast).await; +``` + +Listing 17-21: Using <code>race</code> to get the result of whichever future finishes first + +Notice that if you flip the order of the arguments to `race`, the order of the +“started” messages changes, even though the `fast` future always completes +first. That’s because the implementation of this particular `race` function is +not fair. It always runs the futures passed as arguments in the order they’re +passed. Other implementations *are* fair, and will randomly choose which future +to poll first. Regardless of whether the implementation of race we’re using is +fair, though, *one* of the futures will run up to the first `await` in its body +before another task can start. + +Recall from Our First Async Program at *ch17-01-futures-and-syntax.html#our-first-async-program* that at each await point, +Rust gives a runtime a chance to pause the task and switch to another one if the +future being awaited isn’t ready. The inverse is also true: Rust *only* pauses +async blocks and hands control back to a runtime at an await point. Everything +between await points is synchronous. + +That means if you do a bunch of work in an async block without an await point, +that future will block any other futures from making progress. You may sometimes +hear this referred to as one future *starving* other futures. In some cases, +that may not be a big deal. However, if you are doing some kind of expensive +setup or long-running work, or if you have a future which will keep doing some +particular task indefinitely, you’ll need to think about when and where to +hand control back to the runtime. + +By the same token, if you have long-running blocking operations, async can be a +useful tool for providing ways for different parts of the program to relate to +each other. + +But *how* would you hand control back to the runtime in those cases? + +### Yielding + +Let’s simulate a long-running operation. Listing 17-22 introduces a `slow` +function. It uses `std::thread::sleep` instead of `trpl::sleep` so that calling +`slow` will block the current thread for some number of milliseconds. We can use +`slow` to stand in for real-world operations which are both long-running and +blocking. + + +Filename: src/main.rs + +``` +fn slow(name: &str, ms: u64) { + thread::sleep(Duration::from_millis(ms)); + println!("'{name}' ran for {ms}ms"); +} +``` + +Listing 17-22: Using <code>thread::sleep</code> to simulate slow operations + +In Listing 17-23, we use `slow` to emulate doing this kind of CPU-bound work in +a pair of futures. To begin, each future only hands control back to the runtime +*after* carrying out a bunch of slow operations. + + +Filename: src/main.rs + +``` + let a = async { + println!("'a' started."); + slow("a", 30); + slow("a", 10); + slow("a", 20); + trpl::sleep(Duration::from_millis(50)).await; + println!("'a' finished."); + }; + + let b = async { + println!("'b' started."); + slow("b", 75); + slow("b", 10); + slow("b", 15); + slow("b", 350); + trpl::sleep(Duration::from_millis(50)).await; + println!("'b' finished."); + }; + + trpl::race(a, b).await; +``` + +Listing 17-23: Using <code>thread::sleep</code> to simulate slow operations + +If you run this, you will see this output: + +<!-- manual-regeneration +cd listings/ch17-async-await/listing-17-24/ +cargo run +copy just the output +--> + +``` +'a' started. +'a' ran for 30ms +'a' ran for 10ms +'a' ran for 20ms +'b' started. +'b' ran for 75ms +'b' ran for 10ms +'b' ran for 15ms +'b' ran for 350ms +'a' finished. +``` + +As with our earlier example, `race` still finishes as soon as `a` is done. +There’s no interleaving between the two futures, though. The `a` future does all +of its work until the `trpl::sleep` call is awaited, then the `b` future does +all of its work until its own `trpl::sleep` call is awaited, and then the `a` +future completes. To allow both futures to make progress between their slow +tasks, we need await points so we can hand control back to the runtime. That +means we need something we can await! + +We can already see this kind of handoff happening in Listing 17-23: if we +removed the `trpl::sleep` at the end of the `a` future, it would complete +without the `b` future running *at all*. Maybe we could use the `sleep` function +as a starting point? + + +Filename: src/main.rs + +``` + let one_ms = Duration::from_millis(1); + + let a = async { + println!("'a' started."); + slow("a", 30); + trpl::sleep(one_ms).await; + slow("a", 10); + trpl::sleep(one_ms).await; + slow("a", 20); + trpl::sleep(one_ms).await; + println!("'a' finished."); + }; + + let b = async { + println!("'b' started."); + slow("b", 75); + trpl::sleep(one_ms).await; + slow("b", 10); + trpl::sleep(one_ms).await; + slow("b", 15); + trpl::sleep(one_ms).await; + slow("b", 35); + trpl::sleep(one_ms).await; + println!("'b' finished."); + }; +``` + +Listing 17-24: Using <code>sleep</code> to let operations switch off making progress + +In Listing 17-24, we add `trpl::sleep` calls with await points between each call +to `slow`. Now the two futures’ work is interleaved: + +<!-- manual-regeneration +cd listings/ch17-async-await/listing-17-24 +cargo run +copy just the output +--> + +``` +'a' started. +'a' ran for 30ms +'b' started. +'b' ran for 75ms +'a' ran for 10ms +'b' ran for 10ms +'a' ran for 20ms +'b' ran for 15ms +'a' finished. +``` + +The `a` future still runs for a bit before handing off control to `b`, because +it calls `slow` before ever calling `trpl::sleep`, but after that the futures +swap back and forth each time one of them hits an await point. In this case, we +have done that after every call to `slow`, but we could break up the work +however makes the most sense to us. + +We don’t really want to *sleep* here, though: we want to make progress as fast +as we can. We just need to hand back control to the runtime. We can do that +directly, using the `yield_now` function. In Listing 17-25, we replace all those +`sleep` calls with `yield_now`. + + +Filename: src/main.rs + +``` + let a = async { + println!("'a' started."); + slow("a", 30); + trpl::yield_now().await; + slow("a", 10); + trpl::yield_now().await; + slow("a", 20); + trpl::yield_now().await; + println!("'a' finished."); + }; + + let b = async { + println!("'b' started."); + slow("b", 75); + trpl::yield_now().await; + slow("b", 10); + trpl::yield_now().await; + slow("b", 15); + trpl::yield_now().await; + slow("b", 35); + trpl::yield_now().await; + println!("'b' finished."); + }; +``` + +Listing 17-25: Using <code>yield_now</code> to let operations switch off making progress + +This is both clearer about the actual intent and can be significantly faster +than using `sleep`, because timers such as the one used by `sleep` often have +limits to how granular they can be. The version of `sleep` we are using, for +example, will always sleep for at least a millisecond, even if we pass it a +`Duration` of one nanosecond. Again, modern computers are *fast*: they can do a +lot in one millisecond! + +You can see this for yourself by setting up a little benchmark, such as the one +in Listing 17-26. (This isn’t an especially rigorous way to do performance +testing, but it suffices to show the difference here.) Here, we skip all the +status printing, pass a one-nanosecond `Duration` to `trpl::sleep`, and let +each future run by itself, with no switching between the futures. Then we run +for 1,000 iterations and see how long the future using `trpl::sleep` takes +compared to the future using `trpl::yield_now`. + + +Filename: src/main.rs + +``` + let one_ns = Duration::from_nanos(1); + let start = Instant::now(); + async { + for _ in 1..1000 { + trpl::sleep(one_ns).await; + } + } + .await; + let time = Instant::now() - start; + println!( + "'sleep' version finished after {} seconds.", + time.as_secs_f32() + ); + + let start = Instant::now(); + async { + for _ in 1..1000 { + trpl::yield_now().await; + } + } + .await; + let time = Instant::now() - start; + println!( + "'yield' version finished after {} seconds.", + time.as_secs_f32() + ); +``` + +Listing 17-26: Comparing the performance of <code>sleep</code> and <code>yield_now</code> + +The version with `yield_now` is *way* faster! + +This means that async can be useful even for compute-bound tasks, depending on +what else your program is doing, because it provides a useful tool for +structuring the relationships between different parts of the program. This is a +form of *cooperative multitasking*, where each future has both the power to +determine when it hands over control via await points. Each future therefore +also has the responsibility to avoid blocking for too long. In some Rust-based +embedded operating systems, this is the *only* kind of multitasking! + +In real-world code, you won’t usually be alternating function calls with await +points on every single line, of course. While yielding control in this way is +relatively inexpensive, it’s not free! In many cases, trying to break up a +compute-bound task might make it significantly slower, so sometimes it’s better +for *overall* performance to let an operation block briefly. You should always +measure to see what your code’s actual performance bottlenecks are. The +underlying dynamic is an important one to keep in mind if you *are* seeing a +lot of work happening in serial that you expected to happen concurrently, +though! + +### Building Our Own Async Abstractions + +We can also compose futures together to create new patterns. For example, we can +build a `timeout` function with async building blocks we already have. When +we’re done, the result will be another building block we could use to build up +yet further async abstractions. + +Listing 17-27 shows how we would expect this `timeout` to work with a slow +future. + + +Filename: src/main.rs + +``` + let slow = async { + trpl::sleep(Duration::from_millis(100)).await; + "I finished!" + }; + + match timeout(slow, Duration::from_millis(10)).await { + Ok(message) => println!("Succeeded with '{message}'"), + Err(duration) => { + println!("Failed after {} seconds", duration.as_secs()) + } + } +``` + +Listing 17-27: Using our imagined <code>timeout</code> to run a slow operation with a time limit + +Let’s implement this! To begin, let’s think about the API for `timeout`: + +* It needs to be an async function itself so we can await it. +* Its first parameter should be a future to run. We can make it generic to allow + it to work with any future. +* Its second parameter will be the maximum time to wait. If we use a `Duration`, + that will make it easy to pass along to `trpl::sleep`. +* It should return a `Result`. If the future completes successfully, the + `Result` will be `Ok` with the value produced by the future. If the timeout + elapses first, the `Result` will be `Err` with the duration that the timeout + waited for. + +Listing 17-28 shows this declaration. + +<!-- This is not tested because it intentionally does not compile. --> + + +Filename: src/main.rs + +``` +async fn timeout<F: Future>( + future_to_try: F, + max_time: Duration, +) -> Result<F::Output, Duration> { + // Here is where our implementation will go! +} +``` + +Listing 17-28: Defining the signature of <code>timeout</code> + +That satisfies our goals for the types. Now let’s think about the *behavior* we +need: we want to race the future passed in against the duration. We can use +`trpl::sleep` to make a timer future from the duration, and use `trpl::race` to +run that timer with the future the caller passes in. + +We also know that `race` is not fair, and polls arguments in the order they are +passed. Thus, we pass `future_to_try` to `race` first so it gets a chance to +complete even if `max_time` is a very short duration. If `future_to_try` +finishes first, `race` will return `Left` with the output from `future`. If +`timer` finishes first, `race` will return `Right` with the timer’s output of +`()`. + +In Listing 17-29, we match on the result of awaiting `trpl::race`. If the +`future_to_try` succeeded and we get a `Left(output)`, we return `Ok(output)`. +If the sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` +with `_` and return `Err(max_time)` instead. + + +Filename: src/main.rs + +``` +use trpl::Either; + +// --snip-- + +fn main() { + trpl::run(async { + let slow = async { + trpl::sleep(Duration::from_secs(5)).await; + "Finally finished" + }; + + match timeout(slow, Duration::from_secs(2)).await { + Ok(message) => println!("Succeeded with '{message}'"), + Err(duration) => { + println!("Failed after {} seconds", duration.as_secs()) + } + } + }); +} + +async fn timeout<F: Future>( + future_to_try: F, + max_time: Duration, +) -> Result<F::Output, Duration> { + match trpl::race(future_to_try, trpl::sleep(max_time)).await { + Either::Left(output) => Ok(output), + Either::Right(_) => Err(max_time), + } +``` + +Listing 17-29: Defining <code>timeout</code> with <code>race</code> and <code>sleep</code> + +With that, we have a working `timeout`, built out of two other async helpers. If +we run our code, it will print the failure mode after the timeout: + +``` +Failed after 2 seconds +``` + +Because futures compose with other futures, you can build really powerful tools +using smaller async building blocks. For example, you can use this same +approach to combine timeouts with retries, and in turn use those with things +such as network calls—one of the examples from the beginning of the chapter! + +In practice, you will usually work directly with `async` and `await`, and +secondarily with functions and macros such as `join`, `join_all`, `race`, and +so on. You’ll only need to reach for `pin` now and again to use them with those +APIs. + +We’ve now seen a number of ways to work with multiple futures at the same +time. Up next, we’ll look at how we can work with multiple futures in a +sequence over time, with *streams*. Here are a couple more things you might want +to consider first, though: + +* We used a `Vec` with `join_all` to wait for all of the futures in some group + to finish. How could you use a `Vec` to process a group of futures in + sequence, instead? What are the tradeoffs of doing that? + +* Take a look at the `futures::stream::FuturesUnordered` type from the `futures` + crate. How would using it be different from using a `Vec`? (Don’t worry about + the fact that it is from the `stream` part of the crate; it works just fine + with any collection of futures.) + +## Streams + +So far in this chapter, we have mostly stuck to individual futures. The one big +exception was the async channel we used. Recall how we used the receiver for our +async channel in the “Message Passing” at *ch17-02-concurrency-with-async.html#message-passing* earlier in the chapter. +The async `recv` method produces a sequence of items over time. This is an +instance of a much more general pattern, often called a *stream*. + +A sequence of items is something we’ve seen before, when we looked at the +`Iterator` trait in Chapter 13, but there are two differences between iterators +and the async channel receiver. The first difference is the element of time: +iterators are synchronous, while the channel receiver is asynchronous. The +second difference is the API. When working directly with an `Iterator`, we call +its synchronous `next` method. With the `trpl::Receiver` stream in particular, +we called an asynchronous `recv` method instead, but these APIs otherwise feel +very similar. + +That similarity isn’t a coincidence. A stream is similar to an asynchronous +form of iteration. Whereas the `trpl::Receiver` specifically waits to receive +messages, though, the general-purpose stream API is much more general: it +provides the next item the way `Iterator` does, but asynchronously. The +similarity between iterators and streams in Rust means we can actually create a +stream from any iterator. As with an iterator, we can work with a stream by +calling its `next` method and then awaiting the output, as in Listing 17-30. + + +Filename: src/main.rs + +``` + let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let iter = values.iter().map(|n| n * 2); + let mut stream = trpl::stream_from_iter(iter); + + while let Some(value) = stream.next().await { + println!("The value was: {value}"); + } +``` + +Listing 17-30: Creating a stream from an iterator and printing its values + +We start with an array of numbers, which we convert to an iterator and then call +`map` on to double all the values. Then we convert the iterator into a stream +using the `trpl::stream_from_iter` function. Then we loop over the items in the +stream as they arrive with the `while let` loop. + +Unfortunately, when we try to run the code, it doesn’t compile. Instead, as we +can see in the output, it reports that there is no `next` method available. + +<!-- TODO: fix up the path here? --> + +<!-- manual-regeneration +cd listings/chapter-17-async-await/listing-17-30 +cargo build +copy only the error output +--> + +``` +error[E0599]: no method named `next` found for struct `Iter` in the current scope + --> src/main.rs:8:40 + | +8 | while let Some(value) = stream.next().await { + | ^^^^ + | + = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-30/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' + = note: consider using `--verbose` to print the full type name to the console + = help: items from traits can only be used if the trait is in scope +help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them + | +1 + use futures_util::stream::stream::StreamExt; + | +1 + use std::iter::Iterator; + | +1 + use std::str::pattern::Searcher; + | +1 + use trpl::StreamExt; + | +help: there is a method `try_next` with a similar name + | +8 | while let Some(value) = stream.try_next().await { + | ~~~~~~~~ + +For more information about this error, try `rustc --explain E0599`. +``` + +As the output suggests, the problem is that we need the right trait in scope to +be able to use the `next` method. Given our discussion so far, you might +reasonably expect that to be `Stream`, but the trait we need *here* is actually +`StreamExt`. The `Ext` there is for “extension”: this is a common pattern in +the Rust community for extending one trait with another. + +You might be wondering why `StreamExt` instead of `Stream`, and for that matter +whether there is a `Stream` trait at all. Briefly, the answer is that throughout +the Rust ecosystem, the `Stream` trait defines a low-level interface which +effectively combines the `Iterator` and `Future` traits. The `StreamExt` trait +supplies a higher-level set of APIs on top of `Stream`, including the `next` +method as well as other utility methods similar to those provided by the +`Iterator` trait. We’ll return to the `Stream` and `StreamExt` traits in a +bit more detail at the end of the chapter. For now, this is enough to let us +keep moving. + +The fix to the compiler error is to add a `use` statement for `trpl::StreamExt`, +as in Listing 17-31. + + +Filename: src/main.rs + +``` +use trpl::StreamExt; + +fn main() { + trpl::run(async { + let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let iter = values.iter().map(|n| n * 2); + let mut stream = trpl::stream_from_iter(iter); + + while let Some(value) = stream.next().await { + println!("The value was: {value}"); + } + }); +} +``` + +Listing 17-31: Successfully using an iterator as the basis for a stream + +With all those pieces put together, this code works the way we want! What’s +more, now that we have `StreamExt` in scope, we can use all of its utility +methods, just as with iterators. For example, in Listing 17-32, we use the +`filter` method to filter out everything but multiples of three and five. + + +Filename: src/main.rs + +``` +use trpl::StreamExt; + +fn main() { + trpl::run(async { + let values = 1..101; + let iter = values.map(|n| n * 2); + let stream = trpl::stream_from_iter(iter); + + let mut filtered = + stream.filter(|value| value % 3 == 0 || value % 5 == 0); + + while let Some(value) = filtered.next().await { + println!("The value was: {value}"); + } + }); +} +``` + +Listing 17-32: Filtering a <code>Stream</code> with the <code>StreamExt::filter</code> method + +Of course, this isn’t very interesting. We could do that with normal iterators +and without any async at all. So let’s look at some of the other things we can +do which are unique to streams. + +### Composing Streams + +Many concepts are naturally represented as streams: items becoming available in +a queue, or working with more data than can fit in a computer’s memory by only +pulling chunks of it from the file system at a time, or data arriving over the +network over time. Because streams are futures, we can use them with any other +kind of future, too, and we can combine them in interesting ways. For example, +we can batch up events to avoid triggering too many network calls, set timeouts +on sequences of long-running operations, or throttle user interface events to +avoid doing needless work. + +Let’s start by building a little stream of messages, as a stand-in for a stream +of data we might see from a WebSocket or another real-time communication +protocol. In Listing 17-33, we create a function `get_messages` which returns +`impl Stream<Item = String>`. For its implementation, we create an async +channel, loop over the first ten letters of the English alphabet, and send them +across the channel. + +We also use a new type: `ReceiverStream`, which converts the `rx` receiver from +the `trpl::channel` into a `Stream` with a `next` method. Back in `main`, we use +a `while let` loop to print all the messages from the stream. + + +Filename: src/main.rs + +``` +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::run(async { + let mut messages = get_messages(); + + while let Some(message) = messages.next().await { + println!("{message}"); + } + }); +} + +fn get_messages() -> impl Stream<Item = String> { + let (tx, rx) = trpl::channel(); + + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for message in messages { + tx.send(format!("Message: '{message}'")).unwrap(); + } + + ReceiverStream::new(rx) +} +``` + +Listing 17-33: Using the <code>rx</code> receiver as a <code>ReceiverStream</code> + +When we run this code, we get exactly the results we would expect: + +<!-- Not extracting output because changes to this output aren't significant; +the changes are likely to be due to the threads running differently rather than +changes in the compiler --> + +``` +Message: 'a' +Message: 'b' +Message: 'c' +Message: 'd' +Message: 'e' +Message: 'f' +Message: 'g' +Message: 'h' +Message: 'i' +Message: 'j' +``` + +We could do this with the regular `Receiver` API, or even the regular `Iterator` +API, though. Let’s add something that requires streams: adding a timeout +which applies to every item in the stream, and a delay on the items we emit. + +In Listing 17-34, we start by adding a timeout to the stream with the `timeout` +method, which comes from the `StreamExt` trait. Then we update the body of the +`while let` loop, because the stream now returns a `Result`. The `Ok` variant +indicates a message arrived in time; the `Err` variant indicates that the +timeout elapsed before any message arrived. We `match` on that result and either +print the message when we receive it successfully, or print a notice about the +timeout. Finally, notice that we pin the messages after applying the timeout to +them, because the timeout helper produces a future which needs to be pinned to +be polled. + + +Filename: src/main.rs + +``` +use std::{pin::pin, time::Duration}; +use trpl::{ReceiverStream, Stream, StreamExt}; + +fn main() { + trpl::run(async { + let mut messages = + pin!(get_messages().timeout(Duration::from_millis(200))); + + while let Some(result) = messages.next().await { + match result { + Ok(message) => println!("{message}"), + Err(reason) => eprintln!("Problem: {reason:?}"), + } + } + }) +} +``` + +Listing 17-34: Using the <code>StreamExt::timeout</code> method to set a time limit on the items in a stream + +However, because there are no delays between messages, this timeout does not +change the behavior of the program. Let’s add a variable delay to the messages +we send. In `get_messages`, we use the `enumerate` iterator method with the +`messages` array so that we can get the index of each item we are sending along +with the item itself. Then we apply a 100 millisecond delay to even-index items +and a 300 millisecond delay to odd-index items, to simulate the different delays +we might see from a stream of messages in the real world. Because our timeout is +for 200 milliseconds, this should affect half of the messages. + + +Filename: src/main.rs + +``` +fn get_messages() -> impl Stream<Item = String> { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + tx.send(format!("Message: '{message}'")).unwrap(); + } + }); + + ReceiverStream::new(rx) +} +``` + +Listing 17-35: Sending messages through <code>tx</code> with an async delay without making <code>get_messages</code> an async function + +To sleep between messages in the `get_messages` function without blocking, we +need to use async. However, we can’t make `get_messages` itself into an async +function, because then we’d return a `Future<Output = Stream<Item = String>>` instead of just a `Stream<Item = String>>`. The caller would have to +await `get_messages` itself to get access to the stream. But remember: +everything in a given future happens linearly; concurrency happens *between* +futures. Awaiting `get_messages` would require it to send all the messages, +including sleeping between sending each message, before returning the receiver +stream. As a result, the timeout would end up useless. There would be no delays +in the stream itself: the delays would all happen before the stream was even +available. + +Instead, we leave `get_messages` as a regular function which returns a stream, +and spawn a task to handle the async `sleep` calls. + + > + > Note: calling `spawn_task` in this way works because we already set up our + > runtime. Calling this particular implementation of `spawn_task` *without* + > first setting up a runtime will cause a panic. Other implementations choose + > different tradeoffs: they might spawn a new runtime and so avoid the panic but + > end up with a bit of extra overhead, or simply not provide a standalone way to + > spawn tasks without reference to a runtime. You should make sure you know what + > tradeoff your runtime has chosen and write your code accordingly! + +Now our code has a much more interesting result! Between every other pair of +messages, we see an error reported: `Problem: Elapsed(())`. + +<!-- manual-regeneration +cd listings/listing-17-35 +cargo run +copy only the program output, *not* the compiler output +--> + +``` +Message: 'a' +Problem: Elapsed(()) +Message: 'b' +Message: 'c' +Problem: Elapsed(()) +Message: 'd' +Message: 'e' +Problem: Elapsed(()) +Message: 'f' +Message: 'g' +Problem: Elapsed(()) +Message: 'h' +Message: 'i' +Problem: Elapsed(()) +Message: 'j' +``` + +The timeout doesn’t prevent the messages from arriving in the end—we still get +all of the original messages. This is because our channel is unbounded: it can +hold as many messages as we can fit in memory. If the message doesn’t arrive +before the timeout, our stream handler will account for that, but when it polls +the stream again, the message may now have arrived. + +You can get different behavior if needed by using other kinds of channels, or +other kinds of streams more generally. Let’s see one of those in practice in our +final example for this section, by combining a stream of time intervals with +this stream of messages. + +### Merging Streams + +First, let’s create another stream, which will emit an item every millisecond if +we let it run directly. For simplicity, we can use the `sleep` function to send +a message on a delay, and combine it with the same approach of creating a stream +from a channel we used in `get_messages`. The difference is that this time, +we’re going to send back the count of intervals which has elapsed, so the return +type will be `impl Stream<Item = u32>`, and we can call the function +`get_intervals`. + +In Listing 17-36, we start by defining a `count` in the task. (We could define +it outside the task, too, but it is clearer to limit the scope of any given +variable.) Then we create an infinite loop. Each iteration of the loop +asynchronously sleeps for one millisecond, increments the count, and then sends +it over the channel. Because this is all wrapped in the task created by +`spawn_task`, all of it will get cleaned up along with the runtime, including +the infinite loop. + + +Filename: src/main.rs + +``` +fn get_intervals() -> impl Stream<Item = u32> { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let mut count = 0; + loop { + trpl::sleep(Duration::from_millis(1)).await; + count += 1; + tx.send(count).unwrap(); + } + }); + + ReceiverStream::new(rx) +} +``` + +Listing 17-36: Creating a stream with a counter that will be emitted once every millisecond + +This kind of infinite loop, which only ends when the whole runtime gets torn +down, is fairly common in async Rust: many programs need to keep running +indefinitely. With async, this doesn’t block anything else, as long as there is +at least one await point in each iteration through the loop. + +Back in our main function’s async block, we start by calling `get_intervals`. +Then we merge the `messages` and `intervals` streams with the `merge` method, +which combines multiple streams into one stream that produces items from any of +the source streams as soon as the items are available, without imposing any +particular ordering. Finally, we loop over that combined stream instead of over +`messages` (Listing 17-37). + + +Filename: src/main.rs + +``` + let messages = get_messages().timeout(Duration::from_millis(200)); + let intervals = get_intervals(); + let merged = messages.merge(intervals); +``` + +Listing 17-37: Attempting to merge streams of messages and intervals + +At this point, neither `messages` nor `intervals` needs to be pinned or mutable, +because both will be combined into the single `merged` stream. However, this +call to `merge` does not compile! (Neither does the `next` call in the `while let` loop, but we’ll come back to that after fixing this.) The two streams +have different types. The `messages` stream has the type `Timeout<impl Stream<Item = String>>`, where `Timeout` is the type which implements `Stream` +for a `timeout` call. Meanwhile, the `intervals` stream has the type `impl Stream<Item = u32>`. To merge these two streams, we need to transform one of +them to match the other. + +In Listing 17-38, we rework the `intervals` stream, because `messages` is +already in the basic format we want and has to handle timeout errors. First, we +can use the `map` helper method to transform the `intervals` into a string. +Second, we need to match the `Timeout` from `messages`. Because we don’t +actually *want* a timeout for `intervals`, though, we can just create a timeout +which is longer than the other durations we are using. Here, we create a +10-second timeout with `Duration::from_secs(10)`. Finally, we need to make +`stream` mutable, so that the `while let` loop’s `next` calls can iterate +through the stream, and pin it so that it’s safe to do so. + +<!-- We cannot directly test this one, because it never stops. --> + + +Filename: src/main.rs + +``` + let messages = get_messages().timeout(Duration::from_millis(200)); + let intervals = get_intervals() + .map(|count| format!("Interval: {count}")) + .timeout(Duration::from_secs(10)); + let merged = messages.merge(intervals); + let mut stream = pin!(merged); +``` + +Listing 17-38: Aligning the types of the the <code>intervals</code> stream with the type of the <code>messages</code> stream + +That gets us *almost* to where we need to be. Everything type checks. If you run +this, though, there will be two problems. First, it will never stop! You’ll +need to stop it with <span class="keystroke">ctrl-c</span>. Second, the +messages from the English alphabet will be buried in the midst of all the +interval counter messages: + +<!-- Not extracting output because changes to this output aren't significant; +the changes are likely to be due to the tasks running differently rather than +changes in the compiler --> + +``` +--snip-- +Interval: 38 +Interval: 39 +Interval: 40 +Message: 'a' +Interval: 41 +Interval: 42 +Interval: 43 +--snip-- +``` + +Listing 17-39 shows one way to solve these last two problems. First, we use the +`throttle` method on the `intervals` stream, so that it doesn’t overwhelm the +`messages` stream. Throttling is a way of limiting the rate at which a function +will be called—or, in this case, how often the stream will be polled. Once every +hundred milliseconds should do, because that is in the same ballpark as how +often our messages arrive. + +To limit the number of items we will accept from a stream, we can use the `take` +method. We apply it to the *merged* stream, because we want to limit the final +output, not just one stream or the other. + + +Filename: src/main.rs + +``` + let messages = get_messages().timeout(Duration::from_millis(200)); + let intervals = get_intervals() + .map(|count| format!("Interval: {count}")) + .throttle(Duration::from_millis(100)) + .timeout(Duration::from_secs(10)); + let merged = messages.merge(intervals).take(20); + let mut stream = pin!(merged); +``` + +Listing 17-39: Using <code>throttle</code> and <code>take</code> to manage the merged streams + +Now when we run the program, it stops after pulling twenty items from the +stream, and the intervals don’t overwhelm the messages. We also don’t get +`Interval: 100` or `Interval: 200` or so on, but instead get `Interval: 1`, +`Interval: 2`, and so on—even though we have a source stream which *can* +produce an event every millisecond. That’s because the `throttle` call +produces a new stream, wrapping the original stream, so that the original +stream only gets polled at the throttle rate, not its own “native” rate. We +don’t have a bunch of unhandled interval messages we’re choosing to +ignore. Instead, we never produce those interval messages in the first place! +This is the inherent “laziness” of Rust’s futures at work again, allowing us to +choose our performance characteristics. + +<!-- manual-regeneration +cd listings/listing-17-39 +cargo run +copy and paste only the program output +--> + +``` +Interval: 1 +Message: 'a' +Interval: 2 +Interval: 3 +Problem: Elapsed(()) +Interval: 4 +Message: 'b' +Interval: 5 +Message: 'c' +Interval: 6 +Interval: 7 +Problem: Elapsed(()) +Interval: 8 +Message: 'd' +Interval: 9 +Message: 'e' +Interval: 10 +Interval: 11 +Problem: Elapsed(()) +Interval: 12 +``` + +There’s one last thing we need to handle: errors! With both of these +channel-based streams, the `send` calls could fail when the other side of the +channel closes—and that’s just a matter of how the runtime executes the futures +which make up the stream. Up until now we have ignored this by calling `unwrap`, +but in a well-behaved app, we should explicitly handle the error, at minimum by +ending the loop so we don’t try to send any more messages! Listing 17-40 shows +a simple error strategy: print the issue and then `break` from the loops. As +usual, the correct way to handle a message send error will vary—just make sure +you have a strategy. + + +``` +fn get_messages() -> impl Stream<Item = String> { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let messages = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; + + for (index, message) in messages.into_iter().enumerate() { + let time_to_sleep = if index % 2 == 0 { 100 } else { 300 }; + trpl::sleep(Duration::from_millis(time_to_sleep)).await; + + if let Err(send_error) = tx.send(format!("Message: '{message}'")) { + eprintln!("Cannot send message '{message}': {send_error}"); + break; + } + } + }); + + ReceiverStream::new(rx) +} + +fn get_intervals() -> impl Stream<Item = u32> { + let (tx, rx) = trpl::channel(); + + trpl::spawn_task(async move { + let mut count = 0; + loop { + trpl::sleep(Duration::from_millis(1)).await; + count += 1; + + if let Err(send_error) = tx.send(count) { + eprintln!("Could not send interval {count}: {send_error}"); + break; + }; + } + }); + + ReceiverStream::new(rx) +} +``` + +Listing 17-40: Handling errors and shutting down the loops + +Now that we’ve seen a bunch of async in practice, let’s take a step back and +dig into a few of the details of how `Future`, `Stream`, and the other key +traits which Rust uses to make async work. + +## Digging Into the Traits for Async + +Throughout the chapter, we’ve used the `Future`, `Pin`, `Unpin`, `Stream`, and +`StreamExt` traits in various ways. So far, though, we’ve avoided digging too +far into the details of how they work or how they fit together. Much of the time +when writing Rust day to day, this is fine. Sometimes, though, you’ll hit +situations where understanding a few more of these details matters. In this +section, we’ll dig down *enough* further to help with those situations—while +still leaving the *really* deep dive for other documentation! + +### Future + +Back in Futures and the Async Syntax at *ch17-01-futures-and-syntax.html*, we noted that `Future` +is a trait. Let’s start by taking a closer look at how it works. Here is how +Rust defines a `Future`: + +``` +use std::pin::Pin; +use std::task::{Context, Poll}; + +pub trait Future { + type Output; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>; +} +``` + +That trait definition includes a bunch of new types and also some syntax we +haven’t seen before, so let’s walk through the definition piece by piece. + +First, `Future`’s associated type `Output` says what the future resolves to. +This is analogous to the `Item` associated type for the `Iterator` trait. +Second, `Future` also has the `poll` method, which takes a special `Pin` +reference for its `self` parameter and a mutable reference to a `Context` type, +and returns a `Poll<Self::Output>`. We’ll talk a little more about `Pin` and +`Context` later in the section. For now, let’s focus on what the method returns, +the `Poll` type: + +``` +enum Poll<T> { + Ready(T), + Pending, +} +``` + +This `Poll` type is similar to an `Option`: it has one variant which has a value +(`Ready(T)`), and one which does not (`Pending`). It means something quite +different, though! The `Pending` variant indicates that the future still has +work to do, so the caller will need to check again later. The `Ready` variant +indicates that the `Future` has finished its work and the `T` value is +available. + + > + > Note: With most futures, the caller should not call `poll` again after the + > future has returned `Ready`. Many futures will panic if polled again after + > becoming ready! Futures which are safe to poll again will say so explicitly in + > their documentation. This is similar to how `Iterator::next` behaves! + +Under the hood, when you see code which uses `await`, Rust compiles that to code +which calls `poll`. If you look back at Listing 17-4, where we printed out the +page title for a single URL once it resolved, Rust compiles it into something +kind of (although not exactly) like this: + +``` +match page_title(url).poll() { + Ready(page_title) => match page_title { + Some(title) => println!("The title for {url} was {title}"), + None => println!("{url} had no title"), + } + Pending => { + // But what goes here? + } +} +``` + +What should we do when the `Future` is still `Pending`? We need some way to try +again… and again, and again, until the future is finally ready. In other words, +a loop: + +``` +let mut page_title_fut = page_title(url); +loop { + match page_title_fut.poll() { + Ready(value) => match page_title { + Some(title) => println!("The title for {url} was {title}"), + None => println!("{url} had no title"), + } + Pending => { + // continue + } + } +} +``` + +If Rust compiled it to exactly that code, though, every `await` would be +blocking—exactly the opposite of what we were going for! Instead, Rust needs +makes sure that the loop can hand off control to something which can pause work +on this future and work on other futures and check this one again later. That +“something” is an async runtime, and this scheduling and coordination work is +one of the main jobs for a runtime. + +Recall our description (in the Counting at *ch17-02-concurrency-with-async.html* section) of waiting on +`rx.recv`. The `recv` call returns a `Future`, and awaiting it polls it. In our +initial discussion, we noted that a runtime will pause the future until it’s +ready with either `Some(message)` or `None` when the channel closes. With our +deeper understanding of `Future` in place, and specifically `Future::poll`, we +can see how that works. The runtime knows the future isn’t ready when it +returns `Poll::Pending`. Conversely, the runtime knows the future is ready and +advances it when `poll` returns `Poll::Ready(Some(message))` or +`Poll::Ready(None)`. + +The exact details of how a runtime does that are more than we will cover in even +this deep dive section. The key here is to see the basic mechanic of futures: a +runtime *polls* each future it is responsible for, putting it back to sleep when +it is not yet ready. + +### Pinning and the Pin and Unpin Traits + +<!-- TODO: get a *very* careful technical review of this section! --> + +When we introduced the idea of pinning, while working on Listing 17-17, we ran +into a very gnarly error message. Here is the relevant part of it again: + +<!-- manual-regeneration +cd listings/ch17-async-await/listing-17-17 +cargo build +copy *only* the final `error` block from the errors +--> + +``` +error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned + --> src/main.rs:46:33 + | +46 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + | + = note: consider using the `pin!` macro + consider using `Box::pin` if you need to access the pinned value outside of the current scope + = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` +note: required by a bound in `JoinAll` + --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + | +27 | pub struct JoinAll<F> + | ------- required by a bound in this struct +28 | where +29 | F: Future, + | ^^^^^^ required by this bound in `JoinAll` + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. +``` + +When we read this error message carefully, it not only tells us that we need to +pin the values, but also tells us why pinning is required. The `trpl::join_all` +function returns a struct called `JoinAll`. That struct, in turn, is generic +over a type `F`, which is constrained to implement the `Future` trait. Finally, +directly awaiting a Future requires that the future in question implement the +`Unpin` trait. That’s a lot! But we can understand it, if we dive a little +further into how the `Future` type actually works, in particular around +*pinning*. + +Let’s look again at the definition of `Future`: + +``` +use std::pin::Pin; +use std::task::{Context, Poll}; + +pub trait Future { + type Output; + + // Required method + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>; +} +``` + +The `cx` parameter and its `Context` type is interesting, but is beyond the +scope of this chapter: you generally only need to worry about it when writing a +custom `Future` implementation. + +Instead, we’ll focus on the type for `self`. This is the first time we’ve seen +a method where `self` has a type annotation. A type annotation for `self` is +similar to type annotations for other function parameters, with two key +differences. First, when we specify the type of `self` in this way, we’re +telling Rust what type `self` must be to call this method. Second, a type +annotation on `self` can’t be just any type. It’s only allowed to be the type +on which the method is implemented, a reference or smart pointer to that type, +or a `Pin` wrapping a reference to that type. We’ll see more on this syntax in +Chapter 18. For now, it’s enough to know that if we want to poll a future (to +check whether it is `Pending` or `Ready(Output)`), we need a mutable reference +to the type, which is wrapped in a `Pin`. + +`Pin` is a wrapper type. In some ways, it’s similar to the `Box`, `Rc`, and +other smart pointer types we saw in Chapter 15, which also wrap other types. +Unlike those, however, `Pin` only works with *pointer types* such as references +(`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, +`Pin` works with types which implement the `Deref` or `DerefMut` traits, which +we covered in Chapter 15. You can think of this restriction as equivalent to +only working with pointers, though, because implementing `Deref` or `DerefMut` +means your type behaves similarly to a pointer type. `Pin` is also not a +pointer itself, and it doesn’t have any behavior of its own as the ref counting +of `Rc` or `Arc` does. It’s purely a tool the compiler can use to uphold the +relevant guarantees, by wrapping pointers in the type. + +Recalling that `await` is implemented in terms of calls to `poll`, this starts +to explain the error message we saw above—but that was in terms of `Unpin`, not +`Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, and why does +`Future` need `self` to be in a `Pin` type to call `poll`? + +In Our First Async Program at *ch17-01-futures-and-syntax.html#our-first-async-program*, we described how a series of await +points in a future get compiled into a state machine—and noted how the compiler +helps make sure that state machine follows all of Rust’s normal rules around +safety, including borrowing and ownership. To make that work, Rust looks at what +data is needed between each await point and the next await point or the end of +the async block. It then creates a corresponding variant in the state machine it +creates. Each variant gets the access it needs to the data that will be used in +that section of the source code, whether by taking ownership of that data or by +getting a mutable or immutable reference to it. + +So far so good: if we get anything wrong about the ownership or references in a +given async block, the borrow checker will tell us. When we want to move around +the future that corresponds to that block—like moving it into a `Vec` to pass to +`join_all`, the way we did back in—things get trickier. + +When we move a future—whether by pushing into a data structure to use as an +iterator with `join_all`, or returning them from a function—that actually means +moving the state machine Rust creates for us. And unlike most other types in +Rust, the futures Rust creates for async blocks can end up with references to +themselves in the fields of any given variant, as in Figure 17-3 (a simplified +illustration to help you get a feel for the idea, rather than digging into what +are often fairly complicated details). + +<figure> + +<img alt="Concurrent work flow" src="img/trpl17-03.svg" class="center" /> + +<figcaption>Figure 17-3: A self-referential data type.</figcaption> + +</figure> + +By default, though, any object which has a reference to itself is unsafe to +move, because references always point to the actual memory address of the thing +they refer to. If you move the data structure itself, those internal references +will be left pointing to the old location. However, that memory location is now +invalid. For one thing, its value will not be updated when you make changes to +the data structure. For another—and more importantly!—the computer is now free +to reuse that memory for other things! You could end up reading completely +unrelated data later. + +<figure> + +<img alt="Concurrent work flow" src="img/trpl17-04.svg" class="center" /> + +<figcaption>Figure 17-4: The unsafe result of moving a self-referential data type.</figcaption> + +</figure> + +In principle, the Rust compiler could try to update every reference to an object +every time it gets moved. That would potentially be a lot of performance +overhead, especially given there can be a whole web of references that need +updating. On the other hand, if we could make sure the data structure in +question *doesn’t move in memory*, we don’t have to update any references. +This is exactly what Rust’s borrow checker requires: you can’t move an item +which has any active references to it using safe code. + +`Pin` builds on that to give us the exact guarantee we need. When we *pin* a +value by wrapping a pointer to that value in `Pin`, it can no longer move. Thus, +if you have `Pin<Box<SomeType>>`, you actually pin the `SomeType` value, *not* +the `Box` pointer. Figure 17-5 illustrates this: + +<figure> + +<img alt="Concurrent work flow" src="img/trpl17-05.svg" class="center" /> + +<figcaption>Figure 17-5: Pinning a `Box` which points to a self-referential future type.</figcaption> + +</figure> + +In fact, the `Box` pointer can still move around freely. Remember: we care about +making sure the data ultimately being referenced stays in its place. If a +pointer moves around, but the data it points to is in the same place, as in +Figure 17-6, there’s no potential problem. (How you would do this with a `Pin` +wrapping a `Box` is more than we’ll get into in this particular discussion, +but it would make for a good exercise! If you look at the docs for the types as +well as the `std::pin` module, you might be able to work out how you would do +that.) The key is that the self-referential type itself cannot move, because it +is still pinned. + +<figure> + +<img alt="Concurrent work flow" src="img/trpl17-06.svg" class="center" /> + +<figcaption>Figure 17-6: Moving a `Box` which points to a self-referential future type.</figcaption> + +</figure> + +However, most types are perfectly safe to move around, even if they happen to +be behind a `Pin` pointer. We only need to think about pinning when items have +internal references. Primitive values such as numbers and booleans don’t have +any internal references, so they’re obviously safe. Neither do most types you +normally work with in Rust. A `Vec`, for example, doesn’t have any internal +references it needs to keep up to date this way, so you can move it around +without worrying. If you have a `Pin<Vec<String>>`, you’d have to do everything +via the safe but restrictive APIs provided by `Pin`, even though a +`Vec<String>` is always safe to move if there are no other references to it. We +need a way to tell the compiler that it’s actually just fine to move items +around in cases such as these. For that, we have `Unpin`. + +`Unpin` is a marker trait, as `Send` and `Sync` are, which we saw in Chapter 16. +Recall that marker traits have no functionality of their own. They exist only to +tell the compiler that it’s safe to use the type which implements a given trait +in a particular context. `Unpin` informs the compiler that a given type does +*not* need to uphold any particular guarantees about whether the value in +question can be moved. + +Just as with `Send` and `Sync`, the compiler implements `Unpin` automatically +for all types where it can prove it is safe. Implementing `Unpin` manually is +unsafe because it requires *you* to uphold all the guarantees which make `Pin` +and `Unpin` safe yourself for a type with internal references. In practice, +this is a very rare thing to implement yourself! + +To make that concrete, think about a `String`: it has a length and the Unicode +characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure +17-7. However + +<figure> + +<img alt="Concurrent work flow" src="img/trpl17-07.svg" class="center" /> + +<figcaption>Figure 17-7: Pinning a String, with a dotted line indicating that the String implements the `Unpin` trait, so it is not pinned.</figcaption> + +</figure> + +This means that we can do things such as replace one string with another at the +exact same location in memory as in Figure 17-8. This doesn’t violate the `Pin` +contract because `String`—like most other types in Rust—implements `Unpin`, +because it has no internal references that make it unsafe to move around! + +<figure> + +<img alt="Concurrent work flow" src="img/trpl17-08.svg" class="center" /> + +<figcaption>Figure 17-8: Replacing the String with an entirely different String in memory.</figcaption> + +</figure> + +Now we know enough to understand the errors reported for that `join_all` call +from back in Listing 17-17. We originally tried to move the futures produced by +async blocks into a `Vec<Box<dyn Future<Output = ()>>>`, but as we’ve seen, +those futures may have internal references, so they don’t implement `Unpin`. +They need to be pinned, and then we can pass the `Pin` type into the `Vec`, +confident that the underlying data in the futures will *not* be moved. + +`Pin` and `Unpin` are mostly important for building lower-level libraries, or +when you’re building a runtime itself, rather than for day to day Rust code. +When you see these traits in error messages, though, now you’ll have a better +idea of how to fix the code! + + > + > Note: This combination of `Pin` and `Unpin` allows a whole class of complex + > types to be safe in Rust which are otherwise difficult to implement because + > they’re self-referential. Types which require `Pin` show up *most* commonly + > in async Rust today, but you might—very rarely!—see it in other contexts, too. + > + > The specifics of how `Pin` and `Unpin` work, and the rules they’re required + > to uphold, are covered extensively in the API documentation for `std::pin`, so + > if you’d like to understand them more deeply, that’s a great place to start. + > + > If you want to understand how things work “under the hood” in even more + > detail, the official *Asynchronous Programming in Rust* at *https://rust-lang.github.io/async-book/* book has + > you covered: + > + > * Chapter 2: Under the Hood: Executing Futures and Tasks at *https://rust-lang.github.io/async-book/02_execution/01_chapter.html* + > * Chapter 4: Pinning at *https://rust-lang.github.io/async-book/04_pinning/01_chapter.html* + +### The Stream Trait + +Now that we have a deeper grasp on the `Future`, `Pin`, and `Unpin` traits, we +can turn our attention to the `Stream` trait. As described in the section +introducing streams, streams are similar to asynchronous iterators. Unlike +`Iterator` and `Future`, there is no definition of a `Stream` trait in the +standard library as of the time of writing,<!-- TODO: verify before press time! +--> but there *is* a very common definition from the `futures` crate used +throughout the ecosystem. + +Let’s review the definitions of the `Iterator` and `Future` traits, so we can +build up to how a `Stream` trait that merges them together might look. From +`Iterator`, we have the idea of a sequence: its `next` method provides an +`Option<Self::Item>`. From `Future`, we have the idea of readiness over time: +its `poll` method provides a `Poll<Self::Output>`. To represent a sequence of +items which become ready over time, we define a `Stream` trait which puts those +features together: + +``` +use std::pin::Pin; +use std::task::{Context, Poll}; + +trait Stream { + type Item; + + fn poll_next( + self: Pin<&mut Self>, + cx: &mut Context<'_> + ) -> Poll<Option<Self::Item>>; +} +``` + +The `Stream` trait defines an associated type `Item` for the type of the items +produced by the stream. This is similar to `Iterator`: there may be zero to +many of these, and unlike `Future`, where there is always a single `Output` +(even if it’s the unit type `()`). + +`Stream` also defines a method to get those items. We call it `poll_next`, to +make it clear that it polls in the same way `Future::poll` does and produces a +sequence of items in the same way `Iterator::next` does. Its return type +combines `Poll` with `Option`. The outer type is `Poll`, because it has to be +checked for readiness, just as a future does. The inner type is `Option`, +because it needs to signal whether there are more messages, just as an iterator +does. + +Something very similar to this will likely end up standardized as part of Rust’s +standard library. In the meantime, it’s part of the toolkit of most runtimes, +so you can rely on it, and everything we cover below should generally apply! + +In the example we saw in the section on streaming, though, we didn’t use +`poll_next` *or* `Stream`, but instead used `next` and `StreamExt`. We *could* +work directly in terms of the `poll_next` API by hand-writing our own `Stream` +state machines, of course, just as we *could* work with futures directly via +their `poll` method. Using `await` is much nicer, though, so the `StreamExt` +trait supplies the `next` method so we can do just that. + +``` +trait StreamExt: Stream { + async fn next(&mut self) -> Option<Self::Item> + where + Self: Unpin; + + // other methods... +} +``` + +<!-- +TODO: update this if/when tokio/etc. update their MSRV and switch to using async functions +in traits, since the lack thereof is the reason they do not yet have this. +--> + + > + > Note: The actual definition we used earlier in the chapter looks slightly + > different than this, because it supports versions of Rust which did not yet + > support using async functions in traits. As a result, it looks like this: + > + > ````rust,ignore + > fn next(&mut self) -> Next<'_, Self> where Self: Unpin; + > ```` + > + > That `Next` type is a `struct` which implements `Future` and gives a way to + > name the lifetime of the reference to `self` with `Next<'_, Self>`, so that + > `await` can work with this method! + +The `StreamExt` trait is also the home of all the interesting methods available +to use with streams. `StreamExt` is automatically implemented for every type +which implements `Stream`, but these traits are defined separately so that the +community can iterate on the foundational trait distinctly from the convenience +APIs. + +In the version of `StreamExt` used in the `trpl` crate, the trait not only +defines the `next` method, it also supplies an implementation of `next`, which +correctly handles the details of calling `Stream::poll_next`. This means that +even when you need to write your own streaming data type, you *only* have to +implement `Stream`, and then anyone who uses your data type can use `StreamExt` +and its methods with it automatically. + +That’s all we’re going to cover for the lower-level details on these traits. To +wrap up, let’s consider how futures (including streams), tasks, and threads all +fit together! + +## Futures, Tasks, and Threads + +As we saw in the previous chapter, threads provide one approach to concurrency. +We’ve seen another approach to concurrency in this chapter, using async with +futures and streams. You might be wondering why you would choose one or the +other. The answer is: it depends! And in many cases, the choice isn’t threads +*or* async but rather threads *and* async. + +Many operating systems have supplied threading-based concurrency models for +decades now, and many programming languages have support for them as a result. +However, they are not without their tradeoffs. On many operating systems, they +use a fair bit of memory for each thread, and they come with some overhead for +starting up and shutting down. Threads are also only an option when your +operating system and hardware support them! Unlike mainstream desktop and mobile +computers, some embedded systems don’t have an OS at all, so they also don’t +have threads! + +The async model provides a different—and ultimately complementary—set of +tradeoffs. In the async model, concurrent operations don’t require their own +threads. Instead, they can run on tasks, as when we used `trpl::spawn_task` to +kick off work from a synchronous function throughout the streams section. A +*task* is similar to a thread—but instead of being managed by the operating +system, it’s managed by library-level code: the runtime. + +In the previous section, we saw that we could build a `Stream` by using an async +channel and spawning an async task which we could call from synchronous code. We +could do the exact same thing with a thread! In Listing 17-40, we used +`trpl::spawn_task` and `trpl::sleep`. In Listing 17-41, we replace those with +the `thread::spawn` and `thread::sleep` APIs from the standard library in the +`get_intervals` function. + + +Filename: src/main.rs + +``` +fn get_intervals() -> impl Stream<Item = u32> { + let (tx, rx) = trpl::channel(); + + // This is *not* `trpl::spawn` but `std::thread::spawn`! + thread::spawn(move || { + let mut count = 0; + loop { + // Likewise, this is *not* `trpl::sleep` but `std::thread::sleep`! + thread::sleep(Duration::from_millis(1)); + count += 1; + + if let Err(send_error) = tx.send(count) { + eprintln!("Could not send interval {count}: {send_error}"); + break; + }; + } + }); + + ReceiverStream::new(rx) +} +``` + +Listing 17-41: Using the <code>std::thread</code> APIs instead of the async <code>trpl</code> APIs for the <code>get_intervals</code> function + +If you run this, the output is identical. And notice how little changes here +from the perspective of the calling code! What’s more, even though one of our +functions spawned an async task on the runtime and the other spawned an +OS thread, the resulting streams were unaffected by the differences. + +However, there’s a significant difference between how these two approaches +behave, although we might have a hard time measuring it in this very simple +example. We could spawn hundreds of thousands or even millions of async tasks +on any modern personal computer. If we tried to do that with threads, we would +literally run out of memory! + +However, there’s a reason these APIs are so similar. Threads act as a boundary +for sets of synchronous operations; concurrency is possible *between* threads. +Tasks act as a boundary for sets of *asynchronous* operations; concurrency is +possible both *between* and *within* tasks. In that regard, tasks are similar to +lightweight, runtime-managed threads with added capabilities that come from +being managed by a runtime instead of by the operating system. Futures are an +even more granular unit of concurrency, where each future may represent a tree +of other futures. That is, the runtime—specifically, its executor—manages tasks, +and tasks manage futures. + +However, this doesn’t mean that async tasks are always better than threads, any +more than that threads are always better than tasks. + +On the one hand, concurrency with threads is in some ways a simpler programming +model than concurrency with `async`. Threads are somewhat “fire and forget,” +they have no native equivalent to a future, so they simply run to completion, +without interruption except by the operating system itself. That is, they have +no *intra-task concurrency* as futures can. Threads in Rust also have no +mechanisms for cancellation—a subject we haven’t covered in depth in this +chapter, but which is implicit in the fact that whenever we ended a future, its +state got cleaned up correctly. + +These limitations make threads harder to compose than futures. It’s much more +difficult, for example, to build something similar to the `timeout` we built in +“Building Our Own Async Abstractions” at *ch17-03-more-futures.html#building-our-own-async-abstractions*, or the `throttle` +method we used with streams in “Composing Streams” at *ch17-04-streams.html#composing-streams*. The fact that +futures are richer data structures means they *can* be composed together more +naturally, as we have seen. + +Tasks then give *additional* control over futures, allowing you to choose where +and how to group the futures. And it turns out that threads and tasks often +work very well together, because tasks can (at least in some runtimes) be moved +around between threads. We haven’t mentioned it up until now, but under the +hood the `Runtime` we have been using, including the `spawn_blocking` and +`spawn_task` functions, is multithreaded by default! Many runtimes use an +approach called *work stealing* to transparently move tasks around between +threads based on the current utilization of the threads, with the aim of +improving the overall performance of the system. To build, that actually +requires threads *and* tasks, and therefore futures. + +As a default way of thinking about which to use when: + +* If the task is *very parallelizable*, such as processing a bunch of data where + each part can be processed separately, threads are a better choice. +* If the task is *very concurrent*, such as handling messages from a bunch of + different sources which may come in a different intervals or different rates, + async is a better choice. + +And if you need some mix of parallelism and concurrency, you don’t have to +choose between threads and async. You can use them together freely, letting each +one serve the part it is best at. For example, Listing 17-42 shows a fairly +common example of this kind of mix in real-world Rust code. + + +Filename: src/main.rs + +``` +use std::{thread, time::Duration}; + +fn main() { + let (tx, mut rx) = trpl::channel(); + + thread::spawn(move || { + for i in 1..11 { + tx.send(i).unwrap(); + thread::sleep(Duration::from_secs(1)); + } + }); + + trpl::run(async { + while let Some(message) = rx.recv().await { + println!("{message}"); + } + }); +} +``` + +Listing 17-42: Sending messages with blocking code in a thread and awaiting the messages in an async block + +We begin by creating an async channel. Then we spawn a thread which takes +ownership of the sender side of the channel. Within the thread, we send the +numbers 1 through 10, and sleep for a second in between each. Finally, we run a +future created with an async block passed to `trpl::run` just as we have +throughout the chapter. In that future, we await those messages, just as in +the other message-passing examples we have seen. + +To return to the examples we opened the chapter with: you could imagine running +a set of video encoding tasks using a dedicated thread, because video encoding +is compute bound, but notifying the UI that those operations are done with an +async channel. Examples of this kind of mix abound! + +## Summary + +This isn’t the last you’ll see of concurrency in this book: the project in +Chapter 21 will use the concepts in this chapter in a more realistic situation +than the smaller examples discussed here—and compare more directly what it looks +like to solve these kinds of problems with threading vs. with tasks and futures. + +Whether with threads, with futures and tasks, or with the combination of them +all, Rust gives you the tools you need to write safe, fast, concurrent +code—whether for a high-throughput web server or an embedded operating system. + +Next, we’ll talk about idiomatic ways to model problems and structure solutions +as your Rust programs get bigger. In addition, we’ll discuss how Rust’s idioms +relate to those you might be familiar with from object-oriented programming. From daccf5eca3cdc8b19c01bb15ad14ac196fc529a7 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <carol.nichols@gmail.com> Date: Thu, 3 Oct 2024 21:22:49 -0400 Subject: [PATCH 601/720] Manual changes to the async chapter snapshot Some of these could be scripted but I'm just trying to get this done right now. --- nostarch/chapter17.md | 1316 ++++++++++++++++++----------------------- 1 file changed, 579 insertions(+), 737 deletions(-) diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index 57e90e6704..97d8b7ce39 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -1,9 +1,3 @@ -<!-- DO NOT EDIT THIS FILE. - -This file is periodically generated from the content in the `/src/` -directory, so all fixes need to be made in `/src/`. ---> - [TOC] ## Async and Await @@ -33,14 +27,13 @@ other work while waiting for the network call to finish—so, again, your operating system will invisibly interrupt your program so other things can happen while the network operation is still ongoing. - > - > Note: The video export is the kind of operation which is often described as - > “CPU-bound” or “compute-bound”. It’s limited by the speed of the computer’s - > ability to process data within the *CPU* or *GPU*, and how much of that speed - > it can use. The video download is the kind of operation which is often - > described as “IO-bound,” because it’s limited by the speed of the computer’s - > *input and output*. It can only go as fast as the data can be sent across the - > network. +> Note: The video export is the kind of operation which is often described as +> “CPU-bound” or “compute-bound”. It’s limited by the speed of the computer’s +> ability to process data within the *CPU* or *GPU*, and how much of that speed +> it can use. The video download is the kind of operation which is often +> described as “IO-bound,” because it’s limited by the speed of the computer’s +> *input and output*. It can only go as fast as the data can be sent across the +> network. In both of these examples, the operating system’s invisible interrupts provide a form of concurrency. That concurrency only happens at the level of a whole @@ -56,12 +49,11 @@ time. Many operating system APIs for interacting with the network are *blocking*, though. That is, these APIs block the program’s progress until the data that they are processing is completely ready. - > - > Note: This is how *most* function calls work, if you think about it! However, - > we normally reserve the term “blocking” for function calls which interact with - > files, the network, or other resources on the computer, because those are the - > places where an individual program would benefit from the operation being - > *non*-blocking. +> Note: This is how *most* function calls work, if you think about it! However, +> we normally reserve the term “blocking” for function calls which interact with +> files, the network, or other resources on the computer, because those are the +> places where an individual program would benefit from the operation being +> *non*-blocking. We could avoid blocking our main thread by spawning a dedicated thread to download each file. However, we would eventually find that the overhead of those @@ -80,9 +72,9 @@ between parallelism and concurrency. ### Parallelism and Concurrency -In the previous chapter, we treated parallelism and concurrency as mostly -interchangeable. Now we need to distinguish between them more precisely, because -the differences will show up as we start working. +In the “Fearless Concurrency” chapter on page XX, we treated parallelism and +concurrency as mostly interchangeable. Now we need to distinguish between them +more precisely, because the differences will show up as we start working. Consider the different ways a team could split up work on a software project. We could assign a single individual multiple tasks, or we could assign one task per @@ -95,25 +87,18 @@ to the other. You’re just one person, so you can’t make progress on both tas at the exact same time—but you can multi-task, making progress on multiple tasks by switching between them. -<figure> - -<img alt="Concurrent work flow" src="img/trpl17-01.svg" class="center" /> +<img alt="Concurrent work flow" src="img/trpl17-01.svg" /> -<figcaption>Figure 17-1: A concurrent workflow, switching between Task A and Task B</figcaption> - -</figure> +Figure 17-1: A concurrent workflow, switching between Task A and Task B When you agree to split up a group of tasks between the people on the team, with each person taking one task and working on it alone, this is *parallelism*. Each person on the team can make progress at the exact same time. -<figure> - -<img alt="Concurrent work flow" src="img/trpl17-02.svg" class="center" /> - -<figcaption>Figure 17-2: A parallel workflow, where work happens on Task A and Task B independently</figcaption> +<img alt="Concurrent work flow" src="img/trpl17-02.svg" /> -</figure> +Figure 17-2: A parallel workflow, where work happens on Task A and Task B +independently With both of these situations, you might have to coordinate between different tasks. Maybe you *thought* the task that one person was working on was totally @@ -198,8 +183,8 @@ everything you need to know as we go. To keep this chapter focused on learning async, rather than juggling parts of the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust Programming Language”). It re-exports all the types, traits, and functions -you’ll need, primarily from the `futures` at *https://crates.io/crates/futures* and `tokio` at *https://tokio.rs* -crates. +you’ll need, primarily from the `futures` and `tokio` crates, available on +*https://crates.io*. * The `futures` crate is an official home for Rust experimentation for async code, and is actually where the `Future` type was originally designed. @@ -211,7 +196,8 @@ crates. In some cases, `trpl` also renames or wraps the original APIs to let us stay focused on the details relevant to this chapter. If you want to understand what -the crate does, we encourage you to check out its source code at *https://github.com/rust-lang/book/tree/main/packages/trpl*. +the crate does, we encourage you to check out its source code at +*https://github.com/rust-lang/book/tree/main/packages/trpl*. You’ll be able to see what crate each re-export comes from, and we’ve left extensive comments explaining what the crate does. @@ -232,7 +218,6 @@ finishes that whole process first. Let’s start by writing a function that takes one page URL as a parameter, makes a request to it, and returns the text of the title element: - Filename: src/main.rs ``` @@ -264,18 +249,18 @@ is also async. We have to explicitly await both of these futures, because futures in Rust are *lazy*: they don’t do anything until you ask them to with `await`. (In fact, Rust will show a compiler warning if you don’t use a future.) This should -remind you of our discussion of iterators back in Chapter 13 at *ch13-02-iterators.html*. -Iterators do nothing unless you call their `next` method—whether directly, or -using `for` loops or methods such as `map` which use `next` under the hood. With -futures, the same basic idea applies: they do nothing unless you explicitly ask -them to. This laziness allows Rust to avoid running async code until it’s -actually needed. - - > - > Note: This is different from the behavior we saw when using `thread::spawn` in - > the previous chapter, where the closure we passed to another thread started - > running immediately. It’s also different from how many other languages - > approach async! But it’s important for Rust. We’ll see why that is later. +remind you of our discussion of iterators back in the “Processing a Series of +Items with Iterators” section of Chapter 13 on page XX. Iterators do nothing +unless you call their `next` method—whether directly, or using `for` loops or +methods such as `map` which use `next` under the hood. With futures, the same +basic idea applies: they do nothing unless you explicitly ask them to. This +laziness allows Rust to avoid running async code until it’s actually needed. + +> Note: This is different from the behavior we saw when using `thread::spawn` in +> the “Creating a New Thread with `spawn`” section of Chapter 16 on page XX, +> where the closure we passed to another thread started running immediately. +> It’s also different from how many other languages approach async! But it’s +> important for Rust. We’ll see why that is later. Once we have `response_text`, we can then parse it into an instance of the `Html` type using `Html::parse`. Instead of a raw string, we now have a data @@ -297,14 +282,13 @@ this because it makes chains of methods much nicer to work with. As a result, we can change the body of `page_url_for` to chain the `trpl::get` and `text` function calls together with `await` between them, as shown in Listing 17-2: - Filename: src/main.rs ``` let response_text = trpl::get(url).await.text().await; ``` -Listing 17-2: Chaining with the <code>await</code> keyword +Listing 17-2: Chaining with the `await` keyword With that, we have successfully written our first async function! Before we add some code in `main` to call it, let’s talk a little more about what we’ve @@ -338,7 +322,7 @@ fn page_title(url: &str) -> impl Future<Output = Option<String>> + '_ { Let’s walk through each part of the transformed version: * It uses the `impl Trait` syntax we discussed back in the “Traits as - Parameters” at *ch10-02-traits.html#traits-as-parameters* section in Chapter 10. + Parameters” section in Chapter 10 on page XX. * The returned trait is a `Future`, with an associated type of `Output`. Notice that the `Output` type is `Option<String>`, which is the same as the the original return type from the `async fn` version of `page_title`. @@ -359,13 +343,13 @@ Let’s walk through each part of the transformed version: reference which could be involved, but we *do* have to be explicit that the resulting `Future` is bound by that lifetime. -Now we can call `page_title` in `main`. To start, we’ll just get the title -for a single page. In Listing 17-3, we follow the same pattern we used for -getting command line arguments back in Chapter 12. Then we pass the first URL -`page_title`, and await the result. Because the value produced by the future is -an `Option<String>`, we use a `match` expression to print different messages to -account for whether the page had a `<title>`. - +Now we can call `page_title` in `main`. To start, we’ll just get the title for +a single page. In Listing 17-3, we follow the same pattern we used for getting +command line arguments back in the “Accepting Command Line Arguments” section +of Chapter 12 on page XX. Then we pass the first URL `page_title`, and await +the result. Because the value produced by the future is an `Option<String>`, we +use a `match` expression to print different messages to account for whether the +page had a `<title>`. Filename: src/main.rs @@ -380,18 +364,13 @@ async fn main() { } ``` -Listing 17-3: Calling the <code>page_title</code> function from <code>main</code> with a user-supplied argument +Listing 17-3: Calling the `page_title` function from `main` with a +user-supplied argument Unfortunately, this doesn’t compile. The only place we can use the `await` keyword is in async functions or blocks, and Rust won’t let us mark the special `main` function as `async`. -<!-- manual-regeneration -cd listings/ch17-async-await/listing-17-03 -cargo build -copy just the compiler error ---> - ``` error[E0752]: `main` function is not allowed to be `async` --> src/main.rs:6:1 @@ -429,11 +408,8 @@ we tried to do in Listing 17-3. However, for most of the examples in the chapter async function call, so instead we’ll pass an `async` block and explicitly await the result of calling `page_title`, as in Listing 17-4. - Filename: src/main.rs -<!-- should_panic,noplayground because mdbook does not pass args --> - ``` trpl::run(async { let url = &args[1]; @@ -444,7 +420,7 @@ Filename: src/main.rs }) ``` -Listing 17-4: Awaiting an async block with <code>trpl::run</code> +Listing 17-4: Awaiting an async block with `trpl::run` When we run this, we get the behavior we might have expected initially: @@ -494,20 +470,17 @@ but `main` is the starting point for the program! Instead, we call the `trpl::run` function in `main`, which sets up a runtime and runs the future returned by the `async` block until it returns `Ready`. - > - > Note: some runtimes provide macros to make it so you *can* write an async main - > function. Those macros rewrite `async fn main() { ... }` to be a normal `fn main` which does the same thing we did by hand in Listing 17-5: call a - > function which runs a future to completion the way `trpl::run` does. +> Note: some runtimes provide macros to make it so you *can* write an async +> main function. Those macros rewrite `async fn main() { ... }` to be a normal +> `fn main` which does the same thing we did by hand in Listing 17-5: call a +> function which runs a future to completion the way `trpl::run` does. Let’s put these pieces together and see how we can write concurrent code, by calling `page_title` with two different URLs passed in from the command line and racing them. - Filename: src/main.rs -<!-- should_panic,noplayground because mdbook does not pass args --> - ``` use trpl::{Either, Html}; @@ -541,7 +514,7 @@ async fn page_title(url: &str) -> (&str, Option<String>) { } ``` -Listing 17-5: +Listing 17-5: Calling `page_title` for two URLs to see which returns first In Listing 17-5, we begin by calling `page_title` for each of the user-supplied URLs. We save the futures produced by calling `page_title` as `title_fut_1` and @@ -550,11 +523,10 @@ and we haven’t yet awaited them. Then we pass the futures to `trpl::race`, which returns a value to indicate which of the futures passed to it finishes first. - > - > Note: Under the hood, `race` is built on a more general function, `select`, - > which you will encounter more often in real-world Rust code. A `select` - > function can do a lot of things that `trpl::race` function can’t, but it also - > has some additional complexity that we can skip over for now. +> Note: Under the hood, `race` is built on a more general function, `select`, +> which you will encounter more often in real-world Rust code. A `select` +> function can do a lot of things that `trpl::race` function can’t, but it also +> has some additional complexity that we can skip over for now. Either future can legitimately “win,” so it doesn’t make sense to return a `Result`. Instead, `race` returns a type we haven’t seen before, @@ -587,12 +559,10 @@ others, while in other cases which site “wins” varies from run to run. More importantly, you’ve learned the basics of working with futures, so we can now dig into even more of the things we can *do* with async. -<!-- TODO: map source link version to version of Rust? --> - ## Concurrency With Async In this section, we’ll apply async to some of the same concurrency challenges -we tackled with threads in chapter 16. Because we already talked about a lot of +we tackled with threads in Chapter 16. Because we already talked about a lot of the key ideas there, in this section we’ll focus on what’s different between threads and futures. @@ -604,12 +574,12 @@ performance characteristics. ### Counting -The first task we tackled in Chapter 16 was counting up on two separate threads. -Let’s do the same using async. The `trpl` crate supplies a `spawn_task` function -which looks very similar to the `thread::spawn` API, and a `sleep` function -which is an async version of the `thread::sleep` API. We can use these together -to implement the same counting example as with threads, in Listing 17-6. - +The first task we tackled in the “Creating a New Thread with spawn” section of +Chapter 16 on page XX was counting up on two separate threads. Let’s do the +same using async. The `trpl` crate supplies a `spawn_task` function which looks +very similar to the `thread::spawn` API, and a `sleep` function which is an +async version of the `thread::sleep` API. We can use these together to +implement the same counting example as with threads, in Listing 17-6. Filename: src/main.rs @@ -633,15 +603,14 @@ fn main() { } ``` -Listing 17-6: Using <code>spawn_task</code> to count with two +Listing 17-6: Using `spawn_task` to count with two As our starting point, we set up our `main` function with `trpl::run`, so that our top-level function can be async. - > - > Note: From this point forward in the chapter, every example will include this - > exact same wrapping code with `trpl::run` in `main`, so we’ll often skip it - > just as we do with `main`. Don’t forget to include it in your code! +> Note: From this point forward in the chapter, every example will include this +> exact same wrapping code with `trpl::run` in `main`, so we’ll often skip it +> just as we do with `main`. Don’t forget to include it in your code! Then we write two loops within that block, each with a `trpl::sleep` call in it, which waits for half a second (500 milliseconds) before sending the next @@ -652,10 +621,6 @@ This does something similar to the thread-based implementation—including the fact that you may see the messages appear in a different order in your own terminal when you run it. -<!-- Not extracting output because changes to this output aren't significant; -the changes are likely to be due to the threads running differently rather than -changes in the compiler --> - ``` hi number 1 from the second task! hi number 1 from the first task! @@ -677,33 +642,28 @@ In Listing 17-7, we can use `await` to do the same thing, because the task handle itself is a future. Its `Output` type is a `Result`, so we also unwrap it after awaiting it. - Filename: src/main.rs ``` - let handle = trpl::spawn_task(async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(500)).await; - } - }); +let handle = trpl::spawn_task(async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(500)).await; + } +}); - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(500)).await; - } +for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(500)).await; +} - handle.await.unwrap(); +handle.await.unwrap(); ``` -Listing 17-7: Using <code>await</code> with a join handle to run a task to completion +Listing 17-7: Using `await` with a join handle to run a task to completion This updated version runs till *both* loops finish. -<!-- Not extracting output because changes to this output aren't significant; -the changes are likely to be due to the threads running differently rather than -changes in the compiler --> - ``` hi number 1 from the second task! hi number 1 from the first task! @@ -730,44 +690,40 @@ async blocks compile to anonymous futures, we can put each loop in an async block and have the runtime run them both to completion using the `trpl::join` function. -In Chapter 16, we showed how to use the `join` method on the `JoinHandle` type -returned when you call `std::thread::spawn`. The `trpl::join` function is -similar, but for futures. When you give it two futures, it produces a single new -future whose output is a tuple with the output of each of the futures you passed -in once *both* complete. Thus, in Listing 17-8, we use `trpl::join` to wait for -both `fut1` and `fut2` to finish. We do *not* await `fut1` and `fut2`, but -instead the new future produced by `trpl::join`. We ignore the output, because -it’s just a tuple with two unit values in it. - +In the “Waiting for All Threads to Finish Using `join` Handles” section of +Chapter 16 on page XX, we showed how to use the `join` method on the +`JoinHandle` type returned when you call `std::thread::spawn`. The `trpl::join` +function is similar, but for futures. When you give it two futures, it produces +a single new future whose output is a tuple with the output of each of the +futures you passed in once *both* complete. Thus, in Listing 17-8, we use +`trpl::join` to wait for both `fut1` and `fut2` to finish. We do *not* await +`fut1` and `fut2`, but instead the new future produced by `trpl::join`. We +ignore the output, because it’s just a tuple with two unit values in it. Filename: src/main.rs ``` - let fut1 = async { - for i in 1..10 { - println!("hi number {i} from the first task!"); - trpl::sleep(Duration::from_millis(500)).await; - } - }; +let fut1 = async { + for i in 1..10 { + println!("hi number {i} from the first task!"); + trpl::sleep(Duration::from_millis(500)).await; + } +}; - let fut2 = async { - for i in 1..5 { - println!("hi number {i} from the second task!"); - trpl::sleep(Duration::from_millis(500)).await; - } - }; +let fut2 = async { + for i in 1..5 { + println!("hi number {i} from the second task!"); + trpl::sleep(Duration::from_millis(500)).await; + } +}; - trpl::join(fut1, fut2).await; +trpl::join(fut1, fut2).await; ``` -Listing 17-8: Using <code>trpl::join</code> to await two anonymous futures +Listing 17-8: Using `trpl::join` to await two anonymous futures When we run this, we see both futures run to completion: -<!-- Not extracting output because changes to this output aren't significant; -the changes are likely to be due to the threads running differently rather than -changes in the compiler --> - ``` hi number 1 from the first task! hi number 1 from the second task! @@ -811,34 +767,36 @@ each case *before* running the code! Sharing data between futures will also be familiar: we’ll use message passing again, but this with async versions of the types and functions. We’ll take a -slightly different path than we did in Chapter 16, to illustrate some of the key -differences between thread-based and futures-based concurrency. In Listing 17-9, -we’ll begin with just a single async block—*not* spawning a separate task as -we spawned a separate thread. - +slightly different path than we did in the “Using Message Passing to Transfer +Data Between Threads” section of Chapter 16 on page XX, to illustrate some of +the key differences between thread-based and futures-based concurrency. In +Listing 17-9, we’ll begin with just a single async block—*not* spawning a +separate task as we spawned a separate thread. Filename: src/main.rs ``` - let (tx, mut rx) = trpl::channel(); +let (tx, mut rx) = trpl::channel(); - let val = String::from("hi"); - tx.send(val).unwrap(); +let val = String::from("hi"); +tx.send(val).unwrap(); - let received = rx.recv().await.unwrap(); - println!("Got: {received}"); +let received = rx.recv().await.unwrap(); +println!("Got: {received}"); ``` -Listing 17-9: Creating an async channel and assigning the two halves to <code>tx</code> and <code>rx</code> +Listing 17-9: Creating an async channel and assigning the two halves to `tx` +and `rx` Here, we use `trpl::channel`, an async version of the multiple-producer, -single-consumer channel API we used with threads back in Chapter 16. The async -version of the API is only a little different from the thread-based version: it -uses a mutable rather than an immutable receiver `rx`, and its `recv` method -produces a future we need to await rather than producing the value directly. Now -we can send messages from the sender to the receiver. Notice that we don’t have -to spawn a separate thread or even a task; we merely need to await the `rx.recv` -call. +single-consumer channel API we used with threads back in the “Using Message +Passing to Transfer Data Between Threads” section of Chapter 16 on page XX. The +async version of the API is only a little different from the thread-based +version: it uses a mutable rather than an immutable receiver `rx`, and its +`recv` method produces a future we need to await rather than producing the +value directly. Now we can send messages from the sender to the receiver. +Notice that we don’t have to spawn a separate thread or even a task; we merely +need to await the `rx.recv` call. The synchronous `Receiver::recv` method in `std::mpsc::channel` blocks until it receives a message. The `trpl::Receiver::recv` method does not, because it @@ -847,13 +805,12 @@ a message is received or the send side of the channel closes. By contrast, we don’t await the `send` call, because it doesn’t block. It doesn’t need to, because the channel we’re sending it into is unbounded. - > - > Note: Because all of this async code runs in an async block in a `trpl::run` - > call, everything within it can avoid blocking. However, the code *outside* it - > will block on the `run` function returning. That is the whole point of the - > `trpl::run` function: it lets you *choose* where to block on some set of async - > code, and thus where to transition between sync and async code. In most async - > runtimes, `run` is actually named `block_on` for exactly this reason. +> Note: Because all of this async code runs in an async block in a `trpl::run` +> call, everything within it can avoid blocking. However, the code *outside* it +> will block on the `run` function returning. That is the whole point of the +> `trpl::run` function: it lets you *choose* where to block on some set of async +> code, and thus where to transition between sync and async code. In most async +> runtimes, `run` is actually named `block_on` for exactly this reason. Notice two things about this example: First, the message will arrive right away! Second, although we use a future here, there’s no concurrency yet. Everything @@ -863,32 +820,30 @@ involved. Let’s address the first part by sending a series of messages, and sleep in between them, as shown in Listing 17-10: -<!-- We cannot test this one because it never stops! --> - - Filename: src/main.rs ``` - let (tx, mut rx) = trpl::channel(); +let (tx, mut rx) = trpl::channel(); - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; +let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), +]; - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_millis(500)).await; - } +for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; +} - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } +while let Some(value) = rx.recv().await { + println!("received '{value}'"); +} ``` -Listing 17-10: Sending and receiving multiple messages over the async channel and sleeping with an <code>await</code> between each message +Listing 17-10: Sending and receiving multiple messages over the async channel +and sleeping with an `await` between each message In addition to sending the messages, we need to receive them. In this case, we could do that manually, by just doing `rx.recv().await` four times, because we @@ -900,11 +855,10 @@ In Listing 16-10, we used a `for` loop to process all the items received from a synchronous channel. However, Rust doesn’t yet have a way to write a `for` loop over an *asynchronous* series of items. Instead, we need to use a new kind of loop we haven’t seen before, the `while let` conditional loop. A `while let` -loop is the loop version of the `if let` construct we saw back in Chapter 6. The -loop will continue executing as long as the pattern it specifies continues to -match the value. - -<!-- TODO: update text in ch. 19 to account for our having introduced this. --> +loop is the loop version of the `if let` construct we saw back in the “Concise +Control Flow with `if let`” section in Chapter 6 on page XX. The loop will +continue executing as long as the pattern it specifies continues to match the +value. The `rx.recv` call produces a `Future`, which we await. The runtime will pause the `Future` until it is ready. Once a message arrives, the future will resolve @@ -945,36 +899,34 @@ just as in the counting example. Once again, we await the result of calling in sequence, we would just end up back in a sequential flow—exactly what we’re trying *not* to do. -<!-- We cannot test this one because it never stops! --> - - Filename: src/main.rs ``` - let tx_fut = async { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; +let tx_fut = async { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_millis(500)).await; - } - }; + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } +}; - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; +let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } +}; - trpl::join(tx_fut, rx_fut).await; +trpl::join(tx_fut, rx_fut).await; ``` -Listing 17-11: Separating <code>send</code> and <code>recv</code> into their own <code>async</code> blocks and awaiting the futures for those blocks +Listing 17-11: Separating `send` and `recv` into their own `async` blocks and +awaiting the futures for those blocks With the updated code in Listing 17-11, the messages get printed at 500-millisecond intervals, rather than all in a rush after two seconds. @@ -1004,46 +956,48 @@ to make sure that `tx` gets dropped *before* the end of the function. Right now, the async block where we send the messages only borrows `tx` because sending a message doesn’t require ownership, but if we could move `tx` into -that async block, it would be dropped once that block ends. In Chapter 13, we -learned how to use the `move` keyword with closures, and in Chapter 16, we saw -that we often need to move data into closures when working with threads. The -same basic dynamics apply to async blocks, so the `move` keyword works with -async blocks just as it does with closures. +that async block, it would be dropped once that block ends. In the “Capturing +References or Moving Ownership” section of Chapter 13 on page XX, we learned +how to use the `move` keyword with closures, and in the “Using `move` Closures +with Threads” section of Chapter 16 on page XX, we saw that we often need to +move data into closures when working with threads. The same basic dynamics +apply to async blocks, so the `move` keyword works with async blocks just as it +does with closures. In Listing 17-12, we change the async block for sending messages from a plain `async` block to an `async move` block. When we run *this* version of the code, it shuts down gracefully after the last message is sent and received. - Filename: src/main.rs ``` - let (tx, mut rx) = trpl::channel(); +let (tx, mut rx) = trpl::channel(); - let tx_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; +let tx_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_millis(500)).await; - } - }; + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } +}; - let rx_fut = async { - while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); - } - }; +let rx_fut = async { + while let Some(value) = rx.recv().await { + eprintln!("received '{value}'"); + } +}; - trpl::join(tx_fut, rx_fut).await; +trpl::join(tx_fut, rx_fut).await; ``` -Listing 17-12: A working example of sending and receiving messages between futures which correctly shuts down when complete +Listing 17-12: A working example of sending and receiving messages between +futures which correctly shuts down when complete This async channel is also a multiple-producer channel, so we can call `clone` on `tx` if we want to send messages from multiple futures. In Listing 17-13, we @@ -1059,48 +1013,47 @@ that both `tx` and `tx1` get dropped when those blocks finish. Otherwise we’ll end up back in the same infinite loop we started out in. Finally, we switch from `trpl::join` to `trpl::join3` to handle the additional future. - Filename: src/main.rs ``` - let (tx, mut rx) = trpl::channel(); +let (tx, mut rx) = trpl::channel(); - let tx1 = tx.clone(); - let tx1_fut = async move { - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; +let tx1 = tx.clone(); +let tx1_fut = async move { + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - for val in vals { - tx1.send(val).unwrap(); - trpl::sleep(Duration::from_millis(500)).await; - } - }; + for val in vals { + tx1.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } +}; - let rx_fut = async { - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } - }; +let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } +}; - let tx_fut = async move { - let vals = vec![ - String::from("more"), - String::from("messages"), - String::from("for"), - String::from("you"), - ]; - - for val in vals { - tx.send(val).unwrap(); - trpl::sleep(Duration::from_millis(1500)).await; - } - }; +let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(1500)).await; + } +}; - trpl::join3(tx1_fut, tx_fut, rx_fut).await; +trpl::join3(tx1_fut, tx_fut, rx_fut).await; ``` Listing 17-13: Using multiple producers with async blocks @@ -1109,10 +1062,6 @@ Now we see all the messages from both sending futures. Because the sending futures use slightly different delays after sending, the messages are also received at those different intervals. -<!-- Not extracting output because changes to this output aren't significant; -the changes are likely to be due to the threads running differently rather than -changes in the compiler --> - ``` received 'hi' received 'more' @@ -1137,14 +1086,13 @@ arbitrary number of arguments. It also handles awaiting the futures itself. Thus, we could rewrite the code from Listing 17-13 to use `join!` instead of `join3`, as in Listing 17-14: - Filename: src/main.rs ``` - trpl::join!(tx1_fut, tx_fut, rx_fut); +trpl::join!(tx1_fut, tx_fut, rx_fut); ``` -Listing 17-14: Using <code>join!</code> to wait for multiple futures +Listing 17-14: Using `join!` to wait for multiple futures This is definitely a nice improvement over needing to swap between `join` and `join3` and `join4` and so on! However, even this macro form only works when we @@ -1154,27 +1102,21 @@ collection to complete is a common pattern. To check all the futures in some collection, we’ll need to iterate over and join on *all* of them. The `trpl::join_all` function accepts any type which -implements the `Iterator` trait, which we learned about back in Chapter 13, so -it seems like just the ticket. Let’s try putting our futures in a vector, and -replace `join!` with `join_all`. - +implements the `Iterator` trait, which we learned about back in “The Iterator +Trait and the next Method” section of Chapter 13 on page XX, so it seems like +just the ticket. Let’s try putting our futures in a vector, and replace `join!` +with `join_all`. ``` - let futures = vec![tx1_fut, rx_fut, tx_fut]; +let futures = vec![tx1_fut, rx_fut, tx_fut]; - trpl::join_all(futures).await; +trpl::join_all(futures).await; ``` -Listing 17-15: Storing anonymous futures in a vector and calling <code>join_all</code> +Listing 17-15: Storing anonymous futures in a vector and calling `join_all` Unfortunately, this doesn’t compile. Instead, we get this error: -<!-- manual-regeneration -cd listings/ch17-async-await/listing-17-16/ -cargo build -copy just the compiler error ---> - ``` error[E0308]: mismatched types --> src/main.rs:43:37 @@ -1213,35 +1155,35 @@ by the compiler for async blocks. You can’t put two different hand-written structs in a `Vec`, and the same thing applies to the different structs generated by the compiler. -To make this work, we need to use *trait objects*, just as we did in “Returning -Errors from the run function” at *ch12-03-improving-error-handling-and-modularity.html* in Chapter 12. (We’ll cover trait objects -in detail in Chapter 18.) Using trait objects lets us treat each of the -anonymous futures produced by these types as the same type, because all of them -implement the `Future` trait. - - > - > Note: In Chapter 8, we discussed another way to include multiple types in a - > `Vec`: using an enum to represent each of the different types which can - > appear in the vector. We can’t do that here, though. For one thing, we have - > no way to name the different types, because they are anonymous. For another, - > the reason we reached for a vector and `join_all` in the first place was to be - > able to work with a dynamic collection of futures where we don’t know what - > they will all be until runtime. +To make this work, we need to use *trait objects*, just as we did in the +“Returning Errors from the run function” section in Chapter 12 on page XX. +(We’ll cover trait objects in detail in Chapter 18.) Using trait objects lets +us treat each of the anonymous futures produced by these types as the same +type, because all of them implement the `Future` trait. + +> Note: In the “Using an Enum to Store Multiple Types” section of Chapter 8 on +> page XX, we discussed another way to include multiple types in a `Vec`: using +> an enum to represent each of the different types which can appear in the +> vector. We can’t do that here, though. For one thing, we have no way to name +> the different types, because they are anonymous. For another, the reason we +> reached for a vector and `join_all` in the first place was to be able to work +> with a dynamic collection of futures where we don’t know what they will all +> be until runtime. We start by wrapping each of the futures in the `vec!` in a `Box::new`, as shown in Listing 17-16. - Filename: src/main.rs ``` - let futures = - vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; +let futures = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; - trpl::join_all(futures).await; +trpl::join_all(futures).await; ``` -Listing 17-16: Trying to use <code>Box::new</code> to align the types of the futures in a <code>Vec</code> +Listing 17-16: Trying to use `Box::new` to align the types of the futures in a +`Vec` Unfortunately, this still doesn’t compile. In fact, we have the same basic error we did before, but we get one for both the second and third `Box::new` @@ -1249,15 +1191,15 @@ calls, and we also get new errors referring to the `Unpin` trait. We will come back to the `Unpin` errors in a moment. First, let’s fix the type errors on the `Box::new` calls, by explicitly annotating the type of the `futures` variable: - Filename: src/main.rs ``` - let futures: Vec<Box<dyn Future<Output = ()>>> = - vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; +let futures: Vec<Box<dyn Future<Output = ()>>> = + vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; ``` -Listing 17-17: Fixing the rest of the type mismatch errors by using an explicit type declaration +Listing 17-17: Fixing the rest of the type mismatch errors by using an explicit +type declaration The type we had to write here is a little involved, so let’s walk through it: @@ -1271,12 +1213,6 @@ That already made a big difference. Now when we run the compiler, we only have the errors mentioning `Unpin`. Although there are three of them, notice that each is very similar in its contents. -<!-- manual-regeneration -cd listings/ch17-async-await/listing-17-17 -cargo build -copy *only* the errors ---> - ``` error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned --> src/main.rs:46:24 @@ -1290,7 +1226,7 @@ error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned consider using `Box::pin` if you need to access the pinned value outside of the current scope = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` note: required by a bound in `join_all` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 + --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 | 102 | pub fn join_all<I>(iter: I) -> JoinAll<I::Item> | -------- required by a bound in this function @@ -1308,7 +1244,7 @@ error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned consider using `Box::pin` if you need to access the pinned value outside of the current scope = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll<F> | ------- required by a bound in this struct @@ -1326,7 +1262,7 @@ error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned consider using `Box::pin` if you need to access the pinned value outside of the current scope = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll<F> | ------- required by a bound in this struct @@ -1347,22 +1283,17 @@ unstuck! In Listing 17-18, we start by updating the type annotation for `futures`, with a `Pin` wrapping each `Box`. Second, we use `Box::pin` to pin the futures themselves. - Filename: src/main.rs ``` - let futures: Vec<Pin<Box<dyn Future<Output = ()>>>> = - vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; +let futures: Vec<Pin<Box<dyn Future<Output = ()>>>> = + vec![Box::pin(tx1_fut), Box::pin(rx_fut), Box::pin(tx_fut)]; ``` -Listing 17-18: Using <code>Pin</code> and <code>Box::pin</code> to make the <code>Vec</code> type check +Listing 17-18: Using `Pin` and `Box::pin` to make the `Vec` type check If we compile and run this, we finally get the output we hoped for: -<!-- Not extracting output because changes to this output aren't significant; -the changes are likely to be due to the threads running differently rather than -changes in the compiler --> - ``` received 'hi' received 'more' @@ -1391,32 +1322,33 @@ which is what we need them to be in the `Vec`. We therefore `pin!` each future when we define it, and define `futures` as a `Vec` containing pinned mutable references to the dynamic `Future` type, as in Listing 17-19. - Filename: src/main.rs ``` - let tx1_fut = pin!(async move { - // --snip-- - }); +let tx1_fut = pin!(async move { + // --snip-- +}); - let rx_fut = pin!(async { - // --snip-- - }); +let rx_fut = pin!(async { + // --snip-- +}); - let tx_fut = pin!(async move { - // --snip-- - }); +let tx_fut = pin!(async move { + // --snip-- +}); - let futures: Vec<Pin<&mut dyn Future<Output = ()>>> = - vec![tx1_fut, rx_fut, tx_fut]; +let futures: Vec<Pin<&mut dyn Future<Output = ()>>> = + vec![tx1_fut, rx_fut, tx_fut]; ``` -Listing 17-19: Using <code>Pin</code> directly with the <code>pin!</code> macro to avoid unnecessary heap allocations +Listing 17-19: Using `Pin` directly with the `pin!` macro to avoid unnecessary +heap allocations We got this far by ignoring the fact that we might have different `Output` types. For example, in Listing 17-20, the anonymous future for `a` implements -`Future<Output = u32>`, the anonymous future for `b` implements `Future<Output = &str>`, and the anonymous future for `c` implements `Future<Output = bool>`. - +`Future<Output = u32>`, the anonymous future for `b` implements +`Future<Output = &str>`, and the anonymous future for `c` implements +`Future<Output = bool>`. Filename: src/main.rs @@ -1455,30 +1387,29 @@ In Listing 17-21, we once again use `trpl::race` to run two futures, `slow` and pauses for some amount of time by calling and awaiting `sleep`, and then prints another message when it finishes. Then we pass both to `trpl::race` and wait for one of them to finish. (The outcome here won’t be too surprising: `fast` wins!) -Unlike when we used `race` back in Our First Async Program at *ch17-01-futures-and-syntax.html#our-first-async-program*, we -just ignore the `Either` instance it returns here, because all of the -interesting behavior happens in the body of the async blocks. - +Unlike when we used `race` back in the “Our First Async Program” section of this +chapter on page XX, we just ignore the `Either` instance it returns here, +because all of the interesting behavior happens in the body of the async blocks. Filename: src/main.rs ``` - let slow = async { - println!("'slow' started."); - trpl::sleep(Duration::from_millis(100)).await; - println!("'slow' finished."); - }; +let slow = async { + println!("'slow' started."); + trpl::sleep(Duration::from_millis(100)).await; + println!("'slow' finished."); +}; - let fast = async { - println!("'fast' started."); - trpl::sleep(Duration::from_millis(50)).await; - println!("'fast' finished."); - }; +let fast = async { + println!("'fast' started."); + trpl::sleep(Duration::from_millis(50)).await; + println!("'fast' finished."); +}; - trpl::race(slow, fast).await; +trpl::race(slow, fast).await; ``` -Listing 17-21: Using <code>race</code> to get the result of whichever future finishes first +Listing 17-21: Using `race` to get the result of whichever future finishes first Notice that if you flip the order of the arguments to `race`, the order of the “started” messages changes, even though the `fast` future always completes @@ -1489,11 +1420,11 @@ to poll first. Regardless of whether the implementation of race we’re using is fair, though, *one* of the futures will run up to the first `await` in its body before another task can start. -Recall from Our First Async Program at *ch17-01-futures-and-syntax.html#our-first-async-program* that at each await point, -Rust gives a runtime a chance to pause the task and switch to another one if the -future being awaited isn’t ready. The inverse is also true: Rust *only* pauses -async blocks and hands control back to a runtime at an await point. Everything -between await points is synchronous. +Recall from the “Our First Async Program” section of this chapter on page XX +that at each await point, Rust gives a runtime a chance to pause the task and +switch to another one if the future being awaited isn’t ready. The inverse is +also true: Rust *only* pauses async blocks and hands control back to a runtime +at an await point. Everything between await points is synchronous. That means if you do a bunch of work in an async block without an await point, that future will block any other futures from making progress. You may sometimes @@ -1517,7 +1448,6 @@ function. It uses `std::thread::sleep` instead of `trpl::sleep` so that calling `slow` to stand in for real-world operations which are both long-running and blocking. - Filename: src/main.rs ``` @@ -1527,48 +1457,41 @@ fn slow(name: &str, ms: u64) { } ``` -Listing 17-22: Using <code>thread::sleep</code> to simulate slow operations +Listing 17-22: Using `thread::sleep` to simulate slow operations In Listing 17-23, we use `slow` to emulate doing this kind of CPU-bound work in a pair of futures. To begin, each future only hands control back to the runtime *after* carrying out a bunch of slow operations. - Filename: src/main.rs ``` - let a = async { - println!("'a' started."); - slow("a", 30); - slow("a", 10); - slow("a", 20); - trpl::sleep(Duration::from_millis(50)).await; - println!("'a' finished."); - }; +let a = async { + println!("'a' started."); + slow("a", 30); + slow("a", 10); + slow("a", 20); + trpl::sleep(Duration::from_millis(50)).await; + println!("'a' finished."); +}; - let b = async { - println!("'b' started."); - slow("b", 75); - slow("b", 10); - slow("b", 15); - slow("b", 350); - trpl::sleep(Duration::from_millis(50)).await; - println!("'b' finished."); - }; +let b = async { + println!("'b' started."); + slow("b", 75); + slow("b", 10); + slow("b", 15); + slow("b", 350); + trpl::sleep(Duration::from_millis(50)).await; + println!("'b' finished."); +}; - trpl::race(a, b).await; +trpl::race(a, b).await; ``` -Listing 17-23: Using <code>thread::sleep</code> to simulate slow operations +Listing 17-23: Using `thread::sleep` to simulate slow operations If you run this, you will see this output: -<!-- manual-regeneration -cd listings/ch17-async-await/listing-17-24/ -cargo run -copy just the output ---> - ``` 'a' started. 'a' ran for 30ms @@ -1595,48 +1518,41 @@ removed the `trpl::sleep` at the end of the `a` future, it would complete without the `b` future running *at all*. Maybe we could use the `sleep` function as a starting point? - Filename: src/main.rs ``` - let one_ms = Duration::from_millis(1); +let one_ms = Duration::from_millis(1); - let a = async { - println!("'a' started."); - slow("a", 30); - trpl::sleep(one_ms).await; - slow("a", 10); - trpl::sleep(one_ms).await; - slow("a", 20); - trpl::sleep(one_ms).await; - println!("'a' finished."); - }; +let a = async { + println!("'a' started."); + slow("a", 30); + trpl::sleep(one_ms).await; + slow("a", 10); + trpl::sleep(one_ms).await; + slow("a", 20); + trpl::sleep(one_ms).await; + println!("'a' finished."); +}; - let b = async { - println!("'b' started."); - slow("b", 75); - trpl::sleep(one_ms).await; - slow("b", 10); - trpl::sleep(one_ms).await; - slow("b", 15); - trpl::sleep(one_ms).await; - slow("b", 35); - trpl::sleep(one_ms).await; - println!("'b' finished."); - }; +let b = async { + println!("'b' started."); + slow("b", 75); + trpl::sleep(one_ms).await; + slow("b", 10); + trpl::sleep(one_ms).await; + slow("b", 15); + trpl::sleep(one_ms).await; + slow("b", 35); + trpl::sleep(one_ms).await; + println!("'b' finished."); +}; ``` -Listing 17-24: Using <code>sleep</code> to let operations switch off making progress +Listing 17-24: Using `sleep` to let operations switch off making progress In Listing 17-24, we add `trpl::sleep` calls with await points between each call to `slow`. Now the two futures’ work is interleaved: -<!-- manual-regeneration -cd listings/ch17-async-await/listing-17-24 -cargo run -copy just the output ---> - ``` 'a' started. 'a' ran for 30ms @@ -1660,36 +1576,35 @@ as we can. We just need to hand back control to the runtime. We can do that directly, using the `yield_now` function. In Listing 17-25, we replace all those `sleep` calls with `yield_now`. - Filename: src/main.rs ``` - let a = async { - println!("'a' started."); - slow("a", 30); - trpl::yield_now().await; - slow("a", 10); - trpl::yield_now().await; - slow("a", 20); - trpl::yield_now().await; - println!("'a' finished."); - }; - - let b = async { - println!("'b' started."); - slow("b", 75); - trpl::yield_now().await; - slow("b", 10); - trpl::yield_now().await; - slow("b", 15); - trpl::yield_now().await; - slow("b", 35); - trpl::yield_now().await; - println!("'b' finished."); - }; -``` - -Listing 17-25: Using <code>yield_now</code> to let operations switch off making progress +let a = async { + println!("'a' started."); + slow("a", 30); + trpl::yield_now().await; + slow("a", 10); + trpl::yield_now().await; + slow("a", 20); + trpl::yield_now().await; + println!("'a' finished."); +}; + +let b = async { + println!("'b' started."); + slow("b", 75); + trpl::yield_now().await; + slow("b", 10); + trpl::yield_now().await; + slow("b", 15); + trpl::yield_now().await; + slow("b", 35); + trpl::yield_now().await; + println!("'b' finished."); +}; +``` + +Listing 17-25: Using `yield_now` to let operations switch off making progress This is both clearer about the actual intent and can be significantly faster than using `sleep`, because timers such as the one used by `sleep` often have @@ -1706,39 +1621,38 @@ each future run by itself, with no switching between the futures. Then we run for 1,000 iterations and see how long the future using `trpl::sleep` takes compared to the future using `trpl::yield_now`. - Filename: src/main.rs ``` - let one_ns = Duration::from_nanos(1); - let start = Instant::now(); - async { - for _ in 1..1000 { - trpl::sleep(one_ns).await; - } - } - .await; - let time = Instant::now() - start; - println!( - "'sleep' version finished after {} seconds.", - time.as_secs_f32() - ); - - let start = Instant::now(); - async { - for _ in 1..1000 { - trpl::yield_now().await; - } - } - .await; - let time = Instant::now() - start; - println!( - "'yield' version finished after {} seconds.", - time.as_secs_f32() - ); +let one_ns = Duration::from_nanos(1); +let start = Instant::now(); +async { + for _ in 1..1000 { + trpl::sleep(one_ns).await; + } +} +.await; +let time = Instant::now() - start; +println!( + "'sleep' version finished after {} seconds.", + time.as_secs_f32() +); + +let start = Instant::now(); +async { + for _ in 1..1000 { + trpl::yield_now().await; + } +} +.await; +let time = Instant::now() - start; +println!( + "'yield' version finished after {} seconds.", + time.as_secs_f32() +); ``` -Listing 17-26: Comparing the performance of <code>sleep</code> and <code>yield_now</code> +Listing 17-26: Comparing the performance of `sleep` and `yield_now` The version with `yield_now` is *way* faster! @@ -1770,24 +1684,24 @@ yet further async abstractions. Listing 17-27 shows how we would expect this `timeout` to work with a slow future. - Filename: src/main.rs ``` - let slow = async { - trpl::sleep(Duration::from_millis(100)).await; - "I finished!" - }; +let slow = async { + trpl::sleep(Duration::from_millis(100)).await; + "I finished!" +}; - match timeout(slow, Duration::from_millis(10)).await { - Ok(message) => println!("Succeeded with '{message}'"), - Err(duration) => { - println!("Failed after {} seconds", duration.as_secs()) - } - } +match timeout(slow, Duration::from_millis(10)).await { + Ok(message) => println!("Succeeded with '{message}'"), + Err(duration) => { + println!("Failed after {} seconds", duration.as_secs()) + } +} ``` -Listing 17-27: Using our imagined <code>timeout</code> to run a slow operation with a time limit +Listing 17-27: Using our imagined `timeout` to run a slow operation with a time +limit Let’s implement this! To begin, let’s think about the API for `timeout`: @@ -1803,9 +1717,6 @@ Let’s implement this! To begin, let’s think about the API for `timeout`: Listing 17-28 shows this declaration. -<!-- This is not tested because it intentionally does not compile. --> - - Filename: src/main.rs ``` @@ -1817,7 +1728,7 @@ async fn timeout<F: Future>( } ``` -Listing 17-28: Defining the signature of <code>timeout</code> +Listing 17-28: Defining the signature of `timeout` That satisfies our goals for the types. Now let’s think about the *behavior* we need: we want to race the future passed in against the duration. We can use @@ -1836,7 +1747,6 @@ In Listing 17-29, we match on the result of awaiting `trpl::race`. If the If the sleep timer elapsed instead and we get a `Right(())`, we ignore the `()` with `_` and return `Err(max_time)` instead. - Filename: src/main.rs ``` @@ -1870,7 +1780,7 @@ async fn timeout<F: Future>( } ``` -Listing 17-29: Defining <code>timeout</code> with <code>race</code> and <code>sleep</code> +Listing 17-29: Defining `timeout` with `race` and `sleep` With that, we have a working `timeout`, built out of two other async helpers. If we run our code, it will print the failure mode after the timeout: @@ -1906,18 +1816,19 @@ to consider first, though: ## Streams So far in this chapter, we have mostly stuck to individual futures. The one big -exception was the async channel we used. Recall how we used the receiver for our -async channel in the “Message Passing” at *ch17-02-concurrency-with-async.html#message-passing* earlier in the chapter. +exception was the async channel we used. Recall how we used the receiver for +our async channel in the “Message Passing” section of this chapter on page XX. The async `recv` method produces a sequence of items over time. This is an instance of a much more general pattern, often called a *stream*. A sequence of items is something we’ve seen before, when we looked at the -`Iterator` trait in Chapter 13, but there are two differences between iterators -and the async channel receiver. The first difference is the element of time: -iterators are synchronous, while the channel receiver is asynchronous. The -second difference is the API. When working directly with an `Iterator`, we call -its synchronous `next` method. With the `trpl::Receiver` stream in particular, -we called an asynchronous `recv` method instead, but these APIs otherwise feel +`Iterator` trait in “The `Iterator` Trait and the `next` Method” section of +Chapter 13 on page XX, but there are two differences between iterators and the +async channel receiver. The first difference is the element of time: iterators +are synchronous, while the channel receiver is asynchronous. The second +difference is the API. When working directly with an `Iterator`, we call its +synchronous `next` method. With the `trpl::Receiver` stream in particular, we +called an asynchronous `recv` method instead, but these APIs otherwise feel very similar. That similarity isn’t a coincidence. A stream is similar to an asynchronous @@ -1928,17 +1839,16 @@ similarity between iterators and streams in Rust means we can actually create a stream from any iterator. As with an iterator, we can work with a stream by calling its `next` method and then awaiting the output, as in Listing 17-30. - Filename: src/main.rs ``` - let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - let iter = values.iter().map(|n| n * 2); - let mut stream = trpl::stream_from_iter(iter); +let values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +let iter = values.iter().map(|n| n * 2); +let mut stream = trpl::stream_from_iter(iter); - while let Some(value) = stream.next().await { - println!("The value was: {value}"); - } +while let Some(value) = stream.next().await { + println!("The value was: {value}"); +} ``` Listing 17-30: Creating a stream from an iterator and printing its values @@ -1951,14 +1861,6 @@ stream as they arrive with the `while let` loop. Unfortunately, when we try to run the code, it doesn’t compile. Instead, as we can see in the output, it reports that there is no `next` method available. -<!-- TODO: fix up the path here? --> - -<!-- manual-regeneration -cd listings/chapter-17-async-await/listing-17-30 -cargo build -copy only the error output ---> - ``` error[E0599]: no method named `next` found for struct `Iter` in the current scope --> src/main.rs:8:40 @@ -1966,7 +1868,7 @@ error[E0599]: no method named `next` found for struct `Iter` in the current scop 8 | while let Some(value) = stream.next().await { | ^^^^ | - = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-30/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' + = note: the full type name has been written to '~/projects/hello-async/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' = note: consider using `--verbose` to print the full type name to the console = help: items from traits can only be used if the trait is in scope help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them @@ -2006,7 +1908,6 @@ keep moving. The fix to the compiler error is to add a `use` statement for `trpl::StreamExt`, as in Listing 17-31. - Filename: src/main.rs ``` @@ -2032,7 +1933,6 @@ more, now that we have `StreamExt` in scope, we can use all of its utility methods, just as with iterators. For example, in Listing 17-32, we use the `filter` method to filter out everything but multiples of three and five. - Filename: src/main.rs ``` @@ -2054,7 +1954,7 @@ fn main() { } ``` -Listing 17-32: Filtering a <code>Stream</code> with the <code>StreamExt::filter</code> method +Listing 17-32: Filtering a `Stream` with the `StreamExt::filter` method Of course, this isn’t very interesting. We could do that with normal iterators and without any async at all. So let’s look at some of the other things we can @@ -2082,7 +1982,6 @@ We also use a new type: `ReceiverStream`, which converts the `rx` receiver from the `trpl::channel` into a `Stream` with a `next` method. Back in `main`, we use a `while let` loop to print all the messages from the stream. - Filename: src/main.rs ``` @@ -2110,14 +2009,10 @@ fn get_messages() -> impl Stream<Item = String> { } ``` -Listing 17-33: Using the <code>rx</code> receiver as a <code>ReceiverStream</code> +Listing 17-33: Using the `rx` receiver as a `ReceiverStream` When we run this code, we get exactly the results we would expect: -<!-- Not extracting output because changes to this output aren't significant; -the changes are likely to be due to the threads running differently rather than -changes in the compiler --> - ``` Message: 'a' Message: 'b' @@ -2145,7 +2040,6 @@ timeout. Finally, notice that we pin the messages after applying the timeout to them, because the timeout helper produces a future which needs to be pinned to be polled. - Filename: src/main.rs ``` @@ -2167,7 +2061,8 @@ fn main() { } ``` -Listing 17-34: Using the <code>StreamExt::timeout</code> method to set a time limit on the items in a stream +Listing 17-34: Using the `StreamExt::timeout` method to set a time limit on the +items in a stream However, because there are no delays between messages, this timeout does not change the behavior of the program. Let’s add a variable delay to the messages @@ -2178,7 +2073,6 @@ and a 300 millisecond delay to odd-index items, to simulate the different delays we might see from a stream of messages in the real world. Because our timeout is for 200 milliseconds, this should affect half of the messages. - Filename: src/main.rs ``` @@ -2199,40 +2093,34 @@ fn get_messages() -> impl Stream<Item = String> { } ``` -Listing 17-35: Sending messages through <code>tx</code> with an async delay without making <code>get_messages</code> an async function +Listing 17-35: Sending messages through `tx` with an async delay without making +`get_messages` an async function To sleep between messages in the `get_messages` function without blocking, we need to use async. However, we can’t make `get_messages` itself into an async -function, because then we’d return a `Future<Output = Stream<Item = String>>` instead of just a `Stream<Item = String>>`. The caller would have to -await `get_messages` itself to get access to the stream. But remember: -everything in a given future happens linearly; concurrency happens *between* -futures. Awaiting `get_messages` would require it to send all the messages, -including sleeping between sending each message, before returning the receiver -stream. As a result, the timeout would end up useless. There would be no delays -in the stream itself: the delays would all happen before the stream was even -available. +function, because then we’d return a `Future<Output = Stream<Item = String>>` +instead of just a `Stream<Item = String>>`. The caller would have to await +`get_messages` itself to get access to the stream. But remember: everything in +a given future happens linearly; concurrency happens *between* futures. +Awaiting `get_messages` would require it to send all the messages, including +sleeping between sending each message, before returning the receiver stream. As +a result, the timeout would end up useless. There would be no delays in the +stream itself: the delays would all happen before the stream was even available. Instead, we leave `get_messages` as a regular function which returns a stream, and spawn a task to handle the async `sleep` calls. - > - > Note: calling `spawn_task` in this way works because we already set up our - > runtime. Calling this particular implementation of `spawn_task` *without* - > first setting up a runtime will cause a panic. Other implementations choose - > different tradeoffs: they might spawn a new runtime and so avoid the panic but - > end up with a bit of extra overhead, or simply not provide a standalone way to - > spawn tasks without reference to a runtime. You should make sure you know what - > tradeoff your runtime has chosen and write your code accordingly! +> Note: calling `spawn_task` in this way works because we already set up our +> runtime. Calling this particular implementation of `spawn_task` *without* +> first setting up a runtime will cause a panic. Other implementations choose +> different tradeoffs: they might spawn a new runtime and so avoid the panic but +> end up with a bit of extra overhead, or simply not provide a standalone way to +> spawn tasks without reference to a runtime. You should make sure you know what +> tradeoff your runtime has chosen and write your code accordingly! Now our code has a much more interesting result! Between every other pair of messages, we see an error reported: `Problem: Elapsed(())`. -<!-- manual-regeneration -cd listings/listing-17-35 -cargo run -copy only the program output, *not* the compiler output ---> - ``` Message: 'a' Problem: Elapsed(()) @@ -2280,7 +2168,6 @@ it over the channel. Because this is all wrapped in the task created by `spawn_task`, all of it will get cleaned up along with the runtime, including the infinite loop. - Filename: src/main.rs ``` @@ -2300,7 +2187,8 @@ fn get_intervals() -> impl Stream<Item = u32> { } ``` -Listing 17-36: Creating a stream with a counter that will be emitted once every millisecond +Listing 17-36: Creating a stream with a counter that will be emitted once every +millisecond This kind of infinite loop, which only ends when the whole runtime gets torn down, is fairly common in async Rust: many programs need to keep running @@ -2314,23 +2202,25 @@ the source streams as soon as the items are available, without imposing any particular ordering. Finally, we loop over that combined stream instead of over `messages` (Listing 17-37). - Filename: src/main.rs ``` - let messages = get_messages().timeout(Duration::from_millis(200)); - let intervals = get_intervals(); - let merged = messages.merge(intervals); +let messages = get_messages().timeout(Duration::from_millis(200)); +let intervals = get_intervals(); +let merged = messages.merge(intervals); ``` Listing 17-37: Attempting to merge streams of messages and intervals -At this point, neither `messages` nor `intervals` needs to be pinned or mutable, -because both will be combined into the single `merged` stream. However, this -call to `merge` does not compile! (Neither does the `next` call in the `while let` loop, but we’ll come back to that after fixing this.) The two streams -have different types. The `messages` stream has the type `Timeout<impl Stream<Item = String>>`, where `Timeout` is the type which implements `Stream` -for a `timeout` call. Meanwhile, the `intervals` stream has the type `impl Stream<Item = u32>`. To merge these two streams, we need to transform one of -them to match the other. +At this point, neither `messages` nor `intervals` needs to be pinned or +mutable, because both will be combined into the single `merged` stream. +However, this call to `merge` does not compile! (Neither does the `next` call +in the `while let` loop, but we’ll come back to that after fixing this.) The +two streams have different types. The `messages` stream has the type +`Timeout<impl Stream<Item = String>>`, where `Timeout` is the type which +implements `Stream` for a `timeout` call. Meanwhile, the `intervals` stream has +the type `impl Stream<Item = u32>`. To merge these two streams, we need to +transform one of them to match the other. In Listing 17-38, we rework the `intervals` stream, because `messages` is already in the basic format we want and has to handle timeout errors. First, we @@ -2342,21 +2232,19 @@ which is longer than the other durations we are using. Here, we create a `stream` mutable, so that the `while let` loop’s `next` calls can iterate through the stream, and pin it so that it’s safe to do so. -<!-- We cannot directly test this one, because it never stops. --> - - Filename: src/main.rs ``` - let messages = get_messages().timeout(Duration::from_millis(200)); - let intervals = get_intervals() - .map(|count| format!("Interval: {count}")) - .timeout(Duration::from_secs(10)); - let merged = messages.merge(intervals); - let mut stream = pin!(merged); +let messages = get_messages().timeout(Duration::from_millis(200)); +let intervals = get_intervals() + .map(|count| format!("Interval: {count}")) + .timeout(Duration::from_secs(10)); +let merged = messages.merge(intervals); +let mut stream = pin!(merged); ``` -Listing 17-38: Aligning the types of the the <code>intervals</code> stream with the type of the <code>messages</code> stream +Listing 17-38: Aligning the types of the the `intervals` stream with the type +of the `messages` stream That gets us *almost* to where we need to be. Everything type checks. If you run this, though, there will be two problems. First, it will never stop! You’ll @@ -2364,10 +2252,6 @@ need to stop it with <span class="keystroke">ctrl-c</span>. Second, the messages from the English alphabet will be buried in the midst of all the interval counter messages: -<!-- Not extracting output because changes to this output aren't significant; -the changes are likely to be due to the tasks running differently rather than -changes in the compiler --> - ``` --snip-- Interval: 38 @@ -2391,20 +2275,19 @@ To limit the number of items we will accept from a stream, we can use the `take` method. We apply it to the *merged* stream, because we want to limit the final output, not just one stream or the other. - Filename: src/main.rs ``` - let messages = get_messages().timeout(Duration::from_millis(200)); - let intervals = get_intervals() - .map(|count| format!("Interval: {count}")) - .throttle(Duration::from_millis(100)) - .timeout(Duration::from_secs(10)); - let merged = messages.merge(intervals).take(20); - let mut stream = pin!(merged); +let messages = get_messages().timeout(Duration::from_millis(200)); +let intervals = get_intervals() + .map(|count| format!("Interval: {count}")) + .throttle(Duration::from_millis(100)) + .timeout(Duration::from_secs(10)); +let merged = messages.merge(intervals).take(20); +let mut stream = pin!(merged); ``` -Listing 17-39: Using <code>throttle</code> and <code>take</code> to manage the merged streams +Listing 17-39: Using `throttle` and `take` to manage the merged streams Now when we run the program, it stops after pulling twenty items from the stream, and the intervals don’t overwhelm the messages. We also don’t get @@ -2418,12 +2301,6 @@ ignore. Instead, we never produce those interval messages in the first place! This is the inherent “laziness” of Rust’s futures at work again, allowing us to choose our performance characteristics. -<!-- manual-regeneration -cd listings/listing-17-39 -cargo run -copy and paste only the program output ---> - ``` Interval: 1 Message: 'a' @@ -2457,7 +2334,6 @@ a simple error strategy: print the issue and then `break` from the loops. As usual, the correct way to handle a message send error will vary—just make sure you have a strategy. - ``` fn get_messages() -> impl Stream<Item = String> { let (tx, rx) = trpl::channel(); @@ -2517,9 +2393,9 @@ still leaving the *really* deep dive for other documentation! ### Future -Back in Futures and the Async Syntax at *ch17-01-futures-and-syntax.html*, we noted that `Future` -is a trait. Let’s start by taking a closer look at how it works. Here is how -Rust defines a `Future`: +Back in the “Futures and the Async Syntax” section of this chapter on page XX, +we noted that `Future` is a trait. Let’s start by taking a closer look at how +it works. Here is how Rust defines a `Future`: ``` use std::pin::Pin; @@ -2557,11 +2433,10 @@ work to do, so the caller will need to check again later. The `Ready` variant indicates that the `Future` has finished its work and the `T` value is available. - > - > Note: With most futures, the caller should not call `poll` again after the - > future has returned `Ready`. Many futures will panic if polled again after - > becoming ready! Futures which are safe to poll again will say so explicitly in - > their documentation. This is similar to how `Iterator::next` behaves! +> Note: With most futures, the caller should not call `poll` again after the +> future has returned `Ready`. Many futures will panic if polled again after +> becoming ready! Futures which are safe to poll again will say so explicitly in +> their documentation. This is similar to how `Iterator::next` behaves! Under the hood, when you see code which uses `await`, Rust compiles that to code which calls `poll`. If you look back at Listing 17-4, where we printed out the @@ -2606,14 +2481,14 @@ on this future and work on other futures and check this one again later. That “something” is an async runtime, and this scheduling and coordination work is one of the main jobs for a runtime. -Recall our description (in the Counting at *ch17-02-concurrency-with-async.html* section) of waiting on -`rx.recv`. The `recv` call returns a `Future`, and awaiting it polls it. In our -initial discussion, we noted that a runtime will pause the future until it’s -ready with either `Some(message)` or `None` when the channel closes. With our -deeper understanding of `Future` in place, and specifically `Future::poll`, we -can see how that works. The runtime knows the future isn’t ready when it -returns `Poll::Pending`. Conversely, the runtime knows the future is ready and -advances it when `poll` returns `Poll::Ready(Some(message))` or +Recall our description (in the “Counting” section of this chapter on page XX) +of waiting on `rx.recv`. The `recv` call returns a `Future`, and awaiting it +polls it. In our initial discussion, we noted that a runtime will pause the +future until it’s ready with either `Some(message)` or `None` when the channel +closes. With our deeper understanding of `Future` in place, and specifically +`Future::poll`, we can see how that works. The runtime knows the future isn’t +ready when it returns `Poll::Pending`. Conversely, the runtime knows the future +is ready and advances it when `poll` returns `Poll::Ready(Some(message))` or `Poll::Ready(None)`. The exact details of how a runtime does that are more than we will cover in even @@ -2623,17 +2498,9 @@ it is not yet ready. ### Pinning and the Pin and Unpin Traits -<!-- TODO: get a *very* careful technical review of this section! --> - When we introduced the idea of pinning, while working on Listing 17-17, we ran into a very gnarly error message. Here is the relevant part of it again: -<!-- manual-regeneration -cd listings/ch17-async-await/listing-17-17 -cargo build -copy *only* the final `error` block from the errors ---> - ``` error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned --> src/main.rs:46:33 @@ -2645,7 +2512,7 @@ error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned consider using `Box::pin` if you need to access the pinned value outside of the current scope = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll<F> | ------- required by a bound in this struct @@ -2701,27 +2568,30 @@ other smart pointer types we saw in Chapter 15, which also wrap other types. Unlike those, however, `Pin` only works with *pointer types* such as references (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` works with types which implement the `Deref` or `DerefMut` traits, which -we covered in Chapter 15. You can think of this restriction as equivalent to -only working with pointers, though, because implementing `Deref` or `DerefMut` -means your type behaves similarly to a pointer type. `Pin` is also not a -pointer itself, and it doesn’t have any behavior of its own as the ref counting -of `Rc` or `Arc` does. It’s purely a tool the compiler can use to uphold the -relevant guarantees, by wrapping pointers in the type. +we covered in the “Treating Smart Pointers Like Regular References with the +Deref Trait” section of Chapter 15 on page XX. You can think of this +restriction as equivalent to only working with pointers, though, because +implementing `Deref` or `DerefMut` means your type behaves similarly to a +pointer type. `Pin` is also not a pointer itself, and it doesn’t have any +behavior of its own as the ref counting of `Rc` or `Arc` does. It’s purely a +tool the compiler can use to uphold the relevant guarantees, by wrapping +pointers in the type. Recalling that `await` is implemented in terms of calls to `poll`, this starts to explain the error message we saw above—but that was in terms of `Unpin`, not `Pin`. So what exactly are `Pin` and `Unpin`, how do they relate, and why does `Future` need `self` to be in a `Pin` type to call `poll`? -In Our First Async Program at *ch17-01-futures-and-syntax.html#our-first-async-program*, we described how a series of await -points in a future get compiled into a state machine—and noted how the compiler -helps make sure that state machine follows all of Rust’s normal rules around -safety, including borrowing and ownership. To make that work, Rust looks at what -data is needed between each await point and the next await point or the end of -the async block. It then creates a corresponding variant in the state machine it -creates. Each variant gets the access it needs to the data that will be used in -that section of the source code, whether by taking ownership of that data or by -getting a mutable or immutable reference to it. +In the “”ur First Async Program” section of this chapter on page XX, we +described how a series of await points in a future get compiled into a state +machine—and noted how the compiler helps make sure that state machine follows +all of Rust’s normal rules around safety, including borrowing and ownership. To +make that work, Rust looks at what data is needed between each await point and +the next await point or the end of the async block. It then creates a +corresponding variant in the state machine it creates. Each variant gets the +access it needs to the data that will be used in that section of the source +code, whether by taking ownership of that data or by getting a mutable or +immutable reference to it. So far so good: if we get anything wrong about the ownership or references in a given async block, the borrow checker will tell us. When we want to move around @@ -2736,13 +2606,9 @@ themselves in the fields of any given variant, as in Figure 17-3 (a simplified illustration to help you get a feel for the idea, rather than digging into what are often fairly complicated details). -<figure> - -<img alt="Concurrent work flow" src="img/trpl17-03.svg" class="center" /> +<img alt="Concurrent work flow" src="img/trpl17-03.svg" /> -<figcaption>Figure 17-3: A self-referential data type.</figcaption> - -</figure> +Figure 17-3: A self-referential data type. By default, though, any object which has a reference to itself is unsafe to move, because references always point to the actual memory address of the thing @@ -2753,13 +2619,9 @@ the data structure. For another—and more importantly!—the computer is now fr to reuse that memory for other things! You could end up reading completely unrelated data later. -<figure> - -<img alt="Concurrent work flow" src="img/trpl17-04.svg" class="center" /> +<img alt="Concurrent work flow" src="img/trpl17-04.svg" /> -<figcaption>Figure 17-4: The unsafe result of moving a self-referential data type.</figcaption> - -</figure> +Figure 17-4: The unsafe result of moving a self-referential data type. In principle, the Rust compiler could try to update every reference to an object every time it gets moved. That would potentially be a lot of performance @@ -2774,13 +2636,9 @@ value by wrapping a pointer to that value in `Pin`, it can no longer move. Thus, if you have `Pin<Box<SomeType>>`, you actually pin the `SomeType` value, *not* the `Box` pointer. Figure 17-5 illustrates this: -<figure> - -<img alt="Concurrent work flow" src="img/trpl17-05.svg" class="center" /> - -<figcaption>Figure 17-5: Pinning a `Box` which points to a self-referential future type.</figcaption> +<img alt="Concurrent work flow" src="img/trpl17-05.svg" /> -</figure> +Figure 17-5: Pinning a `Box` which points to a self-referential future type. In fact, the `Box` pointer can still move around freely. Remember: we care about making sure the data ultimately being referenced stays in its place. If a @@ -2792,13 +2650,9 @@ well as the `std::pin` module, you might be able to work out how you would do that.) The key is that the self-referential type itself cannot move, because it is still pinned. -<figure> +<img alt="Concurrent work flow" src="img/trpl17-06.svg" /> -<img alt="Concurrent work flow" src="img/trpl17-06.svg" class="center" /> - -<figcaption>Figure 17-6: Moving a `Box` which points to a self-referential future type.</figcaption> - -</figure> +Figure 17-6: Moving a `Box` which points to a self-referential future type. However, most types are perfectly safe to move around, even if they happen to be behind a `Pin` pointer. We only need to think about pinning when items have @@ -2812,12 +2666,13 @@ via the safe but restrictive APIs provided by `Pin`, even though a need a way to tell the compiler that it’s actually just fine to move items around in cases such as these. For that, we have `Unpin`. -`Unpin` is a marker trait, as `Send` and `Sync` are, which we saw in Chapter 16. -Recall that marker traits have no functionality of their own. They exist only to -tell the compiler that it’s safe to use the type which implements a given trait -in a particular context. `Unpin` informs the compiler that a given type does -*not* need to uphold any particular guarantees about whether the value in -question can be moved. +`Unpin` is a marker trait, as `Send` and `Sync` are, which we saw in the +“Extensible Concurrency with the `Sync` and `Send` Traits” section of Chapter +16 on page XX. Recall that marker traits have no functionality of their own. +They exist only to tell the compiler that it’s safe to use the type which +implements a given trait in a particular context. `Unpin` informs the compiler +that a given type does *not* need to uphold any particular guarantees about +whether the value in question can be moved. Just as with `Send` and `Sync`, the compiler implements `Unpin` automatically for all types where it can prove it is safe. Implementing `Unpin` manually is @@ -2829,26 +2684,19 @@ To make that concrete, think about a `String`: it has a length and the Unicode characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure 17-7. However -<figure> - -<img alt="Concurrent work flow" src="img/trpl17-07.svg" class="center" /> +<img alt="Concurrent work flow" src="img/trpl17-07.svg" /> -<figcaption>Figure 17-7: Pinning a String, with a dotted line indicating that the String implements the `Unpin` trait, so it is not pinned.</figcaption> - -</figure> +Figure 17-7: Pinning a String, with a dotted line indicating that the String +implements the `Unpin` trait, so it is not pinned. This means that we can do things such as replace one string with another at the exact same location in memory as in Figure 17-8. This doesn’t violate the `Pin` contract because `String`—like most other types in Rust—implements `Unpin`, because it has no internal references that make it unsafe to move around! -<figure> - -<img alt="Concurrent work flow" src="img/trpl17-08.svg" class="center" /> - -<figcaption>Figure 17-8: Replacing the String with an entirely different String in memory.</figcaption> +<img alt="Concurrent work flow" src="img/trpl17-08.svg" /> -</figure> +Figure 17-8: Replacing the String with an entirely different String in memory. Now we know enough to understand the errors reported for that `join_all` call from back in Listing 17-17. We originally tried to move the futures produced by @@ -2862,22 +2710,21 @@ when you’re building a runtime itself, rather than for day to day Rust code. When you see these traits in error messages, though, now you’ll have a better idea of how to fix the code! - > - > Note: This combination of `Pin` and `Unpin` allows a whole class of complex - > types to be safe in Rust which are otherwise difficult to implement because - > they’re self-referential. Types which require `Pin` show up *most* commonly - > in async Rust today, but you might—very rarely!—see it in other contexts, too. - > - > The specifics of how `Pin` and `Unpin` work, and the rules they’re required - > to uphold, are covered extensively in the API documentation for `std::pin`, so - > if you’d like to understand them more deeply, that’s a great place to start. - > - > If you want to understand how things work “under the hood” in even more - > detail, the official *Asynchronous Programming in Rust* at *https://rust-lang.github.io/async-book/* book has - > you covered: - > - > * Chapter 2: Under the Hood: Executing Futures and Tasks at *https://rust-lang.github.io/async-book/02_execution/01_chapter.html* - > * Chapter 4: Pinning at *https://rust-lang.github.io/async-book/04_pinning/01_chapter.html* +> Note: This combination of `Pin` and `Unpin` allows a whole class of complex +> types to be safe in Rust which are otherwise difficult to implement because +> they’re self-referential. Types which require `Pin` show up *most* commonly +> in async Rust today, but you might—very rarely!—see it in other contexts, too. +> +> The specifics of how `Pin` and `Unpin` work, and the rules they’re required +> to uphold, are covered extensively in the API documentation for `std::pin`, so +> if you’d like to understand them more deeply, that’s a great place to start. +> +> If you want to understand how things work “under the hood” in even more +> detail, the official *Asynchronous Programming in Rust* book available at +> *https://rust-lang.github.io/async-book/* has you covered: +> +> * Chapter 2: Under the Hood: Executing Futures and Tasks +> * Chapter 4: Pinning ### The Stream Trait @@ -2885,9 +2732,8 @@ Now that we have a deeper grasp on the `Future`, `Pin`, and `Unpin` traits, we can turn our attention to the `Stream` trait. As described in the section introducing streams, streams are similar to asynchronous iterators. Unlike `Iterator` and `Future`, there is no definition of a `Stream` trait in the -standard library as of the time of writing,<!-- TODO: verify before press time! ---> but there *is* a very common definition from the `futures` crate used -throughout the ecosystem. +standard library as of the time of writing, but there *is* a very common +definition from the `futures` crate used throughout the ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, so we can build up to how a `Stream` trait that merges them together might look. From @@ -2945,23 +2791,17 @@ trait StreamExt: Stream { } ``` -<!-- -TODO: update this if/when tokio/etc. update their MSRV and switch to using async functions -in traits, since the lack thereof is the reason they do not yet have this. ---> - - > - > Note: The actual definition we used earlier in the chapter looks slightly - > different than this, because it supports versions of Rust which did not yet - > support using async functions in traits. As a result, it looks like this: - > - > ````rust,ignore - > fn next(&mut self) -> Next<'_, Self> where Self: Unpin; - > ```` - > - > That `Next` type is a `struct` which implements `Future` and gives a way to - > name the lifetime of the reference to `self` with `Next<'_, Self>`, so that - > `await` can work with this method! +> Note: The actual definition we used earlier in the chapter looks slightly +> different than this, because it supports versions of Rust which did not yet +> support using async functions in traits. As a result, it looks like this: +> +> ``` +> fn next(&mut self) -> Next<'_, Self> where Self: Unpin; +> ``` +> +> That `Next` type is a `struct` which implements `Future` and gives a way to +> name the lifetime of the reference to `self` with `Next<'_, Self>`, so that +> `await` can work with this method! The `StreamExt` trait is also the home of all the interesting methods available to use with streams. `StreamExt` is automatically implemented for every type @@ -2982,11 +2822,12 @@ fit together! ## Futures, Tasks, and Threads -As we saw in the previous chapter, threads provide one approach to concurrency. -We’ve seen another approach to concurrency in this chapter, using async with -futures and streams. You might be wondering why you would choose one or the -other. The answer is: it depends! And in many cases, the choice isn’t threads -*or* async but rather threads *and* async. +As we saw in the “Using Threads to Run Code Simultaneously” section of Chapter +16 on page XX, threads provide one approach to concurrency. We’ve seen another +approach to concurrency in this chapter, using async with futures and streams. +You might be wondering why you would choose one or the other. The answer is: it +depends! And in many cases, the choice isn’t threads *or* async but rather +threads *and* async. Many operating systems have supplied threading-based concurrency models for decades now, and many programming languages have support for them as a result. @@ -3011,7 +2852,6 @@ could do the exact same thing with a thread! In Listing 17-40, we used the `thread::spawn` and `thread::sleep` APIs from the standard library in the `get_intervals` function. - Filename: src/main.rs ``` @@ -3037,7 +2877,8 @@ fn get_intervals() -> impl Stream<Item = u32> { } ``` -Listing 17-41: Using the <code>std::thread</code> APIs instead of the async <code>trpl</code> APIs for the <code>get_intervals</code> function +Listing 17-41: Using the `std::thread` APIs instead of the async `trpl` APIs +for the `get_intervals` function If you run this, the output is identical. And notice how little changes here from the perspective of the calling code! What’s more, even though one of our @@ -3074,10 +2915,11 @@ state got cleaned up correctly. These limitations make threads harder to compose than futures. It’s much more difficult, for example, to build something similar to the `timeout` we built in -“Building Our Own Async Abstractions” at *ch17-03-more-futures.html#building-our-own-async-abstractions*, or the `throttle` -method we used with streams in “Composing Streams” at *ch17-04-streams.html#composing-streams*. The fact that -futures are richer data structures means they *can* be composed together more -naturally, as we have seen. +the “Building Our Own Async Abstractions” section of this chapter on page XX, +or the `throttle` method we used with streams in the “Composing Streams” +section of this chapter on page XX. The fact that futures are richer data +structures means they *can* be composed together more naturally, as we have +seen. Tasks then give *additional* control over futures, allowing you to choose where and how to group the futures. And it turns out that threads and tasks often @@ -3103,7 +2945,6 @@ choose between threads and async. You can use them together freely, letting each one serve the part it is best at. For example, Listing 17-42 shows a fairly common example of this kind of mix in real-world Rust code. - Filename: src/main.rs ``` @@ -3127,7 +2968,8 @@ fn main() { } ``` -Listing 17-42: Sending messages with blocking code in a thread and awaiting the messages in an async block +Listing 17-42: Sending messages with blocking code in a thread and awaiting the +messages in an async block We begin by creating an async channel. Then we spawn a thread which takes ownership of the sender side of the channel. Within the thread, we send the From 6b3fb812c8a4caf5b47ecf6cf23a134586f67e1d Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Fri, 4 Oct 2024 08:15:51 -0600 Subject: [PATCH 602/720] A bit more clarity about all the stack types in 3.2 Fixes #4009 --- src/ch03-02-data-types.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ch03-02-data-types.md b/src/ch03-02-data-types.md index 2cfc156e89..84af90e3f6 100644 --- a/src/ch03-02-data-types.md +++ b/src/ch03-02-data-types.md @@ -271,14 +271,14 @@ brackets: {{#rustdoc_include ../listings/ch03-common-programming-concepts/no-listing-13-arrays/src/main.rs}} ``` -Arrays are useful when you want your data allocated on the stack rather than -the heap (we will discuss the stack and the heap more in [Chapter -4][stack-and-heap]<!-- ignore -->) or when you want to ensure you always have a -fixed number of elements. An array isn’t as flexible as the vector type, -though. A *vector* is a similar collection type provided by the standard -library that *is* allowed to grow or shrink in size. If you’re unsure whether -to use an array or a vector, chances are you should use a vector. [Chapter -8][vectors]<!-- ignore --> discusses vectors in more detail. +Arrays are useful when you want your data allocated on the stack, the same as +the other types we have seen so far, rather than the heap (we will discuss the +stack and the heap more in [Chapter 4][stack-and-heap]<!-- ignore -->) or when +you want to ensure you always have a fixed number of elements. An array isn’t as +flexible as the vector type, though. A *vector* is a similar collection type +provided by the standard library that *is* allowed to grow or shrink in size. If +you’re unsure whether to use an array or a vector, chances are you should use a +vector. [Chapter 8][vectors]<!-- ignore --> discusses vectors in more detail. However, arrays are more useful when you know the number of elements will not need to change. For example, if you were using the names of the month in a From a50711a2ca6519bebc2aca5eb8ec84380a64442c Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Fri, 4 Oct 2024 14:19:25 -0600 Subject: [PATCH 603/720] Correct the explanation of what `::<path>` means MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This changed in the 2018 Edition (thank goodness: paths were *bad* back then, and now they’re much less bad!) Fixes #3841 --- src/appendix-02-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appendix-02-operators.md b/src/appendix-02-operators.md index 0a8dab9d61..45de3e56aa 100644 --- a/src/appendix-02-operators.md +++ b/src/appendix-02-operators.md @@ -102,7 +102,7 @@ hierarchy to an item. | Symbol | Explanation | |--------|-------------| | `ident::ident` | Namespace path | -| `::path` | Path relative to the crate root (i.e., an explicitly absolute path) | +| `::path` | Path relative to the extern prelude, where all other crates are rooted (i.e., an explicitly absolute path including crate name) | | `self::path` | Path relative to the current module (i.e., an explicitly relative path). | | `super::path` | Path relative to the parent of the current module | | `type::ident`, `<type as trait>::ident` | Associated constants, functions, and types | From 52fa1c9f5e6a621622b06bad4b3d4a9ca7148051 Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Fri, 4 Oct 2024 14:39:55 -0600 Subject: [PATCH 604/720] Standardize on 'adapter', not 'adaptor' This matches what Rust docs use (since rust-lang/rust#87629). Fixes #3824 --- ci/dictionary.txt | 2 -- src/ch13-02-iterators.md | 14 +++++++------- src/ch13-03-improving-our-io-project.md | 10 +++++----- src/ch13-04-performance.md | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 6329ed1238..e2f5f670f0 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -2,8 +2,6 @@ personal_ws-1.1 en 0 utf-8 abcabcabc abcd abcdefghijklmnopqrstuvwxyz -adaptor -adaptors AddAssign Addr adfb diff --git a/src/ch13-02-iterators.md b/src/ch13-02-iterators.md index c99fcd6998..4ce9170de0 100644 --- a/src/ch13-02-iterators.md +++ b/src/ch13-02-iterators.md @@ -111,7 +111,7 @@ trait. Some of these methods call the `next` method in their definition, which is why you’re required to implement the `next` method when implementing the `Iterator` trait. -Methods that call `next` are called *consuming adaptors*, because calling them +Methods that call `next` are called *consuming adapters*, because calling them uses up the iterator. One example is the `sum` method, which takes ownership of the iterator and iterates through the items by repeatedly calling `next`, thus consuming the iterator. As it iterates through, it adds each item to a running @@ -131,17 +131,17 @@ ownership of the iterator we call it on. ### Methods that Produce Other Iterators -*Iterator adaptors* are methods defined on the `Iterator` trait that don’t +*Iterator adapters* are methods defined on the `Iterator` trait that don’t consume the iterator. Instead, they produce different iterators by changing some aspect of the original iterator. -Listing 13-14 shows an example of calling the iterator adaptor method `map`, +Listing 13-14 shows an example of calling the iterator adapter method `map`, which takes a closure to call on each item as the items are iterated through. The `map` method returns a new iterator that produces the modified items. The closure here creates a new iterator in which each item from the vector will be incremented by 1: -<Listing number="13-14" file-name="src/main.rs" caption="Calling the iterator adaptor `map` to create a new iterator"> +<Listing number="13-14" file-name="src/main.rs" caption="Calling the iterator adapter `map` to create a new iterator"> ```rust,not_desired_behavior {{#rustdoc_include ../listings/ch13-functional-features/listing-13-14/src/main.rs:here}} @@ -156,7 +156,7 @@ However, this code produces a warning: ``` The code in Listing 13-14 doesn’t do anything; the closure we’ve specified -never gets called. The warning reminds us why: iterator adaptors are lazy, and +never gets called. The warning reminds us why: iterator adapters are lazy, and we need to consume the iterator here. To fix this warning and consume the iterator, we’ll use the `collect` method, @@ -181,9 +181,9 @@ on each item. This is a great example of how closures let you customize some behavior while reusing the iteration behavior that the `Iterator` trait provides. -You can chain multiple calls to iterator adaptors to perform complex actions in +You can chain multiple calls to iterator adapters to perform complex actions in a readable way. But because all iterators are lazy, you have to call one of the -consuming adaptor methods to get results from calls to iterator adaptors. +consuming adapter methods to get results from calls to iterator adapters. ### Using Closures that Capture Their Environment diff --git a/src/ch13-03-improving-our-io-project.md b/src/ch13-03-improving-our-io-project.md index 4c1a508458..c560bc1124 100644 --- a/src/ch13-03-improving-our-io-project.md +++ b/src/ch13-03-improving-our-io-project.md @@ -116,7 +116,7 @@ value we want to put in the `query` field of `Config`. If `next` returns a not enough arguments were given and we return early with an `Err` value. We do the same thing for the `file_path` value. -### Making Code Clearer with Iterator Adaptors +### Making Code Clearer with Iterator Adapters We can also take advantage of iterators in the `search` function in our I/O project, which is reproduced here in Listing 13-21 as it was in Listing 12-19: @@ -129,14 +129,14 @@ project, which is reproduced here in Listing 13-21 as it was in Listing 12-19: </Listing> -We can write this code in a more concise way using iterator adaptor methods. +We can write this code in a more concise way using iterator adapter methods. Doing so also lets us avoid having a mutable intermediate `results` vector. The functional programming style prefers to minimize the amount of mutable state to make code clearer. Removing the mutable state might enable a future enhancement to make searching happen in parallel, because we wouldn’t have to manage concurrent access to the `results` vector. Listing 13-22 shows this change: -<Listing number="13-22" file-name="src/lib.rs" caption="Using iterator adaptor methods in the implementation of the `search` function"> +<Listing number="13-22" file-name="src/lib.rs" caption="Using iterator adapter methods in the implementation of the `search` function"> ```rust,ignore {{#rustdoc_include ../listings/ch13-functional-features/listing-13-22/src/lib.rs:here}} @@ -146,7 +146,7 @@ concurrent access to the `results` vector. Listing 13-22 shows this change: Recall that the purpose of the `search` function is to return all lines in `contents` that contain the `query`. Similar to the `filter` example in Listing -13-16, this code uses the `filter` adaptor to keep only the lines that +13-16, this code uses the `filter` adapter to keep only the lines that `line.contains(query)` returns `true` for. We then collect the matching lines into another vector with `collect`. Much simpler! Feel free to make the same change to use iterator methods in the `search_case_insensitive` function as @@ -158,7 +158,7 @@ The next logical question is which style you should choose in your own code and why: the original implementation in Listing 13-21 or the version using iterators in Listing 13-22. Most Rust programmers prefer to use the iterator style. It’s a bit tougher to get the hang of at first, but once you get a feel -for the various iterator adaptors and what they do, iterators can be easier to +for the various iterator adapters and what they do, iterators can be easier to understand. Instead of fiddling with the various bits of looping and building new vectors, the code focuses on the high-level objective of the loop. This abstracts away some of the commonplace code so it’s easier to see the concepts diff --git a/src/ch13-04-performance.md b/src/ch13-04-performance.md index 5d09bf2940..0dbc7420a0 100644 --- a/src/ch13-04-performance.md +++ b/src/ch13-04-performance.md @@ -65,7 +65,7 @@ multiply the values together, sum all the results, and shift the bits in the sum `qlp_shift` bits to the right. Calculations in applications like audio decoders often prioritize performance -most highly. Here, we’re creating an iterator, using two adaptors, and then +most highly. Here, we’re creating an iterator, using two adapters, and then consuming the value. What assembly code would this Rust code compile to? Well, as of this writing, it compiles down to the same assembly you’d write by hand. There’s no loop at all corresponding to the iteration over the values in From 65c0eaa8f6568904957115aef7a7e16a643aa5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= <jpmelos@gmail.com> Date: Sat, 5 Oct 2024 10:32:40 +0100 Subject: [PATCH 605/720] Just mention that when destructuring, need to mention type name --- .../no-listing-01-tuple-structs/src/main.rs | 4 ---- src/ch05-01-defining-structs.md | 11 ++--------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs b/listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs index ca0c2aa1cd..0d993162bf 100644 --- a/listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs +++ b/listings/ch05-using-structs-to-structure-related-data/no-listing-01-tuple-structs/src/main.rs @@ -4,8 +4,4 @@ struct Point(i32, i32, i32); fn main() { let black = Color(0, 0, 0); let origin = Point(0, 0, 0); - - let Color(r, g, b) = black; - - assert_eq!(r, 0); } diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index fe30214f24..4771cea7f4 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -177,15 +177,8 @@ example, a function that takes a parameter of type `Color` cannot take a `Point` as an argument, even though both types are made up of three `i32` values. Otherwise, tuple struct instances are similar to tuples in that you can destructure them into their individual pieces, and you can use a `.` followed -by the index to access an individual value. - -When destructuring tuple structs, you must mention the type of the instance -being destructured. For example, the line below would not compile when used in -the previous listing: - -```rust,ignore - let (r, g, b) = black; -``` +by the index to access an individual value. Unlike tuples, tuple structs +require you to name the type of the struct when you destructure them. ### Unit-Like Structs Without Any Fields From 2017a78b413f73c593a9a4ad339da4c629eefab9 Mon Sep 17 00:00:00 2001 From: Herbert Reiter <46045854+damoasda@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:55:47 +0200 Subject: [PATCH 606/720] Swap assert_eq! parameters --- .../output-only-01-show-output/output.txt | 4 ++-- .../output-only-01-show-output/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt index 58f1ff4a51..b6fa60de53 100644 --- a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt @@ -22,8 +22,8 @@ failures: I got the value 8 thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9: assertion `left == right` failed - left: 5 - right: 10 + left: 10 + right: 5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs b/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs index 462d224709..141d51ee6e 100644 --- a/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs +++ b/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs @@ -10,12 +10,12 @@ mod tests { #[test] fn this_test_will_pass() { let value = prints_and_returns_10(4); - assert_eq!(10, value); + assert_eq!(value, 10); } #[test] fn this_test_will_fail() { let value = prints_and_returns_10(8); - assert_eq!(5, value); + assert_eq!(value, 5); } } From db949d6a96fd0d8bd444c7f6786feabb1362662b Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 7 Oct 2024 07:59:07 -0600 Subject: [PATCH 607/720] Ch. 17: Remove TODO about `Stream` stabilization Per the [async working group][wg], the _status quo_ for this is unlikely to change before we go to print. We can of course update the online copy as soon as it *does* change, and if it happens to change such that we can sneak it in before going to press, great. [wg]: https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async/topic/Rename.20AsyncIterator.20back.20to.20Stream.2C.20introduce.20an.20AFIT-based/near/475300446 --- src/ch17-05-traits-for-async.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 7cc3825886..94494b7171 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -376,9 +376,8 @@ Now that we have a deeper grasp on the `Future`, `Pin`, and `Unpin` traits, we can turn our attention to the `Stream` trait. As described in the section introducing streams, streams are similar to asynchronous iterators. Unlike `Iterator` and `Future`, there is no definition of a `Stream` trait in the -standard library as of the time of writing,<!-- TODO: verify before press time! ---> but there *is* a very common definition from the `futures` crate used -throughout the ecosystem. +standard library as of the time of writing, but there *is* a very common +definition from the `futures` crate used throughout the ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, so we can build up to how a `Stream` trait that merges them together might look. From From 80158e197e8491dd9c1ff827bfae2318a0becf1f Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 7 Oct 2024 08:20:27 -0600 Subject: [PATCH 608/720] Inline example of destructuring a tuple struct. --- src/ch05-01-defining-structs.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index 4771cea7f4..e1325c63ec 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -178,7 +178,8 @@ example, a function that takes a parameter of type `Color` cannot take a values. Otherwise, tuple struct instances are similar to tuples in that you can destructure them into their individual pieces, and you can use a `.` followed by the index to access an individual value. Unlike tuples, tuple structs -require you to name the type of the struct when you destructure them. +require you to name the type of the struct when you destructure them. For +example, we would write `let Point(x, y, z) = point`. ### Unit-Like Structs Without Any Fields From c1d60d0696402152b9859e13f4f041d5ba0b8189 Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 7 Oct 2024 08:31:33 -0600 Subject: [PATCH 609/720] =?UTF-8?q?Ch.=2017:=20some=20alternative=20wordin?= =?UTF-8?q?gs=20for=20=E2=80=9Clike=E2=80=9D=20substitutions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nostarch/chapter17.md | 15 +++++++-------- src/ch17-05-traits-for-async.md | 6 +++--- src/ch17-06-futures-tasks-threads.md | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index 97d8b7ce39..45757777d4 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -2569,13 +2569,12 @@ Unlike those, however, `Pin` only works with *pointer types* such as references (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` works with types which implement the `Deref` or `DerefMut` traits, which we covered in the “Treating Smart Pointers Like Regular References with the -Deref Trait” section of Chapter 15 on page XX. You can think of this -restriction as equivalent to only working with pointers, though, because -implementing `Deref` or `DerefMut` means your type behaves similarly to a -pointer type. `Pin` is also not a pointer itself, and it doesn’t have any -behavior of its own as the ref counting of `Rc` or `Arc` does. It’s purely a -tool the compiler can use to uphold the relevant guarantees, by wrapping -pointers in the type. +Deref Trait” section of Chapter 15 on page XX. You can think of this restriction +as equivalent to only working with pointers, though, because implementing +`Deref` or `DerefMut` means your type behaves similarly to a pointer type. `Pin` +is also not a pointer itself, and it doesn’t have any behavior of its own the +way `Rc` and `Arc` do with ref counting. It’s purely a tool the compiler can use +to uphold the relevant guarantees, by wrapping pointers in the type. Recalling that `await` is implemented in terms of calls to `poll`, this starts to explain the error message we saw above—but that was in terms of `Unpin`, not @@ -2908,7 +2907,7 @@ On the one hand, concurrency with threads is in some ways a simpler programming model than concurrency with `async`. Threads are somewhat “fire and forget,” they have no native equivalent to a future, so they simply run to completion, without interruption except by the operating system itself. That is, they have -no *intra-task concurrency* as futures can. Threads in Rust also have no +no *intra-task concurrency* the way futures can. Threads in Rust also have no mechanisms for cancellation—a subject we haven’t covered in depth in this chapter, but which is implicit in the fact that whenever we ended a future, its state got cleaned up correctly. diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 94494b7171..a7c5feee50 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -195,9 +195,9 @@ Unlike those, however, `Pin` only works with *pointer types* such as references `Pin` works with types which implement the `Deref` or `DerefMut` traits, which we covered in Chapter 15. You can think of this restriction as equivalent to only working with pointers, though, because implementing `Deref` or `DerefMut` -means your type behaves similarly to a pointer type. `Pin` is also not a -pointer itself, and it doesn’t have any behavior of its own as the ref counting -of `Rc` or `Arc` does. It’s purely a tool the compiler can use to uphold the +means your type behaves similarly to a pointer type. `Pin` is also not a pointer +itself, and it doesn’t have any behavior of its own the way `Rc` and `Arc` do +with ref counting. It’s purely a tool the compiler can use to uphold the relevant guarantees, by wrapping pointers in the type. Recalling that `await` is implemented in terms of calls to `poll`, this starts diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 428eb61c9c..21556b658c 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -65,7 +65,7 @@ On the one hand, concurrency with threads is in some ways a simpler programming model than concurrency with `async`. Threads are somewhat “fire and forget,” they have no native equivalent to a future, so they simply run to completion, without interruption except by the operating system itself. That is, they have -no *intra-task concurrency* as futures can. Threads in Rust also have no +no *intra-task concurrency* the way futures can. Threads in Rust also have no mechanisms for cancellation—a subject we haven’t covered in depth in this chapter, but which is implicit in the fact that whenever we ended a future, its state got cleaned up correctly. From 8f63245b5c8cef562453aaef579cd9d6b850549f Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 7 Oct 2024 12:47:44 -0600 Subject: [PATCH 610/720] Ch. 17: fix task names in Figure 17-2 --- dot/trpl17-02.dot | 18 +++++++++--------- src/img/trpl17-02.svg | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dot/trpl17-02.dot b/dot/trpl17-02.dot index 07d66a3e4b..3e4116a7de 100644 --- a/dot/trpl17-02.dot +++ b/dot/trpl17-02.dot @@ -1,25 +1,25 @@ digraph { dpi = 300.0; - + rankdir = "LR"; splines = false; cluster = true; - + node [shape = diamond;]; - + // The graphs end up with the correct order, i.e. Task 1 *above* Task 2, when // this is first. subgraph cluster_ColleagueB { - label = "Task 2"; + label = "Task B"; B1 -> B2 -> B3; - + B0 [style = invis;]; - B3 -> B0 [style = invis;] + B3 -> B0 [style = invis;]; } - + subgraph cluster_ColleagueA { newrank = true; - label = "Task 1"; + label = "Task A"; A1 -> A2 -> A3 -> A4; } -} +} \ No newline at end of file diff --git a/src/img/trpl17-02.svg b/src/img/trpl17-02.svg index b2df090c23..5c32a1a262 100644 --- a/src/img/trpl17-02.svg +++ b/src/img/trpl17-02.svg @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<!-- Generated by graphviz version 12.1.0 (20240811.2233) +<!-- Generated by graphviz version 12.1.2 (20240928.0832) --> <!-- Pages: 1 --> <svg @@ -11,12 +11,12 @@ <g id="clust1" class="cluster"> <title>cluster_ColleagueB -Task 2 +Task B cluster_ColleagueA -Task 1 +Task A From 3111eda07a4a4692bf69e3aaad999d840ac9c138 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 7 Oct 2024 13:25:41 -0600 Subject: [PATCH 611/720] Ch. 17: create a diagram showing blocked parallelism --- dot/trpl17-03.dot | 35 +++++++--- dot/trpl17-04.dot | 31 +++------ dot/trpl17-05.dot | 52 ++++++-------- dot/trpl17-06.dot | 58 +++++---------- dot/trpl17-07.dot | 73 ++++++++++++------- dot/trpl17-08.dot | 41 +++-------- dot/trpl17-09.dot | 62 +++++++++++++++++ nostarch/chapter17.md | 46 ++++++------ src/ch17-00-async-await.md | 18 +++-- src/ch17-05-traits-for-async.md | 32 ++++----- src/img/trpl17-03.svg | 120 ++++++++++++++++++++++++++------ 11 files changed, 348 insertions(+), 220 deletions(-) create mode 100644 dot/trpl17-09.dot diff --git a/dot/trpl17-03.dot b/dot/trpl17-03.dot index 6c63b7bde4..7d5a4971cf 100644 --- a/dot/trpl17-03.dot +++ b/dot/trpl17-03.dot @@ -1,19 +1,32 @@ digraph { - rankdir = RL; - overlap = false; dpi = 300.0; + + rankdir = "LR"; splines = false; cluster = true; - node [shape = "plaintext";]; + node [shape = diamond;]; + + // The graphs end up with the correct order, i.e. Task 1 *above* Task 2, when + // this is first. + subgraph cluster_ColleagueB { + label = "Task A"; + A1; + A2; + A0_1 [style = invis;]; + A3; + + A1 -> A2; + A2 -> A0_1 [arrowhead = "tee"; headport = "A0_1:c"; headclip = false;]; + A0_1; + A0_1 -> A3 [dir = both; arrowtail = "tee"; tailclip = false;]; + } - fut1 [label = < - - - - -
fut1
0
1
>;]; + subgraph cluster_ColleagueA { + newrank = true; + label = "Task B"; + B1 -> B2 -> B3 -> B4; + } - edge [tailclip = "false";]; - fut1:source:c -> fut1:target [dir = forward;]; + B3 -> A3; } \ No newline at end of file diff --git a/dot/trpl17-04.dot b/dot/trpl17-04.dot index afcf8e77a1..6c63b7bde4 100644 --- a/dot/trpl17-04.dot +++ b/dot/trpl17-04.dot @@ -7,26 +7,13 @@ digraph { node [shape = "plaintext";]; - // Group the two together, which results in the desired alignment. - subgraph { - // But don't show the frame! - style = "invis"; - - fut1 [label = < - - - - -
fut1
?
?
?
>;]; - - fut2 [label = < - - - - -
fut2
0
1
>;]; - - edge [tailclip = "false"; dir = forward]; - fut2:source:c -> fut1:target:e; - } + fut1 [label = < + + + + +
fut1
0
1
>;]; + + edge [tailclip = "false";]; + fut1:source:c -> fut1:target [dir = forward;]; } \ No newline at end of file diff --git a/dot/trpl17-05.dot b/dot/trpl17-05.dot index e036a385c3..afcf8e77a1 100644 --- a/dot/trpl17-05.dot +++ b/dot/trpl17-05.dot @@ -1,42 +1,32 @@ digraph { - rankdir = LR; + rankdir = RL; + overlap = false; dpi = 300.0; + splines = false; + cluster = true; node [shape = "plaintext";]; - pinned_box [label = < - - -
Pin
>;]; - - subgraph cluster_box { - label = ""; - peripheries = 0; + // Group the two together, which results in the desired alignment. + subgraph { + // But don't show the frame! + style = "invis"; - subgraph cluster_box_internal { - peripheries = 1; - label = "b1"; - shape = box; - style = solid; - pin [shape = "point";]; - } - } - - subgraph cluster_deref { - style = bold; - label = "pinned"; + fut1 [label = < + + + + +
fut1
?
?
?
>;]; - box [label = < - - + fut2 [label = <
fut
0
+ + + - -
fut2
0
1
...
1
>;]; + + edge [tailclip = "false"; dir = forward]; + fut2:source:c -> fut1:target:e; } - - edge [tailclip = false;]; - pinned_box -> pin [tailport = "source:c"; arrowhead = "none";]; - pin -> box [headport = "target";]; - box -> box [tailport = "source:c"; headport = "internal";]; } \ No newline at end of file diff --git a/dot/trpl17-06.dot b/dot/trpl17-06.dot index 11b79574c4..e036a385c3 100644 --- a/dot/trpl17-06.dot +++ b/dot/trpl17-06.dot @@ -1,50 +1,32 @@ digraph { rankdir = LR; - newrank = true; dpi = 300.0; node [shape = "plaintext";]; + pinned_box [label = < + + +
Pin
>;]; - subgraph cluster_not_fut { + subgraph cluster_box { + label = ""; peripheries = 0; - pin [label = < - - -
Pin
>;]; - - subgraph cluster_boxes { - peripheries = 0; - rank = same; - - subgraph cluster_box_1 { - subgraph cluster_box_2_internal { - label = "b1"; - shape = box; - style = solid; - style = filled; - peripheries = 1; - box1 [shape = "point";style = "invis";]; - } - } - - subgraph cluster_box_2 { - subgraph cluster_box_2_internal { - label = "b2"; - shape = box; - style = solid; - peripheries = 1; - box2 [shape = "point";]; - } - } + subgraph cluster_box_internal { + peripheries = 1; + label = "b1"; + shape = box; + style = solid; + pin [shape = "point";]; } } - subgraph cluster_target { + + subgraph cluster_deref { style = bold; label = "pinned"; - fut [label = < + box [label = <
@@ -53,12 +35,8 @@ digraph {
fut
0
>;]; } - - box1 -> box2 [rankdir = TB; style = invis;]; - edge [tailclip = false;]; - pin -> box1 [style = "invis";]; - pin -> box2 [tailport = "source:c"; arrowhead = "none";]; - box2 -> fut [headport = "target";]; - fut -> fut [tailport = "source:c"; headport = "internal";]; + pinned_box -> pin [tailport = "source:c"; arrowhead = "none";]; + pin -> box [headport = "target";]; + box -> box [tailport = "source:c"; headport = "internal";]; } \ No newline at end of file diff --git a/dot/trpl17-07.dot b/dot/trpl17-07.dot index 8e9897f46d..11b79574c4 100644 --- a/dot/trpl17-07.dot +++ b/dot/trpl17-07.dot @@ -1,39 +1,64 @@ digraph { rankdir = LR; - overlap = false; - dpi = 300.0; - splines = false; - cluster = true; newrank = true; - outputorder = in; - compound = true; - labelloc = "c"; + dpi = 300.0; node [shape = "plaintext";]; - pinned_box [label = < - - -
Pin
>;]; - - subgraph cluster_deref { - style = dashed; - label = "String"; + subgraph cluster_not_fut { + peripheries = 0; + + pin [label = < + + +
Pin
>;]; - pin [shape = "point";]; + subgraph cluster_boxes { + peripheries = 0; + rank = same; + + subgraph cluster_box_1 { + subgraph cluster_box_2_internal { + label = "b1"; + shape = box; + style = solid; + style = filled; + peripheries = 1; + box1 [shape = "point";style = "invis";]; + } + } + + subgraph cluster_box_2 { + subgraph cluster_box_2_internal { + label = "b2"; + shape = box; + style = solid; + peripheries = 1; + box2 [shape = "point";]; + } + } + } + } + subgraph cluster_target { + style = bold; + label = "pinned"; fut [label = < - - - - - - + + + + +
5usizehello
fut
0
...
1
>;]; } + + box1 -> box2 [rankdir = TB; style = invis;]; + edge [tailclip = false;]; - pinned_box -> pin [tailport = "source:c"; arrowhead = "none";]; - pin -> fut [headport = "target";]; + pin -> box1 [style = "invis";]; + pin -> box2 [tailport = "source:c"; arrowhead = "none";]; + box2 -> fut [headport = "target";]; + fut -> fut [tailport = "source:c"; headport = "internal";]; } \ No newline at end of file diff --git a/dot/trpl17-08.dot b/dot/trpl17-08.dot index de73007511..8e9897f46d 100644 --- a/dot/trpl17-08.dot +++ b/dot/trpl17-08.dot @@ -16,47 +16,24 @@ digraph { >;]; - subgraph cluster_both { - peripheries = 0; - + + subgraph cluster_deref { + style = dashed; + label = "String"; + pin [shape = "point";]; - string1 [label = < - - - + fut [label = <
s1
5usize
+ - - +
5usize h e l lo
o
>;]; - - subgraph cluster_deref { - style = dashed; - label = "String"; - peripheries = 1; - - pin [shape = "point";]; - - string2 [label = < - - - - - - - - - - - -
s2
7usizegoodbye
>;]; - } } edge [tailclip = false;]; pinned_box -> pin [tailport = "source:c"; arrowhead = "none";]; - pin -> string2 [headport = "target";]; + pin -> fut [headport = "target";]; } \ No newline at end of file diff --git a/dot/trpl17-09.dot b/dot/trpl17-09.dot new file mode 100644 index 0000000000..de73007511 --- /dev/null +++ b/dot/trpl17-09.dot @@ -0,0 +1,62 @@ +digraph { + rankdir = LR; + overlap = false; + dpi = 300.0; + splines = false; + cluster = true; + newrank = true; + outputorder = in; + compound = true; + labelloc = "c"; + + node [shape = "plaintext";]; + + pinned_box [label = < + + +
Pin
>;]; + + subgraph cluster_both { + peripheries = 0; + + + + string1 [label = < + + + + + + + + + +
s1
5usizehello
>;]; + + subgraph cluster_deref { + style = dashed; + label = "String"; + peripheries = 1; + + pin [shape = "point";]; + + string2 [label = < + + + + + + + + + + + +
s2
7usizegoodbye
>;]; + } + } + + edge [tailclip = false;]; + pinned_box -> pin [tailport = "source:c"; arrowhead = "none";]; + pin -> string2 [headport = "target";]; +} \ No newline at end of file diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index 45757777d4..a8149cf5c6 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -89,7 +89,7 @@ tasks by switching between them. Concurrent work flow -Figure 17-1: A concurrent workflow, switching between Task A and Task B +Figure 17-1: A concurrent workflow, switching between Task A and Task B. When you agree to split up a group of tasks between the people on the team, with each person taking one task and working on it alone, this is *parallelism*. Each @@ -98,15 +98,21 @@ person on the team can make progress at the exact same time. Concurrent work flow Figure 17-2: A parallel workflow, where work happens on Task A and Task B -independently +independently. With both of these situations, you might have to coordinate between different tasks. Maybe you *thought* the task that one person was working on was totally independent from everyone else’s work, but it actually needs something finished by another person on the team. Some of the work could be done in parallel, but some of it was actually *serial*: it could only happen in a series, one thing -after the other. Likewise, you might realize that one of your own tasks depends -on another of your tasks. Now your concurrent work has also become serial. +after the other, as in Figure 17-3. + +Concurrent work flow + +Figure 17-3: A partially parallel workflow, where work happens on Task A and Task B independently until task A3 is blocked on the results of task B3. + +Likewise, you might realize that one of your own tasks depends on another of +your tasks. Now your concurrent work has also become serial. Parallelism and concurrency can intersect with each other, too. If you learn that a colleague is stuck until you finish one of your tasks, you’ll probably @@ -2601,13 +2607,13 @@ When we move a future—whether by pushing into a data structure to use as an iterator with `join_all`, or returning them from a function—that actually means moving the state machine Rust creates for us. And unlike most other types in Rust, the futures Rust creates for async blocks can end up with references to -themselves in the fields of any given variant, as in Figure 17-3 (a simplified +themselves in the fields of any given variant, as in Figure 17-4 (a simplified illustration to help you get a feel for the idea, rather than digging into what are often fairly complicated details). -Concurrent work flow +Concurrent work flow -Figure 17-3: A self-referential data type. +Figure 17-4: A self-referential data type. By default, though, any object which has a reference to itself is unsafe to move, because references always point to the actual memory address of the thing @@ -2618,9 +2624,9 @@ the data structure. For another—and more importantly!—the computer is now fr to reuse that memory for other things! You could end up reading completely unrelated data later. -Concurrent work flow +Concurrent work flow -Figure 17-4: The unsafe result of moving a self-referential data type. +Figure 17-5: The unsafe result of moving a self-referential data type. In principle, the Rust compiler could try to update every reference to an object every time it gets moved. That would potentially be a lot of performance @@ -2633,25 +2639,25 @@ which has any active references to it using safe code. `Pin` builds on that to give us the exact guarantee we need. When we *pin* a value by wrapping a pointer to that value in `Pin`, it can no longer move. Thus, if you have `Pin>`, you actually pin the `SomeType` value, *not* -the `Box` pointer. Figure 17-5 illustrates this: +the `Box` pointer. Figure 17-6 illustrates this: -Concurrent work flow +Concurrent work flow -Figure 17-5: Pinning a `Box` which points to a self-referential future type. +Figure 17-6: Pinning a `Box` which points to a self-referential future type. In fact, the `Box` pointer can still move around freely. Remember: we care about making sure the data ultimately being referenced stays in its place. If a pointer moves around, but the data it points to is in the same place, as in -Figure 17-6, there’s no potential problem. (How you would do this with a `Pin` +Figure 17-7, there’s no potential problem. (How you would do this with a `Pin` wrapping a `Box` is more than we’ll get into in this particular discussion, but it would make for a good exercise! If you look at the docs for the types as well as the `std::pin` module, you might be able to work out how you would do that.) The key is that the self-referential type itself cannot move, because it is still pinned. -Concurrent work flow +Concurrent work flow -Figure 17-6: Moving a `Box` which points to a self-referential future type. +Figure 17-7: Moving a `Box` which points to a self-referential future type. However, most types are perfectly safe to move around, even if they happen to be behind a `Pin` pointer. We only need to think about pinning when items have @@ -2683,19 +2689,19 @@ To make that concrete, think about a `String`: it has a length and the Unicode characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure 17-7. However -Concurrent work flow +Concurrent work flow -Figure 17-7: Pinning a String, with a dotted line indicating that the String +Figure 17-8: Pinning a String, with a dotted line indicating that the String implements the `Unpin` trait, so it is not pinned. This means that we can do things such as replace one string with another at the -exact same location in memory as in Figure 17-8. This doesn’t violate the `Pin` +exact same location in memory as in Figure 17-9. This doesn’t violate the `Pin` contract because `String`—like most other types in Rust—implements `Unpin`, because it has no internal references that make it unsafe to move around! -Concurrent work flow +Concurrent work flow -Figure 17-8: Replacing the String with an entirely different String in memory. +Figure 17-9: Replacing the String with an entirely different String in memory. Now we know enough to understand the errors reported for that `join_all` call from back in Listing 17-17. We originally tried to move the futures produced by diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 920486d333..5fe7020224 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -89,7 +89,7 @@ tasks by switching between them. Concurrent work flow -
Figure 17-1: A concurrent workflow, switching between Task A and Task B
+
Figure 17-1: A concurrent workflow, switching between Task A and Task B.
@@ -101,7 +101,7 @@ person on the team can make progress at the exact same time. Concurrent work flow -
Figure 17-2: A parallel workflow, where work happens on Task A and Task B independently
+
Figure 17-2: A parallel workflow, where work happens on Task A and Task B independently.
@@ -110,8 +110,18 @@ tasks. Maybe you *thought* the task that one person was working on was totally independent from everyone else’s work, but it actually needs something finished by another person on the team. Some of the work could be done in parallel, but some of it was actually *serial*: it could only happen in a series, one thing -after the other. Likewise, you might realize that one of your own tasks depends -on another of your tasks. Now your concurrent work has also become serial. +after the other, as in Figure 17-3. + +
+ +Concurrent work flow + +
Figure 17-3: A partially parallel workflow, where work happens on Task A and Task B independently until task A3 is blocked on the results of task B3.
+ +
+ +Likewise, you might realize that one of your own tasks depends on another of +your tasks. Now your concurrent work has also become serial. Parallelism and concurrency can intersect with each other, too. If you learn that a colleague is stuck until you finish one of your tasks, you’ll probably diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index a7c5feee50..746264d861 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -224,15 +224,15 @@ When we move a future—whether by pushing into a data structure to use as an iterator with `join_all`, or returning them from a function—that actually means moving the state machine Rust creates for us. And unlike most other types in Rust, the futures Rust creates for async blocks can end up with references to -themselves in the fields of any given variant, as in Figure 17-3 (a simplified +themselves in the fields of any given variant, as in Figure 17-4 (a simplified illustration to help you get a feel for the idea, rather than digging into what are often fairly complicated details).
-Concurrent work flow +Concurrent work flow -
Figure 17-3: A self-referential data type.
+
Figure 17-4: A self-referential data type.
@@ -247,9 +247,9 @@ unrelated data later.
-Concurrent work flow +Concurrent work flow -
Figure 17-4: The unsafe result of moving a self-referential data type.
+
Figure 17-5: The unsafe result of moving a self-referential data type.
@@ -264,20 +264,20 @@ which has any active references to it using safe code. `Pin` builds on that to give us the exact guarantee we need. When we *pin* a value by wrapping a pointer to that value in `Pin`, it can no longer move. Thus, if you have `Pin>`, you actually pin the `SomeType` value, *not* -the `Box` pointer. Figure 17-5 illustrates this: +the `Box` pointer. Figure 17-6 illustrates this:
-Concurrent work flow +Concurrent work flow -
Figure 17-5: Pinning a `Box` which points to a self-referential future type.
+
Figure 17-6: Pinning a `Box` which points to a self-referential future type.
In fact, the `Box` pointer can still move around freely. Remember: we care about making sure the data ultimately being referenced stays in its place. If a pointer moves around, but the data it points to is in the same place, as in -Figure 17-6, there’s no potential problem. (How you would do this with a `Pin` +Figure 17-7, there’s no potential problem. (How you would do this with a `Pin` wrapping a `Box` is more than we’ll get into in this particular discussion, but it would make for a good exercise! If you look at the docs for the types as well as the `std::pin` module, you might be able to work out how you would do @@ -286,9 +286,9 @@ is still pinned.
-Concurrent work flow +Concurrent work flow -
Figure 17-6: Moving a `Box` which points to a self-referential future type.
+
Figure 17-7: Moving a `Box` which points to a self-referential future type.
@@ -323,22 +323,22 @@ characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure
-Concurrent work flow +Concurrent work flow -
Figure 17-7: Pinning a String, with a dotted line indicating that the String implements the `Unpin` trait, so it is not pinned.
+
Figure 17-8: Pinning a String, with a dotted line indicating that the String implements the `Unpin` trait, so it is not pinned.
This means that we can do things such as replace one string with another at the -exact same location in memory as in Figure 17-8. This doesn’t violate the `Pin` +exact same location in memory as in Figure 17-9. This doesn’t violate the `Pin` contract because `String`—like most other types in Rust—implements `Unpin`, because it has no internal references that make it unsafe to move around!
-Concurrent work flow +Concurrent work flow -
Figure 17-8: Replacing the String with an entirely different String in memory.
+
Figure 17-9: Replacing the String with an entirely different String in memory.
diff --git a/src/img/trpl17-03.svg b/src/img/trpl17-03.svg index fed6c36040..ad105a5830 100644 --- a/src/img/trpl17-03.svg +++ b/src/img/trpl17-03.svg @@ -1,30 +1,110 @@ - - - - - + + + + +cluster_ColleagueB + +Task A + + +cluster_ColleagueA + +Task B + + -fut1 - -fut1 - -0 - -1 - -   - - +A1 + +A1 + + + +A2 + +A2 + + -fut1:c->fut1:target - - +A1->A2 + + + + + + +A2->A0_1:c + + + + + + +A3 + +A3 + + + +A0_1->A3 + + + + + + + +B1 + +B1 + + + +B2 + +B2 + + + +B1->B2 + + + + + +B3 + +B3 + + + +B2->B3 + + + + + +B3->A3 + + + + + +B4 + +B4 + + + +B3->B4 + + From a64884fb8b8011840c291168d1ab26c0b0886749 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 7 Oct 2024 13:57:33 -0600 Subject: [PATCH 612/720] =?UTF-8?q?Ch.=2017:=20kill=20a=20double-=E2=80=9C?= =?UTF-8?q?thus=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nostarch/chapter17.md | 8 ++++---- src/ch17-01-futures-and-syntax.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index a8149cf5c6..ad633688d1 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -301,10 +301,10 @@ some code in `main` to call it, let’s talk a little more about what we’ve written and what it means. When Rust sees a block marked with the `async` keyword, it compiles it into a -unique, anonymous data type which implements the `Future` trait. When Rust -sees a function marked with `async`, it compiles it into a non-async function -whose body is an async block. Thus, an async function’s return type is the type -of the anonymous data type the compiler creates for that async block. +unique, anonymous data type which implements the `Future` trait. When Rust sees +a function marked with `async`, it compiles it into a non-async function whose +body is an async block. An async function’s return type is the type of the of +the anonymous data type the compiler creates for that async block. Thus, writing `async fn` is equivalent to writing a function which returns a *future* of the return type. When the compiler sees a function definition such diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 2799ff3276..6edade4551 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -146,10 +146,10 @@ some code in `main` to call it, let’s talk a little more about what we’ve written and what it means. When Rust sees a block marked with the `async` keyword, it compiles it into a -unique, anonymous data type which implements the `Future` trait. When Rust -sees a function marked with `async`, it compiles it into a non-async function -whose body is an async block. Thus, an async function’s return type is the type -of the anonymous data type the compiler creates for that async block. +unique, anonymous data type which implements the `Future` trait. When Rust sees +a function marked with `async`, it compiles it into a non-async function whose +body is an async block. An async function’s return type is the type of the +anonymous data type the compiler creates for that async block. Thus, writing `async fn` is equivalent to writing a function which returns a *future* of the return type. When the compiler sees a function definition such From 8aee93d82d18477e8c0290eda2f4b00852c88d7a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 7 Oct 2024 13:57:33 -0600 Subject: [PATCH 613/720] Ch. 17: include `main` when first showing `trpl::run` This gives people a better chance of understanding how the pieces fit together. --- listings/ch17-async-await/listing-17-04/src/main.rs | 4 ++-- nostarch/chapter17.md | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/listings/ch17-async-await/listing-17-04/src/main.rs b/listings/ch17-async-await/listing-17-04/src/main.rs index dbc0d4c6e1..23b2ea99f0 100644 --- a/listings/ch17-async-await/listing-17-04/src/main.rs +++ b/listings/ch17-async-await/listing-17-04/src/main.rs @@ -2,10 +2,10 @@ extern crate trpl; // required for mdbook test use trpl::Html; +// ANCHOR: run fn main() { let args: Vec = std::env::args().collect(); - // ANCHOR: run trpl::run(async { let url = &args[1]; match page_title(url).await { @@ -13,8 +13,8 @@ fn main() { None => println!("{url} had no title"), } }) - // ANCHOR_END: run } +// ANCHOR_END: run async fn page_title(url: &str) -> Option { let response_text = trpl::get(url).await.text().await; diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index ad633688d1..35ca15f610 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -417,6 +417,9 @@ await the result of calling `page_title`, as in Listing 17-4. Filename: src/main.rs ``` +fn main() { + let args: Vec = std::env::args().collect(); + trpl::run(async { let url = &args[1]; match page_title(url).await { @@ -424,6 +427,7 @@ Filename: src/main.rs None => println!("{url} had no title"), } }) +} ``` Listing 17-4: Awaiting an async block with `trpl::run` From f45980afda19546ea29879ec9bd9aac84d6aeeb8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 7 Oct 2024 14:24:34 -0600 Subject: [PATCH 614/720] Ch. 17: get rid of some extra italics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These made more sense when this section was all about big ideas and the runtimes; now it’s needless since we actually spent the section building something non-trivial. --- nostarch/chapter17.md | 2 +- src/ch17-01-futures-and-syntax.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index 35ca15f610..8055982cb9 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -567,7 +567,7 @@ You have built a small working web scraper now! Pick a couple URLs and run the command line tool. You may discover that some sites are reliably faster than others, while in other cases which site “wins” varies from run to run. More importantly, you’ve learned the basics of working with futures, so we can now -dig into even more of the things we can *do* with async. +dig into even more of the things we can do with async. ## Concurrency With Async diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 6edade4551..a82366f7f3 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -369,7 +369,7 @@ You have built a small working web scraper now! Pick a couple URLs and run the command line tool. You may discover that some sites are reliably faster than others, while in other cases which site “wins” varies from run to run. More importantly, you’ve learned the basics of working with futures, so we can now -dig into even more of the things we can *do* with async. +dig into even more of the things we can do with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters [iterators-lazy]: ch13-02-iterators.html From 7076be0692052f578dfb3e819c42b644202cd403 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 8 Oct 2024 08:09:29 -0600 Subject: [PATCH 615/720] Ch. 17: improve the discussion of streams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - One example compiles that I used to think didn’t. Probably the result of some renumbering. Need to check *all* of those. - Don’t repeat the same basic “you ” form so much. --- nostarch/chapter17.md | 50 +++++++++++++++++++++--------------------- src/ch17-04-streams.md | 48 +++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index 8055982cb9..dbb4296914 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -1899,21 +1899,20 @@ help: there is a method `try_next` with a similar name For more information about this error, try `rustc --explain E0599`. ``` -As the output suggests, the problem is that we need the right trait in scope to -be able to use the `next` method. Given our discussion so far, you might -reasonably expect that to be `Stream`, but the trait we need *here* is actually -`StreamExt`. The `Ext` there is for “extension”: this is a common pattern in -the Rust community for extending one trait with another. - -You might be wondering why `StreamExt` instead of `Stream`, and for that matter -whether there is a `Stream` trait at all. Briefly, the answer is that throughout -the Rust ecosystem, the `Stream` trait defines a low-level interface which -effectively combines the `Iterator` and `Future` traits. The `StreamExt` trait -supplies a higher-level set of APIs on top of `Stream`, including the `next` -method as well as other utility methods similar to those provided by the -`Iterator` trait. We’ll return to the `Stream` and `StreamExt` traits in a -bit more detail at the end of the chapter. For now, this is enough to let us -keep moving. +As the output suggests, the reason for the compiler error is that we need the +right trait in scope to be able to use the `next` method. Given our discussion +so far, you might reasonably expect that to be `Stream`, but the trait we need +here is actually `StreamExt`. The `Ext` there is for “extension”: this is a +common pattern in the Rust community for extending one trait with another. + +Why do we need `StreamExt` instead of `Stream`, and what does the `Stream` trait +itself do? Briefly, the answer is that throughout the Rust ecosystem, the +`Stream` trait defines a low-level interface which effectively combines the +`Iterator` and `Future` traits. The `StreamExt` trait supplies a higher-level +set of APIs on top of `Stream`, including the `next` method as well as other +utility methods similar to those provided by the `Iterator` trait. We’ll return +to the `Stream` and `StreamExt` traits in a bit more detail at the end of the +chapter. For now, this is enough to let us keep moving. The fix to the compiler error is to add a `use` statement for `trpl::StreamExt`, as in Listing 17-31. @@ -2109,13 +2108,13 @@ Listing 17-35: Sending messages through `tx` with an async delay without making To sleep between messages in the `get_messages` function without blocking, we need to use async. However, we can’t make `get_messages` itself into an async function, because then we’d return a `Future>` -instead of just a `Stream>`. The caller would have to await -`get_messages` itself to get access to the stream. But remember: everything in -a given future happens linearly; concurrency happens *between* futures. -Awaiting `get_messages` would require it to send all the messages, including -sleeping between sending each message, before returning the receiver stream. As -a result, the timeout would end up useless. There would be no delays in the -stream itself: the delays would all happen before the stream was even available. +instead of a `Stream>`. The caller would have to await +`get_messages` itself to get access to the stream. But remember: everything in a +given future happens linearly; concurrency happens *between* futures. Awaiting +`get_messages` would require it to send all the messages, including sleeping +between sending each message, before returning the receiver stream. As a result, +the timeout would end up useless. There would be no delays in the stream itself: +the delays would all happen before the stream was even available. Instead, we leave `get_messages` as a regular function which returns a stream, and spawn a task to handle the async `sleep` calls. @@ -2557,9 +2556,10 @@ pub trait Future { } ``` -The `cx` parameter and its `Context` type is interesting, but is beyond the -scope of this chapter: you generally only need to worry about it when writing a -custom `Future` implementation. +The `cx` parameter and its `Context` type is the key to how a runtime actually +knows when to check any given future, while still being lazy. The details of how +that works are beyond the scope of this chapter, though: you generally only need +to worry about it when writing a custom `Future` implementation. Instead, we’ll focus on the type for `self`. This is the first time we’ve seen a method where `self` has a type annotation. A type annotation for `self` is diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 7bcc24ee4e..a3085aa62a 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -74,28 +74,27 @@ help: there is a method `try_next` with a similar name For more information about this error, try `rustc --explain E0599`. ``` -As the output suggests, the problem is that we need the right trait in scope to -be able to use the `next` method. Given our discussion so far, you might -reasonably expect that to be `Stream`, but the trait we need *here* is actually -`StreamExt`. The `Ext` there is for “extension”: this is a common pattern in -the Rust community for extending one trait with another. - -You might be wondering why `StreamExt` instead of `Stream`, and for that matter -whether there is a `Stream` trait at all. Briefly, the answer is that throughout -the Rust ecosystem, the `Stream` trait defines a low-level interface which -effectively combines the `Iterator` and `Future` traits. The `StreamExt` trait -supplies a higher-level set of APIs on top of `Stream`, including the `next` -method as well as other utility methods similar to those provided by the -`Iterator` trait. We’ll return to the `Stream` and `StreamExt` traits in a -bit more detail at the end of the chapter. For now, this is enough to let us -keep moving. +As the output suggests, the reason for the compiler error is that we need the +right trait in scope to be able to use the `next` method. Given our discussion +so far, you might reasonably expect that to be `Stream`, but the trait we need +here is actually `StreamExt`. The `Ext` there is for “extension”: this is a +common pattern in the Rust community for extending one trait with another. + +Why do we need `StreamExt` instead of `Stream`, and what does the `Stream` trait +itself do? Briefly, the answer is that throughout the Rust ecosystem, the +`Stream` trait defines a low-level interface which effectively combines the +`Iterator` and `Future` traits. The `StreamExt` trait supplies a higher-level +set of APIs on top of `Stream`, including the `next` method as well as other +utility methods similar to those provided by the `Iterator` trait. We’ll return +to the `Stream` and `StreamExt` traits in a bit more detail at the end of the +chapter. For now, this is enough to let us keep moving. The fix to the compiler error is to add a `use` statement for `trpl::StreamExt`, as in Listing 17-31. -```rust,ignore,does_not_compile +```rust {{#rustdoc_include ../listings/ch17-async-await/listing-17-31/src/main.rs:all}} ``` @@ -208,15 +207,14 @@ for 200 milliseconds, this should affect half of the messages. To sleep between messages in the `get_messages` function without blocking, we need to use async. However, we can’t make `get_messages` itself into an async -function, because then we’d return a `Future>` instead of just a `Stream>`. The caller would have to -await `get_messages` itself to get access to the stream. But remember: -everything in a given future happens linearly; concurrency happens *between* -futures. Awaiting `get_messages` would require it to send all the messages, -including sleeping between sending each message, before returning the receiver -stream. As a result, the timeout would end up useless. There would be no delays -in the stream itself: the delays would all happen before the stream was even -available. +function, because then we’d return a `Future>` +instead of a `Stream>`. The caller would have to await +`get_messages` itself to get access to the stream. But remember: everything in a +given future happens linearly; concurrency happens *between* futures. Awaiting +`get_messages` would require it to send all the messages, including sleeping +between sending each message, before returning the receiver stream. As a result, +the timeout would end up useless. There would be no delays in the stream itself: +the delays would all happen before the stream was even available. Instead, we leave `get_messages` as a regular function which returns a stream, and spawn a task to handle the async `sleep` calls. From 3b920cdf3bceec5868b05467467423765de79753 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 8 Oct 2024 08:09:29 -0600 Subject: [PATCH 616/720] Ch. 17: tweaks and fixes for discussion of the traits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix the numbers on the SVG files so they match up again after having added a new 17-3 earlier in the chapter. - Actually explain what `Context` is *for*, even though we don’t get into the details of using it. --- nostarch/chapter17.md | 2 +- src/ch17-05-traits-for-async.md | 19 +++--- src/img/trpl17-04.svg | 48 +++++--------- src/img/trpl17-05.svg | 85 +++++++++--------------- src/img/trpl17-06.svg | 111 ++++++++++++++------------------ src/img/trpl17-07.svg | 107 +++++++++++++++++++----------- src/img/trpl17-08.svg | 94 ++++++++++----------------- src/img/trpl17-09.svg | 85 ++++++++++++++++++++++++ 8 files changed, 291 insertions(+), 260 deletions(-) create mode 100644 src/img/trpl17-09.svg diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index dbb4296914..612740c2cb 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -2675,7 +2675,7 @@ via the safe but restrictive APIs provided by `Pin`, even though a need a way to tell the compiler that it’s actually just fine to move items around in cases such as these. For that, we have `Unpin`. -`Unpin` is a marker trait, as `Send` and `Sync` are, which we saw in the +`Unpin` is a marker trait, similar to the `Send` and `Sync` traits we saw in the “Extensible Concurrency with the `Sync` and `Send` Traits” section of Chapter 16 on page XX. Recall that marker traits have no functionality of their own. They exist only to tell the compiler that it’s safe to use the type which diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 746264d861..c7c82d8711 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -172,9 +172,10 @@ pub trait Future { } ``` -The `cx` parameter and its `Context` type is interesting, but is beyond the -scope of this chapter: you generally only need to worry about it when writing a -custom `Future` implementation. +The `cx` parameter and its `Context` type is the key to how a runtime actually +knows when to check any given future, while still being lazy. The details of how +that works are beyond the scope of this chapter, though: you generally only need +to worry about it when writing a custom `Future` implementation. Instead, we’ll focus on the type for `self`. This is the first time we’ve seen a method where `self` has a type annotation. A type annotation for `self` is @@ -304,12 +305,12 @@ via the safe but restrictive APIs provided by `Pin`, even though a need a way to tell the compiler that it’s actually just fine to move items around in cases such as these. For that, we have `Unpin`. -`Unpin` is a marker trait, as `Send` and `Sync` are, which we saw in Chapter 16. -Recall that marker traits have no functionality of their own. They exist only to -tell the compiler that it’s safe to use the type which implements a given trait -in a particular context. `Unpin` informs the compiler that a given type does -*not* need to uphold any particular guarantees about whether the value in -question can be moved. +`Unpin` is a marker trait, similar to the `Send` and `Sync` traits we saw in +Chapter 16. Recall that marker traits have no functionality of their own. They +exist only to tell the compiler that it’s safe to use the type which implements +a given trait in a particular context. `Unpin` informs the compiler that a given +type does *not* need to uphold any particular guarantees about whether the value +in question can be moved. Just as with `Send` and `Sync`, the compiler implements `Unpin` automatically for all types where it can prove it is safe. Implementing `Unpin` manually is diff --git a/src/img/trpl17-04.svg b/src/img/trpl17-04.svg index e3472baa7c..fed6c36040 100644 --- a/src/img/trpl17-04.svg +++ b/src/img/trpl17-04.svg @@ -4,43 +4,27 @@ - - - - -%3 - + + + fut1 - - -fut1 - -? - -? - -? - - - -fut2 - -fut2 - -0 - -1 - - + +fut1 + +0 + +1 + +   - + -fut2:c->fut1:c - - +fut1:c->fut1:target + + diff --git a/src/img/trpl17-05.svg b/src/img/trpl17-05.svg index 443bb568dc..e3472baa7c 100644 --- a/src/img/trpl17-05.svg +++ b/src/img/trpl17-05.svg @@ -5,65 +5,42 @@ --> - - + viewBox="0.00 0.00 767.00 575.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + + -cluster_box +%3 - -cluster_box_internal - -b1 - - -cluster_deref - -pinned - - + -pinned_box - -Pin - - - - +fut1 + + +fut1 + +? + +? + +? + + -pin - - - +fut2 + +fut2 + +0 + +1 + + + + -pinned_box:c->pin - - - - -box - -fut - -0 - - - -... - -1 - - - -pin->box:target - - - - - -box:c->box:internal - - +fut2:c->fut1:c + + diff --git a/src/img/trpl17-06.svg b/src/img/trpl17-06.svg index 712e3006f6..443bb568dc 100644 --- a/src/img/trpl17-06.svg +++ b/src/img/trpl17-06.svg @@ -4,83 +4,66 @@ - - - + + + -cluster_not_fut +cluster_box -cluster_boxes +cluster_box_internal + +b1 -cluster_box_1 +cluster_deref + +pinned - -cluster_box_2_internal - -b1 - - -cluster_box_2 - - -cluster_box_2_internal - -b2 - - -cluster_target - -pinned + + +pinned_box + +Pin + + - + pin - -Pin - - + - - - - -box2 - - - - -pin:c->box2 - + + +pinned_box:c->pin + - - - -fut - -fut - -0 - - - -... - -1 + + +box + +fut + +0 + + + +... + +1 - - -box2->fut:target - - + + +pin->box:target + + - - -fut:c->fut:internal - - + + +box:c->box:internal + + diff --git a/src/img/trpl17-07.svg b/src/img/trpl17-07.svg index b2275ac19f..712e3006f6 100644 --- a/src/img/trpl17-07.svg +++ b/src/img/trpl17-07.svg @@ -4,54 +4,83 @@ - - - + + + -cluster_deref - -String +cluster_not_fut - - -pinned_box - -Pin - - + +cluster_boxes + + +cluster_box_1 + + +cluster_box_2_internal + +b1 + + +cluster_box_2 + + +cluster_box_2_internal + +b2 + + +cluster_target + +pinned - + pin - + +Pin + + + + + + + +box2 + - - -pinned_box:c->pin - + + +pin:c->box2 + + - + fut - -5usize - -h - -e - -l - -l - -o - - - -pin->fut:target - - + +fut + +0 + + + +... + +1 + + + +box2->fut:target + + + + + +fut:c->fut:internal + + diff --git a/src/img/trpl17-08.svg b/src/img/trpl17-08.svg index 997d9b82e1..b2275ac19f 100644 --- a/src/img/trpl17-08.svg +++ b/src/img/trpl17-08.svg @@ -4,82 +4,54 @@ - - - + + + -cluster_both - - cluster_deref - -String + +String pinned_box - -Pin - - + +Pin + + - + pin - + pinned_box:c->pin - + - - -string1 - - -s1 - -5usize - -h - -e - -l - -l - -o - - - -string2 - -s2 - -7usize - -g - -o - -o - -d - -b - -y - -e - - + + +fut + +5usize + +h + +e + +l + +l + +o + + -pin->string2:target - - +pin->fut:target + + diff --git a/src/img/trpl17-09.svg b/src/img/trpl17-09.svg new file mode 100644 index 0000000000..997d9b82e1 --- /dev/null +++ b/src/img/trpl17-09.svg @@ -0,0 +1,85 @@ + + + + + + + + +cluster_both + + +cluster_deref + +String + + + +pinned_box + +Pin + + + + + +pin + + + + +pinned_box:c->pin + + + + +string1 + + +s1 + +5usize + +h + +e + +l + +l + +o + + + +string2 + +s2 + +7usize + +g + +o + +o + +d + +b + +y + +e + + + +pin->string2:target + + + + + From 1af831aa5e80534d82a13998038630598d85ee2e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 8 Oct 2024 08:09:29 -0600 Subject: [PATCH 617/720] Ch. 17: Fix a lot of wording issues in the conclusion section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So many “however” sections! Etc. --- nostarch/chapter17.md | 72 ++++++++++++++-------------- src/ch17-06-futures-tasks-threads.md | 70 +++++++++++++-------------- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/nostarch/chapter17.md b/nostarch/chapter17.md index 612740c2cb..af8698283c 100644 --- a/nostarch/chapter17.md +++ b/nostarch/chapter17.md @@ -2850,9 +2850,9 @@ have threads! The async model provides a different—and ultimately complementary—set of tradeoffs. In the async model, concurrent operations don’t require their own threads. Instead, they can run on tasks, as when we used `trpl::spawn_task` to -kick off work from a synchronous function throughout the streams section. A -*task* is similar to a thread—but instead of being managed by the operating -system, it’s managed by library-level code: the runtime. +kick off work from a synchronous function throughout the streams section. A task +is similar to a thread, but instead of being managed by the operating system, +it’s managed by library-level code: the runtime. In the previous section, we saw that we could build a `Stream` by using an async channel and spawning an async task which we could call from synchronous code. We @@ -2894,41 +2894,41 @@ from the perspective of the calling code! What’s more, even though one of our functions spawned an async task on the runtime and the other spawned an OS thread, the resulting streams were unaffected by the differences. -However, there’s a significant difference between how these two approaches -behave, although we might have a hard time measuring it in this very simple -example. We could spawn hundreds of thousands or even millions of async tasks -on any modern personal computer. If we tried to do that with threads, we would -literally run out of memory! +Despite the similarities, these two approaches behave very differently, although +we might have a hard time measuring it in this very simple example. We could +spawn millions of async tasks on any modern personal computer. If we tried to do +that with threads, we would literally run out of memory! However, there’s a reason these APIs are so similar. Threads act as a boundary for sets of synchronous operations; concurrency is possible *between* threads. Tasks act as a boundary for sets of *asynchronous* operations; concurrency is -possible both *between* and *within* tasks. In that regard, tasks are similar to -lightweight, runtime-managed threads with added capabilities that come from -being managed by a runtime instead of by the operating system. Futures are an -even more granular unit of concurrency, where each future may represent a tree -of other futures. That is, the runtime—specifically, its executor—manages tasks, -and tasks manage futures. - -However, this doesn’t mean that async tasks are always better than threads, any -more than that threads are always better than tasks. - -On the one hand, concurrency with threads is in some ways a simpler programming -model than concurrency with `async`. Threads are somewhat “fire and forget,” -they have no native equivalent to a future, so they simply run to completion, -without interruption except by the operating system itself. That is, they have -no *intra-task concurrency* the way futures can. Threads in Rust also have no -mechanisms for cancellation—a subject we haven’t covered in depth in this -chapter, but which is implicit in the fact that whenever we ended a future, its -state got cleaned up correctly. - -These limitations make threads harder to compose than futures. It’s much more -difficult, for example, to build something similar to the `timeout` we built in -the “Building Our Own Async Abstractions” section of this chapter on page XX, -or the `throttle` method we used with streams in the “Composing Streams” -section of this chapter on page XX. The fact that futures are richer data -structures means they *can* be composed together more naturally, as we have -seen. +possible both *between* and *within* tasks, because a task can switch between +futures in its body. Finally, futures are Rust’s most granular unit of +concurrency, and each future may represent a tree of other futures. The +runtime—specifically, its executor—manages tasks, and tasks manage futures. In +that regard, tasks are similar to lightweight, runtime-managed threads with +added capabilities that come from being managed by a runtime instead of by the +operating system. + +This doesn’t mean that async tasks are always better than threads, any more than +that threads are always better than tasks. + +Concurrency with threads is in some ways a simpler programming model than +concurrency with `async`. That can be a strength or a weakness. Threads are +somewhat “fire and forget,” they have no native equivalent to a future, so they +simply run to completion, without interruption except by the operating system +itself. That is, they have no built-in support for *intra-task concurrency* the +way futures do. Threads in Rust also have no mechanisms for cancellation—a +subject we haven’t covered in depth in this chapter, but which is implicit in +the fact that whenever we ended a future, its state got cleaned up correctly. + +These limitations also make threads harder to compose than futures. It’s much +more difficult, for example, to use threads to build helpers such as the +`timeout` we built in the “Building Our Own Async Abstractions” section of this +chapter on page XX or the `throttle` method we used with streams in the +“Composing Streams” section of this chapter on page XX. The fact that futures +are richer data structures means they can be composed together more naturally, +as we have seen. Tasks then give *additional* control over futures, allowing you to choose where and how to group the futures. And it turns out that threads and tasks often @@ -2938,8 +2938,8 @@ hood the `Runtime` we have been using, including the `spawn_blocking` and `spawn_task` functions, is multithreaded by default! Many runtimes use an approach called *work stealing* to transparently move tasks around between threads based on the current utilization of the threads, with the aim of -improving the overall performance of the system. To build, that actually -requires threads *and* tasks, and therefore futures. +improving the overall performance of the system. To build that actually requires +threads *and* tasks, and therefore futures. As a default way of thinking about which to use when: diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 21556b658c..bda6177385 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -18,9 +18,9 @@ have threads! The async model provides a different—and ultimately complementary—set of tradeoffs. In the async model, concurrent operations don’t require their own threads. Instead, they can run on tasks, as when we used `trpl::spawn_task` to -kick off work from a synchronous function throughout the streams section. A -*task* is similar to a thread—but instead of being managed by the operating -system, it’s managed by library-level code: the runtime. +kick off work from a synchronous function throughout the streams section. A task +is similar to a thread, but instead of being managed by the operating system, +it’s managed by library-level code: the runtime. In the previous section, we saw that we could build a `Stream` by using an async channel and spawning an async task which we could call from synchronous code. We @@ -42,40 +42,40 @@ from the perspective of the calling code! What’s more, even though one of our functions spawned an async task on the runtime and the other spawned an OS thread, the resulting streams were unaffected by the differences. -However, there’s a significant difference between how these two approaches -behave, although we might have a hard time measuring it in this very simple -example. We could spawn hundreds of thousands or even millions of async tasks -on any modern personal computer. If we tried to do that with threads, we would -literally run out of memory! +Despite the similarities, these two approaches behave very differently, although +we might have a hard time measuring it in this very simple example. We could +spawn millions of async tasks on any modern personal computer. If we tried to do +that with threads, we would literally run out of memory! However, there’s a reason these APIs are so similar. Threads act as a boundary for sets of synchronous operations; concurrency is possible *between* threads. Tasks act as a boundary for sets of *asynchronous* operations; concurrency is -possible both *between* and *within* tasks. In that regard, tasks are similar to -lightweight, runtime-managed threads with added capabilities that come from -being managed by a runtime instead of by the operating system. Futures are an -even more granular unit of concurrency, where each future may represent a tree -of other futures. That is, the runtime—specifically, its executor—manages tasks, -and tasks manage futures. - -However, this doesn’t mean that async tasks are always better than threads, any -more than that threads are always better than tasks. - -On the one hand, concurrency with threads is in some ways a simpler programming -model than concurrency with `async`. Threads are somewhat “fire and forget,” -they have no native equivalent to a future, so they simply run to completion, -without interruption except by the operating system itself. That is, they have -no *intra-task concurrency* the way futures can. Threads in Rust also have no -mechanisms for cancellation—a subject we haven’t covered in depth in this -chapter, but which is implicit in the fact that whenever we ended a future, its -state got cleaned up correctly. - -These limitations make threads harder to compose than futures. It’s much more -difficult, for example, to build something similar to the `timeout` we built in -[“Building Our Own Async Abstractions”][combining-futures], or the `throttle` -method we used with streams in [“Composing Streams”][streams]. The fact that -futures are richer data structures means they *can* be composed together more -naturally, as we have seen. +possible both *between* and *within* tasks, because a task can switch between +futures in its body. Finally, futures are Rust’s most granular unit of +concurrency, and each future may represent a tree of other futures. The +runtime—specifically, its executor—manages tasks, and tasks manage futures. In +that regard, tasks are similar to lightweight, runtime-managed threads with +added capabilities that come from being managed by a runtime instead of by the +operating system. + +This doesn’t mean that async tasks are always better than threads, any more than +that threads are always better than tasks. + +Concurrency with threads is in some ways a simpler programming model than +concurrency with `async`. That can be a strength or a weakness. Threads are +somewhat “fire and forget,” they have no native equivalent to a future, so they +simply run to completion, without interruption except by the operating system +itself. That is, they have no built-in support for *intra-task concurrency* the +way futures do. Threads in Rust also have no mechanisms for cancellation—a +subject we haven’t covered in depth in this chapter, but which is implicit in +the fact that whenever we ended a future, its state got cleaned up correctly. + +These limitations also make threads harder to compose than futures. It’s much +more difficult, for example, to use threads to build helpers such as the +`timeout` we built in [“Building Our Own Async Abstractions”][combining-futures] +or the `throttle` method we used with streams in [“Composing Streams”][streams]. +The fact that futures are richer data structures means they can be composed +together more naturally, as we have seen. Tasks then give *additional* control over futures, allowing you to choose where and how to group the futures. And it turns out that threads and tasks often @@ -85,8 +85,8 @@ hood the `Runtime` we have been using, including the `spawn_blocking` and `spawn_task` functions, is multithreaded by default! Many runtimes use an approach called *work stealing* to transparently move tasks around between threads based on the current utilization of the threads, with the aim of -improving the overall performance of the system. To build, that actually -requires threads *and* tasks, and therefore futures. +improving the overall performance of the system. To build that actually requires +threads *and* tasks, and therefore futures. As a default way of thinking about which to use when: From 887694bfde68cb685eefb74cfc5722097b8b6880 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 8 Oct 2024 08:09:29 -0600 Subject: [PATCH 618/720] Ch. 17: update all the listing lock files --- .../ch17-async-await/listing-17-01/Cargo.lock | 2 +- .../ch17-async-await/listing-17-02/Cargo.lock | 2 +- .../ch17-async-await/listing-17-03/Cargo.lock | 16 +- .../ch17-async-await/listing-17-04/Cargo.lock | 16 +- .../ch17-async-await/listing-17-05/Cargo.lock | 16 +- .../ch17-async-await/listing-17-06/Cargo.lock | 2 +- .../ch17-async-await/listing-17-07/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-08/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-09/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-10/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-11/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-12/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-13/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-14/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-15/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-16/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-17/Cargo.lock | 1653 +++++++++++++++- .../ch17-async-await/listing-17-18/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-19/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-20/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-21/Cargo.lock | 1625 ++++++++++++++-- .../ch17-async-await/listing-17-22/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-23/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-24/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-25/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-26/Cargo.lock | 1625 ++++++++++++++-- .../ch17-async-await/listing-17-27/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-28/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-29/Cargo.lock | 2 +- .../ch17-async-await/listing-17-30/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-31/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-32/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-33/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-34/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-35/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-36/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-37/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-38/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-39/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-40/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-41/Cargo.lock | 1663 ++++++++++++++++- .../ch17-async-await/listing-17-42/Cargo.lock | 2 +- .../no-listing-state-machine/Cargo.lock | 2 +- 43 files changed, 53941 insertions(+), 2575 deletions(-) diff --git a/listings/ch17-async-await/listing-17-01/Cargo.lock b/listings/ch17-async-await/listing-17-01/Cargo.lock index 1109eb84f5..4ee6b7a268 100644 --- a/listings/ch17-async-await/listing-17-01/Cargo.lock +++ b/listings/ch17-async-await/listing-17-01/Cargo.lock @@ -1484,7 +1484,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/listings/ch17-async-await/listing-17-02/Cargo.lock b/listings/ch17-async-await/listing-17-02/Cargo.lock index 1bd5f08c34..9a37f621b1 100644 --- a/listings/ch17-async-await/listing-17-02/Cargo.lock +++ b/listings/ch17-async-await/listing-17-02/Cargo.lock @@ -1484,7 +1484,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/listings/ch17-async-await/listing-17-03/Cargo.lock b/listings/ch17-async-await/listing-17-03/Cargo.lock index cb7d407618..9a37f621b1 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.lock +++ b/listings/ch17-async-await/listing-17-03/Cargo.lock @@ -30,6 +30,13 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -579,13 +586,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "listing-scraper-01" -version = "0.1.0" -dependencies = [ - "trpl", -] - [[package]] name = "lock_api" version = "0.4.12" @@ -1484,7 +1484,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/listings/ch17-async-await/listing-17-04/Cargo.lock b/listings/ch17-async-await/listing-17-04/Cargo.lock index cb7d407618..9a37f621b1 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.lock +++ b/listings/ch17-async-await/listing-17-04/Cargo.lock @@ -30,6 +30,13 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -579,13 +586,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "listing-scraper-01" -version = "0.1.0" -dependencies = [ - "trpl", -] - [[package]] name = "lock_api" version = "0.4.12" @@ -1484,7 +1484,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/listings/ch17-async-await/listing-17-05/Cargo.lock b/listings/ch17-async-await/listing-17-05/Cargo.lock index cb7d407618..9a37f621b1 100644 --- a/listings/ch17-async-await/listing-17-05/Cargo.lock +++ b/listings/ch17-async-await/listing-17-05/Cargo.lock @@ -30,6 +30,13 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "async_await" +version = "0.1.0" +dependencies = [ + "trpl", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -579,13 +586,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "listing-scraper-01" -version = "0.1.0" -dependencies = [ - "trpl", -] - [[package]] name = "lock_api" version = "0.4.12" @@ -1484,7 +1484,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/listings/ch17-async-await/listing-17-06/Cargo.lock b/listings/ch17-async-await/listing-17-06/Cargo.lock index a55aeb1e1c..0be7d2c88b 100644 --- a/listings/ch17-async-await/listing-17-06/Cargo.lock +++ b/listings/ch17-async-await/listing-17-06/Cargo.lock @@ -1485,7 +1485,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/listings/ch17-async-await/listing-17-07/Cargo.lock b/listings/ch17-async-await/listing-17-07/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-07/Cargo.lock +++ b/listings/ch17-async-await/listing-17-07/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-08/Cargo.lock b/listings/ch17-async-await/listing-17-08/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-08/Cargo.lock +++ b/listings/ch17-async-await/listing-17-08/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-09/Cargo.lock b/listings/ch17-async-await/listing-17-09/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-09/Cargo.lock +++ b/listings/ch17-async-await/listing-17-09/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-10/Cargo.lock b/listings/ch17-async-await/listing-17-10/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-10/Cargo.lock +++ b/listings/ch17-async-await/listing-17-10/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-11/Cargo.lock b/listings/ch17-async-await/listing-17-11/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-11/Cargo.lock +++ b/listings/ch17-async-await/listing-17-11/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-12/Cargo.lock b/listings/ch17-async-await/listing-17-12/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-12/Cargo.lock +++ b/listings/ch17-async-await/listing-17-12/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-13/Cargo.lock b/listings/ch17-async-await/listing-17-13/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-13/Cargo.lock +++ b/listings/ch17-async-await/listing-17-13/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-14/Cargo.lock b/listings/ch17-async-await/listing-17-14/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-14/Cargo.lock +++ b/listings/ch17-async-await/listing-17-14/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-15/Cargo.lock b/listings/ch17-async-await/listing-17-15/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-15/Cargo.lock +++ b/listings/ch17-async-await/listing-17-15/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-16/Cargo.lock b/listings/ch17-async-await/listing-17-16/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-16/Cargo.lock +++ b/listings/ch17-async-await/listing-17-16/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-17/Cargo.lock b/listings/ch17-async-await/listing-17-17/Cargo.lock index c0e8bb2b3f..973206db69 100644 --- a/listings/ch17-async-await/listing-17-17/Cargo.lock +++ b/listings/ch17-async-await/listing-17-17/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,12 +337,66 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -159,122 +404,1414 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "libc" -version = "0.2.154" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "memchr" -version = "2.7.2" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "adler", + "bytes", + "http", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", ] [[package]] -name = "object" -version = "0.32.2" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "memchr", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "quote" -version = "1.0.36" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown", +] [[package]] -name = "slab" -version = "0.4.9" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "autocfg", + "wasm-bindgen", ] [[package]] -name = "syn" -version = "2.0.63" +name = "libc" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "autocfg", + "scopeguard", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ - "futures", - "tokio", + "adler", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-18/Cargo.lock b/listings/ch17-async-await/listing-17-18/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-18/Cargo.lock +++ b/listings/ch17-async-await/listing-17-18/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-19/Cargo.lock b/listings/ch17-async-await/listing-17-19/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-19/Cargo.lock +++ b/listings/ch17-async-await/listing-17-19/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-20/Cargo.lock b/listings/ch17-async-await/listing-17-20/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-20/Cargo.lock +++ b/listings/ch17-async-await/listing-17-20/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-21/Cargo.lock b/listings/ch17-async-await/listing-17-21/Cargo.lock index 3be4eaaa53..34598194f8 100644 --- a/listings/ch17-async-await/listing-17-21/Cargo.lock +++ b/listings/ch17-async-await/listing-17-21/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,17 +64,35 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" @@ -69,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -112,293 +291,1355 @@ dependencies = [ ] [[package]] -name = "futures-io" -version = "0.3.30" +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] [[package]] -name = "futures-macro" -version = "0.3.30" +name = "string_cache_codegen" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", "proc-macro2", "quote", - "syn", ] [[package]] -name = "futures-sink" -version = "0.3.30" +name = "subtle" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] -name = "futures-task" -version = "0.3.30" +name = "syn" +version = "2.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] -name = "futures-util" -version = "0.3.30" +name = "sync_wrapper" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", ] [[package]] -name = "gimli" -version = "0.28.1" +name = "system-configuration" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "system-configuration-sys" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] -name = "libc" -version = "0.2.154" +name = "tempfile" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] [[package]] -name = "lock_api" -version = "0.4.12" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "autocfg", - "scopeguard", + "futf", + "mac", + "utf-8", ] [[package]] -name = "memchr" -version = "2.7.2" +name = "tinyvec" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "tinyvec_macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] -name = "mio" -version = "0.8.11" +name = "tokio" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ + "backtrace", + "bytes", "libc", - "wasi", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", "windows-sys 0.48.0", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "tokio-native-tls" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ - "hermit-abi", - "libc", + "native-tls", + "tokio", ] [[package]] -name = "object" -version = "0.32.2" +name = "tokio-rustls" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "memchr", + "rustls", + "rustls-pki-types", + "tokio", ] [[package]] -name = "parking_lot" -version = "0.12.2" +name = "tokio-stream" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ - "lock_api", - "parking_lot_core", + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] -name = "parking_lot_core" -version = "0.9.10" +name = "tokio-util" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "tower-service" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] -name = "pin-utils" -version = "0.1.0" +name = "tracing" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "tracing-core" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ - "unicode-ident", + "once_cell", ] [[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +name = "trpl" +version = "0.2.0" dependencies = [ - "proc-macro2", + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", ] [[package]] -name = "redox_syscall" -version = "0.5.1" +name = "try-lock" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ - "bitflags", + "tinyvec", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "unicode-width" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] -name = "scopeguard" -version = "1.2.0" +name = "untrusted" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] -name = "signal-hook-registry" -version = "1.4.2" +name = "url" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ - "libc", + "form_urlencoded", + "idna", + "percent-encoding", ] [[package]] -name = "slab" -version = "0.4.9" +name = "utf-8" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "autocfg", + "try-lock", ] [[package]] -name = "smallvec" -version = "1.13.2" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "socket2" -version = "0.5.7" +name = "wasm-bindgen" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ - "libc", - "windows-sys 0.52.0", + "cfg-if", + "once_cell", + "wasm-bindgen-macro", ] [[package]] -name = "syn" -version = "2.0.63" +name = "wasm-bindgen-backend" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ + "bumpalo", + "log", + "once_cell", "proc-macro2", "quote", - "unicode-ident", + "syn", + "wasm-bindgen-shared", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "wasm-bindgen-futures" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] -name = "tokio-macros" -version = "2.2.0" +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ - "futures", - "tokio", + "js-sys", + "wasm-bindgen", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "windows-registry" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +name = "windows-result" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] [[package]] name = "windows-sys" @@ -415,7 +1656,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -435,18 +1685,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -457,9 +1707,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -469,9 +1719,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -481,15 +1731,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -499,9 +1749,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -511,9 +1761,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -523,9 +1773,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -535,6 +1785,33 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-22/Cargo.lock b/listings/ch17-async-await/listing-17-22/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-22/Cargo.lock +++ b/listings/ch17-async-await/listing-17-22/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-23/Cargo.lock b/listings/ch17-async-await/listing-17-23/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-23/Cargo.lock +++ b/listings/ch17-async-await/listing-17-23/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-24/Cargo.lock b/listings/ch17-async-await/listing-17-24/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-24/Cargo.lock +++ b/listings/ch17-async-await/listing-17-24/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-25/Cargo.lock b/listings/ch17-async-await/listing-17-25/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-25/Cargo.lock +++ b/listings/ch17-async-await/listing-17-25/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-26/Cargo.lock b/listings/ch17-async-await/listing-17-26/Cargo.lock index 3be4eaaa53..34598194f8 100644 --- a/listings/ch17-async-await/listing-17-26/Cargo.lock +++ b/listings/ch17-async-await/listing-17-26/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,17 +64,35 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" @@ -69,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -112,293 +291,1355 @@ dependencies = [ ] [[package]] -name = "futures-io" -version = "0.3.30" +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "html5ever" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +dependencies = [ + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] [[package]] -name = "futures-macro" -version = "0.3.30" +name = "string_cache_codegen" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", "proc-macro2", "quote", - "syn", ] [[package]] -name = "futures-sink" -version = "0.3.30" +name = "subtle" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] -name = "futures-task" -version = "0.3.30" +name = "syn" +version = "2.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] -name = "futures-util" -version = "0.3.30" +name = "sync_wrapper" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", ] [[package]] -name = "gimli" -version = "0.28.1" +name = "system-configuration" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "system-configuration-sys" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] -name = "libc" -version = "0.2.154" +name = "tempfile" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] [[package]] -name = "lock_api" -version = "0.4.12" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "autocfg", - "scopeguard", + "futf", + "mac", + "utf-8", ] [[package]] -name = "memchr" -version = "2.7.2" +name = "tinyvec" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "tinyvec_macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] -name = "mio" -version = "0.8.11" +name = "tokio" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ + "backtrace", + "bytes", "libc", - "wasi", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", "windows-sys 0.48.0", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "tokio-native-tls" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ - "hermit-abi", - "libc", + "native-tls", + "tokio", ] [[package]] -name = "object" -version = "0.32.2" +name = "tokio-rustls" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "memchr", + "rustls", + "rustls-pki-types", + "tokio", ] [[package]] -name = "parking_lot" -version = "0.12.2" +name = "tokio-stream" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ - "lock_api", - "parking_lot_core", + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] -name = "parking_lot_core" -version = "0.9.10" +name = "tokio-util" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "tower-service" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] -name = "pin-utils" -version = "0.1.0" +name = "tracing" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "tracing-core" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ - "unicode-ident", + "once_cell", ] [[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +name = "trpl" +version = "0.2.0" dependencies = [ - "proc-macro2", + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", ] [[package]] -name = "redox_syscall" -version = "0.5.1" +name = "try-lock" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ - "bitflags", + "tinyvec", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "unicode-width" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] -name = "scopeguard" -version = "1.2.0" +name = "untrusted" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] -name = "signal-hook-registry" -version = "1.4.2" +name = "url" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ - "libc", + "form_urlencoded", + "idna", + "percent-encoding", ] [[package]] -name = "slab" -version = "0.4.9" +name = "utf-8" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "autocfg", + "try-lock", ] [[package]] -name = "smallvec" -version = "1.13.2" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "socket2" -version = "0.5.7" +name = "wasm-bindgen" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ - "libc", - "windows-sys 0.52.0", + "cfg-if", + "once_cell", + "wasm-bindgen-macro", ] [[package]] -name = "syn" -version = "2.0.63" +name = "wasm-bindgen-backend" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ + "bumpalo", + "log", + "once_cell", "proc-macro2", "quote", - "unicode-ident", + "syn", + "wasm-bindgen-shared", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "wasm-bindgen-futures" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] -name = "tokio-macros" -version = "2.2.0" +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ - "futures", - "tokio", + "js-sys", + "wasm-bindgen", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "windows-registry" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +name = "windows-result" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] [[package]] name = "windows-sys" @@ -415,7 +1656,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -435,18 +1685,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -457,9 +1707,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -469,9 +1719,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -481,15 +1731,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -499,9 +1749,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -511,9 +1761,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -523,9 +1773,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -535,6 +1785,33 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-27/Cargo.lock b/listings/ch17-async-await/listing-17-27/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-27/Cargo.lock +++ b/listings/ch17-async-await/listing-17-27/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-28/Cargo.lock b/listings/ch17-async-await/listing-17-28/Cargo.lock index 2e0f3ebedb..f09d29189b 100644 --- a/listings/ch17-async-await/listing-17-28/Cargo.lock +++ b/listings/ch17-async-await/listing-17-28/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.97" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.154" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.2" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.2" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.32.2" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.82" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.63" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.37.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-29/Cargo.lock b/listings/ch17-async-await/listing-17-29/Cargo.lock index a55aeb1e1c..0be7d2c88b 100644 --- a/listings/ch17-async-await/listing-17-29/Cargo.lock +++ b/listings/ch17-async-await/listing-17-29/Cargo.lock @@ -1485,7 +1485,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/listings/ch17-async-await/listing-17-30/Cargo.lock b/listings/ch17-async-await/listing-17-30/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-30/Cargo.lock +++ b/listings/ch17-async-await/listing-17-30/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-31/Cargo.lock b/listings/ch17-async-await/listing-17-31/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-31/Cargo.lock +++ b/listings/ch17-async-await/listing-17-31/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-32/Cargo.lock b/listings/ch17-async-await/listing-17-32/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-32/Cargo.lock +++ b/listings/ch17-async-await/listing-17-32/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-33/Cargo.lock b/listings/ch17-async-await/listing-17-33/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-33/Cargo.lock +++ b/listings/ch17-async-await/listing-17-33/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-34/Cargo.lock b/listings/ch17-async-await/listing-17-34/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-34/Cargo.lock +++ b/listings/ch17-async-await/listing-17-34/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-35/Cargo.lock b/listings/ch17-async-await/listing-17-35/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-35/Cargo.lock +++ b/listings/ch17-async-await/listing-17-35/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-36/Cargo.lock b/listings/ch17-async-await/listing-17-36/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-36/Cargo.lock +++ b/listings/ch17-async-await/listing-17-36/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-37/Cargo.lock b/listings/ch17-async-await/listing-17-37/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-37/Cargo.lock +++ b/listings/ch17-async-await/listing-17-37/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-38/Cargo.lock b/listings/ch17-async-await/listing-17-38/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-38/Cargo.lock +++ b/listings/ch17-async-await/listing-17-38/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-39/Cargo.lock b/listings/ch17-async-await/listing-17-39/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-39/Cargo.lock +++ b/listings/ch17-async-await/listing-17-39/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-40/Cargo.lock b/listings/ch17-async-await/listing-17-40/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-40/Cargo.lock +++ b/listings/ch17-async-await/listing-17-40/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-41/Cargo.lock b/listings/ch17-async-await/listing-17-41/Cargo.lock index 36905af42a..72e870c80c 100644 --- a/listings/ch17-async-await/listing-17-41/Cargo.lock +++ b/listings/ch17-async-await/listing-17-41/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "async_await" version = "0.1.0" @@ -24,6 +37,12 @@ dependencies = [ "trpl", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -45,6 +64,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cc" version = "1.0.99" @@ -57,6 +106,148 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cssparser" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b3df4f93e5fbbe73ec01ec8d3f68bba73107993a5b1e7519273c32db9b0d5be" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.11.2", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "ego-tree" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" +dependencies = [ + "mac", + "new_debug_unreachable", +] + [[package]] name = "futures" version = "0.3.30" @@ -146,6 +337,35 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.29.0" @@ -153,140 +373,1445 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "h2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] -name = "libc" -version = "0.2.155" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] -name = "memchr" -version = "2.7.4" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "miniz_oxide" -version = "0.7.4" +name = "html5ever" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ - "adler", + "log", + "mac", + "markup5ever", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "http" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ - "hermit-abi", - "libc", + "bytes", + "fnv", + "itoa", ] [[package]] -name = "object" -version = "0.36.0" +name = "http-body" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ - "memchr", + "bytes", + "http", ] [[package]] -name = "pin-project-lite" -version = "0.2.14" +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "httparse" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] -name = "proc-macro2" -version = "1.0.85" +name = "hyper" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ - "unicode-ident", + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", ] [[package]] -name = "quote" -version = "1.0.36" +name = "hyper-rustls" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ - "proc-macro2", + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", ] [[package]] -name = "rustc-demangle" -version = "0.1.24" +name = "hyper-tls" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] [[package]] -name = "slab" -version = "0.4.9" +name = "hyper-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ - "autocfg", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", ] [[package]] -name = "syn" -version = "2.0.66" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "tokio" -version = "1.38.0" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "backtrace", - "num_cpus", - "pin-project-lite", + "equivalent", + "hashbrown", ] [[package]] -name = "tokio-stream" -version = "0.1.15" +name = "ipnet" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "wasm-bindgen", ] [[package]] -name = "trpl" -version = "0.1.0" +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ - "futures", - "tokio", - "tokio-stream", + "autocfg", + "scopeguard", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "mac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" + +[[package]] +name = "markup5ever" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +dependencies = [ + "log", + "phf 0.11.2", + "phf_codegen 0.11.2", + "string_cache", + "string_cache_codegen", + "tendril", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scraper" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90460b31bfe1fc07be8262e42c665ad97118d4585869de9345a84d501a9eaf0" +dependencies = [ + "ahash", + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "once_cell", + "selectors", + "tendril", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "selectors" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb30575f3638fc8f6815f448d50cb1a2e255b0897985c8c59f4d37b72a07b06" +dependencies = [ + "bitflags", + "cssparser", + "derive_more", + "fxhash", + "log", + "new_debug_unreachable", + "phf 0.10.1", + "phf_codegen 0.10.0", + "precomputed-hash", + "servo_arc", + "smallvec", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "servo_arc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d036d71a959e00c77a63538b90a6c2390969f9772b096ea837205c6bd0491a44" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tendril" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +dependencies = [ + "futf", + "mac", + "utf-8", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trpl" +version = "0.2.0" +dependencies = [ + "futures", + "reqwest", + "scraper", + "tokio", + "tokio-stream", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/listings/ch17-async-await/listing-17-42/Cargo.lock b/listings/ch17-async-await/listing-17-42/Cargo.lock index 35391aee48..071a0943b4 100644 --- a/listings/ch17-async-await/listing-17-42/Cargo.lock +++ b/listings/ch17-async-await/listing-17-42/Cargo.lock @@ -1485,7 +1485,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", diff --git a/listings/ch17-async-await/no-listing-state-machine/Cargo.lock b/listings/ch17-async-await/no-listing-state-machine/Cargo.lock index 5e72795fea..7b6b110bc2 100644 --- a/listings/ch17-async-await/no-listing-state-machine/Cargo.lock +++ b/listings/ch17-async-await/no-listing-state-machine/Cargo.lock @@ -1484,7 +1484,7 @@ dependencies = [ [[package]] name = "trpl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "reqwest", From fb0215d9107b4609c3f24d702c96daa1caf0540b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 26 Sep 2024 11:09:39 -0600 Subject: [PATCH 619/720] Ch. 17: Listings for Ch. 20 -> Ch. 21 --- .../listing-21-01}/Cargo.lock | 0 .../listing-21-01}/Cargo.toml | 0 .../listing-21-01}/src/main.rs | 0 .../listing-21-02}/Cargo.lock | 0 .../listing-21-02}/Cargo.toml | 0 .../listing-21-02}/src/main.rs | 0 .../listing-21-03}/Cargo.lock | 0 .../listing-21-03}/Cargo.toml | 0 .../listing-21-03}/src/main.rs | 0 .../listing-21-05}/Cargo.lock | 0 .../listing-21-05}/Cargo.toml | 0 .../listing-21-05}/hello.html | 0 .../listing-21-05}/src/main.rs | 0 .../listing-21-06}/Cargo.lock | 0 .../listing-21-06}/Cargo.toml | 0 .../listing-21-06}/hello.html | 0 .../listing-21-06}/src/main.rs | 0 .../listing-21-07}/404.html | 0 .../listing-21-07}/Cargo.lock | 0 .../listing-21-07}/Cargo.toml | 0 .../listing-21-07}/hello.html | 0 .../listing-21-07}/src/main.rs | 0 .../listing-21-09}/404.html | 0 .../listing-21-09}/Cargo.lock | 0 .../listing-21-09}/Cargo.toml | 0 .../listing-21-09}/hello.html | 0 .../listing-21-09}/src/main.rs | 0 .../listing-21-10}/404.html | 0 .../listing-21-10}/Cargo.lock | 0 .../listing-21-10}/Cargo.toml | 0 .../listing-21-10}/hello.html | 0 .../listing-21-10}/src/main.rs | 0 .../listing-21-11}/404.html | 0 .../listing-21-11}/Cargo.lock | 0 .../listing-21-11}/Cargo.toml | 0 .../listing-21-11}/hello.html | 0 .../listing-21-11}/src/main.rs | 0 .../listing-21-12}/404.html | 0 .../listing-21-12}/Cargo.lock | 0 .../listing-21-12}/Cargo.toml | 0 .../listing-21-12}/hello.html | 0 .../listing-21-12}/output.txt | 0 .../listing-21-12}/src/main.rs | 0 .../listing-21-13}/404.html | 0 .../listing-21-13}/Cargo.lock | 0 .../listing-21-13}/Cargo.toml | 0 .../listing-21-13}/hello.html | 0 .../listing-21-13}/src/lib.rs | 0 .../listing-21-13}/src/main.rs | 0 .../listing-21-14}/404.html | 0 .../listing-21-14}/Cargo.lock | 0 .../listing-21-14}/Cargo.toml | 0 .../listing-21-14}/hello.html | 0 .../listing-21-14}/src/lib.rs | 0 .../listing-21-14}/src/main.rs | 0 .../listing-21-15}/404.html | 0 .../listing-21-15}/Cargo.lock | 0 .../listing-21-15}/Cargo.toml | 0 .../listing-21-15}/hello.html | 0 .../listing-21-15}/src/lib.rs | 0 .../listing-21-15}/src/main.rs | 0 .../listing-21-16}/404.html | 0 .../listing-21-16}/Cargo.lock | 0 .../listing-21-16}/Cargo.toml | 0 .../listing-21-16}/hello.html | 0 .../listing-21-16}/src/lib.rs | 0 .../listing-21-16}/src/main.rs | 0 .../listing-21-17}/404.html | 0 .../listing-21-17}/Cargo.lock | 0 .../listing-21-17}/Cargo.toml | 0 .../listing-21-17}/hello.html | 0 .../listing-21-17}/output.txt | 0 .../listing-21-17}/src/lib.rs | 0 .../listing-21-17}/src/main.rs | 0 .../listing-21-18}/404.html | 0 .../listing-21-18}/Cargo.lock | 0 .../listing-21-18}/Cargo.toml | 0 .../listing-21-18}/hello.html | 0 .../listing-21-18}/src/lib.rs | 0 .../listing-21-18}/src/main.rs | 0 .../listing-21-19}/404.html | 0 .../listing-21-19}/Cargo.lock | 0 .../listing-21-19}/Cargo.toml | 0 .../listing-21-19}/hello.html | 0 .../listing-21-19}/src/lib.rs | 0 .../listing-21-19}/src/main.rs | 0 .../listing-21-20}/404.html | 0 .../listing-21-20}/Cargo.lock | 0 .../listing-21-20}/Cargo.toml | 0 .../listing-21-20}/hello.html | 0 .../listing-21-20}/src/lib.rs | 0 .../listing-21-20}/src/main.rs | 0 .../listing-21-21}/404.html | 0 .../listing-21-21}/Cargo.lock | 0 .../listing-21-21}/Cargo.toml | 0 .../listing-21-21}/hello.html | 0 .../listing-21-21}/src/lib.rs | 0 .../listing-21-21}/src/main.rs | 0 .../listing-21-22}/404.html | 0 .../listing-21-22}/Cargo.lock | 0 .../listing-21-22}/Cargo.toml | 0 .../listing-21-22}/hello.html | 0 .../listing-21-22}/output.txt | 0 .../listing-21-22}/src/lib.rs | 0 .../listing-21-22}/src/main.rs | 0 .../listing-21-23}/404.html | 0 .../listing-21-23}/Cargo.lock | 0 .../listing-21-23}/Cargo.toml | 0 .../listing-21-23}/hello.html | 0 .../listing-21-23}/src/lib.rs | 0 .../listing-21-23}/src/main.rs | 0 .../listing-21-24}/404.html | 0 .../listing-21-24}/Cargo.lock | 0 .../listing-21-24}/Cargo.toml | 0 .../listing-21-24}/hello.html | 0 .../listing-21-24}/src/lib.rs | 0 .../listing-21-24}/src/main.rs | 0 .../listing-21-25}/404.html | 0 .../listing-21-25}/Cargo.lock | 0 .../listing-21-25}/Cargo.toml | 0 .../listing-21-25}/hello.html | 0 .../listing-21-25}/src/lib.rs | 0 .../listing-21-25}/src/main.rs | 0 .../404.html | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../hello.html | 0 .../output.txt | 0 .../src/lib.rs | 0 .../src/main.rs | 0 .../404.html | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../hello.html | 0 .../output.txt | 0 .../src/lib.rs | 0 .../src/main.rs | 0 .../no-listing-03-define-execute/404.html | 0 .../no-listing-03-define-execute/Cargo.lock | 0 .../no-listing-03-define-execute/Cargo.toml | 0 .../no-listing-03-define-execute/hello.html | 0 .../no-listing-03-define-execute/output.txt | 0 .../no-listing-03-define-execute/src/lib.rs | 0 .../no-listing-03-define-execute/src/main.rs | 0 .../404.html | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../hello.html | 0 .../output.txt | 0 .../src/lib.rs | 0 .../src/main.rs | 0 .../no-listing-05-fix-worker-new/404.html | 0 .../no-listing-05-fix-worker-new/Cargo.lock | 0 .../no-listing-05-fix-worker-new/Cargo.toml | 0 .../no-listing-05-fix-worker-new/hello.html | 0 .../no-listing-05-fix-worker-new/src/lib.rs | 0 .../no-listing-05-fix-worker-new/src/main.rs | 0 .../404.html | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../hello.html | 0 .../src/lib.rs | 0 .../src/main.rs | 0 .../no-listing-07-final-code/404.html | 0 .../no-listing-07-final-code/Cargo.lock | 0 .../no-listing-07-final-code/Cargo.toml | 0 .../no-listing-07-final-code/hello.html | 0 .../no-listing-07-final-code/src/lib.rs | 0 .../no-listing-07-final-code/src/main.rs | 0 src/ch21-01-single-threaded.md | 62 +++++----- src/ch21-02-multithreaded.md | 106 +++++++++--------- src/ch21-03-graceful-shutdown-and-cleanup.md | 42 +++---- 172 files changed, 105 insertions(+), 105 deletions(-) rename listings/{ch20-web-server/listing-20-01 => ch21-web-server/listing-21-01}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-01 => ch21-web-server/listing-21-01}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-01 => ch21-web-server/listing-21-01}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-02 => ch21-web-server/listing-21-02}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-02 => ch21-web-server/listing-21-02}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-02 => ch21-web-server/listing-21-02}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-03 => ch21-web-server/listing-21-03}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-03 => ch21-web-server/listing-21-03}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-03 => ch21-web-server/listing-21-03}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-05 => ch21-web-server/listing-21-05}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-05 => ch21-web-server/listing-21-05}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-05 => ch21-web-server/listing-21-05}/hello.html (100%) rename listings/{ch20-web-server/listing-20-05 => ch21-web-server/listing-21-05}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-06 => ch21-web-server/listing-21-06}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-06 => ch21-web-server/listing-21-06}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-06 => ch21-web-server/listing-21-06}/hello.html (100%) rename listings/{ch20-web-server/listing-20-06 => ch21-web-server/listing-21-06}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-07 => ch21-web-server/listing-21-07}/404.html (100%) rename listings/{ch20-web-server/listing-20-07 => ch21-web-server/listing-21-07}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-07 => ch21-web-server/listing-21-07}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-07 => ch21-web-server/listing-21-07}/hello.html (100%) rename listings/{ch20-web-server/listing-20-07 => ch21-web-server/listing-21-07}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-09 => ch21-web-server/listing-21-09}/404.html (100%) rename listings/{ch20-web-server/listing-20-09 => ch21-web-server/listing-21-09}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-09 => ch21-web-server/listing-21-09}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-09 => ch21-web-server/listing-21-09}/hello.html (100%) rename listings/{ch20-web-server/listing-20-09 => ch21-web-server/listing-21-09}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-10 => ch21-web-server/listing-21-10}/404.html (100%) rename listings/{ch20-web-server/listing-20-10 => ch21-web-server/listing-21-10}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-10 => ch21-web-server/listing-21-10}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-10 => ch21-web-server/listing-21-10}/hello.html (100%) rename listings/{ch20-web-server/listing-20-10 => ch21-web-server/listing-21-10}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-11 => ch21-web-server/listing-21-11}/404.html (100%) rename listings/{ch20-web-server/listing-20-11 => ch21-web-server/listing-21-11}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-11 => ch21-web-server/listing-21-11}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-11 => ch21-web-server/listing-21-11}/hello.html (100%) rename listings/{ch20-web-server/listing-20-11 => ch21-web-server/listing-21-11}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-12 => ch21-web-server/listing-21-12}/404.html (100%) rename listings/{ch20-web-server/listing-20-12 => ch21-web-server/listing-21-12}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-12 => ch21-web-server/listing-21-12}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-12 => ch21-web-server/listing-21-12}/hello.html (100%) rename listings/{ch20-web-server/listing-20-12 => ch21-web-server/listing-21-12}/output.txt (100%) rename listings/{ch20-web-server/listing-20-12 => ch21-web-server/listing-21-12}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-13 => ch21-web-server/listing-21-13}/404.html (100%) rename listings/{ch20-web-server/listing-20-13 => ch21-web-server/listing-21-13}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-13 => ch21-web-server/listing-21-13}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-13 => ch21-web-server/listing-21-13}/hello.html (100%) rename listings/{ch20-web-server/listing-20-13 => ch21-web-server/listing-21-13}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-13 => ch21-web-server/listing-21-13}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-14 => ch21-web-server/listing-21-14}/404.html (100%) rename listings/{ch20-web-server/listing-20-14 => ch21-web-server/listing-21-14}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-14 => ch21-web-server/listing-21-14}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-14 => ch21-web-server/listing-21-14}/hello.html (100%) rename listings/{ch20-web-server/listing-20-14 => ch21-web-server/listing-21-14}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-14 => ch21-web-server/listing-21-14}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-15 => ch21-web-server/listing-21-15}/404.html (100%) rename listings/{ch20-web-server/listing-20-15 => ch21-web-server/listing-21-15}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-15 => ch21-web-server/listing-21-15}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-15 => ch21-web-server/listing-21-15}/hello.html (100%) rename listings/{ch20-web-server/listing-20-15 => ch21-web-server/listing-21-15}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-15 => ch21-web-server/listing-21-15}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-16 => ch21-web-server/listing-21-16}/404.html (100%) rename listings/{ch20-web-server/listing-20-16 => ch21-web-server/listing-21-16}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-16 => ch21-web-server/listing-21-16}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-16 => ch21-web-server/listing-21-16}/hello.html (100%) rename listings/{ch20-web-server/listing-20-16 => ch21-web-server/listing-21-16}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-16 => ch21-web-server/listing-21-16}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-17 => ch21-web-server/listing-21-17}/404.html (100%) rename listings/{ch20-web-server/listing-20-17 => ch21-web-server/listing-21-17}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-17 => ch21-web-server/listing-21-17}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-17 => ch21-web-server/listing-21-17}/hello.html (100%) rename listings/{ch20-web-server/listing-20-17 => ch21-web-server/listing-21-17}/output.txt (100%) rename listings/{ch20-web-server/listing-20-17 => ch21-web-server/listing-21-17}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-17 => ch21-web-server/listing-21-17}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-18 => ch21-web-server/listing-21-18}/404.html (100%) rename listings/{ch20-web-server/listing-20-18 => ch21-web-server/listing-21-18}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-18 => ch21-web-server/listing-21-18}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-18 => ch21-web-server/listing-21-18}/hello.html (100%) rename listings/{ch20-web-server/listing-20-18 => ch21-web-server/listing-21-18}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-18 => ch21-web-server/listing-21-18}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-19 => ch21-web-server/listing-21-19}/404.html (100%) rename listings/{ch20-web-server/listing-20-19 => ch21-web-server/listing-21-19}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-19 => ch21-web-server/listing-21-19}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-19 => ch21-web-server/listing-21-19}/hello.html (100%) rename listings/{ch20-web-server/listing-20-19 => ch21-web-server/listing-21-19}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-19 => ch21-web-server/listing-21-19}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-20 => ch21-web-server/listing-21-20}/404.html (100%) rename listings/{ch20-web-server/listing-20-20 => ch21-web-server/listing-21-20}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-20 => ch21-web-server/listing-21-20}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-20 => ch21-web-server/listing-21-20}/hello.html (100%) rename listings/{ch20-web-server/listing-20-20 => ch21-web-server/listing-21-20}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-20 => ch21-web-server/listing-21-20}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-21 => ch21-web-server/listing-21-21}/404.html (100%) rename listings/{ch20-web-server/listing-20-21 => ch21-web-server/listing-21-21}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-21 => ch21-web-server/listing-21-21}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-21 => ch21-web-server/listing-21-21}/hello.html (100%) rename listings/{ch20-web-server/listing-20-21 => ch21-web-server/listing-21-21}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-21 => ch21-web-server/listing-21-21}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-22 => ch21-web-server/listing-21-22}/404.html (100%) rename listings/{ch20-web-server/listing-20-22 => ch21-web-server/listing-21-22}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-22 => ch21-web-server/listing-21-22}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-22 => ch21-web-server/listing-21-22}/hello.html (100%) rename listings/{ch20-web-server/listing-20-22 => ch21-web-server/listing-21-22}/output.txt (100%) rename listings/{ch20-web-server/listing-20-22 => ch21-web-server/listing-21-22}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-22 => ch21-web-server/listing-21-22}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-23 => ch21-web-server/listing-21-23}/404.html (100%) rename listings/{ch20-web-server/listing-20-23 => ch21-web-server/listing-21-23}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-23 => ch21-web-server/listing-21-23}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-23 => ch21-web-server/listing-21-23}/hello.html (100%) rename listings/{ch20-web-server/listing-20-23 => ch21-web-server/listing-21-23}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-23 => ch21-web-server/listing-21-23}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-24 => ch21-web-server/listing-21-24}/404.html (100%) rename listings/{ch20-web-server/listing-20-24 => ch21-web-server/listing-21-24}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-24 => ch21-web-server/listing-21-24}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-24 => ch21-web-server/listing-21-24}/hello.html (100%) rename listings/{ch20-web-server/listing-20-24 => ch21-web-server/listing-21-24}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-24 => ch21-web-server/listing-21-24}/src/main.rs (100%) rename listings/{ch20-web-server/listing-20-25 => ch21-web-server/listing-21-25}/404.html (100%) rename listings/{ch20-web-server/listing-20-25 => ch21-web-server/listing-21-25}/Cargo.lock (100%) rename listings/{ch20-web-server/listing-20-25 => ch21-web-server/listing-21-25}/Cargo.toml (100%) rename listings/{ch20-web-server/listing-20-25 => ch21-web-server/listing-21-25}/hello.html (100%) rename listings/{ch20-web-server/listing-20-25 => ch21-web-server/listing-21-25}/src/lib.rs (100%) rename listings/{ch20-web-server/listing-20-25 => ch21-web-server/listing-21-25}/src/main.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-01-define-threadpool-struct/404.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-01-define-threadpool-struct/Cargo.lock (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-01-define-threadpool-struct/Cargo.toml (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-01-define-threadpool-struct/hello.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-01-define-threadpool-struct/output.txt (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-01-define-threadpool-struct/src/lib.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-01-define-threadpool-struct/src/main.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-02-impl-threadpool-new/404.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-02-impl-threadpool-new/Cargo.lock (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-02-impl-threadpool-new/Cargo.toml (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-02-impl-threadpool-new/hello.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-02-impl-threadpool-new/output.txt (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-02-impl-threadpool-new/src/lib.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-02-impl-threadpool-new/src/main.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-03-define-execute/404.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-03-define-execute/Cargo.lock (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-03-define-execute/Cargo.toml (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-03-define-execute/hello.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-03-define-execute/output.txt (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-03-define-execute/src/lib.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-03-define-execute/src/main.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-04-update-worker-definition/404.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-04-update-worker-definition/Cargo.lock (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-04-update-worker-definition/Cargo.toml (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-04-update-worker-definition/hello.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-04-update-worker-definition/output.txt (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-04-update-worker-definition/src/lib.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-04-update-worker-definition/src/main.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-05-fix-worker-new/404.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-05-fix-worker-new/Cargo.lock (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-05-fix-worker-new/Cargo.toml (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-05-fix-worker-new/hello.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-05-fix-worker-new/src/lib.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-05-fix-worker-new/src/main.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-06-fix-threadpool-drop/404.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-06-fix-threadpool-drop/Cargo.lock (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-06-fix-threadpool-drop/Cargo.toml (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-06-fix-threadpool-drop/hello.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-06-fix-threadpool-drop/src/lib.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-06-fix-threadpool-drop/src/main.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-07-final-code/404.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-07-final-code/Cargo.lock (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-07-final-code/Cargo.toml (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-07-final-code/hello.html (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-07-final-code/src/lib.rs (100%) rename listings/{ch20-web-server => ch21-web-server}/no-listing-07-final-code/src/main.rs (100%) diff --git a/listings/ch20-web-server/listing-20-01/Cargo.lock b/listings/ch21-web-server/listing-21-01/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-01/Cargo.lock rename to listings/ch21-web-server/listing-21-01/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-01/Cargo.toml b/listings/ch21-web-server/listing-21-01/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-01/Cargo.toml rename to listings/ch21-web-server/listing-21-01/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-01/src/main.rs b/listings/ch21-web-server/listing-21-01/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-01/src/main.rs rename to listings/ch21-web-server/listing-21-01/src/main.rs diff --git a/listings/ch20-web-server/listing-20-02/Cargo.lock b/listings/ch21-web-server/listing-21-02/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-02/Cargo.lock rename to listings/ch21-web-server/listing-21-02/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-02/Cargo.toml b/listings/ch21-web-server/listing-21-02/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-02/Cargo.toml rename to listings/ch21-web-server/listing-21-02/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-02/src/main.rs b/listings/ch21-web-server/listing-21-02/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-02/src/main.rs rename to listings/ch21-web-server/listing-21-02/src/main.rs diff --git a/listings/ch20-web-server/listing-20-03/Cargo.lock b/listings/ch21-web-server/listing-21-03/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-03/Cargo.lock rename to listings/ch21-web-server/listing-21-03/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-03/Cargo.toml b/listings/ch21-web-server/listing-21-03/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-03/Cargo.toml rename to listings/ch21-web-server/listing-21-03/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-03/src/main.rs b/listings/ch21-web-server/listing-21-03/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-03/src/main.rs rename to listings/ch21-web-server/listing-21-03/src/main.rs diff --git a/listings/ch20-web-server/listing-20-05/Cargo.lock b/listings/ch21-web-server/listing-21-05/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-05/Cargo.lock rename to listings/ch21-web-server/listing-21-05/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-05/Cargo.toml b/listings/ch21-web-server/listing-21-05/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-05/Cargo.toml rename to listings/ch21-web-server/listing-21-05/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-05/hello.html b/listings/ch21-web-server/listing-21-05/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-05/hello.html rename to listings/ch21-web-server/listing-21-05/hello.html diff --git a/listings/ch20-web-server/listing-20-05/src/main.rs b/listings/ch21-web-server/listing-21-05/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-05/src/main.rs rename to listings/ch21-web-server/listing-21-05/src/main.rs diff --git a/listings/ch20-web-server/listing-20-06/Cargo.lock b/listings/ch21-web-server/listing-21-06/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-06/Cargo.lock rename to listings/ch21-web-server/listing-21-06/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-06/Cargo.toml b/listings/ch21-web-server/listing-21-06/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-06/Cargo.toml rename to listings/ch21-web-server/listing-21-06/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-06/hello.html b/listings/ch21-web-server/listing-21-06/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-06/hello.html rename to listings/ch21-web-server/listing-21-06/hello.html diff --git a/listings/ch20-web-server/listing-20-06/src/main.rs b/listings/ch21-web-server/listing-21-06/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-06/src/main.rs rename to listings/ch21-web-server/listing-21-06/src/main.rs diff --git a/listings/ch20-web-server/listing-20-07/404.html b/listings/ch21-web-server/listing-21-07/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-07/404.html rename to listings/ch21-web-server/listing-21-07/404.html diff --git a/listings/ch20-web-server/listing-20-07/Cargo.lock b/listings/ch21-web-server/listing-21-07/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-07/Cargo.lock rename to listings/ch21-web-server/listing-21-07/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-07/Cargo.toml b/listings/ch21-web-server/listing-21-07/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-07/Cargo.toml rename to listings/ch21-web-server/listing-21-07/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-07/hello.html b/listings/ch21-web-server/listing-21-07/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-07/hello.html rename to listings/ch21-web-server/listing-21-07/hello.html diff --git a/listings/ch20-web-server/listing-20-07/src/main.rs b/listings/ch21-web-server/listing-21-07/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-07/src/main.rs rename to listings/ch21-web-server/listing-21-07/src/main.rs diff --git a/listings/ch20-web-server/listing-20-09/404.html b/listings/ch21-web-server/listing-21-09/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-09/404.html rename to listings/ch21-web-server/listing-21-09/404.html diff --git a/listings/ch20-web-server/listing-20-09/Cargo.lock b/listings/ch21-web-server/listing-21-09/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-09/Cargo.lock rename to listings/ch21-web-server/listing-21-09/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-09/Cargo.toml b/listings/ch21-web-server/listing-21-09/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-09/Cargo.toml rename to listings/ch21-web-server/listing-21-09/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-09/hello.html b/listings/ch21-web-server/listing-21-09/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-09/hello.html rename to listings/ch21-web-server/listing-21-09/hello.html diff --git a/listings/ch20-web-server/listing-20-09/src/main.rs b/listings/ch21-web-server/listing-21-09/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-09/src/main.rs rename to listings/ch21-web-server/listing-21-09/src/main.rs diff --git a/listings/ch20-web-server/listing-20-10/404.html b/listings/ch21-web-server/listing-21-10/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-10/404.html rename to listings/ch21-web-server/listing-21-10/404.html diff --git a/listings/ch20-web-server/listing-20-10/Cargo.lock b/listings/ch21-web-server/listing-21-10/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-10/Cargo.lock rename to listings/ch21-web-server/listing-21-10/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-10/Cargo.toml b/listings/ch21-web-server/listing-21-10/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-10/Cargo.toml rename to listings/ch21-web-server/listing-21-10/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-10/hello.html b/listings/ch21-web-server/listing-21-10/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-10/hello.html rename to listings/ch21-web-server/listing-21-10/hello.html diff --git a/listings/ch20-web-server/listing-20-10/src/main.rs b/listings/ch21-web-server/listing-21-10/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-10/src/main.rs rename to listings/ch21-web-server/listing-21-10/src/main.rs diff --git a/listings/ch20-web-server/listing-20-11/404.html b/listings/ch21-web-server/listing-21-11/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-11/404.html rename to listings/ch21-web-server/listing-21-11/404.html diff --git a/listings/ch20-web-server/listing-20-11/Cargo.lock b/listings/ch21-web-server/listing-21-11/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-11/Cargo.lock rename to listings/ch21-web-server/listing-21-11/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-11/Cargo.toml b/listings/ch21-web-server/listing-21-11/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-11/Cargo.toml rename to listings/ch21-web-server/listing-21-11/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-11/hello.html b/listings/ch21-web-server/listing-21-11/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-11/hello.html rename to listings/ch21-web-server/listing-21-11/hello.html diff --git a/listings/ch20-web-server/listing-20-11/src/main.rs b/listings/ch21-web-server/listing-21-11/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-11/src/main.rs rename to listings/ch21-web-server/listing-21-11/src/main.rs diff --git a/listings/ch20-web-server/listing-20-12/404.html b/listings/ch21-web-server/listing-21-12/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-12/404.html rename to listings/ch21-web-server/listing-21-12/404.html diff --git a/listings/ch20-web-server/listing-20-12/Cargo.lock b/listings/ch21-web-server/listing-21-12/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-12/Cargo.lock rename to listings/ch21-web-server/listing-21-12/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-12/Cargo.toml b/listings/ch21-web-server/listing-21-12/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-12/Cargo.toml rename to listings/ch21-web-server/listing-21-12/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-12/hello.html b/listings/ch21-web-server/listing-21-12/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-12/hello.html rename to listings/ch21-web-server/listing-21-12/hello.html diff --git a/listings/ch20-web-server/listing-20-12/output.txt b/listings/ch21-web-server/listing-21-12/output.txt similarity index 100% rename from listings/ch20-web-server/listing-20-12/output.txt rename to listings/ch21-web-server/listing-21-12/output.txt diff --git a/listings/ch20-web-server/listing-20-12/src/main.rs b/listings/ch21-web-server/listing-21-12/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-12/src/main.rs rename to listings/ch21-web-server/listing-21-12/src/main.rs diff --git a/listings/ch20-web-server/listing-20-13/404.html b/listings/ch21-web-server/listing-21-13/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-13/404.html rename to listings/ch21-web-server/listing-21-13/404.html diff --git a/listings/ch20-web-server/listing-20-13/Cargo.lock b/listings/ch21-web-server/listing-21-13/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-13/Cargo.lock rename to listings/ch21-web-server/listing-21-13/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-13/Cargo.toml b/listings/ch21-web-server/listing-21-13/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-13/Cargo.toml rename to listings/ch21-web-server/listing-21-13/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-13/hello.html b/listings/ch21-web-server/listing-21-13/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-13/hello.html rename to listings/ch21-web-server/listing-21-13/hello.html diff --git a/listings/ch20-web-server/listing-20-13/src/lib.rs b/listings/ch21-web-server/listing-21-13/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-13/src/lib.rs rename to listings/ch21-web-server/listing-21-13/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-13/src/main.rs b/listings/ch21-web-server/listing-21-13/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-13/src/main.rs rename to listings/ch21-web-server/listing-21-13/src/main.rs diff --git a/listings/ch20-web-server/listing-20-14/404.html b/listings/ch21-web-server/listing-21-14/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-14/404.html rename to listings/ch21-web-server/listing-21-14/404.html diff --git a/listings/ch20-web-server/listing-20-14/Cargo.lock b/listings/ch21-web-server/listing-21-14/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-14/Cargo.lock rename to listings/ch21-web-server/listing-21-14/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-14/Cargo.toml b/listings/ch21-web-server/listing-21-14/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-14/Cargo.toml rename to listings/ch21-web-server/listing-21-14/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-14/hello.html b/listings/ch21-web-server/listing-21-14/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-14/hello.html rename to listings/ch21-web-server/listing-21-14/hello.html diff --git a/listings/ch20-web-server/listing-20-14/src/lib.rs b/listings/ch21-web-server/listing-21-14/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-14/src/lib.rs rename to listings/ch21-web-server/listing-21-14/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-14/src/main.rs b/listings/ch21-web-server/listing-21-14/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-14/src/main.rs rename to listings/ch21-web-server/listing-21-14/src/main.rs diff --git a/listings/ch20-web-server/listing-20-15/404.html b/listings/ch21-web-server/listing-21-15/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-15/404.html rename to listings/ch21-web-server/listing-21-15/404.html diff --git a/listings/ch20-web-server/listing-20-15/Cargo.lock b/listings/ch21-web-server/listing-21-15/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-15/Cargo.lock rename to listings/ch21-web-server/listing-21-15/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-15/Cargo.toml b/listings/ch21-web-server/listing-21-15/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-15/Cargo.toml rename to listings/ch21-web-server/listing-21-15/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-15/hello.html b/listings/ch21-web-server/listing-21-15/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-15/hello.html rename to listings/ch21-web-server/listing-21-15/hello.html diff --git a/listings/ch20-web-server/listing-20-15/src/lib.rs b/listings/ch21-web-server/listing-21-15/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-15/src/lib.rs rename to listings/ch21-web-server/listing-21-15/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-15/src/main.rs b/listings/ch21-web-server/listing-21-15/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-15/src/main.rs rename to listings/ch21-web-server/listing-21-15/src/main.rs diff --git a/listings/ch20-web-server/listing-20-16/404.html b/listings/ch21-web-server/listing-21-16/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-16/404.html rename to listings/ch21-web-server/listing-21-16/404.html diff --git a/listings/ch20-web-server/listing-20-16/Cargo.lock b/listings/ch21-web-server/listing-21-16/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-16/Cargo.lock rename to listings/ch21-web-server/listing-21-16/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-16/Cargo.toml b/listings/ch21-web-server/listing-21-16/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-16/Cargo.toml rename to listings/ch21-web-server/listing-21-16/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-16/hello.html b/listings/ch21-web-server/listing-21-16/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-16/hello.html rename to listings/ch21-web-server/listing-21-16/hello.html diff --git a/listings/ch20-web-server/listing-20-16/src/lib.rs b/listings/ch21-web-server/listing-21-16/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-16/src/lib.rs rename to listings/ch21-web-server/listing-21-16/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-16/src/main.rs b/listings/ch21-web-server/listing-21-16/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-16/src/main.rs rename to listings/ch21-web-server/listing-21-16/src/main.rs diff --git a/listings/ch20-web-server/listing-20-17/404.html b/listings/ch21-web-server/listing-21-17/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-17/404.html rename to listings/ch21-web-server/listing-21-17/404.html diff --git a/listings/ch20-web-server/listing-20-17/Cargo.lock b/listings/ch21-web-server/listing-21-17/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-17/Cargo.lock rename to listings/ch21-web-server/listing-21-17/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-17/Cargo.toml b/listings/ch21-web-server/listing-21-17/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-17/Cargo.toml rename to listings/ch21-web-server/listing-21-17/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-17/hello.html b/listings/ch21-web-server/listing-21-17/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-17/hello.html rename to listings/ch21-web-server/listing-21-17/hello.html diff --git a/listings/ch20-web-server/listing-20-17/output.txt b/listings/ch21-web-server/listing-21-17/output.txt similarity index 100% rename from listings/ch20-web-server/listing-20-17/output.txt rename to listings/ch21-web-server/listing-21-17/output.txt diff --git a/listings/ch20-web-server/listing-20-17/src/lib.rs b/listings/ch21-web-server/listing-21-17/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-17/src/lib.rs rename to listings/ch21-web-server/listing-21-17/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-17/src/main.rs b/listings/ch21-web-server/listing-21-17/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-17/src/main.rs rename to listings/ch21-web-server/listing-21-17/src/main.rs diff --git a/listings/ch20-web-server/listing-20-18/404.html b/listings/ch21-web-server/listing-21-18/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-18/404.html rename to listings/ch21-web-server/listing-21-18/404.html diff --git a/listings/ch20-web-server/listing-20-18/Cargo.lock b/listings/ch21-web-server/listing-21-18/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-18/Cargo.lock rename to listings/ch21-web-server/listing-21-18/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-18/Cargo.toml b/listings/ch21-web-server/listing-21-18/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-18/Cargo.toml rename to listings/ch21-web-server/listing-21-18/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-18/hello.html b/listings/ch21-web-server/listing-21-18/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-18/hello.html rename to listings/ch21-web-server/listing-21-18/hello.html diff --git a/listings/ch20-web-server/listing-20-18/src/lib.rs b/listings/ch21-web-server/listing-21-18/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-18/src/lib.rs rename to listings/ch21-web-server/listing-21-18/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-18/src/main.rs b/listings/ch21-web-server/listing-21-18/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-18/src/main.rs rename to listings/ch21-web-server/listing-21-18/src/main.rs diff --git a/listings/ch20-web-server/listing-20-19/404.html b/listings/ch21-web-server/listing-21-19/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-19/404.html rename to listings/ch21-web-server/listing-21-19/404.html diff --git a/listings/ch20-web-server/listing-20-19/Cargo.lock b/listings/ch21-web-server/listing-21-19/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-19/Cargo.lock rename to listings/ch21-web-server/listing-21-19/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-19/Cargo.toml b/listings/ch21-web-server/listing-21-19/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-19/Cargo.toml rename to listings/ch21-web-server/listing-21-19/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-19/hello.html b/listings/ch21-web-server/listing-21-19/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-19/hello.html rename to listings/ch21-web-server/listing-21-19/hello.html diff --git a/listings/ch20-web-server/listing-20-19/src/lib.rs b/listings/ch21-web-server/listing-21-19/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-19/src/lib.rs rename to listings/ch21-web-server/listing-21-19/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-19/src/main.rs b/listings/ch21-web-server/listing-21-19/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-19/src/main.rs rename to listings/ch21-web-server/listing-21-19/src/main.rs diff --git a/listings/ch20-web-server/listing-20-20/404.html b/listings/ch21-web-server/listing-21-20/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-20/404.html rename to listings/ch21-web-server/listing-21-20/404.html diff --git a/listings/ch20-web-server/listing-20-20/Cargo.lock b/listings/ch21-web-server/listing-21-20/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-20/Cargo.lock rename to listings/ch21-web-server/listing-21-20/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-20/Cargo.toml b/listings/ch21-web-server/listing-21-20/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-20/Cargo.toml rename to listings/ch21-web-server/listing-21-20/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-20/hello.html b/listings/ch21-web-server/listing-21-20/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-20/hello.html rename to listings/ch21-web-server/listing-21-20/hello.html diff --git a/listings/ch20-web-server/listing-20-20/src/lib.rs b/listings/ch21-web-server/listing-21-20/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-20/src/lib.rs rename to listings/ch21-web-server/listing-21-20/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-20/src/main.rs b/listings/ch21-web-server/listing-21-20/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-20/src/main.rs rename to listings/ch21-web-server/listing-21-20/src/main.rs diff --git a/listings/ch20-web-server/listing-20-21/404.html b/listings/ch21-web-server/listing-21-21/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-21/404.html rename to listings/ch21-web-server/listing-21-21/404.html diff --git a/listings/ch20-web-server/listing-20-21/Cargo.lock b/listings/ch21-web-server/listing-21-21/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-21/Cargo.lock rename to listings/ch21-web-server/listing-21-21/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-21/Cargo.toml b/listings/ch21-web-server/listing-21-21/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-21/Cargo.toml rename to listings/ch21-web-server/listing-21-21/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-21/hello.html b/listings/ch21-web-server/listing-21-21/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-21/hello.html rename to listings/ch21-web-server/listing-21-21/hello.html diff --git a/listings/ch20-web-server/listing-20-21/src/lib.rs b/listings/ch21-web-server/listing-21-21/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-21/src/lib.rs rename to listings/ch21-web-server/listing-21-21/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-21/src/main.rs b/listings/ch21-web-server/listing-21-21/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-21/src/main.rs rename to listings/ch21-web-server/listing-21-21/src/main.rs diff --git a/listings/ch20-web-server/listing-20-22/404.html b/listings/ch21-web-server/listing-21-22/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-22/404.html rename to listings/ch21-web-server/listing-21-22/404.html diff --git a/listings/ch20-web-server/listing-20-22/Cargo.lock b/listings/ch21-web-server/listing-21-22/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-22/Cargo.lock rename to listings/ch21-web-server/listing-21-22/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-22/Cargo.toml b/listings/ch21-web-server/listing-21-22/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-22/Cargo.toml rename to listings/ch21-web-server/listing-21-22/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-22/hello.html b/listings/ch21-web-server/listing-21-22/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-22/hello.html rename to listings/ch21-web-server/listing-21-22/hello.html diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch21-web-server/listing-21-22/output.txt similarity index 100% rename from listings/ch20-web-server/listing-20-22/output.txt rename to listings/ch21-web-server/listing-21-22/output.txt diff --git a/listings/ch20-web-server/listing-20-22/src/lib.rs b/listings/ch21-web-server/listing-21-22/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-22/src/lib.rs rename to listings/ch21-web-server/listing-21-22/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-22/src/main.rs b/listings/ch21-web-server/listing-21-22/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-22/src/main.rs rename to listings/ch21-web-server/listing-21-22/src/main.rs diff --git a/listings/ch20-web-server/listing-20-23/404.html b/listings/ch21-web-server/listing-21-23/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-23/404.html rename to listings/ch21-web-server/listing-21-23/404.html diff --git a/listings/ch20-web-server/listing-20-23/Cargo.lock b/listings/ch21-web-server/listing-21-23/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-23/Cargo.lock rename to listings/ch21-web-server/listing-21-23/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-23/Cargo.toml b/listings/ch21-web-server/listing-21-23/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-23/Cargo.toml rename to listings/ch21-web-server/listing-21-23/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-23/hello.html b/listings/ch21-web-server/listing-21-23/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-23/hello.html rename to listings/ch21-web-server/listing-21-23/hello.html diff --git a/listings/ch20-web-server/listing-20-23/src/lib.rs b/listings/ch21-web-server/listing-21-23/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-23/src/lib.rs rename to listings/ch21-web-server/listing-21-23/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-23/src/main.rs b/listings/ch21-web-server/listing-21-23/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-23/src/main.rs rename to listings/ch21-web-server/listing-21-23/src/main.rs diff --git a/listings/ch20-web-server/listing-20-24/404.html b/listings/ch21-web-server/listing-21-24/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-24/404.html rename to listings/ch21-web-server/listing-21-24/404.html diff --git a/listings/ch20-web-server/listing-20-24/Cargo.lock b/listings/ch21-web-server/listing-21-24/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-24/Cargo.lock rename to listings/ch21-web-server/listing-21-24/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-24/Cargo.toml b/listings/ch21-web-server/listing-21-24/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-24/Cargo.toml rename to listings/ch21-web-server/listing-21-24/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-24/hello.html b/listings/ch21-web-server/listing-21-24/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-24/hello.html rename to listings/ch21-web-server/listing-21-24/hello.html diff --git a/listings/ch20-web-server/listing-20-24/src/lib.rs b/listings/ch21-web-server/listing-21-24/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-24/src/lib.rs rename to listings/ch21-web-server/listing-21-24/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-24/src/main.rs b/listings/ch21-web-server/listing-21-24/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-24/src/main.rs rename to listings/ch21-web-server/listing-21-24/src/main.rs diff --git a/listings/ch20-web-server/listing-20-25/404.html b/listings/ch21-web-server/listing-21-25/404.html similarity index 100% rename from listings/ch20-web-server/listing-20-25/404.html rename to listings/ch21-web-server/listing-21-25/404.html diff --git a/listings/ch20-web-server/listing-20-25/Cargo.lock b/listings/ch21-web-server/listing-21-25/Cargo.lock similarity index 100% rename from listings/ch20-web-server/listing-20-25/Cargo.lock rename to listings/ch21-web-server/listing-21-25/Cargo.lock diff --git a/listings/ch20-web-server/listing-20-25/Cargo.toml b/listings/ch21-web-server/listing-21-25/Cargo.toml similarity index 100% rename from listings/ch20-web-server/listing-20-25/Cargo.toml rename to listings/ch21-web-server/listing-21-25/Cargo.toml diff --git a/listings/ch20-web-server/listing-20-25/hello.html b/listings/ch21-web-server/listing-21-25/hello.html similarity index 100% rename from listings/ch20-web-server/listing-20-25/hello.html rename to listings/ch21-web-server/listing-21-25/hello.html diff --git a/listings/ch20-web-server/listing-20-25/src/lib.rs b/listings/ch21-web-server/listing-21-25/src/lib.rs similarity index 100% rename from listings/ch20-web-server/listing-20-25/src/lib.rs rename to listings/ch21-web-server/listing-21-25/src/lib.rs diff --git a/listings/ch20-web-server/listing-20-25/src/main.rs b/listings/ch21-web-server/listing-21-25/src/main.rs similarity index 100% rename from listings/ch20-web-server/listing-20-25/src/main.rs rename to listings/ch21-web-server/listing-21-25/src/main.rs diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/404.html b/listings/ch21-web-server/no-listing-01-define-threadpool-struct/404.html similarity index 100% rename from listings/ch20-web-server/no-listing-01-define-threadpool-struct/404.html rename to listings/ch21-web-server/no-listing-01-define-threadpool-struct/404.html diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/Cargo.lock b/listings/ch21-web-server/no-listing-01-define-threadpool-struct/Cargo.lock similarity index 100% rename from listings/ch20-web-server/no-listing-01-define-threadpool-struct/Cargo.lock rename to listings/ch21-web-server/no-listing-01-define-threadpool-struct/Cargo.lock diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/Cargo.toml b/listings/ch21-web-server/no-listing-01-define-threadpool-struct/Cargo.toml similarity index 100% rename from listings/ch20-web-server/no-listing-01-define-threadpool-struct/Cargo.toml rename to listings/ch21-web-server/no-listing-01-define-threadpool-struct/Cargo.toml diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/hello.html b/listings/ch21-web-server/no-listing-01-define-threadpool-struct/hello.html similarity index 100% rename from listings/ch20-web-server/no-listing-01-define-threadpool-struct/hello.html rename to listings/ch21-web-server/no-listing-01-define-threadpool-struct/hello.html diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt b/listings/ch21-web-server/no-listing-01-define-threadpool-struct/output.txt similarity index 100% rename from listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt rename to listings/ch21-web-server/no-listing-01-define-threadpool-struct/output.txt diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/lib.rs b/listings/ch21-web-server/no-listing-01-define-threadpool-struct/src/lib.rs similarity index 100% rename from listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/lib.rs rename to listings/ch21-web-server/no-listing-01-define-threadpool-struct/src/lib.rs diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs b/listings/ch21-web-server/no-listing-01-define-threadpool-struct/src/main.rs similarity index 100% rename from listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs rename to listings/ch21-web-server/no-listing-01-define-threadpool-struct/src/main.rs diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/404.html b/listings/ch21-web-server/no-listing-02-impl-threadpool-new/404.html similarity index 100% rename from listings/ch20-web-server/no-listing-02-impl-threadpool-new/404.html rename to listings/ch21-web-server/no-listing-02-impl-threadpool-new/404.html diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/Cargo.lock b/listings/ch21-web-server/no-listing-02-impl-threadpool-new/Cargo.lock similarity index 100% rename from listings/ch20-web-server/no-listing-02-impl-threadpool-new/Cargo.lock rename to listings/ch21-web-server/no-listing-02-impl-threadpool-new/Cargo.lock diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/Cargo.toml b/listings/ch21-web-server/no-listing-02-impl-threadpool-new/Cargo.toml similarity index 100% rename from listings/ch20-web-server/no-listing-02-impl-threadpool-new/Cargo.toml rename to listings/ch21-web-server/no-listing-02-impl-threadpool-new/Cargo.toml diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/hello.html b/listings/ch21-web-server/no-listing-02-impl-threadpool-new/hello.html similarity index 100% rename from listings/ch20-web-server/no-listing-02-impl-threadpool-new/hello.html rename to listings/ch21-web-server/no-listing-02-impl-threadpool-new/hello.html diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt b/listings/ch21-web-server/no-listing-02-impl-threadpool-new/output.txt similarity index 100% rename from listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt rename to listings/ch21-web-server/no-listing-02-impl-threadpool-new/output.txt diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/lib.rs b/listings/ch21-web-server/no-listing-02-impl-threadpool-new/src/lib.rs similarity index 100% rename from listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/lib.rs rename to listings/ch21-web-server/no-listing-02-impl-threadpool-new/src/lib.rs diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs b/listings/ch21-web-server/no-listing-02-impl-threadpool-new/src/main.rs similarity index 100% rename from listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs rename to listings/ch21-web-server/no-listing-02-impl-threadpool-new/src/main.rs diff --git a/listings/ch20-web-server/no-listing-03-define-execute/404.html b/listings/ch21-web-server/no-listing-03-define-execute/404.html similarity index 100% rename from listings/ch20-web-server/no-listing-03-define-execute/404.html rename to listings/ch21-web-server/no-listing-03-define-execute/404.html diff --git a/listings/ch20-web-server/no-listing-03-define-execute/Cargo.lock b/listings/ch21-web-server/no-listing-03-define-execute/Cargo.lock similarity index 100% rename from listings/ch20-web-server/no-listing-03-define-execute/Cargo.lock rename to listings/ch21-web-server/no-listing-03-define-execute/Cargo.lock diff --git a/listings/ch20-web-server/no-listing-03-define-execute/Cargo.toml b/listings/ch21-web-server/no-listing-03-define-execute/Cargo.toml similarity index 100% rename from listings/ch20-web-server/no-listing-03-define-execute/Cargo.toml rename to listings/ch21-web-server/no-listing-03-define-execute/Cargo.toml diff --git a/listings/ch20-web-server/no-listing-03-define-execute/hello.html b/listings/ch21-web-server/no-listing-03-define-execute/hello.html similarity index 100% rename from listings/ch20-web-server/no-listing-03-define-execute/hello.html rename to listings/ch21-web-server/no-listing-03-define-execute/hello.html diff --git a/listings/ch20-web-server/no-listing-03-define-execute/output.txt b/listings/ch21-web-server/no-listing-03-define-execute/output.txt similarity index 100% rename from listings/ch20-web-server/no-listing-03-define-execute/output.txt rename to listings/ch21-web-server/no-listing-03-define-execute/output.txt diff --git a/listings/ch20-web-server/no-listing-03-define-execute/src/lib.rs b/listings/ch21-web-server/no-listing-03-define-execute/src/lib.rs similarity index 100% rename from listings/ch20-web-server/no-listing-03-define-execute/src/lib.rs rename to listings/ch21-web-server/no-listing-03-define-execute/src/lib.rs diff --git a/listings/ch20-web-server/no-listing-03-define-execute/src/main.rs b/listings/ch21-web-server/no-listing-03-define-execute/src/main.rs similarity index 100% rename from listings/ch20-web-server/no-listing-03-define-execute/src/main.rs rename to listings/ch21-web-server/no-listing-03-define-execute/src/main.rs diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/404.html b/listings/ch21-web-server/no-listing-04-update-worker-definition/404.html similarity index 100% rename from listings/ch20-web-server/no-listing-04-update-worker-definition/404.html rename to listings/ch21-web-server/no-listing-04-update-worker-definition/404.html diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/Cargo.lock b/listings/ch21-web-server/no-listing-04-update-worker-definition/Cargo.lock similarity index 100% rename from listings/ch20-web-server/no-listing-04-update-worker-definition/Cargo.lock rename to listings/ch21-web-server/no-listing-04-update-worker-definition/Cargo.lock diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/Cargo.toml b/listings/ch21-web-server/no-listing-04-update-worker-definition/Cargo.toml similarity index 100% rename from listings/ch20-web-server/no-listing-04-update-worker-definition/Cargo.toml rename to listings/ch21-web-server/no-listing-04-update-worker-definition/Cargo.toml diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/hello.html b/listings/ch21-web-server/no-listing-04-update-worker-definition/hello.html similarity index 100% rename from listings/ch20-web-server/no-listing-04-update-worker-definition/hello.html rename to listings/ch21-web-server/no-listing-04-update-worker-definition/hello.html diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt similarity index 100% rename from listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt rename to listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/src/lib.rs b/listings/ch21-web-server/no-listing-04-update-worker-definition/src/lib.rs similarity index 100% rename from listings/ch20-web-server/no-listing-04-update-worker-definition/src/lib.rs rename to listings/ch21-web-server/no-listing-04-update-worker-definition/src/lib.rs diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs b/listings/ch21-web-server/no-listing-04-update-worker-definition/src/main.rs similarity index 100% rename from listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs rename to listings/ch21-web-server/no-listing-04-update-worker-definition/src/main.rs diff --git a/listings/ch20-web-server/no-listing-05-fix-worker-new/404.html b/listings/ch21-web-server/no-listing-05-fix-worker-new/404.html similarity index 100% rename from listings/ch20-web-server/no-listing-05-fix-worker-new/404.html rename to listings/ch21-web-server/no-listing-05-fix-worker-new/404.html diff --git a/listings/ch20-web-server/no-listing-05-fix-worker-new/Cargo.lock b/listings/ch21-web-server/no-listing-05-fix-worker-new/Cargo.lock similarity index 100% rename from listings/ch20-web-server/no-listing-05-fix-worker-new/Cargo.lock rename to listings/ch21-web-server/no-listing-05-fix-worker-new/Cargo.lock diff --git a/listings/ch20-web-server/no-listing-05-fix-worker-new/Cargo.toml b/listings/ch21-web-server/no-listing-05-fix-worker-new/Cargo.toml similarity index 100% rename from listings/ch20-web-server/no-listing-05-fix-worker-new/Cargo.toml rename to listings/ch21-web-server/no-listing-05-fix-worker-new/Cargo.toml diff --git a/listings/ch20-web-server/no-listing-05-fix-worker-new/hello.html b/listings/ch21-web-server/no-listing-05-fix-worker-new/hello.html similarity index 100% rename from listings/ch20-web-server/no-listing-05-fix-worker-new/hello.html rename to listings/ch21-web-server/no-listing-05-fix-worker-new/hello.html diff --git a/listings/ch20-web-server/no-listing-05-fix-worker-new/src/lib.rs b/listings/ch21-web-server/no-listing-05-fix-worker-new/src/lib.rs similarity index 100% rename from listings/ch20-web-server/no-listing-05-fix-worker-new/src/lib.rs rename to listings/ch21-web-server/no-listing-05-fix-worker-new/src/lib.rs diff --git a/listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs b/listings/ch21-web-server/no-listing-05-fix-worker-new/src/main.rs similarity index 100% rename from listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs rename to listings/ch21-web-server/no-listing-05-fix-worker-new/src/main.rs diff --git a/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/404.html b/listings/ch21-web-server/no-listing-06-fix-threadpool-drop/404.html similarity index 100% rename from listings/ch20-web-server/no-listing-06-fix-threadpool-drop/404.html rename to listings/ch21-web-server/no-listing-06-fix-threadpool-drop/404.html diff --git a/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/Cargo.lock b/listings/ch21-web-server/no-listing-06-fix-threadpool-drop/Cargo.lock similarity index 100% rename from listings/ch20-web-server/no-listing-06-fix-threadpool-drop/Cargo.lock rename to listings/ch21-web-server/no-listing-06-fix-threadpool-drop/Cargo.lock diff --git a/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/Cargo.toml b/listings/ch21-web-server/no-listing-06-fix-threadpool-drop/Cargo.toml similarity index 100% rename from listings/ch20-web-server/no-listing-06-fix-threadpool-drop/Cargo.toml rename to listings/ch21-web-server/no-listing-06-fix-threadpool-drop/Cargo.toml diff --git a/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/hello.html b/listings/ch21-web-server/no-listing-06-fix-threadpool-drop/hello.html similarity index 100% rename from listings/ch20-web-server/no-listing-06-fix-threadpool-drop/hello.html rename to listings/ch21-web-server/no-listing-06-fix-threadpool-drop/hello.html diff --git a/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/lib.rs b/listings/ch21-web-server/no-listing-06-fix-threadpool-drop/src/lib.rs similarity index 100% rename from listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/lib.rs rename to listings/ch21-web-server/no-listing-06-fix-threadpool-drop/src/lib.rs diff --git a/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs b/listings/ch21-web-server/no-listing-06-fix-threadpool-drop/src/main.rs similarity index 100% rename from listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs rename to listings/ch21-web-server/no-listing-06-fix-threadpool-drop/src/main.rs diff --git a/listings/ch20-web-server/no-listing-07-final-code/404.html b/listings/ch21-web-server/no-listing-07-final-code/404.html similarity index 100% rename from listings/ch20-web-server/no-listing-07-final-code/404.html rename to listings/ch21-web-server/no-listing-07-final-code/404.html diff --git a/listings/ch20-web-server/no-listing-07-final-code/Cargo.lock b/listings/ch21-web-server/no-listing-07-final-code/Cargo.lock similarity index 100% rename from listings/ch20-web-server/no-listing-07-final-code/Cargo.lock rename to listings/ch21-web-server/no-listing-07-final-code/Cargo.lock diff --git a/listings/ch20-web-server/no-listing-07-final-code/Cargo.toml b/listings/ch21-web-server/no-listing-07-final-code/Cargo.toml similarity index 100% rename from listings/ch20-web-server/no-listing-07-final-code/Cargo.toml rename to listings/ch21-web-server/no-listing-07-final-code/Cargo.toml diff --git a/listings/ch20-web-server/no-listing-07-final-code/hello.html b/listings/ch21-web-server/no-listing-07-final-code/hello.html similarity index 100% rename from listings/ch20-web-server/no-listing-07-final-code/hello.html rename to listings/ch21-web-server/no-listing-07-final-code/hello.html diff --git a/listings/ch20-web-server/no-listing-07-final-code/src/lib.rs b/listings/ch21-web-server/no-listing-07-final-code/src/lib.rs similarity index 100% rename from listings/ch20-web-server/no-listing-07-final-code/src/lib.rs rename to listings/ch21-web-server/no-listing-07-final-code/src/lib.rs diff --git a/listings/ch20-web-server/no-listing-07-final-code/src/main.rs b/listings/ch21-web-server/no-listing-07-final-code/src/main.rs similarity index 100% rename from listings/ch20-web-server/no-listing-07-final-code/src/main.rs rename to listings/ch21-web-server/no-listing-07-final-code/src/main.rs diff --git a/src/ch21-01-single-threaded.md b/src/ch21-01-single-threaded.md index b474d926fe..11ae851b78 100644 --- a/src/ch21-01-single-threaded.md +++ b/src/ch21-01-single-threaded.md @@ -30,17 +30,17 @@ $ cargo new hello $ cd hello ``` -Now enter the code in Listing 20-1 in *src/main.rs* to start. This code will +Now enter the code in Listing 21-1 in *src/main.rs* to start. This code will listen at the local address `127.0.0.1:7878` for incoming TCP streams. When it gets an incoming stream, it will print `Connection established!`. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-01/src/main.rs}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-01/src/main.rs}} ``` -Listing 20-1: Listening for incoming streams and printing +Listing 21-1: Listening for incoming streams and printing a message when we receive a stream Using `TcpListener`, we can listen for TCP connections at the address @@ -125,15 +125,15 @@ separate the concerns of first getting a connection and then taking some action with the connection, we’ll start a new function for processing connections. In this new `handle_connection` function, we’ll read data from the TCP stream and print it so we can see the data being sent from the browser. Change the code to -look like Listing 20-2. +look like Listing 21-2. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-02/src/main.rs}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-02/src/main.rs}} ``` -Listing 20-2: Reading from the `TcpStream` and printing +Listing 21-2: Reading from the `TcpStream` and printing the data We bring `std::io::prelude` and `std::io::BufReader` into scope to get access @@ -271,15 +271,15 @@ The status code 200 is the standard success response. The text is a tiny successful HTTP response. Let’s write this to the stream as our response to a successful request! From the `handle_connection` function, remove the `println!` that was printing the request data and replace it with the code in -Listing 20-3. +Listing 21-3. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-03/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-03/src/main.rs:here}} ``` -Listing 20-3: Writing a tiny successful HTTP response to +Listing 21-3: Writing a tiny successful HTTP response to the stream The first new line defines the `response` variable that holds the success @@ -299,30 +299,30 @@ request and sending a response! Let’s implement the functionality for returning more than a blank page. Create the new file *hello.html* in the root of your project directory, not in the -*src* directory. You can input any HTML you want; Listing 20-4 shows one +*src* directory. You can input any HTML you want; Listing 21-4 shows one possibility. Filename: hello.html ```html -{{#include ../listings/ch20-web-server/listing-20-05/hello.html}} +{{#include ../listings/ch21-web-server/listing-21-05/hello.html}} ``` -Listing 20-4: A sample HTML file to return in a +Listing 21-4: A sample HTML file to return in a response This is a minimal HTML5 document with a heading and some text. To return this from the server when a request is received, we’ll modify `handle_connection` as -shown in Listing 20-5 to read the HTML file, add it to the response as a body, +shown in Listing 21-5 to read the HTML file, add it to the response as a body, and send it. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-05/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-05/src/main.rs:here}} ``` -Listing 20-5: Sending the contents of *hello.html* as the +Listing 21-5: Sending the contents of *hello.html* as the body of the response We’ve added `fs` to the `use` statement to bring the standard library’s @@ -352,17 +352,17 @@ Right now, our web server will return the HTML in the file no matter what the client requested. Let’s add functionality to check that the browser is requesting */* before returning the HTML file and return an error if the browser requests anything else. For this we need to modify `handle_connection`, -as shown in Listing 20-6. This new code checks the content of the request +as shown in Listing 21-6. This new code checks the content of the request received against what we know a request for */* looks like and adds `if` and `else` blocks to treat requests differently. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-06/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-06/src/main.rs:here}} ``` -Listing 20-6: Handling requests to */* differently from +Listing 21-6: Handling requests to */* differently from other requests We’re only going to be looking at the first line of the HTTP request, so rather @@ -370,7 +370,7 @@ than reading the entire request into a vector, we’re calling `next` to get the first item from the iterator. The first `unwrap` takes care of the `Option` and stops the program if the iterator has no items. The second `unwrap` handles the `Result` and has the same effect as the `unwrap` that was in the `map` added in -Listing 20-2. +Listing 21-2. Next, we check the `request_line` to see if it equals the request line of a GET request to the */* path. If it does, the `if` block returns the contents of our @@ -383,9 +383,9 @@ a moment to respond to all other requests. Run this code now and request *127.0.0.1:7878*; you should get the HTML in *hello.html*. If you make any other request, such as *127.0.0.1:7878/something-else*, you’ll get a connection error like those you -saw when running the code in Listing 20-1 and Listing 20-2. +saw when running the code in Listing 21-1 and Listing 21-2. -Now let’s add the code in Listing 20-7 to the `else` block to return a response +Now let’s add the code in Listing 21-7 to the `else` block to return a response with the status code 404, which signals that the content for the request was not found. We’ll also return some HTML for a page to render in the browser indicating the response to the end user. @@ -393,25 +393,25 @@ indicating the response to the end user. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-07/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-07/src/main.rs:here}} ``` -Listing 20-7: Responding with status code 404 and an +Listing 21-7: Responding with status code 404 and an error page if anything other than */* was requested Here, our response has a status line with status code 404 and the reason phrase `NOT FOUND`. The body of the response will be the HTML in the file *404.html*. You’ll need to create a *404.html* file next to *hello.html* for the error page; again feel free to use any HTML you want or use the example HTML in -Listing 20-8. +Listing 21-8. Filename: 404.html ```html -{{#include ../listings/ch20-web-server/listing-20-07/404.html}} +{{#include ../listings/ch21-web-server/listing-21-07/404.html}} ``` -Listing 20-8: Sample content for the page to send back +Listing 21-8: Sample content for the page to send back with any 404 response With these changes, run your server again. Requesting *127.0.0.1:7878* should @@ -426,16 +426,16 @@ differences are the status line and the filename. Let’s make the code more concise by pulling out those differences into separate `if` and `else` lines that will assign the values of the status line and the filename to variables; we can then use those variables unconditionally in the code to read the file -and write the response. Listing 20-9 shows the resulting code after replacing +and write the response. Listing 21-9 shows the resulting code after replacing the large `if` and `else` blocks. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-09/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-09/src/main.rs:here}} ``` -Listing 20-9: Refactoring the `if` and `else` blocks to +Listing 21-9: Refactoring the `if` and `else` blocks to contain only the code that differs between the two cases Now the `if` and `else` blocks only return the appropriate values for the @@ -447,8 +447,8 @@ The previously duplicated code is now outside the `if` and `else` blocks and uses the `status_line` and `filename` variables. This makes it easier to see the difference between the two cases, and it means we have only one place to update the code if we want to change how the file reading and response writing -work. The behavior of the code in Listing 20-9 will be the same as that in -Listing 20-7. +work. The behavior of the code in Listing 21-9 will be the same as that in +Listing 21-7. Awesome! We now have a simple web server in approximately 40 lines of Rust code that responds to one request with a page of content and responds to all other diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index 82d6fdf8f6..bcb0b133b0 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -11,17 +11,17 @@ this, but first, we’ll look at the problem in action. ### Simulating a Slow Request in the Current Server Implementation We’ll look at how a slow-processing request can affect other requests made to -our current server implementation. Listing 20-10 implements handling a request +our current server implementation. Listing 21-10 implements handling a request to */sleep* with a simulated slow response that will cause the server to sleep for 5 seconds before responding. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-10/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-10/src/main.rs:here}} ``` -Listing 20-10: Simulating a slow request by sleeping for +Listing 21-10: Simulating a slow request by sleeping for 5 seconds We switched from `if` to `match` now that we have three cases. We need to @@ -29,10 +29,10 @@ explicitly match on a slice of `request_line` to pattern match against the string literal values; `match` doesn’t do automatic referencing and dereferencing like the equality method does. -The first arm is the same as the `if` block from Listing 20-9. The second arm +The first arm is the same as the `if` block from Listing 21-9. The second arm matches a request to */sleep*. When that request is received, the server will sleep for 5 seconds before rendering the successful HTML page. The third arm is -the same as the `else` block from Listing 20-9. +the same as the `else` block from Listing 21-9. You can see how primitive our server is: real libraries would handle the recognition of multiple requests in a much less verbose way! @@ -103,16 +103,16 @@ every connection. As mentioned earlier, this isn’t our final plan due to the problems with potentially spawning an unlimited number of threads, but it is a starting point to get a working multithreaded server first. Then we’ll add the thread pool as an improvement, and contrasting the two solutions will be -easier. Listing 20-11 shows the changes to make to `main` to spawn a new thread +easier. Listing 21-11 shows the changes to make to `main` to spawn a new thread to handle each stream within the `for` loop. Filename: src/main.rs ```rust,no_run -{{#rustdoc_include ../listings/ch20-web-server/listing-20-11/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-11/src/main.rs:here}} ``` -Listing 20-11: Spawning a new thread for each +Listing 21-11: Spawning a new thread for each stream As you learned in Chapter 16, `thread::spawn` will create a new thread and then @@ -129,16 +129,16 @@ new threads without any limit. We want our thread pool to work in a similar, familiar way so switching from threads to a thread pool doesn’t require large changes to the code that uses -our API. Listing 20-12 shows the hypothetical interface for a `ThreadPool` +our API. Listing 21-12 shows the hypothetical interface for a `ThreadPool` struct we want to use instead of `thread::spawn`. Filename: src/main.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch20-web-server/listing-20-12/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-12/src/main.rs:here}} ``` -Listing 20-12: Our ideal `ThreadPool` interface +Listing 21-12: Our ideal `ThreadPool` interface We use `ThreadPool::new` to create a new thread pool with a configurable number of threads, in this case four. Then, in the `for` loop, `pool.execute` has a @@ -152,12 +152,12 @@ compile, but we’ll try so the compiler can guide us in how to fix it. #### Building `ThreadPool` Using Compiler Driven Development -Make the changes in Listing 20-12 to *src/main.rs*, and then let’s use the +Make the changes in Listing 21-12 to *src/main.rs*, and then let’s use the compiler errors from `cargo check` to drive our development. Here is the first error we get: ```console -{{#include ../listings/ch20-web-server/listing-20-12/output.txt}} +{{#include ../listings/ch21-web-server/listing-21-12/output.txt}} ``` Great! This error tells us we need a `ThreadPool` type or module, so we’ll @@ -174,7 +174,7 @@ definition of a `ThreadPool` struct that we can have for now: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/lib.rs}} +{{#rustdoc_include ../listings/ch21-web-server/no-listing-01-define-threadpool-struct/src/lib.rs}} ``` Then edit *main.rs* file to bring `ThreadPool` into scope from the library @@ -183,14 +183,14 @@ crate by adding the following code to the top of *src/main.rs*: Filename: src/main.rs ```rust,ignore -{{#rustdoc_include ../listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/no-listing-01-define-threadpool-struct/src/main.rs:here}} ``` This code still won’t work, but let’s check it again to get the next error that we need to address: ```console -{{#include ../listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt}} +{{#include ../listings/ch21-web-server/no-listing-01-define-threadpool-struct/output.txt}} ``` This error indicates that next we need to create an associated function named @@ -202,7 +202,7 @@ characteristics: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/lib.rs}} +{{#rustdoc_include ../listings/ch21-web-server/no-listing-02-impl-threadpool-new/src/lib.rs}} ``` We chose `usize` as the type of the `size` parameter, because we know that a @@ -214,7 +214,7 @@ ignore --> section of Chapter 3. Let’s check the code again: ```console -{{#include ../listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt}} +{{#include ../listings/ch21-web-server/no-listing-02-impl-threadpool-new/output.txt}} ``` Now the error occurs because we don’t have an `execute` method on `ThreadPool`. @@ -258,7 +258,7 @@ the thread will take to execute. Let’s create an `execute` method on Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/no-listing-03-define-execute/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/no-listing-03-define-execute/src/lib.rs:here}} ``` We still use the `()` after `FnOnce` because this `FnOnce` represents a closure @@ -270,7 +270,7 @@ Again, this is the simplest implementation of the `execute` method: it does nothing, but we’re trying only to make our code compile. Let’s check it again: ```console -{{#include ../listings/ch20-web-server/no-listing-03-define-execute/output.txt}} +{{#include ../listings/ch21-web-server/no-listing-03-define-execute/output.txt}} ``` It compiles! But note that if you try `cargo run` and make a request in the @@ -294,15 +294,15 @@ parameter, because a pool with a negative number of threads makes no sense. However, a pool with zero threads also makes no sense, yet zero is a perfectly valid `usize`. We’ll add code to check that `size` is greater than zero before we return a `ThreadPool` instance and have the program panic if it receives a -zero by using the `assert!` macro, as shown in Listing 20-13. +zero by using the `assert!` macro, as shown in Listing 21-13. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/listing-20-13/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-13/src/lib.rs:here}} ``` -Listing 20-13: Implementing `ThreadPool::new` to panic if +Listing 21-13: Implementing `ThreadPool::new` to panic if `size` is zero We’ve also added some documentation for our `ThreadPool` with doc comments. @@ -342,7 +342,7 @@ closure returns. Let’s try using `JoinHandle` too and see what happens. In our case, the closures we’re passing to the thread pool will handle the connection and not return anything, so `T` will be the unit type `()`. -The code in Listing 20-14 will compile but doesn’t create any threads yet. +The code in Listing 21-14 will compile but doesn’t create any threads yet. We’ve changed the definition of `ThreadPool` to hold a vector of `thread::JoinHandle<()>` instances, initialized the vector with a capacity of `size`, set up a `for` loop that will run some code to create the threads, and @@ -351,10 +351,10 @@ returned a `ThreadPool` instance containing them. Filename: src/lib.rs ```rust,ignore,not_desired_behavior -{{#rustdoc_include ../listings/ch20-web-server/listing-20-14/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-14/src/lib.rs:here}} ``` -Listing 20-14: Creating a vector for `ThreadPool` to hold +Listing 21-14: Creating a vector for `ThreadPool` to hold the threads We’ve brought `std::thread` into scope in the library crate, because we’re @@ -372,7 +372,7 @@ When you run `cargo check` again, it should succeed. #### A `Worker` Struct Responsible for Sending Code from the `ThreadPool` to a Thread -We left a comment in the `for` loop in Listing 20-14 regarding the creation of +We left a comment in the `for` loop in Listing 21-14 regarding the creation of threads. Here, we’ll look at how we actually create threads. The standard library provides `thread::spawn` as a way to create threads, and `thread::spawn` expects to get some code the thread should run as soon as the @@ -409,17 +409,17 @@ set up in this way: a new `Worker` with that `id`, and store the worker in the vector. If you’re up for a challenge, try implementing these changes on your own before -looking at the code in Listing 20-15. +looking at the code in Listing 21-15. -Ready? Here is Listing 20-15 with one way to make the preceding modifications. +Ready? Here is Listing 21-15 with one way to make the preceding modifications. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/listing-20-15/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-15/src/lib.rs:here}} ``` -Listing 20-15: Modifying `ThreadPool` to hold `Worker` +Listing 21-15: Modifying `ThreadPool` to hold `Worker` instances instead of holding threads directly We’ve changed the name of the field on `ThreadPool` from `threads` to `workers` @@ -470,17 +470,17 @@ the `Worker` instances, which will send the job to its thread. Here is the plan: closures of any jobs it receives. Let’s start by creating a channel in `ThreadPool::new` and holding the sender -in the `ThreadPool` instance, as shown in Listing 20-16. The `Job` struct +in the `ThreadPool` instance, as shown in Listing 21-16. The `Job` struct doesn’t hold anything for now but will be the type of item we’re sending down the channel. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/listing-20-16/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-16/src/lib.rs:here}} ``` -Listing 20-16: Modifying `ThreadPool` to store the +Listing 21-16: Modifying `ThreadPool` to store the sender of a channel that transmits `Job` instances In `ThreadPool::new`, we create our new channel and have the pool hold the @@ -489,15 +489,15 @@ sender. This will successfully compile. Let’s try passing a receiver of the channel into each worker as the thread pool creates the channel. We know we want to use the receiver in the thread that the workers spawn, so we’ll reference the `receiver` parameter in the closure. The -code in Listing 20-17 won’t quite compile yet. +code in Listing 21-17 won’t quite compile yet. Filename: src/lib.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch20-web-server/listing-20-17/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-17/src/lib.rs:here}} ``` -Listing 20-17: Passing the receiver to the workers +Listing 21-17: Passing the receiver to the workers We’ve made some small and straightforward changes: we pass the receiver into `Worker::new`, and then we use it inside the closure. @@ -505,7 +505,7 @@ We’ve made some small and straightforward changes: we pass the receiver into When we try to check this code, we get this error: ```console -{{#include ../listings/ch20-web-server/listing-20-17/output.txt}} +{{#include ../listings/ch21-web-server/listing-21-17/output.txt}} ``` The code is trying to pass `receiver` to multiple `Worker` instances. This @@ -523,15 +523,15 @@ Recall the thread-safe smart pointers discussed in Chapter 16: to share ownership across multiple threads and allow the threads to mutate the value, we need to use `Arc>`. The `Arc` type will let multiple workers own the receiver, and `Mutex` will ensure that only one worker gets a job from the -receiver at a time. Listing 20-18 shows the changes we need to make. +receiver at a time. Listing 21-18 shows the changes we need to make. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/listing-20-18/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-18/src/lib.rs:here}} ``` -Listing 20-18: Sharing the receiver among the workers +Listing 21-18: Sharing the receiver among the workers using `Arc` and `Mutex` In `ThreadPool::new`, we put the receiver in an `Arc` and a `Mutex`. For each @@ -547,15 +547,15 @@ Let’s finally implement the `execute` method on `ThreadPool`. We’ll also cha closure that `execute` receives. As discussed in the [“Creating Type Synonyms with Type Aliases”][creating-type-synonyms-with-type-aliases] section of Chapter 19, type aliases allow us to make long types shorter for -ease of use. Look at Listing 20-19. +ease of use. Look at Listing 21-19. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/listing-20-19/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-19/src/lib.rs:here}} ``` -Listing 20-19: Creating a `Job` type alias for a `Box` +Listing 21-19: Creating a `Job` type alias for a `Box` that holds each closure and then sending the job down the channel After creating a new `Job` instance using the closure we get in `execute`, we @@ -571,15 +571,15 @@ But we’re not quite done yet! In the worker, our closure being passed to `thread::spawn` still only *references* the receiving end of the channel. Instead, we need the closure to loop forever, asking the receiving end of the channel for a job and running the job when it gets one. Let’s make the change -shown in Listing 20-20 to `Worker::new`. +shown in Listing 21-20 to `Worker::new`. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch20-web-server/listing-20-20/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch21-web-server/listing-21-20/src/lib.rs:here}} ``` -Listing 20-20: Receiving and executing the jobs in the +Listing 21-20: Receiving and executing the jobs in the worker’s thread Here, we first call `lock` on the `receiver` to acquire the mutex, and then we @@ -603,7 +603,7 @@ Our thread pool is now in a working state! Give it a `cargo run` and make some requests: section in @@ -278,15 +278,15 @@ abstraction to the unsafe code with an implementation of the function that uses `unsafe` code in a safe way, because it creates only valid pointers from the data this function has access to. -In contrast, the use of `slice::from_raw_parts_mut` in Listing 19-7 would +In contrast, the use of `slice::from_raw_parts_mut` in Listing 20-7 would likely crash when the slice is used. This code takes an arbitrary memory location and creates a slice 10,000 items long. ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-07/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-07/src/main.rs:here}} ``` -Listing 19-7: Creating a slice from an arbitrary memory +Listing 20-7: Creating a slice from an arbitrary memory location We don’t own the memory at this arbitrary location, and there is no guarantee @@ -301,7 +301,7 @@ and use of a *Foreign Function Interface (FFI)*. An FFI is a way for a programming language to define functions and enable a different (foreign) programming language to call those functions. -Listing 19-8 demonstrates how to set up an integration with the `abs` function +Listing 20-8 demonstrates how to set up an integration with the `abs` function from the C standard library. Functions declared within `extern` blocks are always unsafe to call from Rust code. The reason is that other languages don’t enforce Rust’s rules and guarantees, and Rust can’t check them, so @@ -310,10 +310,10 @@ responsibility falls on the programmer to ensure safety. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-08/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-08/src/main.rs}} ``` -Listing 19-8: Declaring and calling an `extern` function +Listing 20-8: Declaring and calling an `extern` function defined in another language Within the `extern "C"` block, we list the names and signatures of external @@ -353,17 +353,17 @@ In this book, we’ve not yet talked about *global variables*, which Rust does support but can be problematic with Rust’s ownership rules. If two threads are accessing the same mutable global variable, it can cause a data race. -In Rust, global variables are called *static* variables. Listing 19-9 shows an +In Rust, global variables are called *static* variables. Listing 20-9 shows an example declaration and use of a static variable with a string slice as a value. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-09/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-09/src/main.rs}} ``` -Listing 19-9: Defining and using an immutable static +Listing 20-9: Defining and using an immutable static variable Static variables are similar to constants, which we discussed in the @@ -380,16 +380,16 @@ values in a static variable have a fixed address in memory. Using the value will always access the same data. Constants, on the other hand, are allowed to duplicate their data whenever they’re used. Another difference is that static variables can be mutable. Accessing and modifying mutable static variables is -*unsafe*. Listing 19-10 shows how to declare, access, and modify a mutable +*unsafe*. Listing 20-10 shows how to declare, access, and modify a mutable static variable named `COUNTER`. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-10/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-10/src/main.rs}} ``` -Listing 19-10: Reading from or writing to a mutable +Listing 20-10: Reading from or writing to a mutable static variable is unsafe As with regular variables, we specify mutability using the `mut` keyword. Any @@ -410,13 +410,13 @@ We can use `unsafe` to implement an unsafe trait. A trait is unsafe when at least one of its methods has some invariant that the compiler can’t verify. We declare that a trait is `unsafe` by adding the `unsafe` keyword before `trait` and marking the implementation of the trait as `unsafe` too, as shown in -Listing 19-11. +Listing 20-11. ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-11/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-11/src/main.rs}} ``` -Listing 19-11: Defining and implementing an unsafe +Listing 20-11: Defining and implementing an unsafe trait By using `unsafe impl`, we’re promising that we’ll uphold the invariants that diff --git a/src/ch20-03-advanced-traits.md b/src/ch20-03-advanced-traits.md index a32b0e1da7..7dc333e782 100644 --- a/src/ch20-03-advanced-traits.md +++ b/src/ch20-03-advanced-traits.md @@ -23,13 +23,13 @@ One example of a trait with an associated type is the `Iterator` trait that the standard library provides. The associated type is named `Item` and stands in for the type of the values the type implementing the `Iterator` trait is iterating over. The definition of the `Iterator` trait is as shown in Listing -19-12. +20-12. ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-12/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-12/src/lib.rs}} ``` -Listing 19-12: The definition of the `Iterator` trait +Listing 20-12: The definition of the `Iterator` trait that has an associated type `Item` The type `Item` is a placeholder, and the `next` method’s definition shows that @@ -46,20 +46,20 @@ the `Item` type is `u32`: Filename: src/lib.rs ```rust,ignore -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-22-iterator-on-counter/src/lib.rs:ch19}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-22-iterator-on-counter/src/lib.rs:ch19}} ``` This syntax seems comparable to that of generics. So why not just define the -`Iterator` trait with generics, as shown in Listing 19-13? +`Iterator` trait with generics, as shown in Listing 20-13? ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-13/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-13/src/lib.rs}} ``` -Listing 19-13: A hypothetical definition of the +Listing 20-13: A hypothetical definition of the `Iterator` trait using generics -The difference is that when using generics, as in Listing 19-13, we must +The difference is that when using generics, as in Listing 20-13, we must annotate the types in each implementation; because we can also implement `Iterator for Counter` or any other type, we could have multiple implementations of `Iterator` for `Counter`. In other words, when a trait has a @@ -69,7 +69,7 @@ the concrete types of the generic type parameters each time. When we use the indicate which implementation of `Iterator` we want to use. With associated types, we don’t need to annotate types because we can’t -implement a trait on a type multiple times. In Listing 19-12 with the +implement a trait on a type multiple times. In Listing 20-12 with the definition that uses associated types, we can only choose what the type of `Item` will be once, because there can only be one `impl Iterator for Counter`. We don’t have to specify that we want an iterator of `u32` values everywhere @@ -94,17 +94,17 @@ in particular situations. Rust doesn’t allow you to create your own operators or overload arbitrary operators. But you can overload the operations and corresponding traits listed in `std::ops` by implementing the traits associated with the operator. For -example, in Listing 19-14 we overload the `+` operator to add two `Point` +example, in Listing 20-14 we overload the `+` operator to add two `Point` instances together. We do this by implementing the `Add` trait on a `Point` struct: Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-14/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-14/src/main.rs}} ``` -Listing 19-14: Implementing the `Add` trait to overload +Listing 20-14: Implementing the `Add` trait to overload the `+` operator for `Point` instances The `add` method adds the `x` values of two `Point` instances and the `y` @@ -142,15 +142,15 @@ units. This thin wrapping of an existing type in another struct is known as the Pattern to Implement External Traits on External Types”][newtype] section. We want to add values in millimeters to values in meters and have the implementation of `Add` do the conversion correctly. We can implement `Add` -for `Millimeters` with `Meters` as the `Rhs`, as shown in Listing 19-15. +for `Millimeters` with `Meters` as the `Rhs`, as shown in Listing 20-15. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-15/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-15/src/lib.rs}} ``` -Listing 19-15: Implementing the `Add` trait on +Listing 20-15: Implementing the `Add` trait on `Millimeters` to add `Millimeters` to `Meters` To add `Millimeters` and `Meters`, we specify `impl Add` to set the @@ -181,7 +181,7 @@ on one type. It’s also possible to implement a method directly on the type wit the same name as methods from traits. When calling methods with the same name, you’ll need to tell Rust which one you -want to use. Consider the code in Listing 19-16 where we’ve defined two traits, +want to use. Consider the code in Listing 20-16 where we’ve defined two traits, `Pilot` and `Wizard`, that both have a method called `fly`. We then implement both traits on a type `Human` that already has a method named `fly` implemented on it. Each `fly` method does something different. @@ -189,23 +189,23 @@ on it. Each `fly` method does something different. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-16/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-16/src/main.rs:here}} ``` -Listing 19-16: Two traits are defined to have a `fly` +Listing 20-16: Two traits are defined to have a `fly` method and are implemented on the `Human` type, and a `fly` method is implemented on `Human` directly When we call `fly` on an instance of `Human`, the compiler defaults to calling -the method that is directly implemented on the type, as shown in Listing 19-17. +the method that is directly implemented on the type, as shown in Listing 20-17. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-17/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-17/src/main.rs:here}} ``` -Listing 19-17: Calling `fly` on an instance of +Listing 20-17: Calling `fly` on an instance of `Human` Running this code will print `*waving arms furiously*`, showing that Rust @@ -213,27 +213,27 @@ called the `fly` method implemented on `Human` directly. To call the `fly` methods from either the `Pilot` trait or the `Wizard` trait, we need to use more explicit syntax to specify which `fly` method we mean. -Listing 19-18 demonstrates this syntax. +Listing 20-18 demonstrates this syntax. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-18/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-18/src/main.rs:here}} ``` -Listing 19-18: Specifying which trait’s `fly` method we +Listing 20-18: Specifying which trait’s `fly` method we want to call Specifying the trait name before the method name clarifies to Rust which implementation of `fly` we want to call. We could also write `Human::fly(&person)`, which is equivalent to the `person.fly()` that we used -in Listing 19-18, but this is a bit longer to write if we don’t need to +in Listing 20-18, but this is a bit longer to write if we don’t need to disambiguate. Running this code prints the following: ```console -{{#include ../listings/ch19-advanced-features/listing-19-18/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-18/output.txt}} ``` Because the `fly` method takes a `self` parameter, if we had two *types* that @@ -243,7 +243,7 @@ trait to use based on the type of `self`. However, associated functions that are not methods don’t have a `self` parameter. When there are multiple types or traits that define non-method functions with the same function name, Rust doesn't always know which type you -mean unless you use *fully qualified syntax*. For example, in Listing 19-19 we +mean unless you use *fully qualified syntax*. For example, in Listing 20-19 we create a trait for an animal shelter that wants to name all baby dogs *Spot*. We make an `Animal` trait with an associated non-method function `baby_name`. The `Animal` trait is implemented for the struct `Dog`, on which we also @@ -252,10 +252,10 @@ provide an associated non-method function `baby_name` directly. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-19/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-19/src/main.rs}} ``` -Listing 19-19: A trait with an associated function and a +Listing 20-19: A trait with an associated function and a type with an associated function of the same name that also implements the trait @@ -269,22 +269,22 @@ In `main`, we call the `Dog::baby_name` function, which calls the associated function defined on `Dog` directly. This code prints the following: ```console -{{#include ../listings/ch19-advanced-features/listing-19-19/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-19/output.txt}} ``` This output isn’t what we wanted. We want to call the `baby_name` function that is part of the `Animal` trait that we implemented on `Dog` so the code prints `A baby dog is called a puppy`. The technique of specifying the trait name that -we used in Listing 19-18 doesn’t help here; if we change `main` to the code in -Listing 19-20, we’ll get a compilation error. +we used in Listing 20-18 doesn’t help here; if we change `main` to the code in +Listing 20-20, we’ll get a compilation error. Filename: src/main.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-20/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-20/src/main.rs:here}} ``` -Listing 19-20: Attempting to call the `baby_name` +Listing 20-20: Attempting to call the `baby_name` function from the `Animal` trait, but Rust doesn’t know which implementation to use @@ -293,21 +293,21 @@ other types that implement the `Animal` trait, Rust can’t figure out which implementation of `Animal::baby_name` we want. We’ll get this compiler error: ```console -{{#include ../listings/ch19-advanced-features/listing-19-20/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-20/output.txt}} ``` To disambiguate and tell Rust that we want to use the implementation of `Animal` for `Dog` as opposed to the implementation of `Animal` for some other -type, we need to use fully qualified syntax. Listing 19-21 demonstrates how to +type, we need to use fully qualified syntax. Listing 20-21 demonstrates how to use fully qualified syntax. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-21/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-21/src/main.rs:here}} ``` -Listing 19-21: Using fully qualified syntax to specify +Listing 20-21: Using fully qualified syntax to specify that we want to call the `baby_name` function from the `Animal` trait as implemented on `Dog` @@ -317,7 +317,7 @@ implemented on `Dog` by saying that we want to treat the `Dog` type as an `Animal` for this function call. This code will now print what we want: ```console -{{#include ../listings/ch19-advanced-features/listing-19-21/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-21/output.txt}} ``` In general, fully qualified syntax is defined as follows: @@ -362,16 +362,16 @@ In the implementation of the `outline_print` method, we want to use the `OutlinePrint` trait will work only for types that also implement `Display` and provide the functionality that `OutlinePrint` needs. We can do that in the trait definition by specifying `OutlinePrint: Display`. This technique is -similar to adding a trait bound to the trait. Listing 19-22 shows an +similar to adding a trait bound to the trait. Listing 20-22 shows an implementation of the `OutlinePrint` trait. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-22/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-22/src/main.rs:here}} ``` -Listing 19-22: Implementing the `OutlinePrint` trait that +Listing 20-22: Implementing the `OutlinePrint` trait that requires the functionality from `Display` Because we’ve specified that `OutlinePrint` requires the `Display` trait, we @@ -387,13 +387,13 @@ doesn’t implement `Display`, such as the `Point` struct: Filename: src/main.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-02-impl-outlineprint-for-point/src/main.rs:here}} ``` We get an error saying that `Display` is required but not implemented: ```console -{{#include ../listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt}} +{{#include ../listings/ch20-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt}} ``` To fix this, we implement `Display` on `Point` and satisfy the constraint that @@ -402,7 +402,7 @@ To fix this, we implement `Display` on `Point` and satisfy the constraint that Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-03-impl-display-for-point/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-03-impl-display-for-point/src/main.rs:here}} ``` Then implementing the `OutlinePrint` trait on `Point` will compile @@ -429,15 +429,15 @@ As an example, let’s say we want to implement `Display` on `Vec`, which the orphan rule prevents us from doing directly because the `Display` trait and the `Vec` type are defined outside our crate. We can make a `Wrapper` struct that holds an instance of `Vec`; then we can implement `Display` on -`Wrapper` and use the `Vec` value, as shown in Listing 19-23. +`Wrapper` and use the `Vec` value, as shown in Listing 20-23. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-23/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-23/src/main.rs}} ``` -Listing 19-23: Creating a `Wrapper` type around +Listing 20-23: Creating a `Wrapper` type around `Vec` to implement `Display` The implementation of `Display` uses `self.0` to access the inner `Vec`, diff --git a/src/ch20-04-advanced-types.md b/src/ch20-04-advanced-types.md index 427c108aa4..a626529842 100644 --- a/src/ch20-04-advanced-types.md +++ b/src/ch20-04-advanced-types.md @@ -15,7 +15,7 @@ the `!` type and dynamically sized types. The newtype pattern is also useful for tasks beyond those we’ve discussed so far, including statically enforcing that values are never confused and indicating the units of a value. You saw an example of using newtypes to -indicate units in Listing 19-15: recall that the `Millimeters` and `Meters` +indicate units in Listing 20-15: recall that the `Millimeters` and `Meters` structs wrapped `u32` values in a newtype. If we wrote a function with a parameter of type `Millimeters`, we couldn’t compile a program that accidentally tried to call that function with a value of type `Meters` or a @@ -43,16 +43,16 @@ another name. For this we use the `type` keyword. For example, we can create the alias `Kilometers` to `i32` like so: ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-04-kilometers-alias/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-04-kilometers-alias/src/main.rs:here}} ``` Now, the alias `Kilometers` is a *synonym* for `i32`; unlike the `Millimeters` -and `Meters` types we created in Listing 19-15, `Kilometers` is not a separate, +and `Meters` types we created in Listing 20-15, `Kilometers` is not a separate, new type. Values that have the type `Kilometers` will be treated the same as values of type `i32`: ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-04-kilometers-alias/src/main.rs:there}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-04-kilometers-alias/src/main.rs:there}} ``` Because `Kilometers` and `i32` are the same type, we can add values of both @@ -71,23 +71,23 @@ Box Writing this lengthy type in function signatures and as type annotations all over the code can be tiresome and error prone. Imagine having a project full of -code like that in Listing 19-24. +code like that in Listing 20-24. ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-24/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-24/src/main.rs:here}} ``` -Listing 19-24: Using a long type in many places +Listing 20-24: Using a long type in many places A type alias makes this code more manageable by reducing the repetition. In -Listing 19-25, we’ve introduced an alias named `Thunk` for the verbose type and +Listing 20-25, we’ve introduced an alias named `Thunk` for the verbose type and can replace all uses of the type with the shorter alias `Thunk`. ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-25/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-25/src/main.rs:here}} ``` -Listing 19-25: Introducing a type alias `Thunk` to reduce +Listing 20-25: Introducing a type alias `Thunk` to reduce repetition This code is much easier to read and write! Choosing a meaningful name for a @@ -104,14 +104,14 @@ possible I/O errors. Many of the functions in `std::io` will be returning the `Write` trait: ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-05-write-trait/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-05-write-trait/src/lib.rs}} ``` The `Result<..., Error>` is repeated a lot. As such, `std::io` has this type alias declaration: ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-06-result-alias/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-06-result-alias/src/lib.rs:here}} ``` Because this declaration is in the `std::io` module, we can use the fully @@ -120,7 +120,7 @@ filled in as `std::io::Error`. The `Write` trait function signatures end up looking like this: ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-06-result-alias/src/lib.rs:there}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-06-result-alias/src/lib.rs:there}} ``` The type alias helps in two ways: it makes code easier to write *and* it gives @@ -136,7 +136,7 @@ because it stands in the place of the return type when a function will never return. Here is an example: ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-07-never-type/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-07-never-type/src/lib.rs:here}} ``` This code is read as “the function `bar` returns never.” Functions that return @@ -145,13 +145,13 @@ so `bar` can never possibly return. But what use is a type you can never create values for? Recall the code from Listing 2-5, part of the number guessing game; we’ve reproduced a bit of it -here in Listing 19-26. +here in Listing 20-26. ```rust,ignore {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-05/src/main.rs:ch19}} ``` -Listing 19-26: A `match` with an arm that ends in +Listing 20-26: A `match` with an arm that ends in `continue` At the time, we skipped over some details in this code. In Chapter 6 in [“The @@ -160,13 +160,13 @@ section, we discussed that `match` arms must all return the same type. So, for example, the following code doesn’t work: ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-08-match-arms-different-types/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-08-match-arms-different-types/src/main.rs:here}} ``` The type of `guess` in this code would have to be an integer *and* a string, and Rust requires that `guess` have only one type. So what does `continue` return? How were we allowed to return a `u32` from one arm and have another arm -that ends with `continue` in Listing 19-26? +that ends with `continue` in Listing 20-26? As you might have guessed, `continue` has a `!` value. That is, when Rust computes the type of `guess`, it looks at both match arms, the former with a @@ -184,10 +184,10 @@ function that we call on `Option` values to produce a value or panic with this definition: ```rust,ignore -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-09-unwrap-definition/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-09-unwrap-definition/src/lib.rs:here}} ``` -In this code, the same thing happens as in the `match` in Listing 19-26: Rust +In this code, the same thing happens as in the `match` in Listing 20-26: Rust sees that `val` has the type `T` and `panic!` has the type `!`, so the result of the overall `match` expression is `T`. This code works because `panic!` doesn’t produce a value; it ends the program. In the `None` case, we won’t be @@ -196,7 +196,7 @@ returning a value from `unwrap`, so this code is valid. One final expression that has the type `!` is a `loop`: ```rust,ignore -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-10-loop-returns-never/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-10-loop-returns-never/src/main.rs:here}} ``` Here, the loop never ends, so `!` is the value of the expression. However, this @@ -218,7 +218,7 @@ we can’t create a variable of type `str`, nor can we take an argument of type `str`. Consider the following code, which does not work: ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-11-cant-create-str/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-11-cant-create-str/src/main.rs:here}} ``` Rust needs to know how much memory to allocate for any value of a particular @@ -259,13 +259,13 @@ implicitly adds a bound on `Sized` to every generic function. That is, a generic function definition like this: ```rust,ignore -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-12-generic-fn-definition/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-12-generic-fn-definition/src/lib.rs}} ``` is actually treated as though we had written this: ```rust,ignore -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-13-generic-implicit-sized-bound/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-13-generic-implicit-sized-bound/src/lib.rs}} ``` By default, generic functions will work only on types that have a known size at @@ -273,7 +273,7 @@ compile time. However, you can use the following special syntax to relax this restriction: ```rust,ignore -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-14-generic-maybe-sized/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-14-generic-maybe-sized/src/lib.rs}} ``` A trait bound on `?Sized` means “`T` may or may not be `Sized`” and this diff --git a/src/ch20-05-advanced-functions-and-closures.md b/src/ch20-05-advanced-functions-and-closures.md index d0de1dfd0a..ac8305736d 100644 --- a/src/ch20-05-advanced-functions-and-closures.md +++ b/src/ch20-05-advanced-functions-and-closures.md @@ -14,7 +14,7 @@ with function pointers will allow you to use functions as arguments to other functions. The syntax for specifying that a parameter is a function pointer is similar to -that of closures, as shown in Listing 19-27, where we’ve defined a function +that of closures, as shown in Listing 20-27, where we’ve defined a function `add_one` that adds one to its parameter. The function `do_twice` takes two parameters: a function pointer to any function that takes an `i32` parameter and returns an `i32`, and one `i32` value. The `do_twice` function calls the @@ -25,10 +25,10 @@ results together. The `main` function calls `do_twice` with the arguments Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-27/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-27/src/main.rs}} ``` -Listing 19-27: Using the `fn` type to accept a function +Listing 20-27: Using the `fn` type to accept a function pointer as an argument This code prints `The answer is: 12`. We specify that the parameter `f` in @@ -56,14 +56,14 @@ trait in the standard library. To use the `map` function to turn a vector of numbers into a vector of strings, we could use a closure, like this: ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-15-map-closure/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-15-map-closure/src/main.rs:here}} ``` Or we could name a function as the argument to `map` instead of the closure, like this: ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-16-map-function/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-16-map-function/src/main.rs:here}} ``` Note that we must use the fully qualified syntax that we talked about earlier @@ -79,7 +79,7 @@ implement the closure traits, which means we can specify the initializer functions as arguments for methods that take closures, like so: ```rust -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-17-map-initializer/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-17-map-initializer/src/main.rs:here}} ``` Here we create `Status::Value` instances using each `u32` value in the range @@ -99,13 +99,13 @@ pointer `fn` as a return type, for example. The following code tries to return a closure directly, but it won’t compile: ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-18-returns-closure/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-18-returns-closure/src/lib.rs}} ``` The compiler error is as follows: ```console -{{#include ../listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt}} +{{#include ../listings/ch20-advanced-features/no-listing-18-returns-closure/output.txt}} ``` The error references the `Sized` trait again! Rust doesn’t know how much space @@ -113,7 +113,7 @@ it will need to store the closure. We saw a solution to this problem earlier. We can use a trait object: ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-19-returns-closure-trait-object/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-19-returns-closure-trait-object/src/lib.rs}} ``` This code will compile just fine. For more about trait objects, refer to the diff --git a/src/ch20-06-macros.md b/src/ch20-06-macros.md index f24a818c18..b9b97201cc 100644 --- a/src/ch20-06-macros.md +++ b/src/ch20-06-macros.md @@ -73,15 +73,15 @@ We could also use the `vec!` macro to make a vector of two integers or a vector of five string slices. We wouldn’t be able to use a function to do the same because we wouldn’t know the number or type of values up front. -Listing 19-28 shows a slightly simplified definition of the `vec!` macro. +Listing 20-28 shows a slightly simplified definition of the `vec!` macro. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-28/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-28/src/lib.rs}} ``` -Listing 19-28: A simplified version of the `vec!` macro +Listing 20-28: A simplified version of the `vec!` macro definition > Note: The actual definition of the `vec!` macro in the standard library @@ -107,7 +107,7 @@ one arm. Valid pattern syntax in macro definitions is different than the pattern syntax covered in Chapter 18 because macro patterns are matched against Rust code structure rather than values. Let’s walk through what the pattern pieces in -Listing 19-28 mean; for the full macro pattern syntax, see the [Rust +Listing 20-28 mean; for the full macro pattern syntax, see the [Rust Reference][ref]. First, we use a set of parentheses to encompass the whole pattern. We use a @@ -160,7 +160,7 @@ attribute-like, and function-like, and all work in a similar fashion. When creating procedural macros, the definitions must reside in their own crate with a special crate type. This is for complex technical reasons that we hope -to eliminate in the future. In Listing 19-29, we show how to define a +to eliminate in the future. In Listing 20-29, we show how to define a procedural macro, where `some_attribute` is a placeholder for using a specific macro variety. @@ -174,7 +174,7 @@ pub fn some_name(input: TokenStream) -> TokenStream { } ``` -Listing 19-29: An example of defining a procedural +Listing 20-29: An example of defining a procedural macro The function that defines a procedural macro takes a `TokenStream` as an input @@ -200,15 +200,15 @@ we’ll provide a procedural macro so users can annotate their type with function. The default implementation will print `Hello, Macro! My name is TypeName!` where `TypeName` is the name of the type on which this trait has been defined. In other words, we’ll write a crate that enables another -programmer to write code like Listing 19-30 using our crate. +programmer to write code like Listing 20-30 using our crate. Filename: src/main.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-30/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-30/src/main.rs}} ``` -Listing 19-30: The code a user of our crate will be able +Listing 20-30: The code a user of our crate will be able to write when using our procedural macro This code will print `Hello, Macro! My name is Pancakes!` when we’re done. The @@ -223,14 +223,14 @@ Next, we’ll define the `HelloMacro` trait and its associated function: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-20-impl-hellomacro-for-pancakes/hello_macro/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-20-impl-hellomacro-for-pancakes/hello_macro/src/lib.rs}} ``` We have a trait and its function. At this point, our crate user could implement the trait to achieve the desired functionality, like so: ```rust,ignore -{{#rustdoc_include ../listings/ch19-advanced-features/no-listing-20-impl-hellomacro-for-pancakes/pancakes/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/no-listing-20-impl-hellomacro-for-pancakes/pancakes/src/main.rs}} ``` However, they would need to write the implementation block for each type they @@ -272,20 +272,20 @@ in a moment, so we need to add them as dependencies. Add the following to the Filename: hello_macro_derive/Cargo.toml ```toml -{{#include ../listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml:6:12}} +{{#include ../listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/Cargo.toml:6:12}} ``` -To start defining the procedural macro, place the code in Listing 19-31 into +To start defining the procedural macro, place the code in Listing 20-31 into your *src/lib.rs* file for the `hello_macro_derive` crate. Note that this code won’t compile until we add a definition for the `impl_hello_macro` function. Filename: hello_macro_derive/src/lib.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/src/lib.rs}} ``` -Listing 19-31: Code that most procedural macro crates +Listing 20-31: Code that most procedural macro crates will require in order to process Rust code Notice that we’ve split the code into the `hello_macro_derive` function, which @@ -318,7 +318,7 @@ The `hello_macro_derive` function first converts the `input` from a `TokenStream` to a data structure that we can then interpret and perform operations on. This is where `syn` comes into play. The `parse` function in `syn` takes a `TokenStream` and returns a `DeriveInput` struct representing the -parsed Rust code. Listing 19-32 shows the relevant parts of the `DeriveInput` +parsed Rust code. Listing 20-32 shows the relevant parts of the `DeriveInput` struct we get from parsing the `struct Pancakes;` string: ```rust,ignore @@ -341,8 +341,8 @@ DeriveInput { } ``` -Listing 19-32: The `DeriveInput` instance we get when -parsing the code that has the macro’s attribute in Listing 19-30 +Listing 20-32: The `DeriveInput` instance we get when +parsing the code that has the macro’s attribute in Listing 20-30 The fields of this struct show that the Rust code we’ve parsed is a unit struct with the `ident` (identifier, meaning the name) of `Pancakes`. There are more @@ -366,24 +366,24 @@ about what went wrong by using `panic!` or `expect`. Now that we have the code to turn the annotated Rust code from a `TokenStream` into a `DeriveInput` instance, let’s generate the code that implements the -`HelloMacro` trait on the annotated type, as shown in Listing 19-33. +`HelloMacro` trait on the annotated type, as shown in Listing 20-33. Filename: hello_macro_derive/src/lib.rs ```rust,ignore -{{#rustdoc_include ../listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/src/lib.rs:here}} ``` -Listing 19-33: Implementing the `HelloMacro` trait using +Listing 20-33: Implementing the `HelloMacro` trait using the parsed Rust code We get an `Ident` struct instance containing the name (identifier) of the -annotated type using `ast.ident`. The struct in Listing 19-32 shows that when -we run the `impl_hello_macro` function on the code in Listing 19-30, the +annotated type using `ast.ident`. The struct in Listing 20-32 shows that when +we run the `impl_hello_macro` function on the code in Listing 20-30, the `ident` we get will have the `ident` field with a value of `"Pancakes"`. Thus, -the `name` variable in Listing 19-33 will contain an `Ident` struct instance +the `name` variable in Listing 20-33 will contain an `Ident` struct instance that, when printed, will be the string `"Pancakes"`, the name of the struct in -Listing 19-30. +Listing 20-30. The `quote!` macro lets us define the Rust code that we want to return. The compiler expects something different to the direct result of the `quote!` @@ -412,7 +412,7 @@ saves an allocation by converting `#name` to a string literal at compile time. At this point, `cargo build` should complete successfully in both `hello_macro` and `hello_macro_derive`. Let’s hook up these crates to the code in Listing -19-30 to see the procedural macro in action! Create a new binary project in +20-30 to see the procedural macro in action! Create a new binary project in your *projects* directory using `cargo new pancakes`. We need to add `hello_macro` and `hello_macro_derive` as dependencies in the `pancakes` crate’s *Cargo.toml*. If you’re publishing your versions of `hello_macro` and @@ -420,10 +420,10 @@ crate’s *Cargo.toml*. If you’re publishing your versions of `hello_macro` an dependencies; if not, you can specify them as `path` dependencies as follows: ```toml -{{#include ../listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.toml:7:9}} +{{#include ../listings/ch20-advanced-features/no-listing-21-pancakes/pancakes/Cargo.toml:7:9}} ``` -Put the code in Listing 19-30 into *src/main.rs*, and run `cargo run`: it +Put the code in Listing 20-30 into *src/main.rs*, and run `cargo run`: it should print `Hello, Macro! My name is Pancakes!` The implementation of the `HelloMacro` trait from the procedural macro was included without the `pancakes` crate needing to implement it; the `#[derive(HelloMacro)]` added the From 1f6ce678419e9841b34fa0bf21b75a5b6d67c1f4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 26 Sep 2024 14:03:07 -0600 Subject: [PATCH 621/720] Ch. 17: Listings for Ch. 18 -> Ch. 19 --- .../listing-19-01}/Cargo.lock | 0 .../listing-19-01}/Cargo.toml | 0 .../listing-19-01}/src/main.rs | 0 .../listing-19-02}/Cargo.lock | 0 .../listing-19-02}/Cargo.toml | 0 .../listing-19-02}/src/main.rs | 0 .../listing-19-03}/Cargo.lock | 0 .../listing-19-03}/Cargo.toml | 0 .../listing-19-03}/output.txt | 0 .../listing-19-03}/src/main.rs | 0 .../listing-19-04}/Cargo.lock | 0 .../listing-19-04}/Cargo.toml | 0 .../listing-19-04}/src/main.rs | 0 .../listing-19-05}/Cargo.lock | 0 .../listing-19-05}/Cargo.toml | 0 .../listing-19-05}/output.txt | 0 .../listing-19-05}/src/main.rs | 0 .../listing-19-06}/Cargo.lock | 0 .../listing-19-06}/Cargo.toml | 0 .../listing-19-06}/src/main.rs | 0 .../listing-19-07}/Cargo.lock | 0 .../listing-19-07}/Cargo.toml | 0 .../listing-19-07}/src/main.rs | 0 .../listing-19-08}/Cargo.lock | 0 .../listing-19-08}/Cargo.toml | 0 .../listing-19-08}/output.txt | 0 .../listing-19-08}/src/main.rs | 0 .../listing-19-09}/Cargo.lock | 0 .../listing-19-09}/Cargo.toml | 0 .../listing-19-09}/src/main.rs | 0 .../listing-19-10}/Cargo.lock | 0 .../listing-19-10}/Cargo.toml | 0 .../listing-19-10}/output.txt | 0 .../listing-19-10}/src/main.rs | 0 .../listing-19-11}/Cargo.lock | 0 .../listing-19-11}/Cargo.toml | 0 .../listing-19-11}/src/main.rs | 0 .../listing-19-12}/Cargo.lock | 0 .../listing-19-12}/Cargo.toml | 0 .../listing-19-12}/src/main.rs | 0 .../listing-19-13}/Cargo.lock | 0 .../listing-19-13}/Cargo.toml | 0 .../listing-19-13}/src/main.rs | 0 .../listing-19-14}/Cargo.lock | 0 .../listing-19-14}/Cargo.toml | 0 .../listing-19-14}/src/main.rs | 0 .../listing-19-15}/Cargo.lock | 0 .../listing-19-15}/Cargo.toml | 0 .../listing-19-15}/src/main.rs | 0 .../listing-19-16}/Cargo.lock | 0 .../listing-19-16}/Cargo.toml | 0 .../listing-19-16}/src/main.rs | 0 .../listing-19-17}/Cargo.lock | 0 .../listing-19-17}/Cargo.toml | 0 .../listing-19-17}/src/main.rs | 0 .../listing-19-18}/Cargo.lock | 0 .../listing-19-18}/Cargo.toml | 0 .../listing-19-18}/src/main.rs | 0 .../listing-19-19}/Cargo.lock | 0 .../listing-19-19}/Cargo.toml | 0 .../listing-19-19}/src/main.rs | 0 .../listing-19-20}/Cargo.lock | 0 .../listing-19-20}/Cargo.toml | 0 .../listing-19-20}/src/main.rs | 0 .../listing-19-21}/Cargo.lock | 0 .../listing-19-21}/Cargo.toml | 0 .../listing-19-21}/src/main.rs | 0 .../listing-19-22}/Cargo.lock | 0 .../listing-19-22}/Cargo.toml | 0 .../listing-19-22}/src/main.rs | 0 .../listing-19-23}/Cargo.lock | 0 .../listing-19-23}/Cargo.toml | 0 .../listing-19-23}/src/main.rs | 0 .../listing-19-24}/Cargo.lock | 0 .../listing-19-24}/Cargo.toml | 0 .../listing-19-24}/src/main.rs | 0 .../listing-19-25}/Cargo.lock | 0 .../listing-19-25}/Cargo.toml | 0 .../listing-19-25}/output.txt | 0 .../listing-19-25}/rustfmt-ignore | 0 .../listing-19-25}/src/main.rs | 0 .../listing-19-26}/Cargo.lock | 0 .../listing-19-26}/Cargo.toml | 0 .../listing-19-26}/src/main.rs | 0 .../listing-19-27}/Cargo.lock | 0 .../listing-19-27}/Cargo.toml | 0 .../listing-19-27}/src/main.rs | 0 .../listing-19-28}/Cargo.lock | 0 .../listing-19-28}/Cargo.toml | 0 .../listing-19-28}/src/main.rs | 0 .../listing-19-29}/Cargo.lock | 0 .../listing-19-29}/Cargo.toml | 0 .../listing-19-29}/src/main.rs | 0 .../no-listing-01-literals/Cargo.lock | 0 .../no-listing-01-literals/Cargo.toml | 0 .../no-listing-01-literals/src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../no-listing-03-ranges/Cargo.lock | 0 .../no-listing-03-ranges/Cargo.toml | 0 .../no-listing-03-ranges/src/main.rs | 0 .../no-listing-04-ranges-of-char/Cargo.lock | 0 .../no-listing-04-ranges-of-char/Cargo.toml | 0 .../no-listing-04-ranges-of-char/src/main.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 src/ch19-01-all-the-places-for-patterns.md | 50 +++---- src/ch19-02-refutability.md | 22 +-- src/ch19-03-pattern-syntax.md | 134 +++++++++--------- 111 files changed, 103 insertions(+), 103 deletions(-) rename listings/{ch18-patterns-and-matching/listing-18-01 => ch19-patterns-and-matching/listing-19-01}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-01 => ch19-patterns-and-matching/listing-19-01}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-01 => ch19-patterns-and-matching/listing-19-01}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-02 => ch19-patterns-and-matching/listing-19-02}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-02 => ch19-patterns-and-matching/listing-19-02}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-02 => ch19-patterns-and-matching/listing-19-02}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-03 => ch19-patterns-and-matching/listing-19-03}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-03 => ch19-patterns-and-matching/listing-19-03}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-03 => ch19-patterns-and-matching/listing-19-03}/output.txt (100%) rename listings/{ch18-patterns-and-matching/listing-18-03 => ch19-patterns-and-matching/listing-19-03}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-04 => ch19-patterns-and-matching/listing-19-04}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-04 => ch19-patterns-and-matching/listing-19-04}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-04 => ch19-patterns-and-matching/listing-19-04}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-05 => ch19-patterns-and-matching/listing-19-05}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-05 => ch19-patterns-and-matching/listing-19-05}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-05 => ch19-patterns-and-matching/listing-19-05}/output.txt (100%) rename listings/{ch18-patterns-and-matching/listing-18-05 => ch19-patterns-and-matching/listing-19-05}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-06 => ch19-patterns-and-matching/listing-19-06}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-06 => ch19-patterns-and-matching/listing-19-06}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-06 => ch19-patterns-and-matching/listing-19-06}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-07 => ch19-patterns-and-matching/listing-19-07}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-07 => ch19-patterns-and-matching/listing-19-07}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-07 => ch19-patterns-and-matching/listing-19-07}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-08 => ch19-patterns-and-matching/listing-19-08}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-08 => ch19-patterns-and-matching/listing-19-08}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-08 => ch19-patterns-and-matching/listing-19-08}/output.txt (100%) rename listings/{ch18-patterns-and-matching/listing-18-08 => ch19-patterns-and-matching/listing-19-08}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-09 => ch19-patterns-and-matching/listing-19-09}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-09 => ch19-patterns-and-matching/listing-19-09}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-09 => ch19-patterns-and-matching/listing-19-09}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-10 => ch19-patterns-and-matching/listing-19-10}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-10 => ch19-patterns-and-matching/listing-19-10}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-10 => ch19-patterns-and-matching/listing-19-10}/output.txt (100%) rename listings/{ch18-patterns-and-matching/listing-18-10 => ch19-patterns-and-matching/listing-19-10}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-11 => ch19-patterns-and-matching/listing-19-11}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-11 => ch19-patterns-and-matching/listing-19-11}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-11 => ch19-patterns-and-matching/listing-19-11}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-12 => ch19-patterns-and-matching/listing-19-12}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-12 => ch19-patterns-and-matching/listing-19-12}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-12 => ch19-patterns-and-matching/listing-19-12}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-13 => ch19-patterns-and-matching/listing-19-13}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-13 => ch19-patterns-and-matching/listing-19-13}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-13 => ch19-patterns-and-matching/listing-19-13}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-14 => ch19-patterns-and-matching/listing-19-14}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-14 => ch19-patterns-and-matching/listing-19-14}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-14 => ch19-patterns-and-matching/listing-19-14}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-15 => ch19-patterns-and-matching/listing-19-15}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-15 => ch19-patterns-and-matching/listing-19-15}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-15 => ch19-patterns-and-matching/listing-19-15}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-16 => ch19-patterns-and-matching/listing-19-16}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-16 => ch19-patterns-and-matching/listing-19-16}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-16 => ch19-patterns-and-matching/listing-19-16}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-17 => ch19-patterns-and-matching/listing-19-17}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-17 => ch19-patterns-and-matching/listing-19-17}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-17 => ch19-patterns-and-matching/listing-19-17}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-18 => ch19-patterns-and-matching/listing-19-18}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-18 => ch19-patterns-and-matching/listing-19-18}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-18 => ch19-patterns-and-matching/listing-19-18}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-19 => ch19-patterns-and-matching/listing-19-19}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-19 => ch19-patterns-and-matching/listing-19-19}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-19 => ch19-patterns-and-matching/listing-19-19}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-20 => ch19-patterns-and-matching/listing-19-20}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-20 => ch19-patterns-and-matching/listing-19-20}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-20 => ch19-patterns-and-matching/listing-19-20}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-21 => ch19-patterns-and-matching/listing-19-21}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-21 => ch19-patterns-and-matching/listing-19-21}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-21 => ch19-patterns-and-matching/listing-19-21}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-22 => ch19-patterns-and-matching/listing-19-22}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-22 => ch19-patterns-and-matching/listing-19-22}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-22 => ch19-patterns-and-matching/listing-19-22}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-23 => ch19-patterns-and-matching/listing-19-23}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-23 => ch19-patterns-and-matching/listing-19-23}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-23 => ch19-patterns-and-matching/listing-19-23}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-24 => ch19-patterns-and-matching/listing-19-24}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-24 => ch19-patterns-and-matching/listing-19-24}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-24 => ch19-patterns-and-matching/listing-19-24}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-25 => ch19-patterns-and-matching/listing-19-25}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-25 => ch19-patterns-and-matching/listing-19-25}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-25 => ch19-patterns-and-matching/listing-19-25}/output.txt (100%) rename listings/{ch18-patterns-and-matching/listing-18-25 => ch19-patterns-and-matching/listing-19-25}/rustfmt-ignore (100%) rename listings/{ch18-patterns-and-matching/listing-18-25 => ch19-patterns-and-matching/listing-19-25}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-26 => ch19-patterns-and-matching/listing-19-26}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-26 => ch19-patterns-and-matching/listing-19-26}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-26 => ch19-patterns-and-matching/listing-19-26}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-27 => ch19-patterns-and-matching/listing-19-27}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-27 => ch19-patterns-and-matching/listing-19-27}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-27 => ch19-patterns-and-matching/listing-19-27}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-28 => ch19-patterns-and-matching/listing-19-28}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-28 => ch19-patterns-and-matching/listing-19-28}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-28 => ch19-patterns-and-matching/listing-19-28}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching/listing-18-29 => ch19-patterns-and-matching/listing-19-29}/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching/listing-18-29 => ch19-patterns-and-matching/listing-19-29}/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching/listing-18-29 => ch19-patterns-and-matching/listing-19-29}/src/main.rs (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-01-literals/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-01-literals/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-01-literals/src/main.rs (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-02-multiple-patterns/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-02-multiple-patterns/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-02-multiple-patterns/src/main.rs (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-03-ranges/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-03-ranges/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-03-ranges/src/main.rs (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-04-ranges-of-char/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-04-ranges-of-char/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-04-ranges-of-char/src/main.rs (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-05-destructuring-structs-and-tuples/Cargo.lock (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-05-destructuring-structs-and-tuples/Cargo.toml (100%) rename listings/{ch18-patterns-and-matching => ch19-patterns-and-matching}/no-listing-05-destructuring-structs-and-tuples/src/main.rs (100%) diff --git a/listings/ch18-patterns-and-matching/listing-18-01/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-01/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-01/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-01/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-01/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-01/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-01/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-01/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-01/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-01/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-01/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-01/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-02/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-02/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-02/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-02/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-02/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-02/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-02/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-02/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-02/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-02/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-02/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-02/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-03/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-03/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-03/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-03/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-03/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-03/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-03/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-03/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-03/output.txt b/listings/ch19-patterns-and-matching/listing-19-03/output.txt similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-03/output.txt rename to listings/ch19-patterns-and-matching/listing-19-03/output.txt diff --git a/listings/ch18-patterns-and-matching/listing-18-03/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-03/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-03/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-03/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-04/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-04/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-04/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-04/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-04/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-04/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-04/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-04/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-04/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-04/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-04/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-04/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-05/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-05/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-05/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-05/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-05/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-05/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-05/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-05/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-05/output.txt b/listings/ch19-patterns-and-matching/listing-19-05/output.txt similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-05/output.txt rename to listings/ch19-patterns-and-matching/listing-19-05/output.txt diff --git a/listings/ch18-patterns-and-matching/listing-18-05/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-05/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-05/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-05/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-06/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-06/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-06/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-06/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-06/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-06/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-06/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-06/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-06/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-06/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-06/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-06/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-07/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-07/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-07/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-07/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-07/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-07/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-07/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-07/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-07/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-07/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-07/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-07/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-08/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-08/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-08/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-08/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-08/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-08/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-08/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-08/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-08/output.txt b/listings/ch19-patterns-and-matching/listing-19-08/output.txt similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-08/output.txt rename to listings/ch19-patterns-and-matching/listing-19-08/output.txt diff --git a/listings/ch18-patterns-and-matching/listing-18-08/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-08/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-08/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-08/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-09/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-09/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-09/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-09/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-09/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-09/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-09/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-09/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-09/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-09/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-09/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-09/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-10/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-10/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-10/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-10/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-10/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-10/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-10/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-10/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-10/output.txt b/listings/ch19-patterns-and-matching/listing-19-10/output.txt similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-10/output.txt rename to listings/ch19-patterns-and-matching/listing-19-10/output.txt diff --git a/listings/ch18-patterns-and-matching/listing-18-10/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-10/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-10/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-10/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-11/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-11/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-11/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-11/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-11/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-11/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-11/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-11/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-11/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-11/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-11/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-11/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-12/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-12/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-12/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-12/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-12/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-12/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-12/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-12/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-12/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-12/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-12/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-12/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-13/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-13/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-13/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-13/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-13/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-13/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-13/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-13/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-13/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-13/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-13/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-13/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-14/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-14/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-14/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-14/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-14/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-14/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-14/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-14/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-14/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-14/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-14/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-14/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-15/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-15/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-15/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-15/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-15/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-15/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-15/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-15/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-15/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-15/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-15/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-16/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-16/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-16/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-16/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-16/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-16/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-16/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-16/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-16/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-16/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-16/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-16/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-17/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-17/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-17/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-17/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-17/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-17/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-17/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-17/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-17/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-17/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-17/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-17/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-18/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-18/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-18/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-18/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-18/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-18/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-18/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-18/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-18/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-18/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-18/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-18/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-19/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-19/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-19/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-19/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-19/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-19/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-19/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-19/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-19/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-19/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-19/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-19/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-20/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-20/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-20/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-20/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-20/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-20/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-20/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-20/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-20/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-20/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-20/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-20/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-21/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-21/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-21/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-21/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-21/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-21/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-21/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-21/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-21/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-21/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-21/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-21/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-22/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-22/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-22/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-22/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-22/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-22/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-22/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-22/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-22/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-22/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-22/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-22/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-23/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-23/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-23/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-23/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-23/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-23/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-23/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-23/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-23/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-23/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-23/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-23/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-24/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-24/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-24/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-24/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-24/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-24/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-24/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-24/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-24/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-24/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-24/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-24/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-25/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-25/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-25/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-25/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-25/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-25/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-25/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-25/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-25/output.txt b/listings/ch19-patterns-and-matching/listing-19-25/output.txt similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-25/output.txt rename to listings/ch19-patterns-and-matching/listing-19-25/output.txt diff --git a/listings/ch18-patterns-and-matching/listing-18-25/rustfmt-ignore b/listings/ch19-patterns-and-matching/listing-19-25/rustfmt-ignore similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-25/rustfmt-ignore rename to listings/ch19-patterns-and-matching/listing-19-25/rustfmt-ignore diff --git a/listings/ch18-patterns-and-matching/listing-18-25/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-25/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-25/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-25/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-26/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-26/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-26/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-26/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-26/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-26/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-26/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-26/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-26/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-26/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-26/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-26/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-27/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-27/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-27/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-27/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-27/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-27/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-27/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-27/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-27/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-27/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-27/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-27/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-28/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-28/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-28/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-28/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-28/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-28/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-28/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-28/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-28/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-28/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-28/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-28/src/main.rs diff --git a/listings/ch18-patterns-and-matching/listing-18-29/Cargo.lock b/listings/ch19-patterns-and-matching/listing-19-29/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-29/Cargo.lock rename to listings/ch19-patterns-and-matching/listing-19-29/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/listing-18-29/Cargo.toml b/listings/ch19-patterns-and-matching/listing-19-29/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-29/Cargo.toml rename to listings/ch19-patterns-and-matching/listing-19-29/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/listing-18-29/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-29/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/listing-18-29/src/main.rs rename to listings/ch19-patterns-and-matching/listing-19-29/src/main.rs diff --git a/listings/ch18-patterns-and-matching/no-listing-01-literals/Cargo.lock b/listings/ch19-patterns-and-matching/no-listing-01-literals/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-01-literals/Cargo.lock rename to listings/ch19-patterns-and-matching/no-listing-01-literals/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/no-listing-01-literals/Cargo.toml b/listings/ch19-patterns-and-matching/no-listing-01-literals/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-01-literals/Cargo.toml rename to listings/ch19-patterns-and-matching/no-listing-01-literals/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/no-listing-01-literals/src/main.rs b/listings/ch19-patterns-and-matching/no-listing-01-literals/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-01-literals/src/main.rs rename to listings/ch19-patterns-and-matching/no-listing-01-literals/src/main.rs diff --git a/listings/ch18-patterns-and-matching/no-listing-02-multiple-patterns/Cargo.lock b/listings/ch19-patterns-and-matching/no-listing-02-multiple-patterns/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-02-multiple-patterns/Cargo.lock rename to listings/ch19-patterns-and-matching/no-listing-02-multiple-patterns/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/no-listing-02-multiple-patterns/Cargo.toml b/listings/ch19-patterns-and-matching/no-listing-02-multiple-patterns/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-02-multiple-patterns/Cargo.toml rename to listings/ch19-patterns-and-matching/no-listing-02-multiple-patterns/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/no-listing-02-multiple-patterns/src/main.rs b/listings/ch19-patterns-and-matching/no-listing-02-multiple-patterns/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-02-multiple-patterns/src/main.rs rename to listings/ch19-patterns-and-matching/no-listing-02-multiple-patterns/src/main.rs diff --git a/listings/ch18-patterns-and-matching/no-listing-03-ranges/Cargo.lock b/listings/ch19-patterns-and-matching/no-listing-03-ranges/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-03-ranges/Cargo.lock rename to listings/ch19-patterns-and-matching/no-listing-03-ranges/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/no-listing-03-ranges/Cargo.toml b/listings/ch19-patterns-and-matching/no-listing-03-ranges/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-03-ranges/Cargo.toml rename to listings/ch19-patterns-and-matching/no-listing-03-ranges/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/no-listing-03-ranges/src/main.rs b/listings/ch19-patterns-and-matching/no-listing-03-ranges/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-03-ranges/src/main.rs rename to listings/ch19-patterns-and-matching/no-listing-03-ranges/src/main.rs diff --git a/listings/ch18-patterns-and-matching/no-listing-04-ranges-of-char/Cargo.lock b/listings/ch19-patterns-and-matching/no-listing-04-ranges-of-char/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-04-ranges-of-char/Cargo.lock rename to listings/ch19-patterns-and-matching/no-listing-04-ranges-of-char/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/no-listing-04-ranges-of-char/Cargo.toml b/listings/ch19-patterns-and-matching/no-listing-04-ranges-of-char/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-04-ranges-of-char/Cargo.toml rename to listings/ch19-patterns-and-matching/no-listing-04-ranges-of-char/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/no-listing-04-ranges-of-char/src/main.rs b/listings/ch19-patterns-and-matching/no-listing-04-ranges-of-char/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-04-ranges-of-char/src/main.rs rename to listings/ch19-patterns-and-matching/no-listing-04-ranges-of-char/src/main.rs diff --git a/listings/ch18-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/Cargo.lock b/listings/ch19-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/Cargo.lock similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/Cargo.lock rename to listings/ch19-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/Cargo.lock diff --git a/listings/ch18-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/Cargo.toml b/listings/ch19-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/Cargo.toml similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/Cargo.toml rename to listings/ch19-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/Cargo.toml diff --git a/listings/ch18-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/src/main.rs b/listings/ch19-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/src/main.rs similarity index 100% rename from listings/ch18-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/src/main.rs rename to listings/ch19-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/src/main.rs diff --git a/src/ch19-01-all-the-places-for-patterns.md b/src/ch19-01-all-the-places-for-patterns.md index e6f9ebd2cb..92578802e5 100644 --- a/src/ch19-01-all-the-places-for-patterns.md +++ b/src/ch19-01-all-the-places-for-patterns.md @@ -52,13 +52,13 @@ way to write the equivalent of a `match` that only matches one case. Optionally, `if let` can have a corresponding `else` containing code to run if the pattern in the `if let` doesn’t match. -Listing 18-1 shows that it’s also possible to mix and match `if let`, `else +Listing 19-1 shows that it’s also possible to mix and match `if let`, `else if`, and `else if let` expressions. Doing so gives us more flexibility than a `match` expression in which we can express only one value to compare with the patterns. Also, Rust doesn't require that the conditions in a series of `if let`, `else if`, `else if let` arms relate to each other. -The code in Listing 18-1 determines what color to make your background based on +The code in Listing 19-1 determines what color to make your background based on a series of checks for several conditions. For this example, we’ve created variables with hardcoded values that a real program might receive from user input. @@ -66,10 +66,10 @@ input. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-01/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-01/src/main.rs}} ``` -Listing 18-1: Mixing `if let`, `else if`, `else if let`, +Listing 19-1: Mixing `if let`, `else if`, `else if let`, and `else` If the user specifies a favorite color, that color is used as the background. @@ -100,14 +100,14 @@ not alert us to the possible logic bug. Similar in construction to `if let`, the `while let` conditional loop allows a `while` loop to run for as long as a pattern continues to match. In Listing -18-2 we code a `while let` loop that uses a vector as a stack and prints the +19-2 we code a `while let` loop that uses a vector as a stack and prints the values in the vector in the opposite order in which they were pushed. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-02/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-02/src/main.rs:here}} ``` -Listing 18-2: Using a `while let` loop to print values +Listing 19-2: Using a `while let` loop to print values for as long as `stack.pop()` returns `Some` This example prints 3, 2, and then 1. The `pop` method takes the last element @@ -119,21 +119,21 @@ use `while let` to pop every element off our stack. ### `for` Loops In a `for` loop, the value that directly follows the keyword `for` is a -pattern. For example, in `for x in y` the `x` is the pattern. Listing 18-3 +pattern. For example, in `for x in y` the `x` is the pattern. Listing 19-3 demonstrates how to use a pattern in a `for` loop to destructure, or break apart, a tuple as part of the `for` loop. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-03/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-03/src/main.rs:here}} ``` -Listing 18-3: Using a pattern in a `for` loop to +Listing 19-3: Using a pattern in a `for` loop to destructure a tuple -The code in Listing 18-3 will print the following: +The code in Listing 19-3 will print the following: ```console -{{#include ../listings/ch18-patterns-and-matching/listing-18-03/output.txt}} +{{#include ../listings/ch19-patterns-and-matching/listing-19-03/output.txt}} ``` We adapt an iterator using the `enumerate` method so it produces a value and @@ -169,13 +169,13 @@ the variable `x`.” Because the name `x` is the whole pattern, this pattern effectively means “bind everything to the variable `x`, whatever the value is.” To see the pattern matching aspect of `let` more clearly, consider Listing -18-4, which uses a pattern with `let` to destructure a tuple. +19-4, which uses a pattern with `let` to destructure a tuple. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-04/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-04/src/main.rs:here}} ``` -Listing 18-4: Using a pattern to destructure a tuple and +Listing 19-4: Using a pattern to destructure a tuple and create three variables at once Here, we match a tuple against a pattern. Rust compares the value `(1, 2, 3)` @@ -185,20 +185,20 @@ pattern as nesting three individual variable patterns inside it. If the number of elements in the pattern doesn’t match the number of elements in the tuple, the overall type won’t match and we’ll get a compiler error. For -example, Listing 18-5 shows an attempt to destructure a tuple with three +example, Listing 19-5 shows an attempt to destructure a tuple with three elements into two variables, which won’t work. ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-05/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-05/src/main.rs:here}} ``` -Listing 18-5: Incorrectly constructing a pattern whose +Listing 19-5: Incorrectly constructing a pattern whose variables don’t match the number of elements in the tuple Attempting to compile this code results in this type error: ```console -{{#include ../listings/ch18-patterns-and-matching/listing-18-05/output.txt}} +{{#include ../listings/ch19-patterns-and-matching/listing-19-05/output.txt}} ``` To fix the error, we could ignore one or more of the values in the tuple using @@ -210,28 +210,28 @@ of elements in the tuple. ### Function Parameters -Function parameters can also be patterns. The code in Listing 18-6, which +Function parameters can also be patterns. The code in Listing 19-6, which declares a function named `foo` that takes one parameter named `x` of type `i32`, should by now look familiar. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-06/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-06/src/main.rs:here}} ``` -Listing 18-6: A function signature uses patterns in the +Listing 19-6: A function signature uses patterns in the parameters The `x` part is a pattern! As we did with `let`, we could match a tuple in a -function’s arguments to the pattern. Listing 18-7 splits the values in a tuple +function’s arguments to the pattern. Listing 19-7 splits the values in a tuple as we pass it to a function. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-07/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-07/src/main.rs}} ``` -Listing 18-7: A function with parameters that destructure +Listing 19-7: A function with parameters that destructure a tuple This code prints `Current location: (3, 5)`. The values `&(3, 5)` match the diff --git a/src/ch19-02-refutability.md b/src/ch19-02-refutability.md index c8ca8b5766..a648d46a17 100644 --- a/src/ch19-02-refutability.md +++ b/src/ch19-02-refutability.md @@ -23,15 +23,15 @@ those cases, you’ll need to change either the pattern or the construct you’r using the pattern with, depending on the intended behavior of the code. Let’s look at an example of what happens when we try to use a refutable pattern -where Rust requires an irrefutable pattern and vice versa. Listing 18-8 shows a +where Rust requires an irrefutable pattern and vice versa. Listing 19-8 shows a `let` statement, but for the pattern we’ve specified `Some(x)`, a refutable pattern. As you might expect, this code will not compile. ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-08/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-08/src/main.rs:here}} ``` -Listing 18-8: Attempting to use a refutable pattern with +Listing 19-8: Attempting to use a refutable pattern with `let` If `some_option_value` was a `None` value, it would fail to match the pattern @@ -41,7 +41,7 @@ do with a `None` value. At compile time, Rust will complain that we’ve tried t use a refutable pattern where an irrefutable pattern is required: ```console -{{#include ../listings/ch18-patterns-and-matching/listing-18-08/output.txt}} +{{#include ../listings/ch19-patterns-and-matching/listing-19-08/output.txt}} ``` Because we didn’t cover (and couldn’t cover!) every valid value with the @@ -51,32 +51,32 @@ If we have a refutable pattern where an irrefutable pattern is needed, we can fix it by changing the code that uses the pattern: instead of using `let`, we can use `if let`. Then if the pattern doesn’t match, the code will just skip the code in the curly brackets, giving it a way to continue validly. Listing -18-9 shows how to fix the code in Listing 18-8. +19-9 shows how to fix the code in Listing 19-8. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-09/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-09/src/main.rs:here}} ``` -Listing 18-9: Using `if let` and a block with refutable +Listing 19-9: Using `if let` and a block with refutable patterns instead of `let` We’ve given the code an out! This code is perfectly valid now. However, if we give `if let` an irrefutable pattern (a pattern that will always -match), such as `x`, as shown in Listing 18-10, the compiler will give a +match), such as `x`, as shown in Listing 19-10, the compiler will give a warning. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-10/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-10/src/main.rs:here}} ``` -Listing 18-10: Attempting to use an irrefutable pattern +Listing 19-10: Attempting to use an irrefutable pattern with `if let` Rust complains that it doesn’t make sense to use `if let` with an irrefutable pattern: ```console -{{#include ../listings/ch18-patterns-and-matching/listing-18-10/output.txt}} +{{#include ../listings/ch19-patterns-and-matching/listing-19-10/output.txt}} ``` For this reason, match arms must use refutable patterns, except for the last diff --git a/src/ch19-03-pattern-syntax.md b/src/ch19-03-pattern-syntax.md index aeaa766ff3..afdcc4246d 100644 --- a/src/ch19-03-pattern-syntax.md +++ b/src/ch19-03-pattern-syntax.md @@ -9,7 +9,7 @@ As you saw in Chapter 6, you can match patterns against literals directly. The following code gives some examples: ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/no-listing-01-literals/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/no-listing-01-literals/src/main.rs:here}} ``` This code prints `one` because the value in `x` is 1. This syntax is useful @@ -23,7 +23,7 @@ them many times in the book. However, there is a complication when you use named variables in `match` expressions. Because `match` starts a new scope, variables declared as part of a pattern inside the `match` expression will shadow those with the same name outside the `match` construct, as is the case -with all variables. In Listing 18-11, we declare a variable named `x` with the +with all variables. In Listing 19-11, we declare a variable named `x` with the value `Some(5)` and a variable `y` with the value `10`. We then create a `match` expression on the value `x`. Look at the patterns in the match arms and `println!` at the end, and try to figure out what the code will print before @@ -32,10 +32,10 @@ running this code or reading further. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-11/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-11/src/main.rs:here}} ``` -Listing 18-11: A `match` expression with an arm that +Listing 19-11: A `match` expression with an arm that introduces a shadowed variable `y` Let’s walk through what happens when the `match` expression runs. The pattern @@ -75,7 +75,7 @@ meaning if the value of `x` matches either of the values in that arm, that arm’s code will run: ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/no-listing-02-multiple-patterns/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/no-listing-02-multiple-patterns/src/main.rs:here}} ``` This code prints `one or two`. @@ -87,7 +87,7 @@ following code, when a pattern matches any of the values within the given range, that arm will execute: ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/no-listing-03-ranges/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/no-listing-03-ranges/src/main.rs:here}} ``` If `x` is 1, 2, 3, 4, or 5, the first arm will match. This syntax is more @@ -103,7 +103,7 @@ numeric values, ranges are only allowed with numeric or `char` values. Here is an example using ranges of `char` values: ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/no-listing-04-ranges-of-char/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/no-listing-04-ranges-of-char/src/main.rs:here}} ``` Rust can tell that `'c'` is within the first pattern’s range and prints `early @@ -116,16 +116,16 @@ different parts of these values. Let’s walk through each value. #### Destructuring Structs -Listing 18-12 shows a `Point` struct with two fields, `x` and `y`, that we can +Listing 19-12 shows a `Point` struct with two fields, `x` and `y`, that we can break apart using a pattern with a `let` statement. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-12/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-12/src/main.rs}} ``` -Listing 18-12: Destructuring a struct’s fields into +Listing 19-12: Destructuring a struct’s fields into separate variables This code creates the variables `a` and `b` that match the values of the `x` @@ -136,17 +136,17 @@ easier to remember which variables came from which fields. Because of this common usage, and because writing `let Point { x: x, y: y } = p;` contains a lot of duplication, Rust has a shorthand for patterns that match struct fields: you only need to list the name of the struct field, and the variables created -from the pattern will have the same names. Listing 18-13 behaves in the same -way as the code in Listing 18-12, but the variables created in the `let` +from the pattern will have the same names. Listing 19-13 behaves in the same +way as the code in Listing 19-12, but the variables created in the `let` pattern are `x` and `y` instead of `a` and `b`. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-13/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-13/src/main.rs}} ``` -Listing 18-13: Destructuring struct fields using struct +Listing 19-13: Destructuring struct fields using struct field shorthand This code creates the variables `x` and `y` that match the `x` and `y` fields @@ -158,17 +158,17 @@ rather than creating variables for all the fields. Doing so allows us to test some of the fields for particular values while creating variables to destructure the other fields. -In Listing 18-14, we have a `match` expression that separates `Point` values +In Listing 19-14, we have a `match` expression that separates `Point` values into three cases: points that lie directly on the `x` axis (which is true when `y = 0`), on the `y` axis (`x = 0`), or neither. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-14/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-14/src/main.rs:here}} ``` -Listing 18-14: Destructuring and matching literal values +Listing 19-14: Destructuring and matching literal values in one pattern The first arm will match any point that lies on the `x` axis by specifying that @@ -192,16 +192,16 @@ and the `y` axis, this code would only print `On the x axis at 0`. We've destructured enums in this book (for example, Listing 6-5 in Chapter 6), but haven’t yet explicitly discussed that the pattern to destructure an enum corresponds to the way the data stored within the enum is defined. As an -example, in Listing 18-15 we use the `Message` enum from Listing 6-2 and write +example, in Listing 19-15 we use the `Message` enum from Listing 6-2 and write a `match` with patterns that will destructure each inner value. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-15/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-15/src/main.rs}} ``` -Listing 18-15: Destructuring enum variants that hold +Listing 19-15: Destructuring enum variants that hold different kinds of values This code will print `Change the color to red 0, green 160, and blue 255`. Try @@ -215,7 +215,7 @@ For struct-like enum variants, such as `Message::Move`, we can use a pattern similar to the pattern we specify to match structs. After the variant name, we place curly brackets and then list the fields with variables so we break apart the pieces to use in the code for this arm. Here we use the shorthand form as -we did in Listing 18-13. +we did in Listing 19-13. For tuple-like enum variants, like `Message::Write` that holds a tuple with one element and `Message::ChangeColor` that holds a tuple with three elements, the @@ -227,14 +227,14 @@ matching. So far, our examples have all been matching structs or enums one level deep, but matching can work on nested items too! For example, we can refactor the -code in Listing 18-15 to support RGB and HSV colors in the `ChangeColor` -message, as shown in Listing 18-16. +code in Listing 19-15 to support RGB and HSV colors in the `ChangeColor` +message, as shown in Listing 19-16. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-16/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-16/src/main.rs}} ``` -Listing 18-16: Matching on nested enums +Listing 19-16: Matching on nested enums The pattern of the first arm in the `match` expression matches a `Message::ChangeColor` enum variant that contains a `Color::Rgb` variant; then @@ -250,7 +250,7 @@ The following example shows a complicated destructure where we nest structs and tuples inside a tuple and destructure all the primitive values out: ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/no-listing-05-destructuring-structs-and-tuples/src/main.rs:here}} ``` This code lets us break complex types into their component parts so we can use @@ -274,15 +274,15 @@ parts of a value. Let’s explore how and why to use each of these patterns. We’ve used the underscore as a wildcard pattern that will match any value but not bind to the value. This is especially useful as the last arm in a `match` expression, but we can also use it in any pattern, including function -parameters, as shown in Listing 18-17. +parameters, as shown in Listing 19-17. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-17/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-17/src/main.rs}} ``` -Listing 18-17: Using `_` in a function signature +Listing 19-17: Using `_` in a function signature This code will completely ignore the value `3` passed as the first argument, and will print `This code only uses the y parameter: 4`. @@ -299,16 +299,16 @@ would if you used a name instead. We can also use `_` inside another pattern to ignore just part of a value, for example, when we want to test for only part of a value but have no use for the -other parts in the corresponding code we want to run. Listing 18-18 shows code +other parts in the corresponding code we want to run. Listing 19-18 shows code responsible for managing a setting’s value. The business requirements are that the user should not be allowed to overwrite an existing customization of a setting but can unset the setting and give it a value if it is currently unset. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-18/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-18/src/main.rs:here}} ``` -Listing 18-18: Using an underscore within patterns that +Listing 19-18: Using an underscore within patterns that match `Some` variants when we don’t need to use the value inside the `Some` @@ -324,14 +324,14 @@ In all other cases (if either `setting_value` or `new_setting_value` are `new_setting_value` to become `setting_value`. We can also use underscores in multiple places within one pattern to ignore -particular values. Listing 18-19 shows an example of ignoring the second and +particular values. Listing 19-19 shows an example of ignoring the second and fourth values in a tuple of five items. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-19/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-19/src/main.rs:here}} ``` -Listing 18-19: Ignoring multiple parts of a tuple +Listing 19-19: Ignoring multiple parts of a tuple This code will print `Some numbers: 2, 8, 32`, and the values 4 and 16 will be ignored. @@ -343,16 +343,16 @@ warning because an unused variable could be a bug. However, sometimes it’s useful to be able to create a variable you won’t use yet, such as when you’re prototyping or just starting a project. In this situation, you can tell Rust not to warn you about the unused variable by starting the name of the variable -with an underscore. In Listing 18-20, we create two unused variables, but when +with an underscore. In Listing 19-20, we create two unused variables, but when we compile this code, we should only get a warning about one of them. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-20/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-20/src/main.rs}} ``` -Listing 18-20: Starting a variable name with an +Listing 19-20: Starting a variable name with an underscore to avoid getting unused variable warnings Here we get a warning about not using the variable `y`, but we don’t get a @@ -361,25 +361,25 @@ warning about not using `_x`. Note that there is a subtle difference between using only `_` and using a name that starts with an underscore. The syntax `_x` still binds the value to the variable, whereas `_` doesn’t bind at all. To show a case where this -distinction matters, Listing 18-21 will provide us with an error. +distinction matters, Listing 19-21 will provide us with an error. ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-21/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-21/src/main.rs:here}} ``` -Listing 18-21: An unused variable starting with an +Listing 19-21: An unused variable starting with an underscore still binds the value, which might take ownership of the value We’ll receive an error because the `s` value will still be moved into `_s`, which prevents us from using `s` again. However, using the underscore by itself -doesn’t ever bind to the value. Listing 18-22 will compile without any errors +doesn’t ever bind to the value. Listing 19-22 will compile without any errors because `s` doesn’t get moved into `_`. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-22/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-22/src/main.rs:here}} ``` -Listing 18-22: Using an underscore does not bind the +Listing 19-22: Using an underscore does not bind the value This code works just fine because we never bind `s` to anything; it isn’t moved. @@ -389,16 +389,16 @@ This code works just fine because we never bind `s` to anything; it isn’t move With values that have many parts, we can use the `..` syntax to use specific parts and ignore the rest, avoiding the need to list underscores for each ignored value. The `..` pattern ignores any parts of a value that we haven’t -explicitly matched in the rest of the pattern. In Listing 18-23, we have a +explicitly matched in the rest of the pattern. In Listing 19-23, we have a `Point` struct that holds a coordinate in three-dimensional space. In the `match` expression, we want to operate only on the `x` coordinate and ignore the values in the `y` and `z` fields. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-23/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-23/src/main.rs:here}} ``` -Listing 18-23: Ignoring all fields of a `Point` except +Listing 19-23: Ignoring all fields of a `Point` except for `x` by using `..` We list the `x` value and then just include the `..` pattern. This is quicker @@ -406,16 +406,16 @@ than having to list `y: _` and `z: _`, particularly when we’re working with structs that have lots of fields in situations where only one or two fields are relevant. -The syntax `..` will expand to as many values as it needs to be. Listing 18-24 +The syntax `..` will expand to as many values as it needs to be. Listing 19-24 shows how to use `..` with a tuple. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-24/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-24/src/main.rs}} ``` -Listing 18-24: Matching only the first and last values in +Listing 19-24: Matching only the first and last values in a tuple and ignoring all other values In this code, the first and last value are matched with `first` and `last`. The @@ -423,22 +423,22 @@ In this code, the first and last value are matched with `first` and `last`. The However, using `..` must be unambiguous. If it is unclear which values are intended for matching and which should be ignored, Rust will give us an error. -Listing 18-25 shows an example of using `..` ambiguously, so it will not +Listing 19-25 shows an example of using `..` ambiguously, so it will not compile. Filename: src/main.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-25/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-25/src/main.rs}} ``` -Listing 18-25: An attempt to use `..` in an ambiguous +Listing 19-25: An attempt to use `..` in an ambiguous way When we compile this example, we get this error: ```console -{{#include ../listings/ch18-patterns-and-matching/listing-18-25/output.txt}} +{{#include ../listings/ch19-patterns-and-matching/listing-19-25/output.txt}} ``` It’s impossible for Rust to determine how many values in the tuple to ignore @@ -455,15 +455,15 @@ A *match guard* is an additional `if` condition, specified after the pattern in a `match` arm, that must also match for that arm to be chosen. Match guards are useful for expressing more complex ideas than a pattern alone allows. -The condition can use variables created in the pattern. Listing 18-26 shows a +The condition can use variables created in the pattern. Listing 19-26 shows a `match` where the first arm has the pattern `Some(x)` and also has a match guard of `if x % 2 == 0` (which will be true if the number is even). ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-26/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-26/src/main.rs:here}} ``` -Listing 18-26: Adding a match guard to a pattern +Listing 19-26: Adding a match guard to a pattern This example will print `The number 4 is even`. When `num` is compared to the pattern in the first arm, it matches, because `Some(4)` matches `Some(x)`. Then @@ -480,20 +480,20 @@ the match guard gives us the ability to express this logic. The downside of this additional expressiveness is that the compiler doesn't try to check for exhaustiveness when match guard expressions are involved. -In Listing 18-11, we mentioned that we could use match guards to solve our +In Listing 19-11, we mentioned that we could use match guards to solve our pattern-shadowing problem. Recall that we created a new variable inside the pattern in the `match` expression instead of using the variable outside the `match`. That new variable meant we couldn’t test against the value of the -outer variable. Listing 18-27 shows how we can use a match guard to fix this +outer variable. Listing 19-27 shows how we can use a match guard to fix this problem. Filename: src/main.rs ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-27/src/main.rs}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-27/src/main.rs}} ``` -Listing 18-27: Using a match guard to test for equality +Listing 19-27: Using a match guard to test for equality with an outer variable This code will now print `Default case, x = Some(5)`. The pattern in the second @@ -510,16 +510,16 @@ we can look for a value that has the same value as the outer `y` by comparing You can also use the *or* operator `|` in a match guard to specify multiple patterns; the match guard condition will apply to all the patterns. Listing -18-28 shows the precedence when combining a pattern that uses `|` with a match +19-28 shows the precedence when combining a pattern that uses `|` with a match guard. The important part of this example is that the `if y` match guard applies to `4`, `5`, *and* `6`, even though it might look like `if y` only applies to `6`. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-28/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-28/src/main.rs:here}} ``` -Listing 18-28: Combining multiple patterns with a match +Listing 19-28: Combining multiple patterns with a match guard The match condition states that the arm only matches if the value of `x` is @@ -549,17 +549,17 @@ were applied only to the final value in the list of values specified using the ### `@` Bindings The *at* operator `@` lets us create a variable that holds a value at the same -time as we’re testing that value for a pattern match. In Listing 18-29, we want +time as we’re testing that value for a pattern match. In Listing 19-29, we want to test that a `Message::Hello` `id` field is within the range `3..=7`. We also want to bind the value to the variable `id_variable` so we can use it in the code associated with the arm. We could name this variable `id`, the same as the field, but for this example we’ll use a different name. ```rust -{{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-29/src/main.rs:here}} +{{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-29/src/main.rs:here}} ``` -Listing 18-29: Using `@` to bind to a value in a pattern +Listing 19-29: Using `@` to bind to a value in a pattern while also testing it This example will print `Found an id in range: 5`. By specifying `id_variable From c8f446419adcbfa78cdac2f54c75cf62fc054438 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 26 Sep 2024 14:10:09 -0600 Subject: [PATCH 622/720] Ch. 17: Listings for old Ch. 17 -> Ch. 18 --- .../listing-18-01}/Cargo.lock | 0 .../listing-18-01}/Cargo.toml | 0 .../listing-18-01}/src/lib.rs | 0 .../listing-18-02}/Cargo.lock | 0 .../listing-18-02}/Cargo.toml | 0 .../listing-18-02}/src/lib.rs | 0 .../listing-18-03}/Cargo.lock | 0 .../listing-18-03}/Cargo.toml | 0 .../listing-18-03}/src/lib.rs | 0 .../listing-18-04}/Cargo.lock | 0 .../listing-18-04}/Cargo.toml | 0 .../listing-18-04}/src/lib.rs | 0 .../listing-18-05}/Cargo.lock | 0 .../listing-18-05}/Cargo.toml | 0 .../listing-18-05}/src/lib.rs | 0 .../listing-18-06}/Cargo.lock | 0 .../listing-18-06}/Cargo.toml | 0 .../listing-18-06}/src/lib.rs | 0 .../listing-18-07}/Cargo.lock | 0 .../listing-18-07}/Cargo.toml | 0 .../listing-18-07}/src/lib.rs | 0 .../listing-18-08}/Cargo.lock | 0 .../listing-18-08}/Cargo.toml | 0 .../listing-18-08}/src/lib.rs | 0 .../listing-18-08}/src/main.rs | 0 .../listing-18-09}/Cargo.lock | 0 .../listing-18-09}/Cargo.toml | 0 .../listing-18-09}/src/lib.rs | 0 .../listing-18-09}/src/main.rs | 0 .../listing-18-10}/Cargo.lock | 0 .../listing-18-10}/Cargo.toml | 0 .../listing-18-10}/output.txt | 0 .../listing-18-10}/src/lib.rs | 0 .../listing-18-10}/src/main.rs | 0 .../listing-18-11}/Cargo.lock | 0 .../listing-18-11}/Cargo.toml | 0 .../listing-18-11}/src/main.rs | 0 .../listing-18-12}/Cargo.lock | 0 .../listing-18-12}/Cargo.toml | 0 .../listing-18-12}/src/lib.rs | 0 .../listing-18-12}/src/main.rs | 0 .../listing-18-13}/Cargo.lock | 0 .../listing-18-13}/Cargo.toml | 0 .../listing-18-13}/src/lib.rs | 0 .../listing-18-13}/src/main.rs | 0 .../listing-18-14}/Cargo.lock | 0 .../listing-18-14}/Cargo.toml | 0 .../listing-18-14}/src/lib.rs | 0 .../listing-18-14}/src/main.rs | 0 .../listing-18-15}/Cargo.lock | 0 .../listing-18-15}/Cargo.toml | 0 .../listing-18-15}/src/lib.rs | 0 .../listing-18-15}/src/main.rs | 0 .../listing-18-16}/Cargo.lock | 0 .../listing-18-16}/Cargo.toml | 0 .../listing-18-16}/src/lib.rs | 0 .../listing-18-16}/src/main.rs | 0 .../listing-18-17}/Cargo.lock | 0 .../listing-18-17}/Cargo.toml | 0 .../listing-18-17}/src/lib.rs | 0 .../listing-18-17}/src/main.rs | 0 .../listing-18-18}/Cargo.lock | 0 .../listing-18-18}/Cargo.toml | 0 .../listing-18-18}/src/lib.rs | 0 .../listing-18-18}/src/main.rs | 0 .../listing-18-19}/Cargo.lock | 0 .../listing-18-19}/Cargo.toml | 0 .../listing-18-19}/src/lib.rs | 0 .../listing-18-20}/Cargo.lock | 0 .../listing-18-20}/Cargo.toml | 0 .../listing-18-20}/src/lib.rs | 0 .../listing-18-21}/Cargo.lock | 0 .../listing-18-21}/Cargo.toml | 0 .../listing-18-21}/src/lib.rs | 0 .../listing-18-21}/src/main.rs | 0 src/ch18-01-what-is-oo.md | 12 +-- src/ch18-02-trait-objects.md | 56 ++++++------- src/ch18-03-oo-design-patterns.md | 82 +++++++++---------- 78 files changed, 75 insertions(+), 75 deletions(-) rename listings/{ch17-oop/listing-17-01 => ch18-oop/listing-18-01}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-01 => ch18-oop/listing-18-01}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-01 => ch18-oop/listing-18-01}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-02 => ch18-oop/listing-18-02}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-02 => ch18-oop/listing-18-02}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-02 => ch18-oop/listing-18-02}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-03 => ch18-oop/listing-18-03}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-03 => ch18-oop/listing-18-03}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-03 => ch18-oop/listing-18-03}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-04 => ch18-oop/listing-18-04}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-04 => ch18-oop/listing-18-04}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-04 => ch18-oop/listing-18-04}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-05 => ch18-oop/listing-18-05}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-05 => ch18-oop/listing-18-05}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-05 => ch18-oop/listing-18-05}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-06 => ch18-oop/listing-18-06}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-06 => ch18-oop/listing-18-06}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-06 => ch18-oop/listing-18-06}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-07 => ch18-oop/listing-18-07}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-07 => ch18-oop/listing-18-07}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-07 => ch18-oop/listing-18-07}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-08 => ch18-oop/listing-18-08}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-08 => ch18-oop/listing-18-08}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-08 => ch18-oop/listing-18-08}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-08 => ch18-oop/listing-18-08}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-09 => ch18-oop/listing-18-09}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-09 => ch18-oop/listing-18-09}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-09 => ch18-oop/listing-18-09}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-09 => ch18-oop/listing-18-09}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-10 => ch18-oop/listing-18-10}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-10 => ch18-oop/listing-18-10}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-10 => ch18-oop/listing-18-10}/output.txt (100%) rename listings/{ch17-oop/listing-17-10 => ch18-oop/listing-18-10}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-10 => ch18-oop/listing-18-10}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-11 => ch18-oop/listing-18-11}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-11 => ch18-oop/listing-18-11}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-11 => ch18-oop/listing-18-11}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-12 => ch18-oop/listing-18-12}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-12 => ch18-oop/listing-18-12}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-12 => ch18-oop/listing-18-12}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-12 => ch18-oop/listing-18-12}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-13 => ch18-oop/listing-18-13}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-13 => ch18-oop/listing-18-13}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-13 => ch18-oop/listing-18-13}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-13 => ch18-oop/listing-18-13}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-14 => ch18-oop/listing-18-14}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-14 => ch18-oop/listing-18-14}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-14 => ch18-oop/listing-18-14}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-14 => ch18-oop/listing-18-14}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-15 => ch18-oop/listing-18-15}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-15 => ch18-oop/listing-18-15}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-15 => ch18-oop/listing-18-15}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-15 => ch18-oop/listing-18-15}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-16 => ch18-oop/listing-18-16}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-16 => ch18-oop/listing-18-16}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-16 => ch18-oop/listing-18-16}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-16 => ch18-oop/listing-18-16}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-17 => ch18-oop/listing-18-17}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-17 => ch18-oop/listing-18-17}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-17 => ch18-oop/listing-18-17}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-17 => ch18-oop/listing-18-17}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-18 => ch18-oop/listing-18-18}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-18 => ch18-oop/listing-18-18}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-18 => ch18-oop/listing-18-18}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-18 => ch18-oop/listing-18-18}/src/main.rs (100%) rename listings/{ch17-oop/listing-17-19 => ch18-oop/listing-18-19}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-19 => ch18-oop/listing-18-19}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-19 => ch18-oop/listing-18-19}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-20 => ch18-oop/listing-18-20}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-20 => ch18-oop/listing-18-20}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-20 => ch18-oop/listing-18-20}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-21 => ch18-oop/listing-18-21}/Cargo.lock (100%) rename listings/{ch17-oop/listing-17-21 => ch18-oop/listing-18-21}/Cargo.toml (100%) rename listings/{ch17-oop/listing-17-21 => ch18-oop/listing-18-21}/src/lib.rs (100%) rename listings/{ch17-oop/listing-17-21 => ch18-oop/listing-18-21}/src/main.rs (100%) diff --git a/listings/ch17-oop/listing-17-01/Cargo.lock b/listings/ch18-oop/listing-18-01/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-01/Cargo.lock rename to listings/ch18-oop/listing-18-01/Cargo.lock diff --git a/listings/ch17-oop/listing-17-01/Cargo.toml b/listings/ch18-oop/listing-18-01/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-01/Cargo.toml rename to listings/ch18-oop/listing-18-01/Cargo.toml diff --git a/listings/ch17-oop/listing-17-01/src/lib.rs b/listings/ch18-oop/listing-18-01/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-01/src/lib.rs rename to listings/ch18-oop/listing-18-01/src/lib.rs diff --git a/listings/ch17-oop/listing-17-02/Cargo.lock b/listings/ch18-oop/listing-18-02/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-02/Cargo.lock rename to listings/ch18-oop/listing-18-02/Cargo.lock diff --git a/listings/ch17-oop/listing-17-02/Cargo.toml b/listings/ch18-oop/listing-18-02/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-02/Cargo.toml rename to listings/ch18-oop/listing-18-02/Cargo.toml diff --git a/listings/ch17-oop/listing-17-02/src/lib.rs b/listings/ch18-oop/listing-18-02/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-02/src/lib.rs rename to listings/ch18-oop/listing-18-02/src/lib.rs diff --git a/listings/ch17-oop/listing-17-03/Cargo.lock b/listings/ch18-oop/listing-18-03/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-03/Cargo.lock rename to listings/ch18-oop/listing-18-03/Cargo.lock diff --git a/listings/ch17-oop/listing-17-03/Cargo.toml b/listings/ch18-oop/listing-18-03/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-03/Cargo.toml rename to listings/ch18-oop/listing-18-03/Cargo.toml diff --git a/listings/ch17-oop/listing-17-03/src/lib.rs b/listings/ch18-oop/listing-18-03/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-03/src/lib.rs rename to listings/ch18-oop/listing-18-03/src/lib.rs diff --git a/listings/ch17-oop/listing-17-04/Cargo.lock b/listings/ch18-oop/listing-18-04/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-04/Cargo.lock rename to listings/ch18-oop/listing-18-04/Cargo.lock diff --git a/listings/ch17-oop/listing-17-04/Cargo.toml b/listings/ch18-oop/listing-18-04/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-04/Cargo.toml rename to listings/ch18-oop/listing-18-04/Cargo.toml diff --git a/listings/ch17-oop/listing-17-04/src/lib.rs b/listings/ch18-oop/listing-18-04/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-04/src/lib.rs rename to listings/ch18-oop/listing-18-04/src/lib.rs diff --git a/listings/ch17-oop/listing-17-05/Cargo.lock b/listings/ch18-oop/listing-18-05/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-05/Cargo.lock rename to listings/ch18-oop/listing-18-05/Cargo.lock diff --git a/listings/ch17-oop/listing-17-05/Cargo.toml b/listings/ch18-oop/listing-18-05/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-05/Cargo.toml rename to listings/ch18-oop/listing-18-05/Cargo.toml diff --git a/listings/ch17-oop/listing-17-05/src/lib.rs b/listings/ch18-oop/listing-18-05/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-05/src/lib.rs rename to listings/ch18-oop/listing-18-05/src/lib.rs diff --git a/listings/ch17-oop/listing-17-06/Cargo.lock b/listings/ch18-oop/listing-18-06/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-06/Cargo.lock rename to listings/ch18-oop/listing-18-06/Cargo.lock diff --git a/listings/ch17-oop/listing-17-06/Cargo.toml b/listings/ch18-oop/listing-18-06/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-06/Cargo.toml rename to listings/ch18-oop/listing-18-06/Cargo.toml diff --git a/listings/ch17-oop/listing-17-06/src/lib.rs b/listings/ch18-oop/listing-18-06/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-06/src/lib.rs rename to listings/ch18-oop/listing-18-06/src/lib.rs diff --git a/listings/ch17-oop/listing-17-07/Cargo.lock b/listings/ch18-oop/listing-18-07/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-07/Cargo.lock rename to listings/ch18-oop/listing-18-07/Cargo.lock diff --git a/listings/ch17-oop/listing-17-07/Cargo.toml b/listings/ch18-oop/listing-18-07/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-07/Cargo.toml rename to listings/ch18-oop/listing-18-07/Cargo.toml diff --git a/listings/ch17-oop/listing-17-07/src/lib.rs b/listings/ch18-oop/listing-18-07/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-07/src/lib.rs rename to listings/ch18-oop/listing-18-07/src/lib.rs diff --git a/listings/ch17-oop/listing-17-08/Cargo.lock b/listings/ch18-oop/listing-18-08/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-08/Cargo.lock rename to listings/ch18-oop/listing-18-08/Cargo.lock diff --git a/listings/ch17-oop/listing-17-08/Cargo.toml b/listings/ch18-oop/listing-18-08/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-08/Cargo.toml rename to listings/ch18-oop/listing-18-08/Cargo.toml diff --git a/listings/ch17-oop/listing-17-08/src/lib.rs b/listings/ch18-oop/listing-18-08/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-08/src/lib.rs rename to listings/ch18-oop/listing-18-08/src/lib.rs diff --git a/listings/ch17-oop/listing-17-08/src/main.rs b/listings/ch18-oop/listing-18-08/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-08/src/main.rs rename to listings/ch18-oop/listing-18-08/src/main.rs diff --git a/listings/ch17-oop/listing-17-09/Cargo.lock b/listings/ch18-oop/listing-18-09/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-09/Cargo.lock rename to listings/ch18-oop/listing-18-09/Cargo.lock diff --git a/listings/ch17-oop/listing-17-09/Cargo.toml b/listings/ch18-oop/listing-18-09/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-09/Cargo.toml rename to listings/ch18-oop/listing-18-09/Cargo.toml diff --git a/listings/ch17-oop/listing-17-09/src/lib.rs b/listings/ch18-oop/listing-18-09/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-09/src/lib.rs rename to listings/ch18-oop/listing-18-09/src/lib.rs diff --git a/listings/ch17-oop/listing-17-09/src/main.rs b/listings/ch18-oop/listing-18-09/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-09/src/main.rs rename to listings/ch18-oop/listing-18-09/src/main.rs diff --git a/listings/ch17-oop/listing-17-10/Cargo.lock b/listings/ch18-oop/listing-18-10/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-10/Cargo.lock rename to listings/ch18-oop/listing-18-10/Cargo.lock diff --git a/listings/ch17-oop/listing-17-10/Cargo.toml b/listings/ch18-oop/listing-18-10/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-10/Cargo.toml rename to listings/ch18-oop/listing-18-10/Cargo.toml diff --git a/listings/ch17-oop/listing-17-10/output.txt b/listings/ch18-oop/listing-18-10/output.txt similarity index 100% rename from listings/ch17-oop/listing-17-10/output.txt rename to listings/ch18-oop/listing-18-10/output.txt diff --git a/listings/ch17-oop/listing-17-10/src/lib.rs b/listings/ch18-oop/listing-18-10/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-10/src/lib.rs rename to listings/ch18-oop/listing-18-10/src/lib.rs diff --git a/listings/ch17-oop/listing-17-10/src/main.rs b/listings/ch18-oop/listing-18-10/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-10/src/main.rs rename to listings/ch18-oop/listing-18-10/src/main.rs diff --git a/listings/ch17-oop/listing-17-11/Cargo.lock b/listings/ch18-oop/listing-18-11/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-11/Cargo.lock rename to listings/ch18-oop/listing-18-11/Cargo.lock diff --git a/listings/ch17-oop/listing-17-11/Cargo.toml b/listings/ch18-oop/listing-18-11/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-11/Cargo.toml rename to listings/ch18-oop/listing-18-11/Cargo.toml diff --git a/listings/ch17-oop/listing-17-11/src/main.rs b/listings/ch18-oop/listing-18-11/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-11/src/main.rs rename to listings/ch18-oop/listing-18-11/src/main.rs diff --git a/listings/ch17-oop/listing-17-12/Cargo.lock b/listings/ch18-oop/listing-18-12/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-12/Cargo.lock rename to listings/ch18-oop/listing-18-12/Cargo.lock diff --git a/listings/ch17-oop/listing-17-12/Cargo.toml b/listings/ch18-oop/listing-18-12/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-12/Cargo.toml rename to listings/ch18-oop/listing-18-12/Cargo.toml diff --git a/listings/ch17-oop/listing-17-12/src/lib.rs b/listings/ch18-oop/listing-18-12/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-12/src/lib.rs rename to listings/ch18-oop/listing-18-12/src/lib.rs diff --git a/listings/ch17-oop/listing-17-12/src/main.rs b/listings/ch18-oop/listing-18-12/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-12/src/main.rs rename to listings/ch18-oop/listing-18-12/src/main.rs diff --git a/listings/ch17-oop/listing-17-13/Cargo.lock b/listings/ch18-oop/listing-18-13/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-13/Cargo.lock rename to listings/ch18-oop/listing-18-13/Cargo.lock diff --git a/listings/ch17-oop/listing-17-13/Cargo.toml b/listings/ch18-oop/listing-18-13/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-13/Cargo.toml rename to listings/ch18-oop/listing-18-13/Cargo.toml diff --git a/listings/ch17-oop/listing-17-13/src/lib.rs b/listings/ch18-oop/listing-18-13/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-13/src/lib.rs rename to listings/ch18-oop/listing-18-13/src/lib.rs diff --git a/listings/ch17-oop/listing-17-13/src/main.rs b/listings/ch18-oop/listing-18-13/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-13/src/main.rs rename to listings/ch18-oop/listing-18-13/src/main.rs diff --git a/listings/ch17-oop/listing-17-14/Cargo.lock b/listings/ch18-oop/listing-18-14/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-14/Cargo.lock rename to listings/ch18-oop/listing-18-14/Cargo.lock diff --git a/listings/ch17-oop/listing-17-14/Cargo.toml b/listings/ch18-oop/listing-18-14/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-14/Cargo.toml rename to listings/ch18-oop/listing-18-14/Cargo.toml diff --git a/listings/ch17-oop/listing-17-14/src/lib.rs b/listings/ch18-oop/listing-18-14/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-14/src/lib.rs rename to listings/ch18-oop/listing-18-14/src/lib.rs diff --git a/listings/ch17-oop/listing-17-14/src/main.rs b/listings/ch18-oop/listing-18-14/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-14/src/main.rs rename to listings/ch18-oop/listing-18-14/src/main.rs diff --git a/listings/ch17-oop/listing-17-15/Cargo.lock b/listings/ch18-oop/listing-18-15/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-15/Cargo.lock rename to listings/ch18-oop/listing-18-15/Cargo.lock diff --git a/listings/ch17-oop/listing-17-15/Cargo.toml b/listings/ch18-oop/listing-18-15/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-15/Cargo.toml rename to listings/ch18-oop/listing-18-15/Cargo.toml diff --git a/listings/ch17-oop/listing-17-15/src/lib.rs b/listings/ch18-oop/listing-18-15/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-15/src/lib.rs rename to listings/ch18-oop/listing-18-15/src/lib.rs diff --git a/listings/ch17-oop/listing-17-15/src/main.rs b/listings/ch18-oop/listing-18-15/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-15/src/main.rs rename to listings/ch18-oop/listing-18-15/src/main.rs diff --git a/listings/ch17-oop/listing-17-16/Cargo.lock b/listings/ch18-oop/listing-18-16/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-16/Cargo.lock rename to listings/ch18-oop/listing-18-16/Cargo.lock diff --git a/listings/ch17-oop/listing-17-16/Cargo.toml b/listings/ch18-oop/listing-18-16/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-16/Cargo.toml rename to listings/ch18-oop/listing-18-16/Cargo.toml diff --git a/listings/ch17-oop/listing-17-16/src/lib.rs b/listings/ch18-oop/listing-18-16/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-16/src/lib.rs rename to listings/ch18-oop/listing-18-16/src/lib.rs diff --git a/listings/ch17-oop/listing-17-16/src/main.rs b/listings/ch18-oop/listing-18-16/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-16/src/main.rs rename to listings/ch18-oop/listing-18-16/src/main.rs diff --git a/listings/ch17-oop/listing-17-17/Cargo.lock b/listings/ch18-oop/listing-18-17/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-17/Cargo.lock rename to listings/ch18-oop/listing-18-17/Cargo.lock diff --git a/listings/ch17-oop/listing-17-17/Cargo.toml b/listings/ch18-oop/listing-18-17/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-17/Cargo.toml rename to listings/ch18-oop/listing-18-17/Cargo.toml diff --git a/listings/ch17-oop/listing-17-17/src/lib.rs b/listings/ch18-oop/listing-18-17/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-17/src/lib.rs rename to listings/ch18-oop/listing-18-17/src/lib.rs diff --git a/listings/ch17-oop/listing-17-17/src/main.rs b/listings/ch18-oop/listing-18-17/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-17/src/main.rs rename to listings/ch18-oop/listing-18-17/src/main.rs diff --git a/listings/ch17-oop/listing-17-18/Cargo.lock b/listings/ch18-oop/listing-18-18/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-18/Cargo.lock rename to listings/ch18-oop/listing-18-18/Cargo.lock diff --git a/listings/ch17-oop/listing-17-18/Cargo.toml b/listings/ch18-oop/listing-18-18/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-18/Cargo.toml rename to listings/ch18-oop/listing-18-18/Cargo.toml diff --git a/listings/ch17-oop/listing-17-18/src/lib.rs b/listings/ch18-oop/listing-18-18/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-18/src/lib.rs rename to listings/ch18-oop/listing-18-18/src/lib.rs diff --git a/listings/ch17-oop/listing-17-18/src/main.rs b/listings/ch18-oop/listing-18-18/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-18/src/main.rs rename to listings/ch18-oop/listing-18-18/src/main.rs diff --git a/listings/ch17-oop/listing-17-19/Cargo.lock b/listings/ch18-oop/listing-18-19/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-19/Cargo.lock rename to listings/ch18-oop/listing-18-19/Cargo.lock diff --git a/listings/ch17-oop/listing-17-19/Cargo.toml b/listings/ch18-oop/listing-18-19/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-19/Cargo.toml rename to listings/ch18-oop/listing-18-19/Cargo.toml diff --git a/listings/ch17-oop/listing-17-19/src/lib.rs b/listings/ch18-oop/listing-18-19/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-19/src/lib.rs rename to listings/ch18-oop/listing-18-19/src/lib.rs diff --git a/listings/ch17-oop/listing-17-20/Cargo.lock b/listings/ch18-oop/listing-18-20/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-20/Cargo.lock rename to listings/ch18-oop/listing-18-20/Cargo.lock diff --git a/listings/ch17-oop/listing-17-20/Cargo.toml b/listings/ch18-oop/listing-18-20/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-20/Cargo.toml rename to listings/ch18-oop/listing-18-20/Cargo.toml diff --git a/listings/ch17-oop/listing-17-20/src/lib.rs b/listings/ch18-oop/listing-18-20/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-20/src/lib.rs rename to listings/ch18-oop/listing-18-20/src/lib.rs diff --git a/listings/ch17-oop/listing-17-21/Cargo.lock b/listings/ch18-oop/listing-18-21/Cargo.lock similarity index 100% rename from listings/ch17-oop/listing-17-21/Cargo.lock rename to listings/ch18-oop/listing-18-21/Cargo.lock diff --git a/listings/ch17-oop/listing-17-21/Cargo.toml b/listings/ch18-oop/listing-18-21/Cargo.toml similarity index 100% rename from listings/ch17-oop/listing-17-21/Cargo.toml rename to listings/ch18-oop/listing-18-21/Cargo.toml diff --git a/listings/ch17-oop/listing-17-21/src/lib.rs b/listings/ch18-oop/listing-18-21/src/lib.rs similarity index 100% rename from listings/ch17-oop/listing-17-21/src/lib.rs rename to listings/ch18-oop/listing-18-21/src/lib.rs diff --git a/listings/ch17-oop/listing-17-21/src/main.rs b/listings/ch18-oop/listing-18-21/src/main.rs similarity index 100% rename from listings/ch17-oop/listing-17-21/src/main.rs rename to listings/ch18-oop/listing-18-21/src/main.rs diff --git a/src/ch18-01-what-is-oo.md b/src/ch18-01-what-is-oo.md index 4a11b7cc08..f9f22a3a00 100644 --- a/src/ch18-01-what-is-oo.md +++ b/src/ch18-01-what-is-oo.md @@ -41,16 +41,16 @@ can define a struct `AveragedCollection` that has a field containing a vector of `i32` values. The struct can also have a field that contains the average of the values in the vector, meaning the average doesn’t have to be computed on demand whenever anyone needs it. In other words, `AveragedCollection` will -cache the calculated average for us. Listing 17-1 has the definition of the +cache the calculated average for us. Listing 18-1 has the definition of the `AveragedCollection` struct: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-01/src/lib.rs}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-01/src/lib.rs}} ``` -Listing 17-1: An `AveragedCollection` struct that +Listing 18-1: An `AveragedCollection` struct that maintains a list of integers and the average of the items in the collection @@ -58,15 +58,15 @@ The struct is marked `pub` so that other code can use it, but the fields within the struct remain private. This is important in this case because we want to ensure that whenever a value is added or removed from the list, the average is also updated. We do this by implementing `add`, `remove`, and `average` methods -on the struct, as shown in Listing 17-2: +on the struct, as shown in Listing 18-2: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-02/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-02/src/lib.rs:here}} ``` -Listing 17-2: Implementations of the public methods +Listing 18-2: Implementations of the public methods `add`, `remove`, and `average` on `AveragedCollection` The public methods `add`, `remove`, and `average` are the only ways to access diff --git a/src/ch18-02-trait-objects.md b/src/ch18-02-trait-objects.md index c6a90ab2ff..d4f7ee7b51 100644 --- a/src/ch18-02-trait-objects.md +++ b/src/ch18-02-trait-objects.md @@ -63,19 +63,19 @@ a trait object. Trait objects aren’t as generally useful as objects in other languages: their specific purpose is to allow abstraction across common behavior. -Listing 17-3 shows how to define a trait named `Draw` with one method named +Listing 18-3 shows how to define a trait named `Draw` with one method named `draw`: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-03/src/lib.rs}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-03/src/lib.rs}} ``` -Listing 17-3: Definition of the `Draw` trait +Listing 18-3: Definition of the `Draw` trait This syntax should look familiar from our discussions on how to define traits -in Chapter 10. Next comes some new syntax: Listing 17-4 defines a struct named +in Chapter 10. Next comes some new syntax: Listing 18-4 defines a struct named `Screen` that holds a vector named `components`. This vector is of type `Box`, which is a trait object; it’s a stand-in for any type inside a `Box` that implements the `Draw` trait. @@ -83,23 +83,23 @@ a `Box` that implements the `Draw` trait. Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-04/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-04/src/lib.rs:here}} ``` -Listing 17-4: Definition of the `Screen` struct with a +Listing 18-4: Definition of the `Screen` struct with a `components` field holding a vector of trait objects that implement the `Draw` trait On the `Screen` struct, we’ll define a method named `run` that will call the -`draw` method on each of its `components`, as shown in Listing 17-5: +`draw` method on each of its `components`, as shown in Listing 18-5: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-05/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-05/src/lib.rs:here}} ``` -Listing 17-5: A `run` method on `Screen` that calls the +Listing 18-5: A `run` method on `Screen` that calls the `draw` method on each component This works differently from defining a struct that uses a generic type @@ -107,15 +107,15 @@ parameter with trait bounds. A generic type parameter can only be substituted with one concrete type at a time, whereas trait objects allow for multiple concrete types to fill in for the trait object at runtime. For example, we could have defined the `Screen` struct using a generic type and a trait bound -as in Listing 17-6: +as in Listing 18-6: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-06/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-06/src/lib.rs:here}} ``` -Listing 17-6: An alternate implementation of the `Screen` +Listing 18-6: An alternate implementation of the `Screen` struct and its `run` method using generics and trait bounds This restricts us to a `Screen` instance that has a list of components all of @@ -134,15 +134,15 @@ Now we’ll add some types that implement the `Draw` trait. We’ll provide the `Button` type. Again, actually implementing a GUI library is beyond the scope of this book, so the `draw` method won’t have any useful implementation in its body. To imagine what the implementation might look like, a `Button` struct -might have fields for `width`, `height`, and `label`, as shown in Listing 17-7: +might have fields for `width`, `height`, and `label`, as shown in Listing 18-7: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-07/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-07/src/lib.rs:here}} ``` -Listing 17-7: A `Button` struct that implements the +Listing 18-7: A `Button` struct that implements the `Draw` trait The `width`, `height`, and `label` fields on `Button` will differ from the @@ -157,30 +157,30 @@ types like `TextField`. If someone using our library decides to implement a `SelectBox` struct that has `width`, `height`, and `options` fields, they implement the `Draw` trait on the -`SelectBox` type as well, as shown in Listing 17-8: +`SelectBox` type as well, as shown in Listing 18-8: Filename: src/main.rs ```rust,ignore -{{#rustdoc_include ../listings/ch17-oop/listing-17-08/src/main.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-08/src/main.rs:here}} ``` -Listing 17-8: Another crate using `gui` and implementing +Listing 18-8: Another crate using `gui` and implementing the `Draw` trait on a `SelectBox` struct Our library’s user can now write their `main` function to create a `Screen` instance. To the `Screen` instance, they can add a `SelectBox` and a `Button` by putting each in a `Box` to become a trait object. They can then call the `run` method on the `Screen` instance, which will call `draw` on each of the -components. Listing 17-9 shows this implementation: +components. Listing 18-9 shows this implementation: Filename: src/main.rs ```rust,ignore -{{#rustdoc_include ../listings/ch17-oop/listing-17-09/src/main.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-09/src/main.rs:here}} ``` -Listing 17-9: Using trait objects to store values of +Listing 18-9: Using trait objects to store values of different types that implement the same trait When we wrote the library, we didn’t know that someone might add the @@ -192,7 +192,7 @@ This concept—of being concerned only with the messages a value responds to rather than the value’s concrete type—is similar to the concept of *duck typing* in dynamically typed languages: if it walks like a duck and quacks like a duck, then it must be a duck! In the implementation of `run` on `Screen` -in Listing 17-5, `run` doesn’t need to know what the concrete type of each +in Listing 18-5, `run` doesn’t need to know what the concrete type of each component is. It doesn’t check whether a component is an instance of a `Button` or a `SelectBox`, it just calls the `draw` method on the component. By specifying `Box` as the type of the values in the `components` @@ -205,22 +205,22 @@ value implements a particular method at runtime or worry about getting errors if a value doesn’t implement a method but we call it anyway. Rust won’t compile our code if the values don’t implement the traits that the trait objects need. -For example, Listing 17-10 shows what happens if we try to create a `Screen` +For example, Listing 18-10 shows what happens if we try to create a `Screen` with a `String` as a component: Filename: src/main.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-oop/listing-17-10/src/main.rs}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-10/src/main.rs}} ``` -Listing 17-10: Attempting to use a type that doesn’t +Listing 18-10: Attempting to use a type that doesn’t implement the trait object’s trait We’ll get this error because `String` doesn’t implement the `Draw` trait: ```console -{{#include ../listings/ch17-oop/listing-17-10/output.txt}} +{{#include ../listings/ch18-oop/listing-18-10/output.txt}} ``` This error lets us know that either we’re passing something to `Screen` we @@ -248,8 +248,8 @@ runtime, Rust uses the pointers inside the trait object to know which method to call. This lookup incurs a runtime cost that doesn’t occur with static dispatch. Dynamic dispatch also prevents the compiler from choosing to inline a method’s code, which in turn prevents some optimizations. However, we did get -extra flexibility in the code that we wrote in Listing 17-5 and were able to -support in Listing 17-9, so it’s a trade-off to consider. +extra flexibility in the code that we wrote in Listing 18-5 and were able to +support in Listing 18-9, so it’s a trade-off to consider. [performance-of-code-using-generics]: ch10-01-syntax.html#performance-of-code-using-generics diff --git a/src/ch18-03-oo-design-patterns.md b/src/ch18-03-oo-design-patterns.md index 6044841631..9306572825 100644 --- a/src/ch18-03-oo-design-patterns.md +++ b/src/ch18-03-oo-design-patterns.md @@ -36,17 +36,17 @@ Any other changes attempted on a post should have no effect. For example, if we try to approve a draft blog post before we’ve requested a review, the post should remain an unpublished draft. -Listing 17-11 shows this workflow in code form: this is an example usage of the +Listing 18-11 shows this workflow in code form: this is an example usage of the API we’ll implement in a library crate named `blog`. This won’t compile yet because we haven’t implemented the `blog` crate. Filename: src/main.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-oop/listing-17-11/src/main.rs:all}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-11/src/main.rs:all}} ``` -Listing 17-11: Code that demonstrates the desired +Listing 18-11: Code that demonstrates the desired behavior we want our `blog` crate to have We want to allow the user to create a new draft blog post with `Post::new`. We @@ -76,7 +76,7 @@ make a mistake with the states, like publishing a post before it’s reviewed. Let’s get started on the implementation of the library! We know we need a public `Post` struct that holds some content, so we’ll start with the definition of the struct and an associated public `new` function to create an -instance of `Post`, as shown in Listing 17-12. We’ll also make a private +instance of `Post`, as shown in Listing 18-12. We’ll also make a private `State` trait that will define the behavior that all state objects for a `Post` must have. @@ -87,10 +87,10 @@ in a private field named `state` to hold the state object. You’ll see why the Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-12/src/lib.rs}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-12/src/lib.rs}} ``` -Listing 17-12: Definition of a `Post` struct and a `new` +Listing 18-12: Definition of a `Post` struct and a `new` function that creates a new `Post` instance, a `State` trait, and a `Draft` struct @@ -109,21 +109,21 @@ create a `Post` in any other state! In the `Post::new` function, we set the ### Storing the Text of the Post Content -We saw in Listing 17-11 that we want to be able to call a method named +We saw in Listing 18-11 that we want to be able to call a method named `add_text` and pass it a `&str` that is then added as the text content of the blog post. We implement this as a method, rather than exposing the `content` field as `pub`, so that later we can implement a method that will control how the `content` field’s data is read. The `add_text` method is pretty -straightforward, so let’s add the implementation in Listing 17-13 to the `impl +straightforward, so let’s add the implementation in Listing 18-13 to the `impl Post` block: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-13/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-13/src/lib.rs:here}} ``` -Listing 17-13: Implementing the `add_text` method to add +Listing 18-13: Implementing the `add_text` method to add text to a post’s `content` The `add_text` method takes a mutable reference to `self`, because we’re @@ -138,37 +138,37 @@ support. Even after we’ve called `add_text` and added some content to our post, we still want the `content` method to return an empty string slice because the post is -still in the draft state, as shown on line 7 of Listing 17-11. For now, let’s +still in the draft state, as shown on line 7 of Listing 18-11. For now, let’s implement the `content` method with the simplest thing that will fulfill this requirement: always returning an empty string slice. We’ll change this later once we implement the ability to change a post’s state so it can be published. So far, posts can only be in the draft state, so the post content should always -be empty. Listing 17-14 shows this placeholder implementation: +be empty. Listing 18-14 shows this placeholder implementation: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-14/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-14/src/lib.rs:here}} ``` -Listing 17-14: Adding a placeholder implementation for +Listing 18-14: Adding a placeholder implementation for the `content` method on `Post` that always returns an empty string slice -With this added `content` method, everything in Listing 17-11 up to line 7 +With this added `content` method, everything in Listing 18-11 up to line 7 works as intended. ### Requesting a Review of the Post Changes Its State Next, we need to add functionality to request a review of a post, which should -change its state from `Draft` to `PendingReview`. Listing 17-15 shows this code: +change its state from `Draft` to `PendingReview`. Listing 18-15 shows this code: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-15/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-15/src/lib.rs:here}} ``` -Listing 17-15: Implementing `request_review` methods on +Listing 18-15: Implementing `request_review` methods on `Post` and the `State` trait We give `Post` a public method named `request_review` that will take a mutable @@ -211,7 +211,7 @@ state is responsible for its own rules. We’ll leave the `content` method on `Post` as is, returning an empty string slice. We can now have a `Post` in the `PendingReview` state as well as in the `Draft` state, but we want the same behavior in the `PendingReview` state. -Listing 17-11 now works up to line 10! +Listing 18-11 now works up to line 10! @@ -220,15 +220,15 @@ Listing 17-11 now works up to line 10! The `approve` method will be similar to the `request_review` method: it will set `state` to the value that the current state says it should have when that -state is approved, as shown in Listing 17-16: +state is approved, as shown in Listing 18-16: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-16/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-16/src/lib.rs:here}} ``` -Listing 17-16: Implementing the `approve` method on +Listing 18-16: Implementing the `approve` method on `Post` and the `State` trait We add the `approve` method to the `State` trait and add a new struct that @@ -245,15 +245,15 @@ state in those cases. Now we need to update the `content` method on `Post`. We want the value returned from `content` to depend on the current state of the `Post`, so we’re going to have the `Post` delegate to a `content` method defined on its `state`, -as shown in Listing 17-17: +as shown in Listing 18-17: Filename: src/lib.rs ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch17-oop/listing-17-17/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-17/src/lib.rs:here}} ``` -Listing 17-17: Updating the `content` method on `Post` to +Listing 18-17: Updating the `content` method on `Post` to delegate to a `content` method on `State` Because the goal is to keep all these rules inside the structs that implement @@ -280,15 +280,15 @@ will take effect on the `&` and the `Box` so the `content` method will ultimately be called on the type that implements the `State` trait. That means we need to add `content` to the `State` trait definition, and that is where we’ll put the logic for what content to return depending on which state we -have, as shown in Listing 17-18: +have, as shown in Listing 18-18: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-18/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-18/src/lib.rs:here}} ``` -Listing 17-18: Adding the `content` method to the `State` +Listing 18-18: Adding the `content` method to the `State` trait We add a default implementation for the `content` method that returns an empty @@ -301,7 +301,7 @@ Chapter 10. We’re taking a reference to a `post` as an argument and returning reference to part of that `post`, so the lifetime of the returned reference is related to the lifetime of the `post` argument. -And we’re done—all of Listing 17-11 now works! We’ve implemented the state +And we’re done—all of Listing 18-11 now works! We’ve implemented the state pattern with the rules of the blog post workflow. The logic related to the rules lives in the state objects rather than being scattered throughout `Post`. @@ -381,12 +381,12 @@ outside code has no knowledge of them, we’ll encode the states into different types. Consequently, Rust’s type checking system will prevent attempts to use draft posts where only published posts are allowed by issuing a compiler error. -Let’s consider the first part of `main` in Listing 17-11: +Let’s consider the first part of `main` in Listing 18-11: Filename: src/main.rs ```rust,ignore -{{#rustdoc_include ../listings/ch17-oop/listing-17-11/src/main.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-11/src/main.rs:here}} ``` We still enable the creation of new posts in the draft state using `Post::new` @@ -396,16 +396,16 @@ draft posts don’t have the `content` method at all. That way, if we try to get a draft post’s content, we’ll get a compiler error telling us the method doesn’t exist. As a result, it will be impossible for us to accidentally display draft post content in production, because that code won’t even compile. -Listing 17-19 shows the definition of a `Post` struct and a `DraftPost` struct, +Listing 18-19 shows the definition of a `Post` struct and a `DraftPost` struct, as well as methods on each: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-19/src/lib.rs}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-19/src/lib.rs}} ``` -Listing 17-19: A `Post` with a `content` method and a +Listing 18-19: A `Post` with a `content` method and a `DraftPost` without a `content` method Both the `Post` and `DraftPost` structs have a private `content` field that @@ -433,15 +433,15 @@ pending review state should still not display any content. Let’s implement these constraints by adding another struct, `PendingReviewPost`, defining the `request_review` method on `DraftPost` to return a `PendingReviewPost`, and defining an `approve` method on `PendingReviewPost` to return a `Post`, as -shown in Listing 17-20: +shown in Listing 18-20: Filename: src/lib.rs ```rust,noplayground -{{#rustdoc_include ../listings/ch17-oop/listing-17-20/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-20/src/lib.rs:here}} ``` -Listing 17-20: A `PendingReviewPost` that gets created by +Listing 18-20: A `PendingReviewPost` that gets created by calling `request_review` on `DraftPost` and an `approve` method that turns a `PendingReviewPost` into a published `Post` @@ -463,15 +463,15 @@ called on, so we need to add more `let post =` shadowing assignments to save the returned instances. We also can’t have the assertions about the draft and pending review posts’ contents be empty strings, nor do we need them: we can’t compile code that tries to use the content of posts in those states any longer. -The updated code in `main` is shown in Listing 17-21: +The updated code in `main` is shown in Listing 18-21: Filename: src/main.rs ```rust,ignore -{{#rustdoc_include ../listings/ch17-oop/listing-17-21/src/main.rs}} +{{#rustdoc_include ../listings/ch18-oop/listing-18-21/src/main.rs}} ``` -Listing 17-21: Modifications to `main` to use the new +Listing 18-21: Modifications to `main` to use the new implementation of the blog post workflow The changes we needed to make to `main` to reassign `post` mean that this @@ -483,7 +483,7 @@ compile time! This ensures that certain bugs, such as display of the content of an unpublished post, will be discovered before they make it to production. Try the tasks suggested at the start of this section on the `blog` crate as it -is after Listing 17-21 to see what you think about the design of this version +is after Listing 18-21 to see what you think about the design of this version of the code. Note that some of the tasks might be completed already in this design. From 1fb74c3f1d8aeba39373e9f4cdb9a4bdca95604f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 26 Sep 2024 14:17:57 -0600 Subject: [PATCH 623/720] Ch. 17: update all other text references for new ordering --- src/appendix-03-derivable-traits.md | 2 +- src/ch00-00-introduction.md | 15 +++++++++------ src/ch01-02-hello-world.md | 2 +- src/ch02-00-guessing-game-tutorial.md | 4 ++-- src/ch08-01-vectors.md | 2 +- src/ch09-02-recoverable-errors-with-result.md | 2 +- src/ch09-03-to-panic-or-not-to-panic.md | 2 +- src/ch10-02-traits.md | 2 +- src/ch10-03-lifetime-syntax.md | 2 +- src/ch12-00-an-io-project.md | 4 ++-- ...-03-improving-error-handling-and-modularity.md | 4 ++-- src/ch13-02-iterators.md | 2 +- src/ch14-02-publishing-to-crates-io.md | 2 +- src/ch15-01-box.md | 6 +++--- src/ch15-02-deref.md | 2 +- src/ch15-05-interior-mutability.md | 2 +- src/ch16-02-message-passing.md | 2 +- ...h16-04-extensible-concurrency-sync-and-send.md | 6 +++--- src/ch18-02-trait-objects.md | 2 +- src/ch18-03-oo-design-patterns.md | 2 +- src/ch20-00-advanced-features.md | 2 +- src/ch20-04-advanced-types.md | 4 ++-- src/ch20-05-advanced-functions-and-closures.md | 2 +- src/ch20-06-macros.md | 2 +- src/ch21-01-single-threaded.md | 2 +- src/ch21-02-multithreaded.md | 6 +++--- src/ch21-03-graceful-shutdown-and-cleanup.md | 2 +- 27 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/appendix-03-derivable-traits.md b/src/appendix-03-derivable-traits.md index d3951f9e5f..4214f091b9 100644 --- a/src/appendix-03-derivable-traits.md +++ b/src/appendix-03-derivable-traits.md @@ -34,7 +34,7 @@ The list of derivable traits provided in this appendix is not comprehensive: libraries can implement `derive` for their own traits, making the list of traits you can use `derive` with truly open-ended. Implementing `derive` involves using a procedural macro, which is covered in the -[“Macros”][macros] section of Chapter 19. +[“Macros”][macros] section of Chapter 20. ### `Debug` for Programmer Output diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 12632aa0bf..050a627818 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -141,17 +141,20 @@ depth and talk about best practices for sharing your libraries with others. Chapter 15 discusses smart pointers that the standard library provides and the traits that enable their functionality. -In Chapter 16, we’ll walk through different models of concurrent programming -and talk about how Rust helps you to program in multiple threads fearlessly. -Chapter 17 looks at how Rust idioms compare to object-oriented programming +In Chapter 16, we’ll walk through different models of concurrent programming and +talk about how Rust helps you to program in multiple threads fearlessly. In +Chapter 17, we will build on that by exploring Rust’s async and await syntax and +the lightweight concurrency model they support. + +Chapter 18 looks at how Rust idioms compare to object-oriented programming principles you might be familiar with. -Chapter 18 is a reference on patterns and pattern matching, which are powerful -ways of expressing ideas throughout Rust programs. Chapter 19 contains a +Chapter 19 is a reference on patterns and pattern matching, which are powerful +ways of expressing ideas throughout Rust programs. Chapter 20 contains a smorgasbord of advanced topics of interest, including unsafe Rust, macros, and more about lifetimes, traits, types, functions, and closures. -In Chapter 20, we’ll complete a project in which we’ll implement a low-level +In Chapter 21, we’ll complete a project in which we’ll implement a low-level multithreaded web server! Finally, some appendices contain useful information about the language in a diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index f0b97e4949..7efd5726e0 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -125,7 +125,7 @@ First, Rust style is to indent with four spaces, not a tab. Second, `println!` calls a Rust macro. If it had called a function instead, it would be entered as `println` (without the `!`). We’ll discuss Rust macros in -more detail in Chapter 19. For now, you just need to know that using a `!` +more detail in Chapter 20. For now, you just need to know that using a `!` means that you’re calling a macro instead of a normal function and that macros don’t always follow the same rules as functions. diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index 9c9601bf6a..d0d27f2b1b 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -79,7 +79,7 @@ allow the player to input a guess. Enter the code in Listing 2-1 into {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs:all}} ``` - +
This code contains a lot of information, so let’s go over it line by line. To obtain user input and then print the result as output, we need to bring the @@ -612,7 +612,7 @@ fits that arm’s pattern. Rust takes the value given to `match` and looks through each arm’s pattern in turn. Patterns and the `match` construct are powerful Rust features: they let you express a variety of situations your code might encounter and they make sure you handle them all. These features will be -covered in detail in Chapter 6 and Chapter 18, respectively. +covered in detail in Chapter 6 and Chapter 19, respectively. Let’s walk through an example with the `match` expression we use here. Say that the user has guessed 50 and the randomly generated secret number this time is diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index ece5d59dce..7138b35fde 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -219,7 +219,7 @@ at compile time that every possible case is handled, as discussed in Chapter 6. If you don’t know the exhaustive set of types a program will get at runtime to store in a vector, the enum technique won’t work. Instead, you can use a trait -object, which we’ll cover in Chapter 17. +object, which we’ll cover in Chapter 18. Now that we’ve discussed some of the most common ways to use vectors, be sure to review [the API documentation][vec-api] for all of the many diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 78a87c7392..41031c1276 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -507,7 +507,7 @@ allows the use of the `?` operator on `Result` values. The `Box` type is a *trait object*, which we’ll talk about in the [“Using Trait Objects that Allow for Values of Different -Types”][trait-objects] section in Chapter 17. For now, you can +Types”][trait-objects] section in Chapter 18. For now, you can read `Box` to mean “any kind of error.” Using `?` on a `Result` value in a `main` function with the error type `Box` is allowed because it allows any `Err` value to be returned early. Even though the body of diff --git a/src/ch09-03-to-panic-or-not-to-panic.md b/src/ch09-03-to-panic-or-not-to-panic.md index 138a783d00..88e30fd5e1 100644 --- a/src/ch09-03-to-panic-or-not-to-panic.md +++ b/src/ch09-03-to-panic-or-not-to-panic.md @@ -78,7 +78,7 @@ more of the following: rather than checking for the problem at every step. * There’s not a good way to encode this information in the types you use. We’ll work through an example of what we mean in the [“Encoding States and Behavior - as Types”][encoding] section of Chapter 17. + as Types”][encoding] section of Chapter 18. If someone calls your code and passes in values that don’t make sense, it’s best to return an error if you can so the user of the library can decide what diff --git a/src/ch10-02-traits.md b/src/ch10-02-traits.md index 855ee1fc4b..25eaaa3cc0 100644 --- a/src/ch10-02-traits.md +++ b/src/ch10-02-traits.md @@ -325,7 +325,7 @@ around how the `impl Trait` syntax is implemented in the compiler. We’ll cover how to write a function with this behavior in the [“Using Trait Objects That Allow for Values of Different Types”][using-trait-objects-that-allow-for-values-of-different-types] section of Chapter 17. +ignore --> section of Chapter 18. ### Using Trait Bounds to Conditionally Implement Methods diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index d327e512b9..c87f38c4ce 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -608,7 +608,7 @@ that this flexible code won’t have any dangling references. And all of this analysis happens at compile time, which doesn’t affect runtime performance! Believe it or not, there is much more to learn on the topics we discussed in -this chapter: Chapter 17 discusses trait objects, which are another way to use +this chapter: Chapter 18 discusses trait objects, which are another way to use traits. There are also more complex scenarios involving lifetime annotations that you will only need in very advanced scenarios; for those, you should read the [Rust Reference][reference]. But next, you’ll learn how to write tests in diff --git a/src/ch12-00-an-io-project.md b/src/ch12-00-an-io-project.md index f40edcbafe..e179e11800 100644 --- a/src/ch12-00-an-io-project.md +++ b/src/ch12-00-an-io-project.md @@ -36,7 +36,7 @@ Our `grep` project will combine a number of concepts you’ve learned so far: * Writing tests ([Chapter 11][ch11]) We’ll also briefly introduce closures, iterators, and trait objects, which -[Chapter 13][ch13] and [Chapter 17][ch17] will +[Chapter 13][ch13] and [Chapter 18][ch18] will cover in detail. [ch7]: ch07-00-managing-growing-projects-with-packages-crates-and-modules.html @@ -45,4 +45,4 @@ cover in detail. [ch10]: ch10-00-generics.html [ch11]: ch11-00-testing.html [ch13]: ch13-00-functional-features.html -[ch17]: ch18-00-oop.html +[ch18]: ch18-00-oop.html diff --git a/src/ch12-03-improving-error-handling-and-modularity.md b/src/ch12-03-improving-error-handling-and-modularity.md index 64fe188b52..bf2b7c35bd 100644 --- a/src/ch12-03-improving-error-handling-and-modularity.md +++ b/src/ch12-03-improving-error-handling-and-modularity.md @@ -381,7 +381,7 @@ returned the unit type, `()`, and we keep that as the value returned in the For the error type, we used the *trait object* `Box` (and we’ve brought `std::error::Error` into scope with a `use` statement at the top). -We’ll cover trait objects in [Chapter 17][ch17]. For now, just +We’ll cover trait objects in [Chapter 18][ch18]. For now, just know that `Box` means the function will return a type that implements the `Error` trait, but we don’t have to specify what particular type the return value will be. This gives us flexibility to return error values that @@ -490,5 +490,5 @@ write some tests! [ch9-custom-types]: ch09-03-to-panic-or-not-to-panic.html#creating-custom-types-for-validation [ch9-error-guidelines]: ch09-03-to-panic-or-not-to-panic.html#guidelines-for-error-handling [ch9-result]: ch09-02-recoverable-errors-with-result.html -[ch17]: ch18-00-oop.html +[ch18]: ch18-00-oop.html [ch9-question-mark]: ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator diff --git a/src/ch13-02-iterators.md b/src/ch13-02-iterators.md index 4ce9170de0..5942a62c5a 100644 --- a/src/ch13-02-iterators.md +++ b/src/ch13-02-iterators.md @@ -66,7 +66,7 @@ pub trait Iterator { Notice this definition uses some new syntax: `type Item` and `Self::Item`, which are defining an *associated type* with this trait. We’ll talk about -associated types in depth in Chapter 19. For now, all you need to know is that +associated types in depth in Chapter 20. For now, all you need to know is that this code says implementing the `Iterator` trait requires that you also define an `Item` type, and this `Item` type is used in the return type of the `next` method. In other words, the `Item` type will be the type returned from the diff --git a/src/ch14-02-publishing-to-crates-io.md b/src/ch14-02-publishing-to-crates-io.md index b4cfb22d6c..87887a32ac 100644 --- a/src/ch14-02-publishing-to-crates-io.md +++ b/src/ch14-02-publishing-to-crates-io.md @@ -66,7 +66,7 @@ authors commonly use in their documentation: returned can be helpful to callers so they can write code to handle the different kinds of errors in different ways. * **Safety**: If the function is `unsafe` to call (we discuss unsafety in - Chapter 19), there should be a section explaining why the function is unsafe + Chapter 20), there should be a section explaining why the function is unsafe and covering the invariants that the function expects callers to uphold. Most documentation comments don’t need all of these sections, but this is a diff --git a/src/ch15-01-box.md b/src/ch15-01-box.md index 1878f6f195..bc16c2504f 100644 --- a/src/ch15-01-box.md +++ b/src/ch15-01-box.md @@ -23,10 +23,10 @@ time because the data is copied around on the stack. To improve performance in this situation, we can store the large amount of data on the heap in a box. Then, only the small amount of pointer data is copied around on the stack, while the data it references stays in one place on the heap. The third case is -known as a *trait object*, and Chapter 17 devotes an entire section, [“Using +known as a *trait object*, and Chapter 18 devotes an entire section, [“Using Trait Objects That Allow for Values of Different Types,”][trait-objects] just to that topic. So what you learn here you’ll apply again in -Chapter 17! +Chapter 18! ### Using a `Box` to Store Data on the Heap @@ -242,7 +242,7 @@ other special capabilities, like those we’ll see with the other smart pointer types. They also don’t have the performance overhead that these special capabilities incur, so they can be useful in cases like the cons list where the indirection is the only feature we need. We’ll look at more use cases for boxes -in Chapter 17, too. +in Chapter 18, too. The `Box` type is a smart pointer because it implements the `Deref` trait, which allows `Box` values to be treated like references. When a `Box` diff --git a/src/ch15-02-deref.md b/src/ch15-02-deref.md index 56db7c0a02..5017fca434 100644 --- a/src/ch15-02-deref.md +++ b/src/ch15-02-deref.md @@ -148,7 +148,7 @@ contains an implementation of `Deref` to add to the definition of `MyBox`: The `type Target = T;` syntax defines an associated type for the `Deref` trait to use. Associated types are a slightly different way of declaring a generic parameter, but you don’t need to worry about them for now; we’ll cover -them in more detail in Chapter 19. +them in more detail in Chapter 20. We fill in the body of the `deref` method with `&self.0` so `deref` returns a reference to the value we want to access with the `*` operator; recall from the diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index 7b5e825d7e..4c7d3c4f66 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -6,7 +6,7 @@ action is disallowed by the borrowing rules. To mutate data, the pattern uses `unsafe` code inside a data structure to bend Rust’s usual rules that govern mutation and borrowing. Unsafe code indicates to the compiler that we’re checking the rules manually instead of relying on the compiler to check them -for us; we will discuss unsafe code more in Chapter 19. +for us; we will discuss unsafe code more in Chapter 20. We can use types that use the interior mutability pattern only when we can ensure that the borrowing rules will be followed at runtime, even though the diff --git a/src/ch16-02-message-passing.md b/src/ch16-02-message-passing.md index c468b94c33..3782fa5dec 100644 --- a/src/ch16-02-message-passing.md +++ b/src/ch16-02-message-passing.md @@ -57,7 +57,7 @@ receiver. The abbreviations `tx` and `rx` are traditionally used in many fields for *transmitter* and *receiver* respectively, so we name our variables as such to indicate each end. We’re using a `let` statement with a pattern that destructures the tuples; we’ll discuss the use of patterns in `let` statements -and destructuring in Chapter 18. For now, know that using a `let` statement +and destructuring in Chapter 19. For now, know that using a `let` statement this way is a convenient approach to extract the pieces of the tuple returned by `mpsc::channel`. diff --git a/src/ch16-04-extensible-concurrency-sync-and-send.md b/src/ch16-04-extensible-concurrency-sync-and-send.md index ede5c66856..148b68ab3d 100644 --- a/src/ch16-04-extensible-concurrency-sync-and-send.md +++ b/src/ch16-04-extensible-concurrency-sync-and-send.md @@ -28,7 +28,7 @@ compiled. Any type composed entirely of `Send` types is automatically marked as `Send` as well. Almost all primitive types are `Send`, aside from raw pointers, which -we’ll discuss in Chapter 19. +we’ll discuss in Chapter 20. ### Allowing Access from Multiple Threads with `Sync` @@ -54,7 +54,7 @@ marker traits, they don’t even have any methods to implement. They’re just useful for enforcing invariants related to concurrency. Manually implementing these traits involves implementing unsafe Rust code. -We’ll talk about using unsafe Rust code in Chapter 19; for now, the important +We’ll talk about using unsafe Rust code in Chapter 20; for now, the important information is that building new concurrent types not made up of `Send` and `Sync` parts requires careful thought to uphold the safety guarantees. [“The Rustonomicon”][nomicon] has more information about these guarantees and how to @@ -63,7 +63,7 @@ uphold them. ## Summary This isn’t the last you’ll see of concurrency in this book: the whole next -chapter focuses on async programming, and the project in Chapter 20 will use the +chapter focuses on async programming, and the project in Chapter 21 will use the concepts in this chapter in a more realistic situation than the smaller examples discussed here. diff --git a/src/ch18-02-trait-objects.md b/src/ch18-02-trait-objects.md index d4f7ee7b51..751fdaa033 100644 --- a/src/ch18-02-trait-objects.md +++ b/src/ch18-02-trait-objects.md @@ -45,7 +45,7 @@ implementing our specified trait and a table used to look up trait methods on that type at runtime. We create a trait object by specifying some sort of pointer, such as a `&` reference or a `Box` smart pointer, then the `dyn` keyword, and then specifying the relevant trait. (We’ll talk about the reason -trait objects must use a pointer in Chapter 19 in the section [“Dynamically +trait objects must use a pointer in Chapter 20 in the section [“Dynamically Sized Types and the `Sized` Trait.”][dynamically-sized]) We can use trait objects in place of a generic or concrete type. Wherever we use a trait object, Rust’s type system will ensure at compile time that any value diff --git a/src/ch18-03-oo-design-patterns.md b/src/ch18-03-oo-design-patterns.md index 9306572825..9a73091cda 100644 --- a/src/ch18-03-oo-design-patterns.md +++ b/src/ch18-03-oo-design-patterns.md @@ -366,7 +366,7 @@ and `approve` methods on `Post`. Both methods delegate to the implementation of the same method on the value in the `state` field of `Option` and set the new value of the `state` field to the result. If we had a lot of methods on `Post` that followed this pattern, we might consider defining a macro to eliminate the -repetition (see the [“Macros”][macros] section in Chapter 19). +repetition (see the [“Macros”][macros] section in Chapter 20). By implementing the state pattern exactly as it’s defined for object-oriented languages, we’re not taking as full advantage of Rust’s strengths as we could. diff --git a/src/ch20-00-advanced-features.md b/src/ch20-00-advanced-features.md index a0db41fde4..3e612d2af2 100644 --- a/src/ch20-00-advanced-features.md +++ b/src/ch20-00-advanced-features.md @@ -1,7 +1,7 @@ # Advanced Features By now, you’ve learned the most commonly used parts of the Rust programming -language. Before we do one more project in Chapter 20, we’ll look at a few +language. Before we do one more project in Chapter 21, we’ll look at a few aspects of the language you might run into every once in a while, but may not use every day. You can use this chapter as a reference for when you encounter any unknowns. The features covered here are useful in very specific situations. diff --git a/src/ch20-04-advanced-types.md b/src/ch20-04-advanced-types.md index a626529842..1e5b08c106 100644 --- a/src/ch20-04-advanced-types.md +++ b/src/ch20-04-advanced-types.md @@ -34,7 +34,7 @@ internally. The newtype pattern is a lightweight way to achieve encapsulation to hide implementation details, which we discussed in the [“Encapsulation that Hides Implementation Details”][encapsulation-that-hides-implementation-details] -section of Chapter 17. +section of Chapter 18. ### Creating Type Synonyms with Type Aliases @@ -245,7 +245,7 @@ types behind a pointer of some kind. We can combine `str` with all kinds of pointers: for example, `Box` or `Rc`. In fact, you’ve seen this before but with a different dynamically sized type: traits. Every trait is a dynamically sized type we can refer to by -using the name of the trait. In Chapter 17 in the [“Using Trait Objects That +using the name of the trait. In Chapter 18 in the [“Using Trait Objects That Allow for Values of Different Types”][using-trait-objects-that-allow-for-values-of-different-types] section, we mentioned that to use traits as trait objects, we must diff --git a/src/ch20-05-advanced-functions-and-closures.md b/src/ch20-05-advanced-functions-and-closures.md index ac8305736d..ef6a6e46f7 100644 --- a/src/ch20-05-advanced-functions-and-closures.md +++ b/src/ch20-05-advanced-functions-and-closures.md @@ -119,7 +119,7 @@ We can use a trait object: This code will compile just fine. For more about trait objects, refer to the section [“Using Trait Objects That Allow for Values of Different Types”][using-trait-objects-that-allow-for-values-of-different-types] in Chapter 18. +ignore --> in Chapter 19. Next, let’s look at macros! diff --git a/src/ch20-06-macros.md b/src/ch20-06-macros.md index b9b97201cc..2406942df2 100644 --- a/src/ch20-06-macros.md +++ b/src/ch20-06-macros.md @@ -105,7 +105,7 @@ other pattern will result in an error. More complex macros will have more than one arm. Valid pattern syntax in macro definitions is different than the pattern syntax -covered in Chapter 18 because macro patterns are matched against Rust code +covered in Chapter 19 because macro patterns are matched against Rust code structure rather than values. Let’s walk through what the pattern pieces in Listing 20-28 mean; for the full macro pattern syntax, see the [Rust Reference][ref]. diff --git a/src/ch21-01-single-threaded.md b/src/ch21-01-single-threaded.md index 11ae851b78..744a2a7829 100644 --- a/src/ch21-01-single-threaded.md +++ b/src/ch21-01-single-threaded.md @@ -441,7 +441,7 @@ contain only the code that differs between the two cases Now the `if` and `else` blocks only return the appropriate values for the status line and filename in a tuple; we then use destructuring to assign these two values to `status_line` and `filename` using a pattern in the `let` -statement, as discussed in Chapter 18. +statement, as discussed in Chapter 19. The previously duplicated code is now outside the `if` and `else` blocks and uses the `status_line` and `filename` variables. This makes it easier to see diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index bcb0b133b0..4204693508 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -546,7 +546,7 @@ Let’s finally implement the `execute` method on `ThreadPool`. We’ll also cha `Job` from a struct to a type alias for a trait object that holds the type of closure that `execute` receives. As discussed in the [“Creating Type Synonyms with Type Aliases”][creating-type-synonyms-with-type-aliases] -section of Chapter 19, type aliases allow us to make long types shorter for +section of Chapter 20, type aliases allow us to make long types shorter for ease of use. Look at Listing 21-19. Filename: src/lib.rs @@ -658,8 +658,8 @@ thread run them. > multiple instances of the same request sequentially for caching reasons. This > limitation is not caused by our web server. -After learning about the `while let` loop in Chapter 18, you might be wondering -why we didn’t write the worker thread code as shown in Listing 21-21. +After learning about the `while let` loop in Chapters 17 and 18, you might be +wondering why we didn’t write the worker thread code as shown in Listing 21-21. Filename: src/lib.rs diff --git a/src/ch21-03-graceful-shutdown-and-cleanup.md b/src/ch21-03-graceful-shutdown-and-cleanup.md index 38180a580d..24a8aabf6f 100644 --- a/src/ch21-03-graceful-shutdown-and-cleanup.md +++ b/src/ch21-03-graceful-shutdown-and-cleanup.md @@ -90,7 +90,7 @@ The following changes will do so: {{#rustdoc_include ../listings/ch21-web-server/no-listing-06-fix-threadpool-drop/src/lib.rs:here}} ``` -As discussed in Chapter 17, the `take` method on `Option` takes the `Some` +As discussed in Chapter 18, the `take` method on `Option` takes the `Some` variant out and leaves `None` in its place. We’re using `if let` to destructure the `Some` and get the thread; then we call `join` on the thread. If a worker’s thread is already `None`, we know that worker has already had its thread From 54c567b5b23e5358feac45bd8c6a27f85abc8b34 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 26 Sep 2024 14:40:12 -0600 Subject: [PATCH 624/720] Ch. 17: update all internal links for new ordering --- 2018-edition/src/ch17-00-oop.md | 4 ++-- 2018-edition/src/ch17-01-what-is-oo.md | 4 ++-- 2018-edition/src/ch17-02-trait-objects.md | 4 ++-- 2018-edition/src/ch17-03-oo-design-patterns.md | 2 +- 2018-edition/src/ch18-00-patterns.md | 4 ++-- 2018-edition/src/ch18-01-all-the-places-for-patterns.md | 4 ++-- 2018-edition/src/ch18-02-refutability.md | 4 ++-- 2018-edition/src/ch18-03-pattern-syntax.md | 4 ++-- 2018-edition/src/ch19-00-advanced-features.md | 4 ++-- 2018-edition/src/ch19-01-unsafe-rust.md | 4 ++-- 2018-edition/src/ch19-03-advanced-traits.md | 4 ++-- 2018-edition/src/ch19-04-advanced-types.md | 4 ++-- 2018-edition/src/ch19-05-advanced-functions-and-closures.md | 4 ++-- 2018-edition/src/ch19-06-macros.md | 4 ++-- 2018-edition/src/ch20-00-final-project-a-web-server.md | 4 ++-- 2018-edition/src/ch20-01-single-threaded.md | 4 ++-- 2018-edition/src/ch20-02-multithreaded.md | 4 ++-- 2018-edition/src/ch20-03-graceful-shutdown-and-cleanup.md | 4 ++-- first-edition/src/associated-types.md | 2 +- first-edition/src/const-and-static.md | 2 +- first-edition/src/ffi.md | 2 +- first-edition/src/macros.md | 2 +- first-edition/src/operators-and-overloading.md | 2 +- first-edition/src/patterns.md | 2 +- first-edition/src/procedural-macros.md | 2 +- first-edition/src/raw-pointers.md | 2 +- first-edition/src/trait-objects.md | 2 +- first-edition/src/type-aliases.md | 2 +- first-edition/src/unsafe.md | 2 +- first-edition/src/unsized-types.md | 2 +- listings/ch19-patterns-and-matching/listing-19-08/output.txt | 2 +- redirects/associated-types.md | 2 +- redirects/const-and-static.md | 2 +- redirects/ffi.md | 2 +- redirects/macros.md | 2 +- redirects/match.md | 2 +- redirects/operators-and-overloading.md | 2 +- redirects/procedural-macros.md | 2 +- redirects/raw-pointers.md | 2 +- redirects/trait-objects.md | 2 +- redirects/traits.md | 2 +- redirects/type-aliases.md | 2 +- redirects/ufcs.md | 2 +- redirects/unsafe.md | 2 +- redirects/unsized-types.md | 2 +- second-edition/src/appendix-04-macros.md | 4 ++-- second-edition/src/ch17-00-oop.md | 4 ++-- second-edition/src/ch17-01-what-is-oo.md | 4 ++-- second-edition/src/ch17-02-trait-objects.md | 4 ++-- second-edition/src/ch18-01-all-the-places-for-patterns.md | 4 ++-- second-edition/src/ch18-02-refutability.md | 4 ++-- second-edition/src/ch18-03-pattern-syntax.md | 4 ++-- second-edition/src/ch19-00-advanced-features.md | 4 ++-- second-edition/src/ch19-01-unsafe-rust.md | 4 ++-- second-edition/src/ch19-03-advanced-traits.md | 4 ++-- second-edition/src/ch19-04-advanced-types.md | 4 ++-- second-edition/src/ch19-05-advanced-functions-and-closures.md | 4 ++-- second-edition/src/ch20-00-final-project-a-web-server.md | 4 ++-- second-edition/src/ch20-01-single-threaded.md | 4 ++-- second-edition/src/ch20-02-multithreaded.md | 4 ++-- second-edition/src/ch20-03-graceful-shutdown-and-cleanup.md | 4 ++-- 61 files changed, 94 insertions(+), 94 deletions(-) diff --git a/2018-edition/src/ch17-00-oop.md b/2018-edition/src/ch17-00-oop.md index c731bbc95b..6ff4dc33e8 100644 --- a/2018-edition/src/ch17-00-oop.md +++ b/2018-edition/src/ch17-00-oop.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-00-oop.html) instead. +version of the book](../ch18-00-oop.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-00-oop.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-00-oop.html). diff --git a/2018-edition/src/ch17-01-what-is-oo.md b/2018-edition/src/ch17-01-what-is-oo.md index ed1ec4013d..28835201bf 100644 --- a/2018-edition/src/ch17-01-what-is-oo.md +++ b/2018-edition/src/ch17-01-what-is-oo.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-01-what-is-oo.html) instead. +version of the book](../ch18-01-what-is-oo.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-01-what-is-oo.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-01-what-is-oo.html). diff --git a/2018-edition/src/ch17-02-trait-objects.md b/2018-edition/src/ch17-02-trait-objects.md index 1999647aae..b83ab904ee 100644 --- a/2018-edition/src/ch17-02-trait-objects.md +++ b/2018-edition/src/ch17-02-trait-objects.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-02-trait-objects.html) instead. +version of the book](../ch18-02-trait-objects.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-02-trait-objects.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch17-02-trait-objects.html). diff --git a/2018-edition/src/ch17-03-oo-design-patterns.md b/2018-edition/src/ch17-03-oo-design-patterns.md index 9513538f57..c161b3decf 100644 --- a/2018-edition/src/ch17-03-oo-design-patterns.md +++ b/2018-edition/src/ch17-03-oo-design-patterns.md @@ -3,7 +3,7 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-03-oo-design-patterns.html) instead. +version of the book](../ch19-03-oo-design-patterns.html) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/2018-edition/src/ch18-00-patterns.md b/2018-edition/src/ch18-00-patterns.md index f3da1f40d2..213bac305d 100644 --- a/2018-edition/src/ch18-00-patterns.md +++ b/2018-edition/src/ch18-00-patterns.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-00-patterns.html) instead. +version of the book](../ch19-00-patterns.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch18-00-patterns.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch18-00-patterns.html). diff --git a/2018-edition/src/ch18-01-all-the-places-for-patterns.md b/2018-edition/src/ch18-01-all-the-places-for-patterns.md index ccf3884069..f2dfa71a32 100644 --- a/2018-edition/src/ch18-01-all-the-places-for-patterns.md +++ b/2018-edition/src/ch18-01-all-the-places-for-patterns.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-01-all-the-places-for-patterns.html) instead. +version of the book](../ch19-01-all-the-places-for-patterns.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch18-01-all-the-places-for-patterns.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch18-01-all-the-places-for-patterns.html). diff --git a/2018-edition/src/ch18-02-refutability.md b/2018-edition/src/ch18-02-refutability.md index a3e2bcff76..3eddb4dcd5 100644 --- a/2018-edition/src/ch18-02-refutability.md +++ b/2018-edition/src/ch18-02-refutability.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-02-refutability.html) instead. +version of the book](../ch19-02-refutability.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch18-02-refutability.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch18-02-refutability.html). diff --git a/2018-edition/src/ch18-03-pattern-syntax.md b/2018-edition/src/ch18-03-pattern-syntax.md index 0e0929e7b8..44c73500e1 100644 --- a/2018-edition/src/ch18-03-pattern-syntax.md +++ b/2018-edition/src/ch18-03-pattern-syntax.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-03-pattern-syntax.html) instead. +version of the book](../ch19-03-pattern-syntax.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch18-03-pattern-syntax.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch18-03-pattern-syntax.html). diff --git a/2018-edition/src/ch19-00-advanced-features.md b/2018-edition/src/ch19-00-advanced-features.md index b34d6b9b67..16c72a906a 100644 --- a/2018-edition/src/ch19-00-advanced-features.md +++ b/2018-edition/src/ch19-00-advanced-features.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-00-advanced-features.html) instead. +version of the book](../ch20-00-advanced-features.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-00-advanced-features.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-00-advanced-features.html). diff --git a/2018-edition/src/ch19-01-unsafe-rust.md b/2018-edition/src/ch19-01-unsafe-rust.md index 34b569fee6..7316eb44a9 100644 --- a/2018-edition/src/ch19-01-unsafe-rust.md +++ b/2018-edition/src/ch19-01-unsafe-rust.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-01-unsafe-rust.html) instead. +version of the book](../ch20-01-unsafe-rust.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-01-unsafe-rust.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-01-unsafe-rust.html). diff --git a/2018-edition/src/ch19-03-advanced-traits.md b/2018-edition/src/ch19-03-advanced-traits.md index 4219b208b9..88ca1a55b4 100644 --- a/2018-edition/src/ch19-03-advanced-traits.md +++ b/2018-edition/src/ch19-03-advanced-traits.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-03-advanced-traits.html) instead. +version of the book](../ch20-03-advanced-traits.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-03-advanced-traits.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-03-advanced-traits.html). diff --git a/2018-edition/src/ch19-04-advanced-types.md b/2018-edition/src/ch19-04-advanced-types.md index fecbd52dc8..c7c24439f9 100644 --- a/2018-edition/src/ch19-04-advanced-types.md +++ b/2018-edition/src/ch19-04-advanced-types.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-04-advanced-types.html) instead. +version of the book](../ch20-04-advanced-types.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-04-advanced-types.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-04-advanced-types.html). diff --git a/2018-edition/src/ch19-05-advanced-functions-and-closures.md b/2018-edition/src/ch19-05-advanced-functions-and-closures.md index 1bf0450904..c46fd485e1 100644 --- a/2018-edition/src/ch19-05-advanced-functions-and-closures.md +++ b/2018-edition/src/ch19-05-advanced-functions-and-closures.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-05-advanced-functions-and-closures.html) instead. +version of the book](../ch20-05-advanced-functions-and-closures.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-05-advanced-functions-and-closures.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-05-advanced-functions-and-closures.html). diff --git a/2018-edition/src/ch19-06-macros.md b/2018-edition/src/ch19-06-macros.md index bf019c5d68..838a0b8328 100644 --- a/2018-edition/src/ch19-06-macros.md +++ b/2018-edition/src/ch19-06-macros.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-06-macros.html) instead. +version of the book](../ch20-06-macros.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-06-macros.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch19-06-macros.html). diff --git a/2018-edition/src/ch20-00-final-project-a-web-server.md b/2018-edition/src/ch20-00-final-project-a-web-server.md index f9b9e5c2d2..cac5584895 100644 --- a/2018-edition/src/ch20-00-final-project-a-web-server.md +++ b/2018-edition/src/ch20-00-final-project-a-web-server.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch20-00-final-project-a-web-server.html) instead. +version of the book](../ch21-00-final-project-a-web-server.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch20-00-final-project-a-web-server.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch20-00-final-project-a-web-server.html). diff --git a/2018-edition/src/ch20-01-single-threaded.md b/2018-edition/src/ch20-01-single-threaded.md index 30d0884adb..e1b4200be8 100644 --- a/2018-edition/src/ch20-01-single-threaded.md +++ b/2018-edition/src/ch20-01-single-threaded.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch20-01-single-threaded.html) instead. +version of the book](../ch21-01-single-threaded.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch20-01-single-threaded.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch20-01-single-threaded.html). diff --git a/2018-edition/src/ch20-02-multithreaded.md b/2018-edition/src/ch20-02-multithreaded.md index e8b592ad22..7d54d56bc8 100644 --- a/2018-edition/src/ch20-02-multithreaded.md +++ b/2018-edition/src/ch20-02-multithreaded.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch20-02-multithreaded.html) instead. +version of the book](../ch21-02-multithreaded.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch20-02-multithreaded.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch20-02-multithreaded.html). diff --git a/2018-edition/src/ch20-03-graceful-shutdown-and-cleanup.md b/2018-edition/src/ch20-03-graceful-shutdown-and-cleanup.md index 928d199bee..f4879c4ac7 100644 --- a/2018-edition/src/ch20-03-graceful-shutdown-and-cleanup.md +++ b/2018-edition/src/ch20-03-graceful-shutdown-and-cleanup.md @@ -3,8 +3,8 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch20-03-graceful-shutdown-and-cleanup.html) instead. +version of the book](../ch21-03-graceful-shutdown-and-cleanup.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch20-03-graceful-shutdown-and-cleanup.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/2018-edition/ch20-03-graceful-shutdown-and-cleanup.html). diff --git a/first-edition/src/associated-types.md b/first-edition/src/associated-types.md index 626048e9e6..be78034984 100644 --- a/first-edition/src/associated-types.md +++ b/first-edition/src/associated-types.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-03-advanced-traits.html#specifying-placeholder-types-in-trait-definitions-with-associated-types) instead. +version of the book](../ch20-03-advanced-traits.html#specifying-placeholder-types-in-trait-definitions-with-associated-types) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/const-and-static.md b/first-edition/src/const-and-static.md index aa634112b2..7e667e50c6 100644 --- a/first-edition/src/const-and-static.md +++ b/first-edition/src/const-and-static.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-01-unsafe-rust.html#accessing-or-modifying-a-mutable-static-variable) instead. +version of the book](../ch20-01-unsafe-rust.html#accessing-or-modifying-a-mutable-static-variable) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/ffi.md b/first-edition/src/ffi.md index 2adaff9d8f..a8c3f818ee 100644 --- a/first-edition/src/ffi.md +++ b/first-edition/src/ffi.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-01-unsafe-rust.html#calling-rust-functions-from-other-languages) instead. +version of the book](../ch20-01-unsafe-rust.html#calling-rust-functions-from-other-languages) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/macros.md b/first-edition/src/macros.md index 6bafdc1e43..eb9871ca4a 100644 --- a/first-edition/src/macros.md +++ b/first-edition/src/macros.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-06-macros.html) instead. +version of the book](../ch20-06-macros.html) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/operators-and-overloading.md b/first-edition/src/operators-and-overloading.md index 921a2a6854..a13f444376 100644 --- a/first-edition/src/operators-and-overloading.md +++ b/first-edition/src/operators-and-overloading.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-03-advanced-traits.html#default-generic-type-parameters-and-operator-overloading) instead. +version of the book](../ch20-03-advanced-traits.html#default-generic-type-parameters-and-operator-overloading) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/patterns.md b/first-edition/src/patterns.md index d722d397e9..7bc6949b2f 100644 --- a/first-edition/src/patterns.md +++ b/first-edition/src/patterns.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-03-pattern-syntax.html) instead. +version of the book](../ch19-03-pattern-syntax.html) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/procedural-macros.md b/first-edition/src/procedural-macros.md index 9778383d80..3b683a9759 100644 --- a/first-edition/src/procedural-macros.md +++ b/first-edition/src/procedural-macros.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-06-macros.html?highlight=procedural#procedural-macros-for-generating-code-from-attributes) instead. +version of the book](../ch20-06-macros.html?highlight=procedural#procedural-macros-for-generating-code-from-attributes) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/raw-pointers.md b/first-edition/src/raw-pointers.md index c149da8681..a4cc68d474 100644 --- a/first-edition/src/raw-pointers.md +++ b/first-edition/src/raw-pointers.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer) instead. +version of the book](../ch20-01-unsafe-rust.html#dereferencing-a-raw-pointer) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/trait-objects.md b/first-edition/src/trait-objects.md index 871bad6140..a04d16b4b2 100644 --- a/first-edition/src/trait-objects.md +++ b/first-edition/src/trait-objects.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-02-trait-objects.html) instead. +version of the book](../ch18-02-trait-objects.html) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/type-aliases.md b/first-edition/src/type-aliases.md index 7ac51ff191..d79974e550 100644 --- a/first-edition/src/type-aliases.md +++ b/first-edition/src/type-aliases.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-04-advanced-types.html#creating-type-synonyms-with-type-aliases) instead. +version of the book](../ch20-04-advanced-types.html#creating-type-synonyms-with-type-aliases) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/unsafe.md b/first-edition/src/unsafe.md index be816dfd3d..187fef52e1 100644 --- a/first-edition/src/unsafe.md +++ b/first-edition/src/unsafe.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-01-unsafe-rust.html) instead. +version of the book](../ch20-01-unsafe-rust.html) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/first-edition/src/unsized-types.md b/first-edition/src/unsized-types.md index 4ec43ecadf..5fb51b1fd2 100644 --- a/first-edition/src/unsized-types.md +++ b/first-edition/src/unsized-types.md @@ -3,7 +3,7 @@ The first edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait) instead. +version of the book](../ch20-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait) instead. If you have an internet connection, you can [find a copy distributed with Rust diff --git a/listings/ch19-patterns-and-matching/listing-19-08/output.txt b/listings/ch19-patterns-and-matching/listing-19-08/output.txt index 6ce3dfc582..0ed34b7164 100644 --- a/listings/ch19-patterns-and-matching/listing-19-08/output.txt +++ b/listings/ch19-patterns-and-matching/listing-19-08/output.txt @@ -7,7 +7,7 @@ error[E0005]: refutable pattern in local binding | ^^^^^^^ pattern `None` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant - = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html + = note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html = note: the matched value is of type `Option` help: you might want to use `let else` to handle the variant that isn't matched | diff --git a/redirects/associated-types.md b/redirects/associated-types.md index b222f3298f..af052c160d 100644 --- a/redirects/associated-types.md +++ b/redirects/associated-types.md @@ -14,4 +14,4 @@ pub trait Iterator { --- You can find the latest version of this information -[here](ch19-03-advanced-traits.html#specifying-placeholder-types-in-trait-definitions-with-associated-types). \ No newline at end of file +[here](ch20-03-advanced-traits.html#specifying-placeholder-types-in-trait-definitions-with-associated-types). diff --git a/redirects/const-and-static.md b/redirects/const-and-static.md index b87bdd3831..60b13f62ac 100644 --- a/redirects/const-and-static.md +++ b/redirects/const-and-static.md @@ -16,6 +16,6 @@ static HELLO_WORLD: &str = "Hello, world!"; You can find the latest version about constants [here](ch03-01-variables-and-mutability.html#constants), and about statics -[here](ch19-01-unsafe-rust.html#accessing-or-modifying-a-mutable-static-variable). +[here](ch20-01-unsafe-rust.html#accessing-or-modifying-a-mutable-static-variable). diff --git a/redirects/ffi.md b/redirects/ffi.md index 20ed3963ef..63308ab1de 100644 --- a/redirects/ffi.md +++ b/redirects/ffi.md @@ -20,4 +20,4 @@ fn main() { --- You can find the latest version of this information -[here](ch19-01-unsafe-rust.html#using-extern-functions-to-call-external-code) \ No newline at end of file +[here](ch20-01-unsafe-rust.html#using-extern-functions-to-call-external-code) diff --git a/redirects/macros.md b/redirects/macros.md index 08217d115d..828d484dd6 100644 --- a/redirects/macros.md +++ b/redirects/macros.md @@ -25,6 +25,6 @@ Here are the relevant sections in the new and old books: [1]: https://doc.rust-lang.org/1.30.0/book/first-edition/macros.html -[2]: ch19-06-macros.html +[2]: ch20-06-macros.html [3]: https://rustbyexample.com/macros.html [4]: ../reference/macros-by-example.html diff --git a/redirects/match.md b/redirects/match.md index fd28ba8dea..5bcbc89495 100644 --- a/redirects/match.md +++ b/redirects/match.md @@ -34,5 +34,5 @@ Here are the relevant sections in the new and old books: [1]: https://doc.rust-lang.org/1.30.0/book/first-edition/match.html [2]: ch06-02-match.html -[3]: ch18-00-patterns.html +[3]: ch19-00-patterns.html diff --git a/redirects/operators-and-overloading.md b/redirects/operators-and-overloading.md index ff9a33048a..3a61fbabc4 100644 --- a/redirects/operators-and-overloading.md +++ b/redirects/operators-and-overloading.md @@ -33,4 +33,4 @@ fn main() { --- You can find the latest version of this information -[here](ch19-03-advanced-traits.html). +[here](ch20-03-advanced-traits.html). diff --git a/redirects/procedural-macros.md b/redirects/procedural-macros.md index bf6665f1a6..07657f6c88 100644 --- a/redirects/procedural-macros.md +++ b/redirects/procedural-macros.md @@ -16,6 +16,6 @@ You can check out other resources that describe macros. [1]: https://doc.rust-lang.org/1.30.0/book/first-edition/procedural-macros.html -[2]: ch19-06-macros.html +[2]: ch20-06-macros.html [3]: ../proc_macro/index.html [4]: ../reference/procedural-macros.html diff --git a/redirects/raw-pointers.md b/redirects/raw-pointers.md index 773f3abc48..4076907b5c 100644 --- a/redirects/raw-pointers.md +++ b/redirects/raw-pointers.md @@ -14,4 +14,4 @@ let r2 = &mut num as *mut i32; --- You can find the latest version of this information -[here](ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer) \ No newline at end of file +[here](ch20-01-unsafe-rust.html#dereferencing-a-raw-pointer) diff --git a/redirects/trait-objects.md b/redirects/trait-objects.md index 3200e26a15..44ca328235 100644 --- a/redirects/trait-objects.md +++ b/redirects/trait-objects.md @@ -65,4 +65,4 @@ Here are the relevant sections in the new and old books: [1]: https://doc.rust-lang.org/1.30.0/book/first-edition/trait-objects.html -[2]: ch17-02-trait-objects.html +[2]: ch18-02-trait-objects.html diff --git a/redirects/traits.md b/redirects/traits.md index dcb577e97b..b36ede6640 100644 --- a/redirects/traits.md +++ b/redirects/traits.md @@ -21,4 +21,4 @@ Here are the relevant sections in the new and old books: [1]: https://doc.rust-lang.org/1.30.0/book/first-edition/traits.html [2]: ch10-02-traits.html -[3]: ch19-03-advanced-traits.html +[3]: ch20-03-advanced-traits.html diff --git a/redirects/type-aliases.md b/redirects/type-aliases.md index 85cd4c9ecc..84f94e41e9 100644 --- a/redirects/type-aliases.md +++ b/redirects/type-aliases.md @@ -11,4 +11,4 @@ type Kilometers = i32; --- You can find the latest version of this information -[here](ch19-04-advanced-types.html#creating-type-synonyms-with-type-aliases). \ No newline at end of file +[here](ch20-04-advanced-types.html#creating-type-synonyms-with-type-aliases). diff --git a/redirects/ufcs.md b/redirects/ufcs.md index 2959c06bd0..684c02ec77 100644 --- a/redirects/ufcs.md +++ b/redirects/ufcs.md @@ -45,4 +45,4 @@ fn main() { --- You can find the latest version of this information -[here](ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name). \ No newline at end of file +[here](ch20-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name). diff --git a/redirects/unsafe.md b/redirects/unsafe.md index 8628c7aa95..94ee8ad777 100644 --- a/redirects/unsafe.md +++ b/redirects/unsafe.md @@ -14,5 +14,5 @@ Here are the relevant sections in the new and old books: [1]: https://doc.rust-lang.org/1.30.0/book/first-edition/unsafe.html -[2]: ch19-01-unsafe-rust.html +[2]: ch20-01-unsafe-rust.html [3]: ../nomicon/index.html diff --git a/redirects/unsized-types.md b/redirects/unsized-types.md index bd9582cbac..6e8d19da4a 100644 --- a/redirects/unsized-types.md +++ b/redirects/unsized-types.md @@ -15,4 +15,4 @@ fn generic(t: &T) { --- You can find the latest version of this information -[here](ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait). \ No newline at end of file +[here](ch20-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait). diff --git a/second-edition/src/appendix-04-macros.md b/second-edition/src/appendix-04-macros.md index 2798b5d50a..dfcdcec07c 100644 --- a/second-edition/src/appendix-04-macros.md +++ b/second-edition/src/appendix-04-macros.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-06-macros.html) instead. +version of the book](../ch20-06-macros.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/appendix-04-macros.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/appendix-04-macros.html). diff --git a/second-edition/src/ch17-00-oop.md b/second-edition/src/ch17-00-oop.md index 752130915e..e3633405f1 100644 --- a/second-edition/src/ch17-00-oop.md +++ b/second-edition/src/ch17-00-oop.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-00-oop.html) instead. +version of the book](../ch18-00-oop.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch17-00-oop.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch17-00-oop.html). diff --git a/second-edition/src/ch17-01-what-is-oo.md b/second-edition/src/ch17-01-what-is-oo.md index 82c1ed8f9c..a705d19416 100644 --- a/second-edition/src/ch17-01-what-is-oo.md +++ b/second-edition/src/ch17-01-what-is-oo.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-01-what-is-oo.html) instead. +version of the book](../ch18-01-what-is-oo.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch17-01-what-is-oo.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch17-01-what-is-oo.html). diff --git a/second-edition/src/ch17-02-trait-objects.md b/second-edition/src/ch17-02-trait-objects.md index 35f0c18835..16dad6368e 100644 --- a/second-edition/src/ch17-02-trait-objects.md +++ b/second-edition/src/ch17-02-trait-objects.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch17-02-trait-objects.html) instead. +version of the book](../ch18-02-trait-objects.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch17-02-trait-objects.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch17-02-trait-objects.html). diff --git a/second-edition/src/ch18-01-all-the-places-for-patterns.md b/second-edition/src/ch18-01-all-the-places-for-patterns.md index 0374a9a883..4a76aded0a 100644 --- a/second-edition/src/ch18-01-all-the-places-for-patterns.md +++ b/second-edition/src/ch18-01-all-the-places-for-patterns.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-01-all-the-places-for-patterns.html) instead. +version of the book](../ch19-01-all-the-places-for-patterns.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch18-01-all-the-places-for-patterns.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch18-01-all-the-places-for-patterns.html). diff --git a/second-edition/src/ch18-02-refutability.md b/second-edition/src/ch18-02-refutability.md index 2ef5206afd..768df16b25 100644 --- a/second-edition/src/ch18-02-refutability.md +++ b/second-edition/src/ch18-02-refutability.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-02-refutability.html) instead. +version of the book](../ch19-02-refutability.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch18-02-refutability.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch18-02-refutability.html). diff --git a/second-edition/src/ch18-03-pattern-syntax.md b/second-edition/src/ch18-03-pattern-syntax.md index 31c5f79203..08676091e1 100644 --- a/second-edition/src/ch18-03-pattern-syntax.md +++ b/second-edition/src/ch18-03-pattern-syntax.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch18-03-pattern-syntax.html) instead. +version of the book](../ch19-03-pattern-syntax.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch18-03-pattern-syntax.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch18-03-pattern-syntax.html). diff --git a/second-edition/src/ch19-00-advanced-features.md b/second-edition/src/ch19-00-advanced-features.md index f6df05f0aa..3633c0548e 100644 --- a/second-edition/src/ch19-00-advanced-features.md +++ b/second-edition/src/ch19-00-advanced-features.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-00-advanced-features.html) instead. +version of the book](../ch20-00-advanced-features.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-00-advanced-features.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-00-advanced-features.html). diff --git a/second-edition/src/ch19-01-unsafe-rust.md b/second-edition/src/ch19-01-unsafe-rust.md index 8a9a29c096..0e740ce03d 100644 --- a/second-edition/src/ch19-01-unsafe-rust.md +++ b/second-edition/src/ch19-01-unsafe-rust.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-01-unsafe-rust.html) instead. +version of the book](../ch20-01-unsafe-rust.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-01-unsafe-rust.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-01-unsafe-rust.html). diff --git a/second-edition/src/ch19-03-advanced-traits.md b/second-edition/src/ch19-03-advanced-traits.md index cc8433fb38..56b9c7e662 100644 --- a/second-edition/src/ch19-03-advanced-traits.md +++ b/second-edition/src/ch19-03-advanced-traits.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-03-advanced-traits.html) instead. +version of the book](../ch20-03-advanced-traits.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-03-advanced-traits.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-03-advanced-traits.html). diff --git a/second-edition/src/ch19-04-advanced-types.md b/second-edition/src/ch19-04-advanced-types.md index 5081457292..c217a12b5a 100644 --- a/second-edition/src/ch19-04-advanced-types.md +++ b/second-edition/src/ch19-04-advanced-types.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-04-advanced-types.html) instead. +version of the book](../ch20-04-advanced-types.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-04-advanced-types.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-04-advanced-types.html). diff --git a/second-edition/src/ch19-05-advanced-functions-and-closures.md b/second-edition/src/ch19-05-advanced-functions-and-closures.md index 18d369c60d..6c296b9efe 100644 --- a/second-edition/src/ch19-05-advanced-functions-and-closures.md +++ b/second-edition/src/ch19-05-advanced-functions-and-closures.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-05-advanced-functions-and-closures.html) instead. +version of the book](../ch20-05-advanced-functions-and-closures.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-05-advanced-functions-and-closures.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch19-05-advanced-functions-and-closures.html). diff --git a/second-edition/src/ch20-00-final-project-a-web-server.md b/second-edition/src/ch20-00-final-project-a-web-server.md index 059d6824c3..0c99ac623b 100644 --- a/second-edition/src/ch20-00-final-project-a-web-server.md +++ b/second-edition/src/ch20-00-final-project-a-web-server.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch20-00-final-project-a-web-server.html) instead. +version of the book](../ch21-00-final-project-a-web-server.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch20-00-final-project-a-web-server.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch20-00-final-project-a-web-server.html). diff --git a/second-edition/src/ch20-01-single-threaded.md b/second-edition/src/ch20-01-single-threaded.md index 5ff97a2ee1..a06b0cbc1a 100644 --- a/second-edition/src/ch20-01-single-threaded.md +++ b/second-edition/src/ch20-01-single-threaded.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch20-01-single-threaded.html) instead. +version of the book](../ch21-01-single-threaded.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch20-01-single-threaded.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch20-01-single-threaded.html). diff --git a/second-edition/src/ch20-02-multithreaded.md b/second-edition/src/ch20-02-multithreaded.md index 0695d2451c..8826bd9f1a 100644 --- a/second-edition/src/ch20-02-multithreaded.md +++ b/second-edition/src/ch20-02-multithreaded.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch20-02-multithreaded.html) instead. +version of the book](../ch21-02-multithreaded.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch20-02-multithreaded.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch20-02-multithreaded.html). diff --git a/second-edition/src/ch20-03-graceful-shutdown-and-cleanup.md b/second-edition/src/ch20-03-graceful-shutdown-and-cleanup.md index eb7ed59879..457b294f90 100644 --- a/second-edition/src/ch20-03-graceful-shutdown-and-cleanup.md +++ b/second-edition/src/ch20-03-graceful-shutdown-and-cleanup.md @@ -3,8 +3,8 @@ The second edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch20-03-graceful-shutdown-and-cleanup.html) instead. +version of the book](../ch21-03-graceful-shutdown-and-cleanup.html) instead. If you have an internet connection, you can [find a copy distributed with Rust -1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch20-03-graceful-shutdown-and-cleanup.html). \ No newline at end of file +1.30](https://doc.rust-lang.org/1.30.0/book/second-edition/ch20-03-graceful-shutdown-and-cleanup.html). From 809b24a21b1da5479f0339a0cf21900fa37454ac Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 3 Oct 2024 08:24:47 -0600 Subject: [PATCH 625/720] Fix another listing number --- src/ch20-01-unsafe-rust.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index f444ce9f20..4aadf82d83 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -136,7 +136,7 @@ dereference operator `*` on a raw pointer that requires an `unsafe` block. Creating a pointer does no harm; it’s only when we try to access the value that it points at that we might end up dealing with an invalid value. -Note also that in Listing 20-1 and 19-3, we created `*const i32` and `*mut i32` +Note also that in Listing 20-1 and 20-3, we created `*const i32` and `*mut i32` raw pointers that both pointed to the same memory location, where `num` is stored. If we instead tried to create an immutable and a mutable reference to `num`, the code would not have compiled because Rust’s ownership rules don’t From fc62e4055b100bf05ff30ea87e713367187eaaa2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 8 Oct 2024 11:45:06 -0600 Subject: [PATCH 626/720] Fix one more listing number --- src/ch20-01-unsafe-rust.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 4aadf82d83..dfdef6c393 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -175,7 +175,7 @@ We must call the `dangerous` function within a separate `unsafe` block. If we try to call `dangerous` without the `unsafe` block, we’ll get an error: ```console -{{#include ../listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt}} +{{#include ../listings/ch20-advanced-features/output-only-01-missing-unsafe/output.txt}} ``` With the `unsafe` block, we’re asserting to Rust that we’ve read the function’s From 3e4459297a89fc4ebdeb92e7bdeaac91b31b6dbe Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 9 Oct 2024 07:24:09 -0600 Subject: [PATCH 627/720] Adopt for Ch. 18 --- src/ch18-01-what-is-oo.md | 11 +++--- src/ch18-02-trait-objects.md | 40 ++++++++------------ src/ch18-03-oo-design-patterns.md | 61 +++++++++++++------------------ 3 files changed, 46 insertions(+), 66 deletions(-) diff --git a/src/ch18-01-what-is-oo.md b/src/ch18-01-what-is-oo.md index f9f22a3a00..8e81826b9e 100644 --- a/src/ch18-01-what-is-oo.md +++ b/src/ch18-01-what-is-oo.md @@ -44,15 +44,13 @@ on demand whenever anyone needs it. In other words, `AveragedCollection` will cache the calculated average for us. Listing 18-1 has the definition of the `AveragedCollection` struct: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-01/src/lib.rs}} ``` -Listing 18-1: An `AveragedCollection` struct that -maintains a list of integers and the average of the items in the -collection + The struct is marked `pub` so that other code can use it, but the fields within the struct remain private. This is important in this case because we want to @@ -60,14 +58,15 @@ ensure that whenever a value is added or removed from the list, the average is also updated. We do this by implementing `add`, `remove`, and `average` methods on the struct, as shown in Listing 18-2: ++ Filename: src/lib.rs ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-02/src/lib.rs:here}} ``` -Listing 18-2: Implementations of the public methods -`add`, `remove`, and `average` on `AveragedCollection` + The public methods `add`, `remove`, and `average` are the only ways to access or modify data in an instance of `AveragedCollection`. When an item is added diff --git a/src/ch18-02-trait-objects.md b/src/ch18-02-trait-objects.md index 751fdaa033..6f05a4e0df 100644 --- a/src/ch18-02-trait-objects.md +++ b/src/ch18-02-trait-objects.md @@ -66,13 +66,13 @@ behavior. Listing 18-3 shows how to define a trait named `Draw` with one method named `draw`: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-03/src/lib.rs}} ``` -Listing 18-3: Definition of the `Draw` trait + This syntax should look familiar from our discussions on how to define traits in Chapter 10. Next comes some new syntax: Listing 18-4 defines a struct named @@ -80,27 +80,24 @@ in Chapter 10. Next comes some new syntax: Listing 18-4 defines a struct named `Box`, which is a trait object; it’s a stand-in for any type inside a `Box` that implements the `Draw` trait. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-04/src/lib.rs:here}} ``` -Listing 18-4: Definition of the `Screen` struct with a -`components` field holding a vector of trait objects that implement the `Draw` -trait + On the `Screen` struct, we’ll define a method named `run` that will call the `draw` method on each of its `components`, as shown in Listing 18-5: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-05/src/lib.rs:here}} ``` -Listing 18-5: A `run` method on `Screen` that calls the -`draw` method on each component + This works differently from defining a struct that uses a generic type parameter with trait bounds. A generic type parameter can only be substituted @@ -109,14 +106,13 @@ concrete types to fill in for the trait object at runtime. For example, we could have defined the `Screen` struct using a generic type and a trait bound as in Listing 18-6: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-06/src/lib.rs:here}} ``` -Listing 18-6: An alternate implementation of the `Screen` -struct and its `run` method using generics and trait bounds + This restricts us to a `Screen` instance that has a list of components all of type `Button` or all of type `TextField`. If you’ll only ever have homogeneous @@ -136,14 +132,13 @@ of this book, so the `draw` method won’t have any useful implementation in its body. To imagine what the implementation might look like, a `Button` struct might have fields for `width`, `height`, and `label`, as shown in Listing 18-7: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-07/src/lib.rs:here}} ``` -Listing 18-7: A `Button` struct that implements the -`Draw` trait + The `width`, `height`, and `label` fields on `Button` will differ from the fields on other components; for example, a `TextField` type might have those @@ -159,14 +154,13 @@ If someone using our library decides to implement a `SelectBox` struct that has `width`, `height`, and `options` fields, they implement the `Draw` trait on the `SelectBox` type as well, as shown in Listing 18-8: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch18-oop/listing-18-08/src/main.rs:here}} ``` -Listing 18-8: Another crate using `gui` and implementing -the `Draw` trait on a `SelectBox` struct + Our library’s user can now write their `main` function to create a `Screen` instance. To the `Screen` instance, they can add a `SelectBox` and a `Button` @@ -174,14 +168,13 @@ by putting each in a `Box` to become a trait object. They can then call the `run` method on the `Screen` instance, which will call `draw` on each of the components. Listing 18-9 shows this implementation: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch18-oop/listing-18-09/src/main.rs:here}} ``` -Listing 18-9: Using trait objects to store values of -different types that implement the same trait + When we wrote the library, we didn’t know that someone might add the `SelectBox` type, but our `Screen` implementation was able to operate on the @@ -208,14 +201,13 @@ our code if the values don’t implement the traits that the trait objects need. For example, Listing 18-10 shows what happens if we try to create a `Screen` with a `String` as a component: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch18-oop/listing-18-10/src/main.rs}} ``` -Listing 18-10: Attempting to use a type that doesn’t -implement the trait object’s trait + We’ll get this error because `String` doesn’t implement the `Draw` trait: diff --git a/src/ch18-03-oo-design-patterns.md b/src/ch18-03-oo-design-patterns.md index 9a73091cda..683528c5db 100644 --- a/src/ch18-03-oo-design-patterns.md +++ b/src/ch18-03-oo-design-patterns.md @@ -40,14 +40,13 @@ Listing 18-11 shows this workflow in code form: this is an example usage of the API we’ll implement in a library crate named `blog`. This won’t compile yet because we haven’t implemented the `blog` crate. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch18-oop/listing-18-11/src/main.rs:all}} ``` -Listing 18-11: Code that demonstrates the desired -behavior we want our `blog` crate to have + We want to allow the user to create a new draft blog post with `Post::new`. We want to allow text to be added to the blog post. If we try to get the post’s @@ -84,15 +83,13 @@ Then `Post` will hold a trait object of `Box` inside an `Option` in a private field named `state` to hold the state object. You’ll see why the `Option` is necessary in a bit. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-12/src/lib.rs}} ``` -Listing 18-12: Definition of a `Post` struct and a `new` -function that creates a new `Post` instance, a `State` trait, and a `Draft` -struct + The `State` trait defines the behavior shared by different post states. The state objects are `Draft`, `PendingReview`, and `Published`, and they will all @@ -117,14 +114,13 @@ the `content` field’s data is read. The `add_text` method is pretty straightforward, so let’s add the implementation in Listing 18-13 to the `impl Post` block: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-13/src/lib.rs:here}} ``` -Listing 18-13: Implementing the `add_text` method to add -text to a post’s `content` + The `add_text` method takes a mutable reference to `self`, because we’re changing the `Post` instance that we’re calling `add_text` on. We then call @@ -145,14 +141,13 @@ once we implement the ability to change a post’s state so it can be published. So far, posts can only be in the draft state, so the post content should always be empty. Listing 18-14 shows this placeholder implementation: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-14/src/lib.rs:here}} ``` -Listing 18-14: Adding a placeholder implementation for -the `content` method on `Post` that always returns an empty string slice + With this added `content` method, everything in Listing 18-11 up to line 7 works as intended. @@ -162,14 +157,13 @@ works as intended. Next, we need to add functionality to request a review of a post, which should change its state from `Draft` to `PendingReview`. Listing 18-15 shows this code: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-15/src/lib.rs:here}} ``` -Listing 18-15: Implementing `request_review` methods on -`Post` and the `State` trait + We give `Post` a public method named `request_review` that will take a mutable reference to `self`. Then we call an internal `request_review` method on the @@ -222,14 +216,13 @@ The `approve` method will be similar to the `request_review` method: it will set `state` to the value that the current state says it should have when that state is approved, as shown in Listing 18-16: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-16/src/lib.rs:here}} ``` -Listing 18-16: Implementing the `approve` method on -`Post` and the `State` trait + We add the `approve` method to the `State` trait and add a new struct that implements `State`, the `Published` state. @@ -247,14 +240,13 @@ returned from `content` to depend on the current state of the `Post`, so we’re going to have the `Post` delegate to a `content` method defined on its `state`, as shown in Listing 18-17: -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch18-oop/listing-18-17/src/lib.rs:here}} ``` -Listing 18-17: Updating the `content` method on `Post` to -delegate to a `content` method on `State` + Because the goal is to keep all these rules inside the structs that implement `State`, we call a `content` method on the value in `state` and pass the post @@ -282,14 +274,13 @@ we need to add `content` to the `State` trait definition, and that is where we’ll put the logic for what content to return depending on which state we have, as shown in Listing 18-18: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-18/src/lib.rs:here}} ``` -Listing 18-18: Adding the `content` method to the `State` -trait + We add a default implementation for the `content` method that returns an empty string slice. That means we don’t need to implement `content` on the `Draft` @@ -383,12 +374,14 @@ draft posts where only published posts are allowed by issuing a compiler error. Let’s consider the first part of `main` in Listing 18-11: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch18-oop/listing-18-11/src/main.rs:here}} ``` + + We still enable the creation of new posts in the draft state using `Post::new` and the ability to add text to the post’s content. But instead of having a `content` method on a draft post that returns an empty string, we’ll make it so @@ -399,14 +392,13 @@ display draft post content in production, because that code won’t even compile Listing 18-19 shows the definition of a `Post` struct and a `DraftPost` struct, as well as methods on each: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-19/src/lib.rs}} ``` -Listing 18-19: A `Post` with a `content` method and a -`DraftPost` without a `content` method + Both the `Post` and `DraftPost` structs have a private `content` field that stores the blog post text. The structs no longer have the `state` field because @@ -435,15 +427,13 @@ these constraints by adding another struct, `PendingReviewPost`, defining the defining an `approve` method on `PendingReviewPost` to return a `Post`, as shown in Listing 18-20: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-20/src/lib.rs:here}} ``` -Listing 18-20: A `PendingReviewPost` that gets created by -calling `request_review` on `DraftPost` and an `approve` method that turns a -`PendingReviewPost` into a published `Post` + The `request_review` and `approve` methods take ownership of `self`, thus consuming the `DraftPost` and `PendingReviewPost` instances and transforming @@ -465,14 +455,13 @@ pending review posts’ contents be empty strings, nor do we need them: we can compile code that tries to use the content of posts in those states any longer. The updated code in `main` is shown in Listing 18-21: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch18-oop/listing-18-21/src/main.rs}} ``` -Listing 18-21: Modifications to `main` to use the new -implementation of the blog post workflow + The changes we needed to make to `main` to reassign `post` mean that this implementation doesn’t quite follow the object-oriented state pattern anymore: From 7335c653572885503f47e85679e16a2e3736746b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 9 Oct 2024 08:01:17 -0600 Subject: [PATCH 628/720] Adopt for Ch. 19 --- src/ch19-01-all-the-places-for-patterns.md | 35 ++++---- src/ch19-02-refutability.md | 15 ++-- src/ch19-03-pattern-syntax.md | 92 +++++++++++----------- 3 files changed, 75 insertions(+), 67 deletions(-) diff --git a/src/ch19-01-all-the-places-for-patterns.md b/src/ch19-01-all-the-places-for-patterns.md index 92578802e5..30e7135c53 100644 --- a/src/ch19-01-all-the-places-for-patterns.md +++ b/src/ch19-01-all-the-places-for-patterns.md @@ -63,14 +63,13 @@ a series of checks for several conditions. For this example, we’ve created variables with hardcoded values that a real program might receive from user input. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-01/src/main.rs}} ``` -Listing 19-1: Mixing `if let`, `else if`, `else if let`, -and `else` + If the user specifies a favorite color, that color is used as the background. If no favorite color is specified and today is Tuesday, the background color is @@ -103,12 +102,13 @@ Similar in construction to `if let`, the `while let` conditional loop allows a 19-2 we code a `while let` loop that uses a vector as a stack and prints the values in the vector in the opposite order in which they were pushed. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-02/src/main.rs:here}} ``` -Listing 19-2: Using a `while let` loop to print values -for as long as `stack.pop()` returns `Some` + This example prints 3, 2, and then 1. The `pop` method takes the last element out of the vector and returns `Some(value)`. If the vector is empty, `pop` @@ -123,12 +123,13 @@ pattern. For example, in `for x in y` the `x` is the pattern. Listing 19-3 demonstrates how to use a pattern in a `for` loop to destructure, or break apart, a tuple as part of the `for` loop. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-03/src/main.rs:here}} ``` -Listing 19-3: Using a pattern in a `for` loop to -destructure a tuple + The code in Listing 19-3 will print the following: @@ -171,12 +172,13 @@ effectively means “bind everything to the variable `x`, whatever the value is. To see the pattern matching aspect of `let` more clearly, consider Listing 19-4, which uses a pattern with `let` to destructure a tuple. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-04/src/main.rs:here}} ``` -Listing 19-4: Using a pattern to destructure a tuple and -create three variables at once + Here, we match a tuple against a pattern. Rust compares the value `(1, 2, 3)` to the pattern `(x, y, z)` and sees that the value matches the pattern, so Rust @@ -188,12 +190,13 @@ in the tuple, the overall type won’t match and we’ll get a compiler error. F example, Listing 19-5 shows an attempt to destructure a tuple with three elements into two variables, which won’t work. ++ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-05/src/main.rs:here}} ``` -Listing 19-5: Incorrectly constructing a pattern whose -variables don’t match the number of elements in the tuple + Attempting to compile this code results in this type error: @@ -214,25 +217,25 @@ Function parameters can also be patterns. The code in Listing 19-6, which declares a function named `foo` that takes one parameter named `x` of type `i32`, should by now look familiar. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-06/src/main.rs:here}} ``` -Listing 19-6: A function signature uses patterns in the -parameters + The `x` part is a pattern! As we did with `let`, we could match a tuple in a function’s arguments to the pattern. Listing 19-7 splits the values in a tuple as we pass it to a function. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-07/src/main.rs}} ``` -Listing 19-7: A function with parameters that destructure -a tuple + This code prints `Current location: (3, 5)`. The values `&(3, 5)` match the pattern `&(x, y)`, so `x` is the value `3` and `y` is the value `5`. diff --git a/src/ch19-02-refutability.md b/src/ch19-02-refutability.md index a648d46a17..3601f5d14f 100644 --- a/src/ch19-02-refutability.md +++ b/src/ch19-02-refutability.md @@ -27,12 +27,13 @@ where Rust requires an irrefutable pattern and vice versa. Listing 19-8 shows a `let` statement, but for the pattern we’ve specified `Some(x)`, a refutable pattern. As you might expect, this code will not compile. ++ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-08/src/main.rs:here}} ``` -Listing 19-8: Attempting to use a refutable pattern with -`let` + If `some_option_value` was a `None` value, it would fail to match the pattern `Some(x)`, meaning the pattern is refutable. However, the `let` statement can @@ -53,24 +54,26 @@ can use `if let`. Then if the pattern doesn’t match, the code will just skip the code in the curly brackets, giving it a way to continue validly. Listing 19-9 shows how to fix the code in Listing 19-8. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-09/src/main.rs:here}} ``` -Listing 19-9: Using `if let` and a block with refutable -patterns instead of `let` + We’ve given the code an out! This code is perfectly valid now. However, if we give `if let` an irrefutable pattern (a pattern that will always match), such as `x`, as shown in Listing 19-10, the compiler will give a warning. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-10/src/main.rs:here}} ``` -Listing 19-10: Attempting to use an irrefutable pattern -with `if let` + Rust complains that it doesn’t make sense to use `if let` with an irrefutable pattern: diff --git a/src/ch19-03-pattern-syntax.md b/src/ch19-03-pattern-syntax.md index afdcc4246d..4a471bd670 100644 --- a/src/ch19-03-pattern-syntax.md +++ b/src/ch19-03-pattern-syntax.md @@ -29,14 +29,13 @@ value `Some(5)` and a variable `y` with the value `10`. We then create a `println!` at the end, and try to figure out what the code will print before running this code or reading further. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-11/src/main.rs:here}} ``` -Listing 19-11: A `match` expression with an arm that -introduces a shadowed variable `y` + Let’s walk through what happens when the `match` expression runs. The pattern in the first match arm doesn’t match the defined value of `x`, so the code @@ -119,14 +118,13 @@ different parts of these values. Let’s walk through each value. Listing 19-12 shows a `Point` struct with two fields, `x` and `y`, that we can break apart using a pattern with a `let` statement. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-12/src/main.rs}} ``` -Listing 19-12: Destructuring a struct’s fields into -separate variables + This code creates the variables `a` and `b` that match the values of the `x` and `y` fields of the `p` struct. This example shows that the names of the @@ -140,14 +138,13 @@ from the pattern will have the same names. Listing 19-13 behaves in the same way as the code in Listing 19-12, but the variables created in the `let` pattern are `x` and `y` instead of `a` and `b`. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-13/src/main.rs}} ``` -Listing 19-13: Destructuring struct fields using struct -field shorthand + This code creates the variables `x` and `y` that match the `x` and `y` fields of the `p` variable. The outcome is that the variables `x` and `y` contain the @@ -162,14 +159,13 @@ In Listing 19-14, we have a `match` expression that separates `Point` values into three cases: points that lie directly on the `x` axis (which is true when `y = 0`), on the `y` axis (`x = 0`), or neither. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-14/src/main.rs:here}} ``` -Listing 19-14: Destructuring and matching literal values -in one pattern + The first arm will match any point that lies on the `x` axis by specifying that the `y` field matches if its value matches the literal `0`. The pattern still @@ -195,14 +191,13 @@ corresponds to the way the data stored within the enum is defined. As an example, in Listing 19-15 we use the `Message` enum from Listing 6-2 and write a `match` with patterns that will destructure each inner value. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-15/src/main.rs}} ``` -Listing 19-15: Destructuring enum variants that hold -different kinds of values + This code will print `Change the color to red 0, green 160, and blue 255`. Try changing the value of `msg` to see the code from the other arms run. @@ -230,11 +225,13 @@ but matching can work on nested items too! For example, we can refactor the code in Listing 19-15 to support RGB and HSV colors in the `ChangeColor` message, as shown in Listing 19-16. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-16/src/main.rs}} ``` -Listing 19-16: Matching on nested enums + The pattern of the first arm in the `match` expression matches a `Message::ChangeColor` enum variant that contains a `Color::Rgb` variant; then @@ -276,13 +273,13 @@ not bind to the value. This is especially useful as the last arm in a `match` expression, but we can also use it in any pattern, including function parameters, as shown in Listing 19-17. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-17/src/main.rs}} ``` -Listing 19-17: Using `_` in a function signature + This code will completely ignore the value `3` passed as the first argument, and will print `This code only uses the y parameter: 4`. @@ -304,13 +301,13 @@ responsible for managing a setting’s value. The business requirements are that the user should not be allowed to overwrite an existing customization of a setting but can unset the setting and give it a value if it is currently unset. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-18/src/main.rs:here}} ``` -Listing 19-18: Using an underscore within patterns that -match `Some` variants when we don’t need to use the value inside the -`Some` + This code will print `Can't overwrite an existing customized value` and then `setting is Some(5)`. In the first match arm, we don’t need to match on or use @@ -327,11 +324,13 @@ We can also use underscores in multiple places within one pattern to ignore particular values. Listing 19-19 shows an example of ignoring the second and fourth values in a tuple of five items. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-19/src/main.rs:here}} ``` -Listing 19-19: Ignoring multiple parts of a tuple + This code will print `Some numbers: 2, 8, 32`, and the values 4 and 16 will be ignored. @@ -346,14 +345,13 @@ not to warn you about the unused variable by starting the name of the variable with an underscore. In Listing 19-20, we create two unused variables, but when we compile this code, we should only get a warning about one of them. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-20/src/main.rs}} ``` -Listing 19-20: Starting a variable name with an -underscore to avoid getting unused variable warnings + Here we get a warning about not using the variable `y`, but we don’t get a warning about not using `_x`. @@ -363,24 +361,26 @@ that starts with an underscore. The syntax `_x` still binds the value to the variable, whereas `_` doesn’t bind at all. To show a case where this distinction matters, Listing 19-21 will provide us with an error. ++ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-21/src/main.rs:here}} ``` -Listing 19-21: An unused variable starting with an -underscore still binds the value, which might take ownership of the value + We’ll receive an error because the `s` value will still be moved into `_s`, which prevents us from using `s` again. However, using the underscore by itself doesn’t ever bind to the value. Listing 19-22 will compile without any errors because `s` doesn’t get moved into `_`. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-22/src/main.rs:here}} ``` -Listing 19-22: Using an underscore does not bind the -value + This code works just fine because we never bind `s` to anything; it isn’t moved. @@ -394,12 +394,13 @@ explicitly matched in the rest of the pattern. In Listing 19-23, we have a `match` expression, we want to operate only on the `x` coordinate and ignore the values in the `y` and `z` fields. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-23/src/main.rs:here}} ``` -Listing 19-23: Ignoring all fields of a `Point` except -for `x` by using `..` + We list the `x` value and then just include the `..` pattern. This is quicker than having to list `y: _` and `z: _`, particularly when we’re working with @@ -409,14 +410,13 @@ relevant. The syntax `..` will expand to as many values as it needs to be. Listing 19-24 shows how to use `..` with a tuple. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-24/src/main.rs}} ``` -Listing 19-24: Matching only the first and last values in -a tuple and ignoring all other values + In this code, the first and last value are matched with `first` and `last`. The `..` will match and ignore everything in the middle. @@ -426,14 +426,13 @@ intended for matching and which should be ignored, Rust will give us an error. Listing 19-25 shows an example of using `..` ambiguously, so it will not compile. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-25/src/main.rs}} ``` -Listing 19-25: An attempt to use `..` in an ambiguous -way + When we compile this example, we get this error: @@ -459,11 +458,13 @@ The condition can use variables created in the pattern. Listing 19-26 shows a `match` where the first arm has the pattern `Some(x)` and also has a match guard of `if x % 2 == 0` (which will be true if the number is even). ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-26/src/main.rs:here}} ``` -Listing 19-26: Adding a match guard to a pattern + This example will print `The number 4 is even`. When `num` is compared to the pattern in the first arm, it matches, because `Some(4)` matches `Some(x)`. Then @@ -487,14 +488,13 @@ pattern in the `match` expression instead of using the variable outside the outer variable. Listing 19-27 shows how we can use a match guard to fix this problem. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-27/src/main.rs}} ``` -Listing 19-27: Using a match guard to test for equality -with an outer variable + This code will now print `Default case, x = Some(5)`. The pattern in the second match arm doesn’t introduce a new variable `y` that would shadow the outer `y`, @@ -515,12 +515,13 @@ guard. The important part of this example is that the `if y` match guard applies to `4`, `5`, *and* `6`, even though it might look like `if y` only applies to `6`. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-28/src/main.rs:here}} ``` -Listing 19-28: Combining multiple patterns with a match -guard + The match condition states that the arm only matches if the value of `x` is equal to `4`, `5`, or `6` *and* if `y` is `true`. When this code runs, the @@ -555,12 +556,13 @@ want to bind the value to the variable `id_variable` so we can use it in the code associated with the arm. We could name this variable `id`, the same as the field, but for this example we’ll use a different name. ++ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-29/src/main.rs:here}} ``` -Listing 19-29: Using `@` to bind to a value in a pattern -while also testing it + This example will print `Found an id in range: 5`. By specifying `id_variable @` before the range `3..=7`, we’re capturing whatever value matched the range From bfcebbb2ca3617657826eea988efd268aba08f3b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 9 Oct 2024 09:28:11 -0600 Subject: [PATCH 629/720] Adopt for Ch. 20 --- src/ch20-01-unsafe-rust.md | 54 +++++++------ src/ch20-03-advanced-traits.md | 76 +++++++++---------- src/ch20-04-advanced-types.md | 14 ++-- ...ch20-05-advanced-functions-and-closures.md | 5 +- src/ch20-06-macros.md | 38 +++++----- 5 files changed, 95 insertions(+), 92 deletions(-) diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index dfdef6c393..ae4e674f1e 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -91,11 +91,13 @@ interface with another language or hardware where Rust’s guarantees don’t ap Listing 20-1 shows how to create an immutable and a mutable raw pointer from references. ++ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-01/src/main.rs:here}} ``` -Listing 20-1: Creating raw pointers from references + Notice that we don’t include the `unsafe` keyword in this code. We can create raw pointers in safe code; we just can’t dereference raw pointers outside an @@ -115,23 +117,25 @@ so there is no memory access, or the program might error with a segmentation fault. Usually, there is no good reason to write code like this, but it is possible. ++ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-02/src/main.rs:here}} ``` -Listing 20-2: Creating a raw pointer to an arbitrary -memory address + Recall that we can create raw pointers in safe code, but we can’t *dereference* raw pointers and read the data being pointed to. In Listing 20-3, we use the dereference operator `*` on a raw pointer that requires an `unsafe` block. ++ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-03/src/main.rs:here}} ``` -Listing 20-3: Dereferencing raw pointers within an -`unsafe` block + Creating a pointer does no harm; it’s only when we try to access the value that it points at that we might end up dealing with an invalid value. @@ -196,24 +200,26 @@ we might implement it. This safe method is defined on mutable slices: it takes one slice and makes it two by splitting the slice at the index given as an argument. Listing 20-4 shows how to use `split_at_mut`. ++ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-04/src/main.rs:here}} ``` -Listing 20-4: Using the safe `split_at_mut` -function + We can’t implement this function using only safe Rust. An attempt might look something like Listing 20-5, which won’t compile. For simplicity, we’ll implement `split_at_mut` as a function rather than a method and only for slices of `i32` values rather than for a generic type `T`. ++ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-05/src/main.rs:here}} ``` -Listing 20-5: An attempted implementation of -`split_at_mut` using only safe Rust + This function first gets the total length of the slice. Then it asserts that the index given as a parameter is within the slice by checking whether it’s @@ -240,12 +246,13 @@ know code is okay, but Rust doesn’t, it’s time to reach for unsafe code. Listing 20-6 shows how to use an `unsafe` block, a raw pointer, and some calls to unsafe functions to make the implementation of `split_at_mut` work. ++ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-06/src/main.rs:here}} ``` -Listing 20-6: Using unsafe code in the implementation of -the `split_at_mut` function + Recall from [“The Slice Type”][the-slice-type] section in Chapter 4 that slices are a pointer to some data and the length of the slice. @@ -282,12 +289,13 @@ In contrast, the use of `slice::from_raw_parts_mut` in Listing 20-7 would likely crash when the slice is used. This code takes an arbitrary memory location and creates a slice 10,000 items long. ++ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-07/src/main.rs:here}} ``` -Listing 20-7: Creating a slice from an arbitrary memory -location + We don’t own the memory at this arbitrary location, and there is no guarantee that the slice this code creates contains valid `i32` values. Attempting to use @@ -307,14 +315,13 @@ always unsafe to call from Rust code. The reason is that other languages don’t enforce Rust’s rules and guarantees, and Rust can’t check them, so responsibility falls on the programmer to ensure safety. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-08/src/main.rs}} ``` -Listing 20-8: Declaring and calling an `extern` function -defined in another language + Within the `extern "C"` block, we list the names and signatures of external functions from another language we want to call. The `"C"` part defines which @@ -357,14 +364,13 @@ In Rust, global variables are called *static* variables. Listing 20-9 shows an example declaration and use of a static variable with a string slice as a value. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-09/src/main.rs}} ``` -Listing 20-9: Defining and using an immutable static -variable + Static variables are similar to constants, which we discussed in the [“Differences Between Variables and @@ -383,14 +389,13 @@ variables can be mutable. Accessing and modifying mutable static variables is *unsafe*. Listing 20-10 shows how to declare, access, and modify a mutable static variable named `COUNTER`. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-10/src/main.rs}} ``` -Listing 20-10: Reading from or writing to a mutable -static variable is unsafe + As with regular variables, we specify mutability using the `mut` keyword. Any code that reads or writes from `COUNTER` must be within an `unsafe` block. This @@ -412,12 +417,13 @@ declare that a trait is `unsafe` by adding the `unsafe` keyword before `trait` and marking the implementation of the trait as `unsafe` too, as shown in Listing 20-11. ++ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-11/src/main.rs}} ``` -Listing 20-11: Defining and implementing an unsafe -trait + By using `unsafe impl`, we’re promising that we’ll uphold the invariants that the compiler can’t verify. diff --git a/src/ch20-03-advanced-traits.md b/src/ch20-03-advanced-traits.md index 7dc333e782..e411dd57de 100644 --- a/src/ch20-03-advanced-traits.md +++ b/src/ch20-03-advanced-traits.md @@ -25,12 +25,13 @@ for the type of the values the type implementing the `Iterator` trait is iterating over. The definition of the `Iterator` trait is as shown in Listing 20-12. ++ ```rust,noplayground {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-12/src/lib.rs}} ``` -Listing 20-12: The definition of the `Iterator` trait -that has an associated type `Item` + The type `Item` is a placeholder, and the `next` method’s definition shows that it will return values of type `Option`. Implementors of the @@ -43,21 +44,24 @@ handle. To examine the difference between the two concepts, we’ll look at an implementation of the `Iterator` trait on a type named `Counter` that specifies the `Item` type is `u32`: -Filename: src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch20-advanced-features/no-listing-22-iterator-on-counter/src/lib.rs:ch19}} ``` + + This syntax seems comparable to that of generics. So why not just define the `Iterator` trait with generics, as shown in Listing 20-13? ++ ```rust,noplayground {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-13/src/lib.rs}} ``` -Listing 20-13: A hypothetical definition of the -`Iterator` trait using generics + The difference is that when using generics, as in Listing 20-13, we must annotate the types in each implementation; because we can also implement @@ -98,14 +102,13 @@ example, in Listing 20-14 we overload the `+` operator to add two `Point` instances together. We do this by implementing the `Add` trait on a `Point` struct: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-14/src/main.rs}} ``` -Listing 20-14: Implementing the `Add` trait to overload -the `+` operator for `Point` instances + The `add` method adds the `x` values of two `Point` instances and the `y` values of two `Point` instances to create a new `Point`. The `Add` trait has an @@ -144,14 +147,13 @@ Pattern to Implement External Traits on External Types”][newtype] diff --git a/src/ch20-05-advanced-functions-and-closures.md b/src/ch20-05-advanced-functions-and-closures.md index ef6a6e46f7..70385af324 100644 --- a/src/ch20-05-advanced-functions-and-closures.md +++ b/src/ch20-05-advanced-functions-and-closures.md @@ -22,14 +22,13 @@ function `f` twice, passing it the `arg` value, then adds the two function call results together. The `main` function calls `do_twice` with the arguments `add_one` and `5`. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-27/src/main.rs}} ``` -Listing 20-27: Using the `fn` type to accept a function -pointer as an argument + This code prints `The answer is: 12`. We specify that the parameter `f` in `do_twice` is an `fn` that takes one parameter of type `i32` and returns an diff --git a/src/ch20-06-macros.md b/src/ch20-06-macros.md index 2406942df2..7900a015bc 100644 --- a/src/ch20-06-macros.md +++ b/src/ch20-06-macros.md @@ -75,14 +75,13 @@ because we wouldn’t know the number or type of values up front. Listing 20-28 shows a slightly simplified definition of the `vec!` macro. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-28/src/lib.rs}} ``` -Listing 20-28: A simplified version of the `vec!` macro -definition + > Note: The actual definition of the `vec!` macro in the standard library > includes code to preallocate the correct amount of memory up front. That code @@ -164,7 +163,7 @@ to eliminate in the future. In Listing 20-29, we show how to define a procedural macro, where `some_attribute` is a placeholder for using a specific macro variety. -Filename: src/lib.rs + ```rust,ignore use proc_macro; @@ -174,8 +173,7 @@ pub fn some_name(input: TokenStream) -> TokenStream { } ``` -Listing 20-29: An example of defining a procedural -macro + The function that defines a procedural macro takes a `TokenStream` as an input and produces a `TokenStream` as an output. The `TokenStream` type is defined by @@ -202,14 +200,13 @@ TypeName!` where `TypeName` is the name of the type on which this trait has been defined. In other words, we’ll write a crate that enables another programmer to write code like Listing 20-30 using our crate. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-30/src/main.rs}} ``` -Listing 20-30: The code a user of our crate will be able -to write when using our procedural macro + This code will print `Hello, Macro! My name is Pancakes!` when we’re done. The first step is to make a new library crate, like this: @@ -220,12 +217,14 @@ $ cargo new hello_macro --lib Next, we’ll define the `HelloMacro` trait and its associated function: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch20-advanced-features/no-listing-20-impl-hellomacro-for-pancakes/hello_macro/src/lib.rs}} ``` + + We have a trait and its function. At this point, our crate user could implement the trait to achieve the desired functionality, like so: @@ -269,24 +268,25 @@ We’ll also need functionality from the `syn` and `quote` crates, as you’ll s in a moment, so we need to add them as dependencies. Add the following to the *Cargo.toml* file for `hello_macro_derive`: -Filename: hello_macro_derive/Cargo.toml + ```toml {{#include ../listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/Cargo.toml:6:12}} ``` + + To start defining the procedural macro, place the code in Listing 20-31 into your *src/lib.rs* file for the `hello_macro_derive` crate. Note that this code won’t compile until we add a definition for the `impl_hello_macro` function. -Filename: hello_macro_derive/src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/src/lib.rs}} ``` -Listing 20-31: Code that most procedural macro crates -will require in order to process Rust code + Notice that we’ve split the code into the `hello_macro_derive` function, which is responsible for parsing the `TokenStream`, and the `impl_hello_macro` @@ -321,6 +321,8 @@ operations on. This is where `syn` comes into play. The `parse` function in parsed Rust code. Listing 20-32 shows the relevant parts of the `DeriveInput` struct we get from parsing the `struct Pancakes;` string: ++ ```rust,ignore DeriveInput { // --snip-- @@ -341,8 +343,7 @@ DeriveInput { } ``` -Listing 20-32: The `DeriveInput` instance we get when -parsing the code that has the macro’s attribute in Listing 20-30 + The fields of this struct show that the Rust code we’ve parsed is a unit struct with the `ident` (identifier, meaning the name) of `Pancakes`. There are more @@ -368,14 +369,13 @@ Now that we have the code to turn the annotated Rust code from a `TokenStream` into a `DeriveInput` instance, let’s generate the code that implements the `HelloMacro` trait on the annotated type, as shown in Listing 20-33. -Filename: hello_macro_derive/src/lib.rs + ```rust,ignore {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/src/lib.rs:here}} ``` -Listing 20-33: Implementing the `HelloMacro` trait using -the parsed Rust code + We get an `Ident` struct instance containing the name (identifier) of the annotated type using `ast.ident`. The struct in Listing 20-32 shows that when From 7ce0849bc0cc597cb337b865ca0881a0267ad75e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 9 Oct 2024 10:27:11 -0600 Subject: [PATCH 630/720] Adopt for Ch. 21 --- src/ch21-01-single-threaded.md | 45 +++++------- src/ch21-02-multithreaded.md | 74 ++++++++++---------- src/ch21-03-graceful-shutdown-and-cleanup.md | 40 ++++++----- 3 files changed, 77 insertions(+), 82 deletions(-) diff --git a/src/ch21-01-single-threaded.md b/src/ch21-01-single-threaded.md index 744a2a7829..9712b69a41 100644 --- a/src/ch21-01-single-threaded.md +++ b/src/ch21-01-single-threaded.md @@ -34,14 +34,13 @@ Now enter the code in Listing 21-1 in *src/main.rs* to start. This code will listen at the local address `127.0.0.1:7878` for incoming TCP streams. When it gets an incoming stream, it will print `Connection established!`. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-01/src/main.rs}} ``` -Listing 21-1: Listening for incoming streams and printing -a message when we receive a stream + Using `TcpListener`, we can listen for TCP connections at the address `127.0.0.1:7878`. In the address, the section before the colon is an IP address @@ -127,14 +126,13 @@ this new `handle_connection` function, we’ll read data from the TCP stream and print it so we can see the data being sent from the browser. Change the code to look like Listing 21-2. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-02/src/main.rs}} ``` -Listing 21-2: Reading from the `TcpStream` and printing -the data + We bring `std::io::prelude` and `std::io::BufReader` into scope to get access to traits and types that let us read from and write to the stream. In the `for` @@ -273,14 +271,13 @@ successful request! From the `handle_connection` function, remove the `println!` that was printing the request data and replace it with the code in Listing 21-3. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-03/src/main.rs:here}} ``` -Listing 21-3: Writing a tiny successful HTTP response to -the stream + The first new line defines the `response` variable that holds the success message’s data. Then we call `as_bytes` on our `response` to convert the string @@ -302,28 +299,26 @@ the new file *hello.html* in the root of your project directory, not in the *src* directory. You can input any HTML you want; Listing 21-4 shows one possibility. -Filename: hello.html + ```html {{#include ../listings/ch21-web-server/listing-21-05/hello.html}} ``` -Listing 21-4: A sample HTML file to return in a -response + This is a minimal HTML5 document with a heading and some text. To return this from the server when a request is received, we’ll modify `handle_connection` as shown in Listing 21-5 to read the HTML file, add it to the response as a body, and send it. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-05/src/main.rs:here}} ``` -Listing 21-5: Sending the contents of *hello.html* as the -body of the response + We’ve added `fs` to the `use` statement to bring the standard library’s filesystem module into scope. The code for reading the contents of a file to a @@ -356,14 +351,13 @@ as shown in Listing 21-6. This new code checks the content of the request received against what we know a request for */* looks like and adds `if` and `else` blocks to treat requests differently. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-06/src/main.rs:here}} ``` -Listing 21-6: Handling requests to */* differently from -other requests + We’re only going to be looking at the first line of the HTTP request, so rather than reading the entire request into a vector, we’re calling `next` to get the @@ -390,14 +384,13 @@ with the status code 404, which signals that the content for the request was not found. We’ll also return some HTML for a page to render in the browser indicating the response to the end user. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-07/src/main.rs:here}} ``` -Listing 21-7: Responding with status code 404 and an -error page if anything other than */* was requested + Here, our response has a status line with status code 404 and the reason phrase `NOT FOUND`. The body of the response will be the HTML in the file *404.html*. @@ -405,14 +398,13 @@ You’ll need to create a *404.html* file next to *hello.html* for the error page; again feel free to use any HTML you want or use the example HTML in Listing 21-8. -Filename: 404.html + ```html {{#include ../listings/ch21-web-server/listing-21-07/404.html}} ``` -Listing 21-8: Sample content for the page to send back -with any 404 response + With these changes, run your server again. Requesting *127.0.0.1:7878* should return the contents of *hello.html*, and any other request, like @@ -429,14 +421,13 @@ we can then use those variables unconditionally in the code to read the file and write the response. Listing 21-9 shows the resulting code after replacing the large `if` and `else` blocks. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-09/src/main.rs:here}} ``` -Listing 21-9: Refactoring the `if` and `else` blocks to -contain only the code that differs between the two cases + Now the `if` and `else` blocks only return the appropriate values for the status line and filename in a tuple; we then use destructuring to assign these diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index 4204693508..c4220a7bf5 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -15,14 +15,13 @@ our current server implementation. Listing 21-10 implements handling a request to */sleep* with a simulated slow response that will cause the server to sleep for 5 seconds before responding. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-10/src/main.rs:here}} ``` -Listing 21-10: Simulating a slow request by sleeping for -5 seconds + We switched from `if` to `match` now that we have three cases. We need to explicitly match on a slice of `request_line` to pattern match against the @@ -106,14 +105,13 @@ thread pool as an improvement, and contrasting the two solutions will be easier. Listing 21-11 shows the changes to make to `main` to spawn a new thread to handle each stream within the `for` loop. -Filename: src/main.rs + ```rust,no_run {{#rustdoc_include ../listings/ch21-web-server/listing-21-11/src/main.rs:here}} ``` -Listing 21-11: Spawning a new thread for each -stream + As you learned in Chapter 16, `thread::spawn` will create a new thread and then run the code in the closure in the new thread. If you run this code and load @@ -132,13 +130,13 @@ threads to a thread pool doesn’t require large changes to the code that uses our API. Listing 21-12 shows the hypothetical interface for a `ThreadPool` struct we want to use instead of `thread::spawn`. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch21-web-server/listing-21-12/src/main.rs:here}} ``` -Listing 21-12: Our ideal `ThreadPool` interface + We use `ThreadPool::new` to create a new thread pool with a configurable number of threads, in this case four. Then, in the `for` loop, `pool.execute` has a @@ -171,21 +169,25 @@ web requests. Create a *src/lib.rs* that contains the following, which is the simplest definition of a `ThreadPool` struct that we can have for now: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/no-listing-01-define-threadpool-struct/src/lib.rs}} ``` + + Then edit *main.rs* file to bring `ThreadPool` into scope from the library crate by adding the following code to the top of *src/main.rs*: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch21-web-server/no-listing-01-define-threadpool-struct/src/main.rs:here}} ``` + + This code still won’t work, but let’s check it again to get the next error that we need to address: @@ -199,12 +201,14 @@ that can accept `4` as an argument and should return a `ThreadPool` instance. Let’s implement the simplest `new` function that will have those characteristics: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/no-listing-02-impl-threadpool-new/src/lib.rs}} ``` + + We chose `usize` as the type of the `size` parameter, because we know that a negative number of threads doesn’t make any sense. We also know we’ll use this 4 as the number of elements in a collection of threads, which is what the @@ -255,12 +259,14 @@ closure from one thread to another and `'static` because we don’t know how lon the thread will take to execute. Let’s create an `execute` method on `ThreadPool` that will take a generic parameter of type `F` with these bounds: -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/no-listing-03-define-execute/src/lib.rs:here}} ``` + + We still use the `()` after `FnOnce` because this `FnOnce` represents a closure that takes no parameters and returns the unit type `()`. Just like function definitions, the return type can be omitted from the signature, but even if we @@ -296,14 +302,13 @@ valid `usize`. We’ll add code to check that `size` is greater than zero before we return a `ThreadPool` instance and have the program panic if it receives a zero by using the `assert!` macro, as shown in Listing 21-13. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/listing-21-13/src/lib.rs:here}} ``` -Listing 21-13: Implementing `ThreadPool::new` to panic if -`size` is zero + We’ve also added some documentation for our `ThreadPool` with doc comments. Note that we followed good documentation practices by adding a section that @@ -348,14 +353,13 @@ We’ve changed the definition of `ThreadPool` to hold a vector of `size`, set up a `for` loop that will run some code to create the threads, and returned a `ThreadPool` instance containing them. -Filename: src/lib.rs + ```rust,ignore,not_desired_behavior {{#rustdoc_include ../listings/ch21-web-server/listing-21-14/src/lib.rs:here}} ``` -Listing 21-14: Creating a vector for `ThreadPool` to hold -the threads + We’ve brought `std::thread` into scope in the library crate, because we’re using `thread::JoinHandle` as the type of the items in the vector in @@ -413,14 +417,13 @@ looking at the code in Listing 21-15. Ready? Here is Listing 21-15 with one way to make the preceding modifications. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/listing-21-15/src/lib.rs:here}} ``` -Listing 21-15: Modifying `ThreadPool` to hold `Worker` -instances instead of holding threads directly + We’ve changed the name of the field on `ThreadPool` from `threads` to `workers` because it’s now holding `Worker` instances instead of `JoinHandle<()>` @@ -474,14 +477,13 @@ in the `ThreadPool` instance, as shown in Listing 21-16. The `Job` struct doesn’t hold anything for now but will be the type of item we’re sending down the channel. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/listing-21-16/src/lib.rs:here}} ``` -Listing 21-16: Modifying `ThreadPool` to store the -sender of a channel that transmits `Job` instances + In `ThreadPool::new`, we create our new channel and have the pool hold the sender. This will successfully compile. @@ -491,13 +493,13 @@ creates the channel. We know we want to use the receiver in the thread that the workers spawn, so we’ll reference the `receiver` parameter in the closure. The code in Listing 21-17 won’t quite compile yet. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch21-web-server/listing-21-17/src/lib.rs:here}} ``` -Listing 21-17: Passing the receiver to the workers + We’ve made some small and straightforward changes: we pass the receiver into `Worker::new`, and then we use it inside the closure. @@ -525,14 +527,13 @@ need to use `Arc>`. The `Arc` type will let multiple workers own the receiver, and `Mutex` will ensure that only one worker gets a job from the receiver at a time. Listing 21-18 shows the changes we need to make. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/listing-21-18/src/lib.rs:here}} ``` -Listing 21-18: Sharing the receiver among the workers -using `Arc` and `Mutex` + In `ThreadPool::new`, we put the receiver in an `Arc` and a `Mutex`. For each new worker, we clone the `Arc` to bump the reference count so the workers can @@ -549,14 +550,13 @@ with Type Aliases”][creating-type-synonyms-with-type-aliases] section of Chapter 20, type aliases allow us to make long types shorter for ease of use. Look at Listing 21-19. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/listing-21-19/src/lib.rs:here}} ``` -Listing 21-19: Creating a `Job` type alias for a `Box` -that holds each closure and then sending the job down the channel + After creating a new `Job` instance using the closure we get in `execute`, we send that job down the sending end of the channel. We’re calling `unwrap` on @@ -573,14 +573,13 @@ Instead, we need the closure to loop forever, asking the receiving end of the channel for a job and running the job when it gets one. Let’s make the change shown in Listing 21-20 to `Worker::new`. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/listing-21-20/src/lib.rs:here}} ``` -Listing 21-20: Receiving and executing the jobs in the -worker’s thread + Here, we first call `lock` on the `receiver` to acquire the mutex, and then we call `unwrap` to panic on any errors. Acquiring a lock might fail if the mutex @@ -661,14 +660,13 @@ thread run them. After learning about the `while let` loop in Chapters 17 and 18, you might be wondering why we didn’t write the worker thread code as shown in Listing 21-21. -Filename: src/lib.rs + ```rust,ignore,not_desired_behavior {{#rustdoc_include ../listings/ch21-web-server/listing-21-21/src/lib.rs:here}} ``` -Listing 21-21: An alternative implementation of -`Worker::new` using `while let` + This code compiles and runs but doesn’t result in the desired threading behavior: a slow request will still cause other requests to wait to be diff --git a/src/ch21-03-graceful-shutdown-and-cleanup.md b/src/ch21-03-graceful-shutdown-and-cleanup.md index 24a8aabf6f..e73c4a5a59 100644 --- a/src/ch21-03-graceful-shutdown-and-cleanup.md +++ b/src/ch21-03-graceful-shutdown-and-cleanup.md @@ -22,14 +22,13 @@ dropped, our threads should all join to make sure they finish their work. Listing 21-22 shows a first attempt at a `Drop` implementation; this code won’t quite work yet. -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch21-web-server/listing-21-22/src/lib.rs:here}} ``` -Listing 21-22: Joining each thread when the thread pool -goes out of scope + First, we loop through each of the thread pool `workers`. We use `&mut` for this because `self` is a mutable reference, and we also need to be able to @@ -57,12 +56,14 @@ thread to run. So we know we want to update the definition of `Worker` like this: -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch21-web-server/no-listing-04-update-worker-definition/src/lib.rs:here}} ``` + + Now let’s lean on the compiler to find the other places that need to change. Checking this code, we get two errors: @@ -74,22 +75,26 @@ Let’s address the second error, which points to the code at the end of `Worker::new`; we need to wrap the `thread` value in `Some` when we create a new `Worker`. Make the following changes to fix this error: -Filename: src/lib.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch21-web-server/no-listing-05-fix-worker-new/src/lib.rs:here}} ``` + + The first error is in our `Drop` implementation. We mentioned earlier that we intended to call `take` on the `Option` value to move `thread` out of `worker`. The following changes will do so: -Filename: src/lib.rs + ```rust,ignore,not_desired_behavior {{#rustdoc_include ../listings/ch21-web-server/no-listing-06-fix-threadpool-drop/src/lib.rs:here}} ``` + + As discussed in Chapter 18, the `take` method on `Option` takes the `Some` variant out and leaves `None` in its place. We’re using `if let` to destructure the `Some` and get the thread; then we call `join` on the thread. If a worker’s @@ -115,14 +120,13 @@ changes to `ThreadPool` to explicitly drop `sender`. We use the same `Option` and `take` technique as we did with the thread to be able to move `sender` out of `ThreadPool`: -Filename: src/lib.rs + ```rust,noplayground,not_desired_behavior {{#rustdoc_include ../listings/ch21-web-server/listing-21-23/src/lib.rs:here}} ``` -Listing 21-23: Explicitly drop `sender` before joining -the worker threads + Dropping `sender` closes the channel, which indicates no more messages will be sent. When that happens, all the calls to `recv` that the workers do in the @@ -130,26 +134,24 @@ infinite loop will return an error. In Listing 21-24, we change the `Worker` loop to gracefully exit the loop in that case, which means the threads will finish when the `ThreadPool` `drop` implementation calls `join` on them. -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/listing-21-24/src/lib.rs:here}} ``` -Listing 21-24: Explicitly break out of the loop when -`recv` returns an error + To see this code in action, let’s modify `main` to accept only two requests before gracefully shutting down the server, as shown in Listing 21-25. -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch21-web-server/listing-21-25/src/main.rs:here}} ``` -Listing 21-25: Shut down the server after serving two -requests by exiting the loop + You wouldn’t want a real-world web server to shut down after serving only two requests. This code just demonstrates that the graceful shutdown and cleanup is @@ -213,18 +215,22 @@ shutdown of the server, which cleans up all the threads in the pool. Here’s the full code for reference: -Filename: src/main.rs + ```rust,ignore {{#rustdoc_include ../listings/ch21-web-server/no-listing-07-final-code/src/main.rs}} ``` -Filename: src/lib.rs + + + ```rust,noplayground {{#rustdoc_include ../listings/ch21-web-server/no-listing-07-final-code/src/lib.rs}} ``` + + We could do more here! If you want to continue enhancing this project, here are some ideas: From 1324c75002bdfa9f70c2db8ad7df70746d3200f5 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 9 Oct 2024 13:55:25 -0600 Subject: [PATCH 631/720] Add HTML-based redirects for previous chapter numbering Unlike the redirects we have in place for the previous editions, this simply performs an in-place redirect, using the built-in mechanism for this in mdbook. As an alternative, we could hand-craft HTML pages to do what the redirect pages for the first and second edition do: present a page and let the user click through proactively. --- book.toml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/book.toml b/book.toml index 800adcf0f5..2f3319bdba 100644 --- a/book.toml +++ b/book.toml @@ -10,6 +10,26 @@ additional-css = ["ferris.css", "theme/2018-edition.css", "theme/semantic-notes. additional-js = ["ferris.js"] git-repository-url = "https://github.com/rust-lang/book" +[output.html.redirect] +"ch17-00-oop.html" = "ch18-00-oop.html" +"ch17-01-what-is-oo.html" = "ch18-01-what-is-oo.html" +"ch17-02-trait-objects.html" = "ch18-02-trait-objects.html" +"ch17-03-oo-design-patterns.html" = "ch18-03-oo-design-patterns.html" +"ch18-00-patterns.html" = "ch19-00-patterns.html" +"ch18-01-all-the-places-for-patterns.html" = "ch19-01-all-the-places-for-patterns.html" +"ch18-02-refutability.html" = "ch19-02-refutability.html" +"ch18-03-pattern-syntax.html" = "ch19-03-pattern-syntax.html" +"ch19-00-advanced-features.html" = "ch20-00-advanced-features.html" +"ch19-01-unsafe-rust.html" = "ch20-01-unsafe-rust.html" +"ch19-03-advanced-traits.html" = "ch20-03-advanced-traits.html" +"ch19-04-advanced-types.html" = "ch20-04-advanced-types.html" +"ch19-05-advanced-functions-and-closures.html" = "ch20-05-advanced-functions-and-closures.html" +"ch19-06-macros.html" = "ch20-06-macros.html" +"ch20-00-final-project-a-web-server.html" = "ch21-00-final-project-a-web-server.html" +"ch20-01-single-threaded.html" = "ch21-01-single-threaded.html" +"ch20-02-multithreaded.html" = "ch21-02-multithreaded.html" +"ch20-03-graceful-shutdown-and-cleanup.html" = "ch21-03-graceful-shutdown-and-cleanup.html" + # Do not sync this preprocessor; it is for the HTML renderer only. [preprocessor.trpl-note] From 0bee1e62b3944fe0369635f96343131a851f4c31 Mon Sep 17 00:00:00 2001 From: overflaw Date: Thu, 10 Oct 2024 10:51:11 +0200 Subject: [PATCH 632/720] Remove "different" repetition typo in chapter 17.1 --- src/ch17-01-futures-and-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index a82366f7f3..1e95d5d727 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -239,7 +239,7 @@ Most languages which support async bundle a runtime with the language. Rust does not. Instead, there are many different async runtimes available, each of which makes different tradeoffs suitable to the use case they target. For example, a high-throughput web server with many CPU cores and a large amount of RAM has -very different different needs than a microcontroller with a single core, a +very different needs than a microcontroller with a single core, a small amount of RAM, and no ability to do heap allocations. The crates which provide those runtimes also often supply async versions of common functionality such as file or network I/O. From e95efa05706c5c4309df9ed47d5e91d8ed342b7d Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 10 Oct 2024 06:38:27 -0600 Subject: [PATCH 633/720] Re-wrap lines after fixing extra word --- src/ch17-01-futures-and-syntax.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 1e95d5d727..054d1160ce 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -239,10 +239,10 @@ Most languages which support async bundle a runtime with the language. Rust does not. Instead, there are many different async runtimes available, each of which makes different tradeoffs suitable to the use case they target. For example, a high-throughput web server with many CPU cores and a large amount of RAM has -very different needs than a microcontroller with a single core, a -small amount of RAM, and no ability to do heap allocations. The crates which -provide those runtimes also often supply async versions of common functionality -such as file or network I/O. +very different needs than a microcontroller with a single core, a small amount +of RAM, and no ability to do heap allocations. The crates which provide those +runtimes also often supply async versions of common functionality such as file +or network I/O. Here, and throughout the rest of this chapter, we’ll use the `run` function from the `trpl` crate, which takes a future as an argument and runs it to From a51477007575f991ba9cb7d47cd3bf3de294b9c6 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 10 Oct 2024 07:21:10 -0600 Subject: [PATCH 634/720] Add info about handling editions in book.toml to ADMIN.md --- ADMIN_TASKS.md | 5 +++++ nostarch/book.toml | 3 +++ 2 files changed, 8 insertions(+) diff --git a/ADMIN_TASKS.md b/ADMIN_TASKS.md index 9caff3004c..c493a335ce 100644 --- a/ADMIN_TASKS.md +++ b/ADMIN_TASKS.md @@ -23,6 +23,11 @@ occasional maintenance tasks. To update the `edition = "[year]"` metadata in all the listings' `Cargo.toml`s, run the `./tools/update-editions.sh` script and commit the changes. +## Update the `edition` in mdBook config + +Open `book.toml` and `nostarch/book.toml` and set the `edition` value in the +`[rust]` table to the new edition. + ## Release a new version of the listings We now make `.tar` files of complete projects containing every listing diff --git a/nostarch/book.toml b/nostarch/book.toml index 55528625d8..ce0abdc510 100644 --- a/nostarch/book.toml +++ b/nostarch/book.toml @@ -13,3 +13,6 @@ build-dir = "../tmp" [preprocessor.trpl-listing] output-mode = "simple" + +[rust] +edition = "2021" From 27f2d71453958e616c56ea92ecffc67421189b35 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 10 Oct 2024 12:26:39 -0600 Subject: [PATCH 635/720] Add Chris Krycho as an author. --- book.toml | 2 +- ci/dictionary.txt | 1 + src/title-page.md | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/book.toml b/book.toml index 2f3319bdba..491916a1cc 100644 --- a/book.toml +++ b/book.toml @@ -3,7 +3,7 @@ [book] title = "The Rust Programming Language" -authors = ["Steve Klabnik", "Carol Nichols", "Contributions from the Rust Community"] +authors = ["Steve Klabnik", "Carol Nichols", "Chris Krycho", "Contributions from the Rust Community"] [output.html] additional-css = ["ferris.css", "theme/2018-edition.css", "theme/semantic-notes.css", "theme/listing.css"] diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 33d56857fb..4364dc0d61 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -269,6 +269,7 @@ JoinHandle Kay's kinded Klabnik +Krycho lang LastWriteTime latin diff --git a/src/title-page.md b/src/title-page.md index 613de0ddd7..ff45326fd4 100644 --- a/src/title-page.md +++ b/src/title-page.md @@ -1,6 +1,7 @@ # The Rust Programming Language -*by Steve Klabnik and Carol Nichols, with contributions from the Rust Community* +*by Steve Klabnik, Carol Nichols, and Chris Krycho, with contributions from the +Rust Community* 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] From fd145086f910c453479bb58d2684ef16cdb97087 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 11 Oct 2024 07:27:45 -0600 Subject: [PATCH 636/720] Revert "Chapter 6 - Wrap all ``s to comply with the virtual 80 character limit (READ DESC.)" This reverts commit b1bb69fe5d822f637b4a357d49e92affd6ef1002. --- src/ch06-01-defining-an-enum.md | 6 ++---- src/ch06-02-match.md | 9 +++------ src/ch06-03-if-let.md | 3 +-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/ch06-01-defining-an-enum.md b/src/ch06-01-defining-an-enum.md index 04fb327164..3462f38917 100644 --- a/src/ch06-01-defining-an-enum.md +++ b/src/ch06-01-defining-an-enum.md @@ -59,8 +59,7 @@ only know what *kind* it is. Given that you just learned about structs in Chapter 5, you might be tempted to tackle this problem with structs as shown in Listing 6-1. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs:here}} @@ -142,8 +141,7 @@ more about bringing types into scope in Chapter 7. Let’s look at another example of an enum in Listing 6-2: this one has a wide variety of types embedded in its variants. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs:here}} diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index 9b5ec3a03b..2bb8929798 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -22,8 +22,7 @@ function that takes an unknown US coin and, in a similar way as the counting machine, determines which coin it is and returns its value in cents, as shown in Listing 6-3. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs:here}} @@ -77,8 +76,7 @@ designs, so only quarters have this extra value. We can add this information to our `enum` by changing the `Quarter` variant to include a `UsState` value stored inside it, which we’ve done in Listing 6-4. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs:here}} @@ -123,8 +121,7 @@ operations. This function is very easy to write, thanks to `match`, and will look like Listing 6-5. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-05/src/main.rs:here}} diff --git a/src/ch06-03-if-let.md b/src/ch06-03-if-let.md index 37bed8cf2d..fee6b2caf3 100644 --- a/src/ch06-03-if-let.md +++ b/src/ch06-03-if-let.md @@ -6,8 +6,7 @@ program in Listing 6-6 that matches on an `Option` value in the `config_max` variable but only wants to execute code if the value is the `Some` variant. -+ ```rust {{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs:here}} From 577a70bc69b065b010cbddd425f265030e33c598 Mon Sep 17 00:00:00 2001 From: lifeadventurer Date: Fri, 11 Oct 2024 22:32:09 +0800 Subject: [PATCH 637/720] Adopt for Ch. 16 --- src/ch16-01-threads.md | 30 ++++++++++++++---------------- src/ch16-02-message-passing.md | 25 ++++++++++--------------- src/ch16-03-shared-state.md | 20 ++++++++------------ 3 files changed, 32 insertions(+), 43 deletions(-) diff --git a/src/ch16-01-threads.md b/src/ch16-01-threads.md index f3cdbff907..cc64664047 100644 --- a/src/ch16-01-threads.md +++ b/src/ch16-01-threads.md @@ -40,14 +40,13 @@ closure (we talked about closures in Chapter 13) containing the code we want to run in the new thread. The example in Listing 16-1 prints some text from a main thread and other text from a new thread: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-01/src/main.rs}} ``` -Listing 16-1: Creating a new thread to print one thing -while the main thread prints something else + Note that when the main thread of a Rust program completes, all spawned threads are shut down, whether or not they have finished running. The output from this @@ -96,14 +95,13 @@ call the `join` method on it, will wait for its thread to finish. Listing 16-2 shows how to use the `JoinHandle` of the thread we created in Listing 16-1 and call `join` to make sure the spawned thread finishes before `main` exits: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-02/src/main.rs}} ``` -Listing 16-2: Saving a `JoinHandle` from `thread::spawn` -to guarantee the thread is run to completion + Calling `join` on the handle blocks the thread currently running until the thread represented by the handle terminates. *Blocking* a thread means that @@ -137,12 +135,14 @@ call to `handle.join()` and does not end until the spawned thread is finished. But let’s see what happens when we instead move `handle.join()` before the `for` loop in `main`, like this: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs}} ``` + + The main thread will wait for the spawned thread to finish and then run its `for` loop, so the output won’t be interleaved anymore, as shown here: @@ -185,14 +185,13 @@ spawned thread’s closure must capture the values it needs. Listing 16-3 shows an attempt to create a vector in the main thread and use it in the spawned thread. However, this won’t yet work, as you’ll see in a moment. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-03/src/main.rs}} ``` -Listing 16-3: Attempting to use a vector created by the -main thread in another thread + The closure uses `v`, so it will capture `v` and make it part of the closure’s environment. Because `thread::spawn` runs this closure in a new thread, we @@ -211,14 +210,13 @@ to `v` will always be valid. Listing 16-4 provides a scenario that’s more likely to have a reference to `v` that won’t be valid: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-04/src/main.rs}} ``` -Listing 16-4: A thread with a closure that attempts to -capture a reference to `v` from a main thread that drops `v` + If Rust allowed us to run this code, there’s a possibility the spawned thread would be immediately put in the background without running at all. The spawned @@ -246,14 +244,14 @@ ownership of the values it’s using rather than allowing Rust to infer that it should borrow the values. The modification to Listing 16-3 shown in Listing 16-5 will compile and run as we intend: -Filename: src/main.rs ++ ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-05/src/main.rs}} ``` -Listing 16-5: Using the `move` keyword to force a closure -to take ownership of the values it uses + We might be tempted to try the same thing to fix the code in Listing 16-4 where the main thread called `drop` by using a `move` closure. However, this fix will diff --git a/src/ch16-02-message-passing.md b/src/ch16-02-message-passing.md index 3782fa5dec..f2d396bfaa 100644 --- a/src/ch16-02-message-passing.md +++ b/src/ch16-02-message-passing.md @@ -66,14 +66,13 @@ string so the spawned thread is communicating with the main thread, as shown in Listing 16-7. This is like putting a rubber duck in the river upstream or sending a chat message from one thread to another. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-07/src/main.rs}} ``` -Listing 16-7: Moving `tx` to a spawned thread and sending -“hi” + Again, we’re using `thread::spawn` to create a new thread and then using `move` to move `tx` into the closure so the spawned thread owns `tx`. The spawned @@ -89,14 +88,13 @@ In Listing 16-8, we’ll get the value from the receiver in the main thread. Thi is like retrieving the rubber duck from the water at the end of the river or receiving a chat message. -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-08/src/main.rs}} ``` -Listing 16-8: Receiving the value “hi” in the main thread -and printing it + The receiver has two useful methods: `recv` and `try_recv`. We’re using `recv`, short for *receive*, which will block the main thread’s execution and wait @@ -139,14 +137,13 @@ problems: we’ll try to use a `val` value in the spawned thread *after* we’ve sent it down the channel. Try compiling the code in Listing 16-9 to see why this code isn’t allowed: -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-09/src/main.rs}} ``` -Listing 16-9: Attempting to use `val` after we’ve sent it -down the channel + Here, we try to print `val` after we’ve sent it down the channel via `tx.send`. Allowing this would be a bad idea: once the value has been sent to another @@ -172,14 +169,13 @@ two separate threads were talking to each other over the channel. In Listing running concurrently: the spawned thread will now send multiple messages and pause for a second between each message. -Filename: src/main.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-10/src/main.rs}} ``` -Listing 16-10: Sending multiple messages and pausing -between each + This time, the spawned thread has a vector of strings that we want to send to the main thread. We iterate over them, sending each individually, and pause @@ -215,14 +211,13 @@ single consumer*. Let’s put `mpsc` to use and expand the code in Listing 16-10 to create multiple threads that all send values to the same receiver. We can do so by cloning the transmitter, as shown in Listing 16-11: -Filename: src/main.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-11/src/main.rs:here}} ``` -Listing 16-11: Sending multiple messages from multiple -producers + This time, before we create the first spawned thread, we call `clone` on the transmitter. This will give us a new transmitter we can pass to the first diff --git a/src/ch16-03-shared-state.md b/src/ch16-03-shared-state.md index a5f806c5bf..d319c6d6c2 100644 --- a/src/ch16-03-shared-state.md +++ b/src/ch16-03-shared-state.md @@ -52,14 +52,13 @@ system and ownership rules, you can’t get locking and unlocking wrong. As an example of how to use a mutex, let’s start by using a mutex in a single-threaded context, as shown in Listing 16-12: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-12/src/main.rs}} ``` -Listing 16-12: Exploring the API of `Mutex` in a -single-threaded context for simplicity + As with many types, we create a `Mutex` using the associated function `new`. To access the data inside the mutex, we use the `lock` method to acquire the @@ -98,14 +97,13 @@ the counter goes from 0 to 10. The next example in Listing 16-13 will have a compiler error, and we’ll use that error to learn more about using `Mutex` and how Rust helps us use it correctly. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-13/src/main.rs}} ``` -Listing 16-13: Ten threads each increment a counter -guarded by a `Mutex` + We create a `counter` variable to hold an `i32` inside a `Mutex`, as we did in Listing 16-12. Next, we create 10 threads by iterating over a range of @@ -138,14 +136,13 @@ In Chapter 15, we gave a value multiple owners by using the smart pointer what happens. We’ll wrap the `Mutex` in `Rc` in Listing 16-14 and clone the `Rc` before moving ownership to the thread. -Filename: src/main.rs + ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-14/src/main.rs}} ``` -Listing 16-14: Attempting to use `Rc` to allow -multiple threads to own the `Mutex` + Once again, we compile and get... different errors! The compiler is teaching us a lot. @@ -191,14 +188,13 @@ Let’s return to our example: `Arc` and `Rc` have the same API, so we fix our program by changing the `use` line, the call to `new`, and the call to `clone`. The code in Listing 16-15 will finally compile and run: -Filename: src/main.rs + ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-15/src/main.rs}} ``` -Listing 16-15: Using an `Arc` to wrap the `Mutex` -to be able to share ownership across multiple threads + This code will print the following: From 1d595d83721fa8940eb541d79aa8e41878dd67cb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 15 Oct 2024 06:42:07 -0600 Subject: [PATCH 638/720] Fix up `` usage in Ch. 18 Thanks to @LifeAdventurer () for flagging this up on the tracking issue! --- src/ch18-01-what-is-oo.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ch18-01-what-is-oo.md b/src/ch18-01-what-is-oo.md index 8e81826b9e..3d977dadc2 100644 --- a/src/ch18-01-what-is-oo.md +++ b/src/ch18-01-what-is-oo.md @@ -44,7 +44,7 @@ on demand whenever anyone needs it. In other words, `AveragedCollection` will cache the calculated average for us. Listing 18-1 has the definition of the `AveragedCollection` struct: -+ ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-01/src/lib.rs}} @@ -58,9 +58,7 @@ ensure that whenever a value is added or removed from the list, the average is also updated. We do this by implementing `add`, `remove`, and `average` methods on the struct, as shown in Listing 18-2: -- -Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch18-oop/listing-18-02/src/lib.rs:here}} From 8aab8a2115ba310d847dafa3b939c569ffe19281 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 15 Oct 2024 07:09:59 -0600 Subject: [PATCH 639/720] Back out "Chapter 8 - Wrap all ``s to comply with the virtual 80 character limit" This backs out commit 2b3b9f537034e95408a50bcf24c62bc30f5a3463. --- src/ch08-01-vectors.md | 21 +++++++-------------- src/ch08-02-strings.md | 24 ++++++++---------------- src/ch08-03-hash-maps.md | 18 ++++++------------ 3 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index fcec18f17f..718cd597a3 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -11,8 +11,7 @@ lines of text in a file or the prices of items in a shopping cart. To create a new empty vector, we call the `Vec::new` function, as shown in Listing 8-1. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-01/src/main.rs:here}} @@ -54,8 +53,7 @@ to modify a vector. To create a vector and then add elements to it, we can use the `push` method, as shown in Listing 8-3. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-03/src/main.rs:here}} @@ -77,8 +75,7 @@ the values that are returned from these functions for extra clarity. Listing 8-4 shows both methods of accessing a value in a vector, with indexing syntax and the `get` method. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-04/src/main.rs:here}} @@ -98,8 +95,7 @@ existing elements. As an example, let’s see what happens when we have a vector of five elements and then we try to access an element at index 100 with each technique, as shown in Listing 8-5. -+ ```rust,should_panic,panics {{#rustdoc_include ../listings/ch08-common-collections/listing-08-05/src/main.rs:here}} @@ -132,8 +128,7 @@ to the first element in a vector and try to add an element to the end. This program won’t work if we also try to refer to that element later in the function. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch08-common-collections/listing-08-06/src/main.rs:here}} @@ -167,8 +162,7 @@ elements rather than use indices to access one at a time. Listing 8-7 shows how to use a `for` loop to get immutable references to each element in a vector of `i32` values and print them. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-07/src/main.rs:here}} @@ -180,8 +174,7 @@ We can also iterate over mutable references to each element in a mutable vector in order to make changes to all the elements. The `for` loop in Listing 8-8 will add `50` to each element. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-08/src/main.rs:here}} diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index 8f8464cc77..9494fd94cb 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -55,8 +55,7 @@ string. For that, we use the `to_string` method, which is available on any type that implements the `Display` trait, as string literals do. Listing 8-12 shows two examples. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-12/src/main.rs:here}} @@ -70,8 +69,7 @@ We can also use the function `String::from` to create a `String` from a string literal. The code in Listing 8-13 is equivalent to the code in Listing 8-12 that uses `to_string`. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-13/src/main.rs:here}} @@ -88,8 +86,7 @@ readability. Remember that strings are UTF-8 encoded, so we can include any properly encoded data in them, as shown in Listing 8-14. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-14/src/main.rs:here}} @@ -110,8 +107,7 @@ use the `+` operator or the `format!` macro to concatenate `String` values. We can grow a `String` by using the `push_str` method to append a string slice, as shown in Listing 8-15. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-15/src/main.rs:here}} @@ -124,8 +120,7 @@ string slice because we don’t necessarily want to take ownership of the parameter. For example, in the code in Listing 8-16, we want to be able to use `s2` after appending its contents to `s1`. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-16/src/main.rs:here}} @@ -140,8 +135,7 @@ The `push` method takes a single character as a parameter and adds it to the `String`. Listing 8-17 adds the letter *l* to a `String` using the `push` method. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-17/src/main.rs:here}} @@ -156,8 +150,7 @@ As a result, `s` will contain `lol`. Often, you’ll want to combine two existing strings. One way to do so is to use the `+` operator, as shown in Listing 8-18. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-18/src/main.rs:here}} @@ -231,8 +224,7 @@ string by referencing them by index is a valid and common operation. However, if you try to access parts of a `String` using indexing syntax in Rust, you’ll get an error. Consider the invalid code in Listing 8-19. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch08-common-collections/listing-08-19/src/main.rs:here}} diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index c4327a019e..057501415a 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -24,8 +24,7 @@ One way to create an empty hash map is to use `new` and to add elements with names are *Blue* and *Yellow*. The Blue team starts with 10 points, and the Yellow team starts with 50. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-20/src/main.rs:here}} @@ -49,8 +48,7 @@ must have the same type. We can get a value out of the hash map by providing its key to the `get` method, as shown in Listing 8-21. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-21/src/main.rs:here}} @@ -85,8 +83,7 @@ For types that implement the `Copy` trait, like `i32`, the values are copied into the hash map. For owned values like `String`, the values will be moved and the hash map will be the owner of those values, as demonstrated in Listing 8-22. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-22/src/main.rs:here}} @@ -126,8 +123,7 @@ Even though the code in Listing 8-23 calls `insert` twice, the hash map will only contain one key–value pair because we’re inserting the value for the Blue team’s key both times. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-23/src/main.rs:here}} @@ -155,8 +151,7 @@ we want to check whether the key for the Yellow team has a value associated with it. If it doesn’t, we want to insert the value `50`, and the same for the Blue team. Using the `entry` API, the code looks like Listing 8-24. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-24/src/main.rs:here}} @@ -185,8 +180,7 @@ the words as keys and increment the value to keep track of how many times we’v seen that word. If it’s the first time we’ve seen a word, we’ll first insert the value `0`. -+ ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-25/src/main.rs:here}} From d5a89d9db5fd3de8609c73208915bed14b2739ff Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 15 Oct 2024 07:11:40 -0600 Subject: [PATCH 640/720] Back out "Chapter 7 - Wrap all ``s to comply with the virtual 80 character limit" This backs out commit c521d2d4e498ae89174db8349774fe36d8042a1e. --- ...ng-modules-to-control-scope-and-privacy.md | 3 +- ...referring-to-an-item-in-the-module-tree.md | 25 +++++----------- ...g-paths-into-scope-with-the-use-keyword.md | 30 +++++++------------ ...separating-modules-into-different-files.md | 6 ++-- 4 files changed, 21 insertions(+), 43 deletions(-) diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index cfab7cc36b..c1afe4c15a 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -118,8 +118,7 @@ restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to define some modules and function signatures; this code is the front of house section. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-01/src/lib.rs}} diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index 6931dd314d..da07d9fd83 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -29,8 +29,7 @@ The `eat_at_restaurant` function is part of our library crate’s public API, so we mark it with the `pub` keyword. In the [“Exposing Paths with the `pub` Keyword”][pub] section, we’ll go into more detail about `pub`. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-03/src/lib.rs}} @@ -70,8 +69,7 @@ each other. Let’s try to compile Listing 7-3 and find out why it won’t compile yet! The errors we get are shown in Listing 7-4. -+ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-03/output.txt}} @@ -107,8 +105,7 @@ private. We want the `eat_at_restaurant` function in the parent module to have access to the `add_to_waitlist` function in the child module, so we mark the `hosting` module with the `pub` keyword, as shown in Listing 7-5. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-05/src/lib.rs}} @@ -119,8 +116,7 @@ module as `pub` to use it from `eat_at_restaurant`"> Unfortunately, the code in Listing 7-5 still results in compiler errors, as shown in Listing 7-6. -+ ```console {{#include ../listings/ch07-managing-growing-projects/listing-07-05/output.txt}} @@ -144,9 +140,7 @@ modules. Let’s also make the `add_to_waitlist` function public by adding the `pub` keyword before its definition, as in Listing 7-7. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs}} @@ -220,8 +214,7 @@ function `fix_incorrect_order` defined in the `back_of_house` module calls the function `deliver_order` defined in the parent module by specifying the path to `deliver_order`, starting with `super`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-08/src/lib.rs}} @@ -251,8 +244,7 @@ comes with a meal, but the chef decides which fruit accompanies the meal based on what’s in season and in stock. The available fruit changes quickly, so customers can’t choose the fruit or even see which fruit they’ll get. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs}} @@ -276,8 +268,7 @@ have such a function, we couldn’t create an instance of `Breakfast` in In contrast, if we make an enum public, all of its variants are then public. We only need the `pub` before the `enum` keyword, as shown in Listing 7-10. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-10/src/lib.rs}} diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 3de3ec1ad2..aaf7713e95 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -12,8 +12,7 @@ scope of the `eat_at_restaurant` function so we only have to specify `hosting::add_to_waitlist` to call the `add_to_waitlist` function in `eat_at_restaurant`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-11/src/lib.rs}} @@ -32,8 +31,7 @@ Note that `use` only creates the shortcut for the particular scope in which the child module named `customer`, which is then a different scope than the `use` statement, so the function body won’t compile. -+ ```rust,noplayground,test_harness,does_not_compile,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-12/src/lib.rs}} @@ -60,8 +58,7 @@ crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in `eat_at_restaurant`, rather than specifying the `use` path all the way out to the `add_to_waitlist` function to achieve the same result, as in Listing 7-13. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-13/src/lib.rs}} @@ -82,8 +79,7 @@ it’s idiomatic to specify the full path. Listing 7-14 shows the idiomatic way to bring the standard library’s `HashMap` struct into the scope of a binary crate. -+ ```rust {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-14/src/main.rs}} @@ -99,8 +95,7 @@ into scope with `use` statements, because Rust doesn’t allow that. Listing 7-1 shows how to bring two `Result` types into scope that have the same name but different parent modules, and how to refer to them. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-15/src/lib.rs:here}} @@ -120,8 +115,7 @@ into the same scope with `use`: after the path, we can specify `as` and a new local name, or *alias*, for the type. Listing 7-16 shows another way to write the code in Listing 7-15 by renaming one of the two `Result` types using `as`. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-16/src/lib.rs:here}} @@ -146,8 +140,7 @@ their scope. Listing 7-17 shows the code in Listing 7-11 with `use` in the root module changed to `pub use`. -+ ```rust,noplayground,test_harness {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-17/src/lib.rs}} @@ -246,8 +239,7 @@ line. We do this by specifying the common part of the path, followed by two colons, and then curly brackets around a list of the parts of the paths that differ, as shown in Listing 7-18. -+ ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-18/src/main.rs:here}} @@ -264,8 +256,7 @@ two `use` statements that share a subpath. For example, Listing 7-19 shows two `use` statements: one that brings `std::io` into scope and one that brings `std::io::Write` into scope. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-19/src/lib.rs}} @@ -277,8 +268,7 @@ The common part of these two paths is `std::io`, and that’s the complete first path. To merge these two paths into one `use` statement, we can use `self` in the nested path, as shown in Listing 7-20. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-20/src/lib.rs}} diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index d0881a5767..2952e4b156 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -16,8 +16,7 @@ the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code shown in Listing 7-21. Note that this won’t compile until we create the *src/front_of_house.rs* file in Listing 7-22. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/lib.rs}} @@ -30,8 +29,7 @@ Next, place the code that was in the curly brackets into a new file named in this file because it came across the module declaration in the crate root with the name `front_of_house`. -+ ```rust,ignore {{#rustdoc_include ../listings/ch07-managing-growing-projects/listing-07-21-and-22/src/front_of_house.rs}} From 8b443bcd9bbfa96450e28a34e191f1217dedba80 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 15 Oct 2024 07:12:44 -0600 Subject: [PATCH 641/720] Back out "Chapter 10 - Wrap all ``s to comply with the virtual 80 character limit" This backs out commit e82cd3fb2c4cfac1fd8d6a4f3b1ef29e6f95146f. --- src/ch10-00-generics.md | 9 +++------ src/ch10-01-syntax.md | 26 ++++++++------------------ src/ch10-02-traits.md | 12 ++++-------- src/ch10-03-lifetime-syntax.md | 34 ++++++++++------------------------ 4 files changed, 25 insertions(+), 56 deletions(-) diff --git a/src/ch10-00-generics.md b/src/ch10-00-generics.md index 87ad2d6f37..2e68384e11 100644 --- a/src/ch10-00-generics.md +++ b/src/ch10-00-generics.md @@ -42,8 +42,7 @@ duplicated code that can use generics. We’ll begin with the short program in Listing 10-1 that finds the largest number in a list. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-01/src/main.rs:here}} @@ -64,8 +63,7 @@ We’ve now been tasked with finding the largest number in two different lists o numbers. To do so, we can choose to duplicate the code in Listing 10-1 and use the same logic at two different places in the program, as shown in Listing 10-2. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-02/src/main.rs}} @@ -87,8 +85,7 @@ function named `largest`. Then we call the function to find the largest number in the two lists from Listing 10-2. We could also use the function on any other list of `i32` values we might have in the future. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-03/src/main.rs:here}} diff --git a/src/ch10-01-syntax.md b/src/ch10-01-syntax.md index 6277e6e1c2..2a22baf581 100644 --- a/src/ch10-01-syntax.md +++ b/src/ch10-01-syntax.md @@ -16,8 +16,7 @@ Continuing with our `largest` function, Listing 10-4 shows two functions that both find the largest value in a slice. We’ll then combine these into a single function that uses generics. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-04/src/main.rs:here}} @@ -58,8 +57,7 @@ data type in its signature. The listing also shows how we can call the function with either a slice of `i32` values or `char` values. Note that this code won’t compile yet, but we’ll fix it later in this chapter. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/src/main.rs}} @@ -90,8 +88,7 @@ We can also define structs to use a generic type parameter in one or more fields using the `<>` syntax. Listing 10-6 defines a `Point` struct to hold `x` and `y` coordinate values of any type. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-06/src/main.rs}} @@ -111,8 +108,7 @@ the fields `x` and `y` are *both* that same type, whatever that type may be. If we create an instance of a `Point` that has values of different types, as in Listing 10-7, our code won’t compile. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/src/main.rs}} @@ -134,8 +130,7 @@ different types, we can use multiple generic type parameters. For example, in Listing 10-8, we change the definition of `Point` to be generic over types `T` and `U` where `x` is of type `T` and `y` is of type `U`. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-08/src/main.rs}} @@ -198,9 +193,7 @@ We can implement methods on structs and enums (as we did in Chapter 5) and use generic types in their definitions too. Listing 10-9 shows the `Point` struct we defined in Listing 10-6 with a method named `x` implemented on it. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-09/src/main.rs}} @@ -226,9 +219,7 @@ type. We could, for example, implement methods only on `Point` instances rather than on `Point` instances with any generic type. In Listing 10-10 we use the concrete type `f32`, meaning we don’t declare any types after `impl`. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-10/src/main.rs:here}} @@ -249,8 +240,7 @@ signature to make the example clearer. The method creates a new `Point` instance with the `x` value from the `self` `Point` (of type `X1`) and the `y` value from the passed-in `Point` (of type `Y2`). -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-11/src/main.rs}} diff --git a/src/ch10-02-traits.md b/src/ch10-02-traits.md index fcb4dcd854..cfd4201066 100644 --- a/src/ch10-02-traits.md +++ b/src/ch10-02-traits.md @@ -27,8 +27,7 @@ instance. To do this, we need a summary from each type, and we’ll request that summary by calling a `summarize` method on an instance. Listing 10-12 shows the definition of a public `Summary` trait that expresses this behavior. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-12/src/lib.rs}} @@ -62,8 +61,7 @@ the headline, the author, and the location to create the return value of followed by the entire text of the tweet, assuming that the tweet content is already limited to 280 characters. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-13/src/lib.rs:here}} @@ -124,8 +122,7 @@ In Listing 10-14, we specify a default string for the `summarize` method of the `Summary` trait instead of only defining the method signature, as we did in Listing 10-12. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-14/src/lib.rs:here}} @@ -339,8 +336,7 @@ is a type alias for the type of the `impl` block, which in this case is `cmp_display` method if its inner type `T` implements the `PartialOrd` trait that enables comparison *and* the `Display` trait that enables printing. -+ ```rust,noplayground {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-15/src/lib.rs}} diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index 469702d311..1657a1979b 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -26,8 +26,7 @@ program to reference data other than the data it’s intended to reference. Consider the program in Listing 10-16, which has an outer scope and an inner scope. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/src/main.rs}} @@ -67,8 +66,7 @@ The Rust compiler has a *borrow checker* that compares scopes to determine whether all borrows are valid. Listing 10-17 shows the same code as Listing 10-16 but with annotations showing the lifetimes of the variables. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-17/src/main.rs}} @@ -86,8 +84,7 @@ with a lifetime of `'b`. The program is rejected because `'b` is shorter than Listing 10-18 fixes the code so it doesn’t have a dangling reference and it compiles without any errors. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/src/main.rs}} @@ -110,8 +107,7 @@ function will take two string slices and return a single string slice. After we’ve implemented the `longest` function, the code in Listing 10-19 should print `The longest string is abcd`. -+ ```rust,ignore {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/src/main.rs}} @@ -129,9 +125,7 @@ ones we want. If we try to implement the `longest` function as shown in Listing 10-20, it won’t compile. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/src/main.rs:here}} @@ -203,9 +197,7 @@ relationship between lifetimes of the parameters and the return value. We’ll name the lifetime `'a` and then add it to each reference, as shown in Listing 10-21. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-21/src/main.rs:here}} @@ -255,9 +247,7 @@ Let’s look at how the lifetime annotations restrict the `longest` function by passing in references that have different concrete lifetimes. Listing 10-22 is a straightforward example. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-22/src/main.rs:here}} @@ -279,8 +269,7 @@ assignment of the value to the `result` variable inside the scope with inner scope, after the inner scope has ended. The code in Listing 10-23 will not compile. -+ ```rust,ignore,does_not_compile {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/src/main.rs:here}} @@ -378,8 +367,7 @@ to hold references, but in that case we would need to add a lifetime annotation on every reference in the struct’s definition. Listing 10-24 has a struct named `ImportantExcerpt` that holds a string slice. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-24/src/main.rs}} @@ -408,9 +396,7 @@ lifetime parameters for functions or structs that use references. However, we had a function in Listing 4-9, shown again in Listing 10-25, that compiled without lifetime annotations. -+ ```rust {{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-25/src/main.rs:here}} From c5896494f86c77cf44e38229164f5f3ea565039f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 15 Oct 2024 07:14:31 -0600 Subject: [PATCH 642/720] Back out "Chapter 9 - Wrap all ``s to comply with the virtual 80 character limit" This backs out commit dd72f8fbc33fae0a3aaa4294e6b5947a1512932f. --- ...ch09-01-unrecoverable-errors-with-panic.md | 6 ++--- src/ch09-02-recoverable-errors-with-result.md | 27 +++++++------------ src/ch09-03-to-panic-or-not-to-panic.md | 3 +-- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/ch09-01-unrecoverable-errors-with-panic.md b/src/ch09-01-unrecoverable-errors-with-panic.md index dc13226181..2fc98835cd 100644 --- a/src/ch09-01-unrecoverable-errors-with-panic.md +++ b/src/ch09-01-unrecoverable-errors-with-panic.md @@ -66,8 +66,7 @@ a `panic!` call comes from a library because of a bug in our code instead of from our code calling the macro directly. Listing 9-1 has some code that attempts to access an index in a vector beyond the range of valid indexes. -+ ```rust,should_panic,panics {{#rustdoc_include ../listings/ch09-error-handling/listing-09-01/src/main.rs}} @@ -119,8 +118,7 @@ copy the backtrace output below check the backtrace number mentioned in the text below the listing --> -+ ```console $ RUST_BACKTRACE=1 cargo run diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index e04ea0da62..9f3387c292 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -59,8 +59,7 @@ on the value `File::open` returns. Listing 9-4 shows one way to handle the `Result` using a basic tool, the `match` expression that we discussed in Chapter 6. -+ ```rust,should_panic {{#rustdoc_include ../listings/ch09-error-handling/listing-09-04/src/main.rs}} @@ -98,8 +97,7 @@ reason—for example, because we didn’t have permission to open the file—we want the code to `panic!` in the same way it did in Listing 9-4. For this, we add an inner `match` expression, shown in Listing 9-5. -+ @@ -241,8 +239,7 @@ For example, Listing 9-6 shows a function that reads a username from a file. If the file doesn’t exist or can’t be read, this function will return those errors to the code that called the function. -+ -When we introduced the idea of pinning, while working on Listing 17-17, we ran +When we introduced the idea of pinning while working on Listing 17-17, we ran into a very gnarly error message. Here is the relevant part of it again: - When we introduced the idea of pinning while working on Listing 17-17, we ran into a very gnarly error message. Here is the relevant part of it again: @@ -152,10 +150,19 @@ For more information about an error, try `rustc --explain E0277`. When we read this error message carefully, it not only tells us that we need to pin the values, but also tells us why pinning is required. The `trpl::join_all` function returns a struct called `JoinAll`. That struct is generic over a type -`F`, which is constrained to implement the `Future` trait. Finally, directly -awaiting a Future requires that the future in question implement the `Unpin` -trait. That’s a lot! But we can understand it, if we dive a little further into -how the `Future` type actually works, in particular around *pinning*. +`F`, which is constrained to implement the `Future` trait. Directly awaiting a +future with `await` pins the future implicitly. That’s why we don’t need to use +`pin!` everywhere we want to await futures. + +However, we’re not directly awaiting a future here. Instead, we construct a new +future, `JoinAll`, by passing a collection of futures to the `join_all` +function. The signature for `join_all` produces requires that the type of the +items in the collection all implement the `Future` trait, and `Box` only +implements `Future` if the `T` that it wraps is a future which implements the +`Unpin` trait. + +That’s a lot! But we can understand it, if we dive a little further into how the +`Future` type actually works, in particular around *pinning*. Let’s look again at the definition of `Future`: @@ -312,14 +319,21 @@ type does *not* need to uphold any particular guarantees about whether the value in question can be moved. Just as with `Send` and `Sync`, the compiler implements `Unpin` automatically -for all types where it can prove it is safe. Implementing `Unpin` manually is -unsafe because it requires *you* to uphold all the guarantees which make `Pin` -and `Unpin` safe yourself for a type with internal references. In practice, -this is a very rare thing to implement yourself! +for all types where it can prove it is safe. The special case, again similar to +`Send` and `Sync`, is the case where `Unpin` is *not* implemented for a type. +The notation for this is `impl !Unpin for SomeType`, where `SomeType` is the +name of a type which *does* need to uphold those guarantees to be safe whenever +a pointer to that type it is used in a `Pin`. + +In other words, there are two things to keep in mind about the relationship +between `Pin` and `Unpin`. First, `Unpin` is the “normal” case, and `!Unpin` is +the special case. Second, whether a type implements `Unpin` or `!Unpin` *only* +matters when using a pinned pointer to that type like `Pin<&mut SomeType>`. To make that concrete, think about a `String`: it has a length and the Unicode characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure -17-7. However +17-8. However, `String` automatically implements `Unpin`, the same as most other +types in Rust.
@@ -329,10 +343,11 @@ characters which make it up. We can wrap a `String` in `Pin`, as seen in Figure
-This means that we can do things such as replace one string with another at the -exact same location in memory as in Figure 17-9. This doesn’t violate the `Pin` -contract because `String`—like most other types in Rust—implements `Unpin`, -because it has no internal references that make it unsafe to move around! +As a result, we can do things which would be illegal if `String` implemented +`!Unpin` instead, such as replace one string with another at the exact same +location in memory as in Figure 17-9. This doesn’t violate the `Pin` contract, +because `String` has no internal references that make it unsafe to move around! +That is precisely why it implements `Unpin` rather than `!Unpin`.
From 62d441060d66f9a1c3d3cdfffa8eed40f817d1aa Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 16 Oct 2024 11:07:09 -0600 Subject: [PATCH 648/720] Ch. 19: discuss `while let` referencing ch. 17 This is no longer the first time people see `while let` in the book, so (a) update the text to mention Chapter 17, and (b) change the example to show a `Result`-based scenario in addition to the an `Option`-based that readers saw back in Chapter 17, to make it clear that `while let` is not limited to working with `Option`. --- .../listing-19-02/src/main.rs | 15 +++++++------- src/ch17-02-concurrency-with-async.md | 2 -- src/ch19-01-all-the-places-for-patterns.md | 20 ++++++++++--------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/listings/ch19-patterns-and-matching/listing-19-02/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-02/src/main.rs index 2479d845d6..4605557f0b 100644 --- a/listings/ch19-patterns-and-matching/listing-19-02/src/main.rs +++ b/listings/ch19-patterns-and-matching/listing-19-02/src/main.rs @@ -1,13 +1,14 @@ fn main() { // ANCHOR: here - let mut stack = Vec::new(); + let (tx, rx) = std::sync::mpsc::channel(); + std::thread::spawn(move || { + for val in [1, 2, 3] { + tx.send(val).unwrap(); + } + }); - stack.push(1); - stack.push(2); - stack.push(3); - - while let Some(top) = stack.pop() { - println!("{top}"); + while let Ok(value) = rx.recv() { + println!("{value}"); } // ANCHOR_END: here } diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 7683bf5bf4..22557d1b7a 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -242,8 +242,6 @@ loop is the loop version of the `if let` construct we saw back in Chapter 6. The loop will continue executing as long as the pattern it specifies continues to match the value. - - The `rx.recv` call produces a `Future`, which we await. The runtime will pause the `Future` until it is ready. Once a message arrives, the future will resolve to `Some(message)`, as many times as a message arrives. When the channel closes, diff --git a/src/ch19-01-all-the-places-for-patterns.md b/src/ch19-01-all-the-places-for-patterns.md index 30e7135c53..03d132954d 100644 --- a/src/ch19-01-all-the-places-for-patterns.md +++ b/src/ch19-01-all-the-places-for-patterns.md @@ -98,11 +98,13 @@ not alert us to the possible logic bug. ### `while let` Conditional Loops Similar in construction to `if let`, the `while let` conditional loop allows a -`while` loop to run for as long as a pattern continues to match. In Listing -19-2 we code a `while let` loop that uses a vector as a stack and prints the -values in the vector in the opposite order in which they were pushed. +`while` loop to run for as long as a pattern continues to match. We first saw a +`while let` loop in Chapter 17, where we used it to keep looping as long as a +stream produced new values. Similarly, in Listing 19-2 we show a `while let` +loop that waits on messages sent between threads, but in this case checking a +`Result` instead of an `Option`. -+ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-02/src/main.rs:here}} @@ -110,11 +112,11 @@ values in the vector in the opposite order in which they were pushed. -This example prints 3, 2, and then 1. The `pop` method takes the last element -out of the vector and returns `Some(value)`. If the vector is empty, `pop` -returns `None`. The `while` loop continues running the code in its block as -long as `pop` returns `Some`. When `pop` returns `None`, the loop stops. We can -use `while let` to pop every element off our stack. +This example prints 1, 2, and 3. When we saw `recv` back in Chapter 16, we +unwrapped the error directly, or interacted with it as an iterator using a `for` +loop. As Listing 19-2 shows, though, we can also use `while let`, because the +`recv` method returns `Ok` as long as the sender is producing messages, and then +produces an `Err` once the sender side disconnects. ### `for` Loops From 1c6c44568e541bb8ba89d32c09fe70336ef6887c Mon Sep 17 00:00:00 2001 From: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:17:05 -0400 Subject: [PATCH 649/720] add missing semicolon in listing 19-15 --- listings/ch19-patterns-and-matching/listing-19-15/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch19-patterns-and-matching/listing-19-15/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-15/src/main.rs index 9407cc16ab..7edf7f2bb8 100644 --- a/listings/ch19-patterns-and-matching/listing-19-15/src/main.rs +++ b/listings/ch19-patterns-and-matching/listing-19-15/src/main.rs @@ -19,7 +19,7 @@ fn main() { println!("Text message: {text}"); } Message::ChangeColor(r, g, b) => { - println!("Change the color to red {r}, green {g}, and blue {b}") + println!("Change the color to red {r}, green {g}, and blue {b}"); } } } From b1f6e062b48458c7b32fd4232d486df04af8153a Mon Sep 17 00:00:00 2001 From: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:26:15 -0400 Subject: [PATCH 650/720] add semicolon to 19-16 --- listings/ch19-patterns-and-matching/listing-19-16/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch19-patterns-and-matching/listing-19-16/src/main.rs b/listings/ch19-patterns-and-matching/listing-19-16/src/main.rs index 1e7ad5f193..a31eeffb97 100644 --- a/listings/ch19-patterns-and-matching/listing-19-16/src/main.rs +++ b/listings/ch19-patterns-and-matching/listing-19-16/src/main.rs @@ -18,7 +18,7 @@ fn main() { println!("Change color to red {r}, green {g}, and blue {b}"); } Message::ChangeColor(Color::Hsv(h, s, v)) => { - println!("Change color to hue {h}, saturation {s}, value {v}") + println!("Change color to hue {h}, saturation {s}, value {v}"); } _ => (), } From be84fe8322c87406983cfa579ecce272ef55c0d2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 25 Oct 2024 14:59:39 -0600 Subject: [PATCH 651/720] infra: change how packages are opted out of workspaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `trpl`, `mdbook-trpl-note`, and `mdbook-trpl-listing` crates should *never* be part of a host workspace: neither in `rust-lang/book` nor in `rust-lang/rust`. They are always built as independent packages, so they do not end up depending implicitly on the host’s workspace dependencies. Accordingly, opt out by setting an empty `[workspace]` key in each of the packages' `Cargo.toml` files so that they do not have to be configured in both places they might be used. --- Cargo.toml | 8 -------- packages/mdbook-trpl-listing/Cargo.toml | 5 +++++ packages/mdbook-trpl-note/Cargo.toml | 5 +++++ packages/trpl/Cargo.toml | 5 +++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 20fc14643d..73c7ba471a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,14 +6,6 @@ exclude = [ "linkchecker", # linkchecker is part of the CI workflow "listings", # these are intentionally distinct from the workspace "tmp", # listings are built here when updating output via tools/update-rustc.sh - "packages/trpl", # manages its own dependencies as a standalone crate - - # These are used as path dependencies in `rust-lang/rust` (since we are not - # publishing them to crates.io), so they cannot be part of this workspace, - # because path dependencies do not get built as a crate within the hosting - # workspace. - "packages/mdbook-trpl-listing", - "packages/mdbook-trpl-note", ] [workspace.dependencies] diff --git a/packages/mdbook-trpl-listing/Cargo.toml b/packages/mdbook-trpl-listing/Cargo.toml index 20bfe347db..4b90001e23 100644 --- a/packages/mdbook-trpl-listing/Cargo.toml +++ b/packages/mdbook-trpl-listing/Cargo.toml @@ -17,3 +17,8 @@ toml = "0.8.12" [dev-dependencies] assert_cmd = "2" + +# This package is used as a path dependency in `rust-lang/rust`, not published +# to crates.io, so it cannot be part of the `rust-lang/book` workspace, because +# path dependencies do not get built as a crate within the hosting workspace. +[workspace] diff --git a/packages/mdbook-trpl-note/Cargo.toml b/packages/mdbook-trpl-note/Cargo.toml index e8dc53cc4c..4fde2fd878 100644 --- a/packages/mdbook-trpl-note/Cargo.toml +++ b/packages/mdbook-trpl-note/Cargo.toml @@ -14,3 +14,8 @@ serde_json = "1" [dev-dependencies] assert_cmd = "2" + +# This package is used as a path dependency in `rust-lang/rust`, not published +# to crates.io, so it cannot be part of the `rust-lang/book` workspace, because +# path dependencies do not get built as a crate within the hosting workspace. +[workspace] diff --git a/packages/trpl/Cargo.toml b/packages/trpl/Cargo.toml index 61c46319cc..26503e6b88 100644 --- a/packages/trpl/Cargo.toml +++ b/packages/trpl/Cargo.toml @@ -21,3 +21,8 @@ tokio = { version = "1", default-features = false, features = [ "time", ] } tokio-stream = "0.1" + +# This package is built as a standalone package to publish to crates.io, and is +# also built as a path dependency for distribution with Rust, so it must not be +# built as part of the `rust-lang/book` or `rust-lang/rust` workspaces. +[workspace] From 55a2693f20708866f8b001e4452fc7d4d1f35533 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 28 Oct 2024 16:17:57 -0600 Subject: [PATCH 652/720] infra: switch to `rustls` in `reqwest` dep for `trpl` Set `reqwest.default-features = false`, since it includes `native-tls` by default, and explicitly opt into `rustls-tls` instead. This also implicitly drops http2 support, but we do not use that in the examples, so that is actually just a small win. Contributes to rust-lang/rust#131859, which is failing because using `native-tis` requires the environment to have an OpenSSL installation, and the `rust-lang/rust` CI environment does not. --- packages/trpl/Cargo.lock | 392 +++++++++------------------------------ packages/trpl/Cargo.toml | 4 +- 2 files changed, 86 insertions(+), 310 deletions(-) diff --git a/packages/trpl/Cargo.lock b/packages/trpl/Cargo.lock index 475f5d6d00..51f1032120 100644 --- a/packages/trpl/Cargo.lock +++ b/packages/trpl/Cargo.lock @@ -30,12 +30,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -99,22 +93,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -170,58 +148,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -365,31 +297,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -459,7 +366,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -485,22 +391,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -533,16 +424,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -570,12 +451,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -644,23 +519,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -692,50 +550,6 @@ version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -887,12 +701,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -917,6 +725,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -973,38 +829,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1030,17 +885,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1049,6 +897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1088,15 +937,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1119,29 +959,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1310,48 +1127,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1385,16 +1188,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1417,19 +1210,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1543,12 +1323,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1647,6 +1421,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1695,15 +1478,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/packages/trpl/Cargo.toml b/packages/trpl/Cargo.toml index 26503e6b88..a76c8261b9 100644 --- a/packages/trpl/Cargo.toml +++ b/packages/trpl/Cargo.toml @@ -12,7 +12,9 @@ authors = ["Chris Krycho "] [dependencies] futures = "0.3" -reqwest = "0.12" +reqwest = { version = "0.12", default-features = false, features = [ + "rustls-tls", +] } scraper = "0.20" tokio = { version = "1", default-features = false, features = [ "fs", From 5b80fa3d18db877e2b67567b97220965be614e51 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:50:32 +0000 Subject: [PATCH 653/720] Bump quinn-proto from 0.11.6 to 0.11.8 in /packages/trpl Bumps [quinn-proto](https://github.com/quinn-rs/quinn) from 0.11.6 to 0.11.8. - [Release notes](https://github.com/quinn-rs/quinn/releases) - [Commits](https://github.com/quinn-rs/quinn/compare/quinn-proto-0.11.6...quinn-proto-0.11.8) --- updated-dependencies: - dependency-name: quinn-proto dependency-type: indirect ... Signed-off-by: dependabot[bot] --- packages/trpl/Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/trpl/Cargo.lock b/packages/trpl/Cargo.lock index 51f1032120..64b6198c28 100644 --- a/packages/trpl/Cargo.lock +++ b/packages/trpl/Cargo.lock @@ -745,9 +745,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.6" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", "rand", From 7c75ed3cc4e355ce0455673c449eb6e76b3fe43e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 30 Oct 2024 16:36:13 -0600 Subject: [PATCH 654/720] Ch. 17 fixes: correct a bad link in the 2018 edition pages Looks like I basically accidentally did the find-and-replace operation twice on this one. Whoops! --- 2018-edition/src/ch17-03-oo-design-patterns.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2018-edition/src/ch17-03-oo-design-patterns.md b/2018-edition/src/ch17-03-oo-design-patterns.md index c161b3decf..9513538f57 100644 --- a/2018-edition/src/ch17-03-oo-design-patterns.md +++ b/2018-edition/src/ch17-03-oo-design-patterns.md @@ -3,7 +3,7 @@ The 2018 edition of the book is no longer distributed with Rust's documentation. If you came here via a link or web search, you may want to check out [the current -version of the book](../ch19-03-oo-design-patterns.html) instead. +version of the book](../ch18-03-oo-design-patterns.html) instead. If you have an internet connection, you can [find a copy distributed with Rust From 5f04987e24e363e67b5ca7d2793d3f892be23123 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 27 Sep 2024 15:32:13 -0600 Subject: [PATCH 655/720] Ch. 21: Update to mention async/await as appropriate This does not significantly change the flow or text of the chapter; it merely acknowledges that we *did* do async and await and refers to the concepts or suggests the reader think about how things would differ if using futures and async. --- src/ch21-00-final-project-a-web-server.md | 30 +++++++++++++------- src/ch21-02-multithreaded.md | 15 +++++++++- src/ch21-03-graceful-shutdown-and-cleanup.md | 4 +++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/ch21-00-final-project-a-web-server.md b/src/ch21-00-final-project-a-web-server.md index 1004eaf3f1..23c149a393 100644 --- a/src/ch21-00-final-project-a-web-server.md +++ b/src/ch21-00-final-project-a-web-server.md @@ -20,14 +20,22 @@ Here is our plan for building the web server: 4. Create a proper HTTP response. 5. Improve the throughput of our server with a thread pool. -Before we get started, we should mention one detail: the method we’ll use won’t -be the best way to build a web server with Rust. Community members have -published a number of production-ready crates available on -[crates.io](https://crates.io/) that provide more complete web server and -thread pool implementations than we’ll build. However, our intention in this -chapter is to help you learn, not to take the easy route. Because Rust is a -systems programming language, we can choose the level of abstraction we want to -work with and can go to a lower level than is possible or practical in other -languages. We’ll therefore write the basic HTTP server and thread pool manually -so you can learn the general ideas and techniques behind the crates you might -use in the future. +Before we get started, we should mention two details: First, the method we’ll +use won’t be the best way to build a web server with Rust. Community members +have published a number of production-ready crates available on +[crates.io](https://crates.io/) that provide more complete web server and thread +pool implementations than we’ll build. However, our intention in this chapter is +to help you learn, not to take the easy route. Because Rust is a systems +programming language, we can choose the level of abstraction we want to work +with and can go to a lower level than is possible or practical in other +languages. + +Second, we will not be using async and await here. Building a thread pool is a +big enough challenge on its own, without adding in building an async runtime! +However, we will note how async and await might be applicable to some of the +same problems we will see in this chapter. Ultimately, as we noted back in +Chapter 17, many async runtimes use thread pools for managing their work. + +We’ll therefore write the basic HTTP server and thread pool manually so you can +learn the general ideas and techniques behind the crates you might use in the +future. diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index c4220a7bf5..f8043fc30f 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -43,7 +43,8 @@ But if you enter */sleep* and then load */*, you’ll see that */* waits until `sleep` has slept for its full 5 seconds before loading. There are multiple techniques we could use to avoid requests backing up behind -a slow request; the one we’ll implement is a thread pool. +a slow request, including using async as we did Chapter 17; the one we’ll +implement is a thread pool. ### Improving Throughput with a Thread Pool @@ -120,6 +121,10 @@ that the requests to */* don’t have to wait for */sleep* to finish. However, a we mentioned, this will eventually overwhelm the system because you’d be making new threads without any limit. +You may also recall from Chapter 17 that this is exactly the kind of situation +where async and await really shine! Keep that in mind as we build the thread +pool and think about how things would look different or the same with async. + @@ -291,6 +296,9 @@ yet! > writing unit tests to check that the code compiles *and* has the behavior we > want. +Consider: what would be different here if we were going to execute a *future* +instead of a closure? + #### Validating the Number of Threads in `new` We aren’t doing anything with the parameters to `new` and `execute`. Let’s @@ -657,6 +665,11 @@ thread run them. > multiple instances of the same request sequentially for caching reasons. This > limitation is not caused by our web server. +This is a good time to pause and consider how the code in Listings 21-18, 21-19, +and 21-20 would be different if we were using futures instead of a closure for +the work to be done. What types would change? How would the method signatures be +different, if at all? What parts of the code would stay the same? + After learning about the `while let` loop in Chapters 17 and 18, you might be wondering why we didn’t write the worker thread code as shown in Listing 21-21. diff --git a/src/ch21-03-graceful-shutdown-and-cleanup.md b/src/ch21-03-graceful-shutdown-and-cleanup.md index e73c4a5a59..9d2a02e54f 100644 --- a/src/ch21-03-graceful-shutdown-and-cleanup.md +++ b/src/ch21-03-graceful-shutdown-and-cleanup.md @@ -15,6 +15,10 @@ accepting new requests and shut down. To see this code in action, we’ll modify our server to accept only two requests before gracefully shutting down its thread pool. +One thing to notice as we go: none of this affects the parts of the code that +handle executing the closures, so everything here would be just the same if we +were using a thread pool for an async runtime. + ### Implementing the `Drop` Trait on `ThreadPool` Let’s start with implementing `Drop` on our thread pool. When the pool is From f612444e705749541a92358389bd23c12d3e8eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sun, 3 Nov 2024 10:32:43 +0000 Subject: [PATCH 656/720] ch17-01: Fix typos --- src/ch17-01-futures-and-syntax.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 054d1160ce..d33a0d9392 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -88,17 +88,17 @@ a request to it, and returns the text of the title element: In Listing 17-1, we define a function named `page_title`, and we mark it with the `async` keyword. Then we use the `trpl::get` function to fetch whatever URL -is passed in, and, and we await the response by using the `await` keyword. Then -we get the text of the response by calling its `text` method and once again -awaiting it with the `await` keyword. Both of these steps are asynchronous. For -`get`, we need to wait for the server to send back the first part of its -response, which will include HTTP headers, cookies, and so on. That part of the -response can be delivered separately from the body of the request. Especially if -the body is very large, it can take some time for it all to arrive. Thus, we -have to wait for the *entirety* of the response to arrive, so the `text` method -is also async. - -We have to explicitly await both of these futures, because futures in Rust are +is passed in, and we await the response by using the `await` keyword. Then we +get the text of the response by calling its `text` method, and once again await +it with the `await` keyword. Both of these steps are asynchronous. For `get`, +we need to wait for the server to send back the first part of its response, +which will include HTTP headers, cookies, and so on. That part of the response +can be delivered separately from the body of the request. Especially if the +body is very large, it can take some time for it all to arrive. Thus, we have +to wait for the *entirety* of the response to arrive, so the `text` method is +also async. + +We have to explicitly await both of these futures because futures in Rust are *lazy*: they don’t do anything until you ask them to with `await`. (In fact, Rust will show a compiler warning if you don’t use a future.) This should remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. From 3acd2768bea214f6699099eeddb8d22e93500684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sun, 3 Nov 2024 12:18:58 +0000 Subject: [PATCH 657/720] Fix a typo --- src/ch17-05-traits-for-async.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 07ed8c0db7..61b030deb7 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -323,7 +323,7 @@ for all types where it can prove it is safe. The special case, again similar to `Send` and `Sync`, is the case where `Unpin` is *not* implemented for a type. The notation for this is `impl !Unpin for SomeType`, where `SomeType` is the name of a type which *does* need to uphold those guarantees to be safe whenever -a pointer to that type it is used in a `Pin`. +a pointer to that type is used in a `Pin`. In other words, there are two things to keep in mind about the relationship between `Pin` and `Unpin`. First, `Unpin` is the “normal” case, and `!Unpin` is From 850ddec6ae5799e26c2d7adf1177b43bdb07ba55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sun, 3 Nov 2024 12:19:26 +0000 Subject: [PATCH 658/720] Add what seems to be a missing link --- src/ch17-05-traits-for-async.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 61b030deb7..04616ca9c4 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -224,8 +224,9 @@ getting a mutable or immutable reference to it. So far so good: if we get anything wrong about the ownership or references in a given async block, the borrow checker will tell us. When we want to move around -the future that corresponds to that block—like moving it into a `Vec` to pass to -`join_all`, the way we did back in—things get trickier. +the future that corresponds to that block—like moving it into a `Vec` to pass +to `join_all`, the way we did back in the [“Working With Any Number of +Futures”][any-number-futures] section—things get trickier. When we move a future—whether by pushing into a data structure to use as an iterator with `join_all`, or returning them from a function—that actually means @@ -480,6 +481,7 @@ and its methods with it automatically. [under-the-hood]: https://rust-lang.github.io/async-book/02_execution/01_chapter.html [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html [first-async]: ch17-01-futures-and-syntax.html#our-first-async-program +[any-number-futures]: ch17-03-more-futures.html#working-with-any-number-of-futures That’s all we’re going to cover for the lower-level details on these traits. To wrap up, let’s consider how futures (including streams), tasks, and threads all From 4072934a606c233845af8bf7c2546022f39d6746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sun, 3 Nov 2024 12:19:54 +0000 Subject: [PATCH 659/720] Add links to be after the last paragraph --- src/ch17-05-traits-for-async.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 04616ca9c4..836c73b617 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -475,6 +475,10 @@ even when you need to write your own streaming data type, you *only* have to implement `Stream`, and then anyone who uses your data type can use `StreamExt` and its methods with it automatically. +That’s all we’re going to cover for the lower-level details on these traits. To +wrap up, let’s consider how futures (including streams), tasks, and threads all +fit together! + [futures-syntax]: ch17-01-futures-and-syntax.html [counting]: ch17-02-concurrency-with-async.html [async-book]: https://rust-lang.github.io/async-book/ @@ -482,7 +486,3 @@ and its methods with it automatically. [pinning]: https://rust-lang.github.io/async-book/04_pinning/01_chapter.html [first-async]: ch17-01-futures-and-syntax.html#our-first-async-program [any-number-futures]: ch17-03-more-futures.html#working-with-any-number-of-futures - -That’s all we’re going to cover for the lower-level details on these traits. To -wrap up, let’s consider how futures (including streams), tasks, and threads all -fit together! From be7d802e5b8e32aeded9c8ae1e601aea2a955ea3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 4 Nov 2024 09:21:34 -0700 Subject: [PATCH 660/720] Revert comma deletion --- src/ch17-01-futures-and-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index d33a0d9392..8d58f7aa0d 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -98,7 +98,7 @@ body is very large, it can take some time for it all to arrive. Thus, we have to wait for the *entirety* of the response to arrive, so the `text` method is also async. -We have to explicitly await both of these futures because futures in Rust are +We have to explicitly await both of these futures, because futures in Rust are *lazy*: they don’t do anything until you ask them to with `await`. (In fact, Rust will show a compiler warning if you don’t use a future.) This should remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. From b9241f6b142b78ba110a03fadc366ca221261ac3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 4 Nov 2024 09:11:34 -0700 Subject: [PATCH 661/720] infra: support listing deps in `update-rustc.sh` --- tools/update-rustc.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/update-rustc.sh b/tools/update-rustc.sh index de04b3a074..72d8d89177 100755 --- a/tools/update-rustc.sh +++ b/tools/update-rustc.sh @@ -2,6 +2,16 @@ set -eu +# Build book `trpl` crate dependency in the location where the listings will go +# looking for it so they can compile correctly. +echo 'Building book dependencies in tmp/packages...' +mkdir -p tmp/packages +cp -r packages/trpl tmp/packages/trpl +cd tmp/packages/trpl +cargo clean > /dev/null +cargo build > /dev/null +cd - > /dev/null + # Build the book before making any changes for comparison of the output. echo 'Building book into tmp/book-before before updating...' mdbook build -d tmp/book-before From a92d8e6c2d027cae4fb5003dd454f063f466439e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 4 Nov 2024 12:37:17 -0700 Subject: [PATCH 662/720] Update Cargo.lock for all Ch. 17 listings --- .../ch17-async-await/listing-17-01/Cargo.lock | 401 ++++-------------- .../ch17-async-await/listing-17-02/Cargo.lock | 401 ++++-------------- .../ch17-async-await/listing-17-03/Cargo.lock | 401 ++++-------------- .../ch17-async-await/listing-17-04/Cargo.lock | 401 ++++-------------- .../ch17-async-await/listing-17-05/Cargo.lock | 401 ++++-------------- .../ch17-async-await/listing-17-06/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-07/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-08/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-09/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-10/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-11/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-12/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-13/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-14/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-15/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-16/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-17/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-18/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-19/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-20/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-21/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-22/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-23/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-24/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-25/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-26/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-27/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-28/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-29/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-30/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-31/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-32/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-33/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-34/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-35/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-36/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-37/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-38/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-39/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-40/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-41/Cargo.lock | 392 ++++------------- .../ch17-async-await/listing-17-42/Cargo.lock | 392 ++++------------- .../no-listing-state-machine/Cargo.lock | 401 ++++-------------- 43 files changed, 3617 insertions(+), 13293 deletions(-) diff --git a/listings/ch17-async-await/listing-17-01/Cargo.lock b/listings/ch17-async-await/listing-17-01/Cargo.lock index 4ee6b7a268..97939c930f 100644 --- a/listings/ch17-async-await/listing-17-01/Cargo.lock +++ b/listings/ch17-async-await/listing-17-01/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -110,20 +104,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" +name = "cfg_aliases" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "cssparser" @@ -180,58 +164,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -375,31 +313,6 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -469,7 +382,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -495,22 +407,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -543,16 +440,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -580,12 +467,6 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -652,24 +533,7 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "windows-sys", ] [[package]] @@ -693,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -888,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -918,6 +732,55 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e346e016eacfff12233c243718197ca12f148c84e1e84268a896699b41c71780" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys", +] + [[package]] name = "quote" version = "1.0.37" @@ -974,38 +837,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1021,7 +883,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1031,17 +893,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.37" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1050,6 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1089,15 +945,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1120,29 +967,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1249,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1317,48 +1141,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", + "futf", + "mac", + "utf-8", ] [[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "core-foundation-sys", - "libc", + "thiserror-impl", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", -] - -[[package]] -name = "tendril" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" -dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1388,17 +1198,7 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "windows-sys 0.52.0", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", + "windows-sys", ] [[package]] @@ -1423,19 +1223,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1549,12 +1336,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1653,6 +1434,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1692,15 +1482,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" diff --git a/listings/ch17-async-await/listing-17-02/Cargo.lock b/listings/ch17-async-await/listing-17-02/Cargo.lock index 9a37f621b1..92c1ffe0bb 100644 --- a/listings/ch17-async-await/listing-17-02/Cargo.lock +++ b/listings/ch17-async-await/listing-17-02/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -110,20 +104,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" +name = "cfg_aliases" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "cssparser" @@ -180,58 +164,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -375,31 +313,6 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -469,7 +382,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -495,22 +407,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -543,16 +440,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -580,12 +467,6 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -652,24 +533,7 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "windows-sys", ] [[package]] @@ -693,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -888,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -918,6 +732,55 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e346e016eacfff12233c243718197ca12f148c84e1e84268a896699b41c71780" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys", +] + [[package]] name = "quote" version = "1.0.37" @@ -974,38 +837,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1021,7 +883,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1031,17 +893,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.37" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1050,6 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1089,15 +945,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1120,29 +967,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1249,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1317,48 +1141,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", + "futf", + "mac", + "utf-8", ] [[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "core-foundation-sys", - "libc", + "thiserror-impl", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", -] - -[[package]] -name = "tendril" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" -dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1388,17 +1198,7 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "windows-sys 0.52.0", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", + "windows-sys", ] [[package]] @@ -1423,19 +1223,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1549,12 +1336,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1653,6 +1434,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1692,15 +1482,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" diff --git a/listings/ch17-async-await/listing-17-03/Cargo.lock b/listings/ch17-async-await/listing-17-03/Cargo.lock index 9a37f621b1..92c1ffe0bb 100644 --- a/listings/ch17-async-await/listing-17-03/Cargo.lock +++ b/listings/ch17-async-await/listing-17-03/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -110,20 +104,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" +name = "cfg_aliases" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "cssparser" @@ -180,58 +164,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -375,31 +313,6 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -469,7 +382,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -495,22 +407,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -543,16 +440,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -580,12 +467,6 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -652,24 +533,7 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "windows-sys", ] [[package]] @@ -693,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -888,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -918,6 +732,55 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e346e016eacfff12233c243718197ca12f148c84e1e84268a896699b41c71780" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys", +] + [[package]] name = "quote" version = "1.0.37" @@ -974,38 +837,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1021,7 +883,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1031,17 +893,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.37" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1050,6 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1089,15 +945,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1120,29 +967,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1249,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1317,48 +1141,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", + "futf", + "mac", + "utf-8", ] [[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "core-foundation-sys", - "libc", + "thiserror-impl", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", -] - -[[package]] -name = "tendril" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" -dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1388,17 +1198,7 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "windows-sys 0.52.0", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", + "windows-sys", ] [[package]] @@ -1423,19 +1223,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1549,12 +1336,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1653,6 +1434,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1692,15 +1482,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" diff --git a/listings/ch17-async-await/listing-17-04/Cargo.lock b/listings/ch17-async-await/listing-17-04/Cargo.lock index 9a37f621b1..92c1ffe0bb 100644 --- a/listings/ch17-async-await/listing-17-04/Cargo.lock +++ b/listings/ch17-async-await/listing-17-04/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -110,20 +104,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" +name = "cfg_aliases" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "cssparser" @@ -180,58 +164,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -375,31 +313,6 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -469,7 +382,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -495,22 +407,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -543,16 +440,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -580,12 +467,6 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -652,24 +533,7 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "windows-sys", ] [[package]] @@ -693,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -888,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -918,6 +732,55 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e346e016eacfff12233c243718197ca12f148c84e1e84268a896699b41c71780" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys", +] + [[package]] name = "quote" version = "1.0.37" @@ -974,38 +837,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1021,7 +883,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1031,17 +893,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.37" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1050,6 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1089,15 +945,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1120,29 +967,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1249,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1317,48 +1141,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", + "futf", + "mac", + "utf-8", ] [[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "core-foundation-sys", - "libc", + "thiserror-impl", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", -] - -[[package]] -name = "tendril" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" -dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1388,17 +1198,7 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "windows-sys 0.52.0", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", + "windows-sys", ] [[package]] @@ -1423,19 +1223,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1549,12 +1336,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1653,6 +1434,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1692,15 +1482,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" diff --git a/listings/ch17-async-await/listing-17-05/Cargo.lock b/listings/ch17-async-await/listing-17-05/Cargo.lock index 9a37f621b1..92c1ffe0bb 100644 --- a/listings/ch17-async-await/listing-17-05/Cargo.lock +++ b/listings/ch17-async-await/listing-17-05/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -110,20 +104,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" +name = "cfg_aliases" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "cssparser" @@ -180,58 +164,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -375,31 +313,6 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -469,7 +382,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -495,22 +407,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -543,16 +440,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -580,12 +467,6 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -652,24 +533,7 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "windows-sys", ] [[package]] @@ -693,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -888,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -918,6 +732,55 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e346e016eacfff12233c243718197ca12f148c84e1e84268a896699b41c71780" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys", +] + [[package]] name = "quote" version = "1.0.37" @@ -974,38 +837,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1021,7 +883,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1031,17 +893,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.37" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1050,6 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1089,15 +945,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1120,29 +967,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1249,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1317,48 +1141,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", + "futf", + "mac", + "utf-8", ] [[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "core-foundation-sys", - "libc", + "thiserror-impl", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", -] - -[[package]] -name = "tendril" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" -dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1388,17 +1198,7 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "windows-sys 0.52.0", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", + "windows-sys", ] [[package]] @@ -1423,19 +1223,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1549,12 +1336,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1653,6 +1434,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1692,15 +1482,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" diff --git a/listings/ch17-async-await/listing-17-06/Cargo.lock b/listings/ch17-async-await/listing-17-06/Cargo.lock index 0be7d2c88b..e3f560b67c 100644 --- a/listings/ch17-async-await/listing-17-06/Cargo.lock +++ b/listings/ch17-async-await/listing-17-06/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -540,16 +431,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -577,12 +458,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -651,23 +526,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -699,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -894,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -924,6 +732,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -980,38 +836,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1037,17 +892,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1056,6 +904,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1095,15 +944,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1126,29 +966,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1317,48 +1134,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1392,16 +1195,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1424,19 +1217,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1550,12 +1330,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1654,6 +1428,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1702,15 +1485,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-07/Cargo.lock b/listings/ch17-async-await/listing-17-07/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-07/Cargo.lock +++ b/listings/ch17-async-await/listing-17-07/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-08/Cargo.lock b/listings/ch17-async-await/listing-17-08/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-08/Cargo.lock +++ b/listings/ch17-async-await/listing-17-08/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-09/Cargo.lock b/listings/ch17-async-await/listing-17-09/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-09/Cargo.lock +++ b/listings/ch17-async-await/listing-17-09/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-10/Cargo.lock b/listings/ch17-async-await/listing-17-10/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-10/Cargo.lock +++ b/listings/ch17-async-await/listing-17-10/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-11/Cargo.lock b/listings/ch17-async-await/listing-17-11/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-11/Cargo.lock +++ b/listings/ch17-async-await/listing-17-11/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-12/Cargo.lock b/listings/ch17-async-await/listing-17-12/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-12/Cargo.lock +++ b/listings/ch17-async-await/listing-17-12/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-13/Cargo.lock b/listings/ch17-async-await/listing-17-13/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-13/Cargo.lock +++ b/listings/ch17-async-await/listing-17-13/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-14/Cargo.lock b/listings/ch17-async-await/listing-17-14/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-14/Cargo.lock +++ b/listings/ch17-async-await/listing-17-14/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-15/Cargo.lock b/listings/ch17-async-await/listing-17-15/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-15/Cargo.lock +++ b/listings/ch17-async-await/listing-17-15/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-16/Cargo.lock b/listings/ch17-async-await/listing-17-16/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-16/Cargo.lock +++ b/listings/ch17-async-await/listing-17-16/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-17/Cargo.lock b/listings/ch17-async-await/listing-17-17/Cargo.lock index 973206db69..7dc48e0d98 100644 --- a/listings/ch17-async-await/listing-17-17/Cargo.lock +++ b/listings/ch17-async-await/listing-17-17/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-18/Cargo.lock b/listings/ch17-async-await/listing-17-18/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-18/Cargo.lock +++ b/listings/ch17-async-await/listing-17-18/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-19/Cargo.lock b/listings/ch17-async-await/listing-17-19/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-19/Cargo.lock +++ b/listings/ch17-async-await/listing-17-19/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-20/Cargo.lock b/listings/ch17-async-await/listing-17-20/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-20/Cargo.lock +++ b/listings/ch17-async-await/listing-17-20/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-21/Cargo.lock b/listings/ch17-async-await/listing-17-21/Cargo.lock index 34598194f8..00a82573e5 100644 --- a/listings/ch17-async-await/listing-17-21/Cargo.lock +++ b/listings/ch17-async-await/listing-17-21/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.2" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-22/Cargo.lock b/listings/ch17-async-await/listing-17-22/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-22/Cargo.lock +++ b/listings/ch17-async-await/listing-17-22/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-23/Cargo.lock b/listings/ch17-async-await/listing-17-23/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-23/Cargo.lock +++ b/listings/ch17-async-await/listing-17-23/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-24/Cargo.lock b/listings/ch17-async-await/listing-17-24/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-24/Cargo.lock +++ b/listings/ch17-async-await/listing-17-24/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-25/Cargo.lock b/listings/ch17-async-await/listing-17-25/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-25/Cargo.lock +++ b/listings/ch17-async-await/listing-17-25/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-26/Cargo.lock b/listings/ch17-async-await/listing-17-26/Cargo.lock index 34598194f8..00a82573e5 100644 --- a/listings/ch17-async-await/listing-17-26/Cargo.lock +++ b/listings/ch17-async-await/listing-17-26/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.2" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-27/Cargo.lock b/listings/ch17-async-await/listing-17-27/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-27/Cargo.lock +++ b/listings/ch17-async-await/listing-17-27/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-28/Cargo.lock b/listings/ch17-async-await/listing-17-28/Cargo.lock index f09d29189b..7efd72f633 100644 --- a/listings/ch17-async-await/listing-17-28/Cargo.lock +++ b/listings/ch17-async-await/listing-17-28/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-29/Cargo.lock b/listings/ch17-async-await/listing-17-29/Cargo.lock index 0be7d2c88b..e3f560b67c 100644 --- a/listings/ch17-async-await/listing-17-29/Cargo.lock +++ b/listings/ch17-async-await/listing-17-29/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -540,16 +431,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -577,12 +458,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -651,23 +526,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -699,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -894,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -924,6 +732,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -980,38 +836,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1037,17 +892,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1056,6 +904,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1095,15 +944,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1126,29 +966,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1317,48 +1134,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1392,16 +1195,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1424,19 +1217,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1550,12 +1330,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1654,6 +1428,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1702,15 +1485,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-30/Cargo.lock b/listings/ch17-async-await/listing-17-30/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-30/Cargo.lock +++ b/listings/ch17-async-await/listing-17-30/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-31/Cargo.lock b/listings/ch17-async-await/listing-17-31/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-31/Cargo.lock +++ b/listings/ch17-async-await/listing-17-31/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-32/Cargo.lock b/listings/ch17-async-await/listing-17-32/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-32/Cargo.lock +++ b/listings/ch17-async-await/listing-17-32/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-33/Cargo.lock b/listings/ch17-async-await/listing-17-33/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-33/Cargo.lock +++ b/listings/ch17-async-await/listing-17-33/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-34/Cargo.lock b/listings/ch17-async-await/listing-17-34/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-34/Cargo.lock +++ b/listings/ch17-async-await/listing-17-34/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-35/Cargo.lock b/listings/ch17-async-await/listing-17-35/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-35/Cargo.lock +++ b/listings/ch17-async-await/listing-17-35/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-36/Cargo.lock b/listings/ch17-async-await/listing-17-36/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-36/Cargo.lock +++ b/listings/ch17-async-await/listing-17-36/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-37/Cargo.lock b/listings/ch17-async-await/listing-17-37/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-37/Cargo.lock +++ b/listings/ch17-async-await/listing-17-37/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-38/Cargo.lock b/listings/ch17-async-await/listing-17-38/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-38/Cargo.lock +++ b/listings/ch17-async-await/listing-17-38/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-39/Cargo.lock b/listings/ch17-async-await/listing-17-39/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-39/Cargo.lock +++ b/listings/ch17-async-await/listing-17-39/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-40/Cargo.lock b/listings/ch17-async-await/listing-17-40/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-40/Cargo.lock +++ b/listings/ch17-async-await/listing-17-40/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-41/Cargo.lock b/listings/ch17-async-await/listing-17-41/Cargo.lock index 72e870c80c..1a59804c89 100644 --- a/listings/ch17-async-await/listing-17-41/Cargo.lock +++ b/listings/ch17-async-await/listing-17-41/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -539,16 +430,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -576,12 +457,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -650,23 +525,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -698,50 +556,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -873,12 +687,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -903,6 +711,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -959,38 +815,37 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1016,17 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1035,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1073,15 +922,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1104,29 +944,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1295,48 +1112,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1370,16 +1173,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1402,19 +1195,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -1507,12 +1287,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1611,6 +1385,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1659,15 +1442,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/listing-17-42/Cargo.lock b/listings/ch17-async-await/listing-17-42/Cargo.lock index 071a0943b4..0c240d2b4e 100644 --- a/listings/ch17-async-await/listing-17-42/Cargo.lock +++ b/listings/ch17-async-await/listing-17-42/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -106,22 +100,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cssparser" version = "0.31.2" @@ -177,58 +155,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -372,31 +304,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -466,7 +373,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -492,22 +398,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -540,16 +431,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -577,12 +458,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -651,23 +526,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -699,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -894,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -924,6 +732,54 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -980,38 +836,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1037,17 +892,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.34" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1056,6 +904,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1095,15 +944,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1126,29 +966,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1317,48 +1134,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1392,16 +1195,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -1424,19 +1217,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1550,12 +1330,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1654,6 +1428,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1702,15 +1485,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-targets" version = "0.48.5" diff --git a/listings/ch17-async-await/no-listing-state-machine/Cargo.lock b/listings/ch17-async-await/no-listing-state-machine/Cargo.lock index 7b6b110bc2..97939c930f 100644 --- a/listings/ch17-async-await/no-listing-state-machine/Cargo.lock +++ b/listings/ch17-async-await/no-listing-state-machine/Cargo.lock @@ -37,12 +37,6 @@ dependencies = [ "trpl", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.3.0" @@ -110,20 +104,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" +name = "cfg_aliases" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "cssparser" @@ -180,58 +164,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -375,31 +313,6 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -469,7 +382,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http", "http-body", "httparse", @@ -495,22 +407,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -543,16 +440,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -580,12 +467,6 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -652,24 +533,7 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "windows-sys", ] [[package]] @@ -693,50 +557,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -888,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -918,6 +732,55 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e346e016eacfff12233c243718197ca12f148c84e1e84268a896699b41c71780" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys", +] + [[package]] name = "quote" version = "1.0.37" @@ -974,38 +837,37 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", - "encoding_rs", "futures-core", "futures-util", - "h2", "http", "http-body", "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "windows-registry", ] @@ -1021,7 +883,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1031,17 +893,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.37" +name = "rustc-hash" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" @@ -1050,6 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -1089,15 +945,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1120,29 +967,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.25.0" @@ -1249,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1317,48 +1141,34 @@ dependencies = [ ] [[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" +name = "tendril" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" dependencies = [ - "core-foundation-sys", - "libc", + "futf", + "mac", + "utf-8", ] [[package]] -name = "tempfile" -version = "3.12.0" +name = "thiserror" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "cfg-if", - "fastrand", - "once_cell", - "rustix", - "windows-sys 0.59.0", + "thiserror-impl", ] [[package]] -name = "tendril" -version = "0.4.3" +name = "thiserror-impl" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ - "futf", - "mac", - "utf-8", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1388,17 +1198,7 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "windows-sys 0.52.0", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", + "windows-sys", ] [[package]] @@ -1423,19 +1223,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "tower" version = "0.4.13" @@ -1549,12 +1336,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" @@ -1653,6 +1434,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -1692,15 +1482,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" From e28cd5b13f5f8f6bf3698dea86f3e505c1945a9c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 4 Nov 2024 13:03:48 -0700 Subject: [PATCH 663/720] Set the correct baseline for current Rust version Unfortunately missed some of this when updating to Rust 1.81 --- .../listing-02-04/output.txt | 29 ++++++------ .../output.txt | 31 +++++++------ .../output.txt | 5 ++ .../listing-16-14/output.txt | 46 +++++++++++-------- .../ch17-async-await/listing-17-04/output.txt | 3 -- .../ch17-async-await/listing-17-19/output.txt | 14 ------ .../listing-19-08/output.txt | 2 +- .../ch21-web-server/listing-21-22/output.txt | 19 ++++---- .../output.txt | 21 +++++---- src/ch17-01-futures-and-syntax.md | 14 +++++- 10 files changed, 97 insertions(+), 87 deletions(-) delete mode 100644 listings/ch17-async-await/listing-17-04/output.txt delete mode 100644 listings/ch17-async-await/listing-17-19/output.txt diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 0f0bc21025..8ecc695804 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -1,10 +1,4 @@ $ 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 @@ -14,17 +8,20 @@ $ cargo build Compiling rand v0.8.5 Compiling guessing_game v0.1.0 (file:///projects/guessing_game) error[E0308]: mismatched types - --> src/main.rs:22:21 - | -22 | match guess.cmp(&secret_number) { - | --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}` - | | - | arguments to this method are incorrect - | - = note: expected reference `&String` - found reference `&{integer}` + --> src/main.rs:22:21 + | +22 | match guess.cmp(&secret_number) { + | --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}` + | | + | arguments to this method are incorrect + | + = note: expected reference `&String` + found reference `&{integer}` note: method defined here - --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/cmp.rs:839:8 + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/cmp.rs:839:8 + | +839 | fn cmp(&self, other: &Self) -> Ordering; + | ^^^ 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/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 43acd14d63..0b50c4273f 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -1,22 +1,25 @@ $ cargo run Compiling enums v0.1.0 (file:///projects/enums) error[E0004]: non-exhaustive patterns: `None` not covered - --> src/main.rs:3:15 - | -3 | match x { - | ^ pattern `None` not covered - | + --> src/main.rs:3:15 + | +3 | match x { + | ^ pattern `None` not covered + | note: `Option` defined here - --> /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` + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:574:1 + | +574 | pub enum Option { + | ^^^^^^^^^^^^^^^^^^ +... +578 | None, + | ---- not covered + = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown - | -4 ~ Some(i) => Some(i + 1), -5 ~ None => todo!(), - | + | +4 ~ Some(i) => Some(i + 1), +5 ~ None => todo!(), + | For more information about this error, try `rustc --explain E0004`. error: could not compile `enums` (bin "enums") due to 1 previous error diff --git a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt index d1eccd2b22..12664a815b 100644 --- a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt +++ b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt @@ -8,6 +8,11 @@ error[E0277]: can't compare `{integer}` with `&{integer}` | = help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}` = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider dereferencing here + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/macros/mod.rs:40:35 + | +40| if !(*left_val == **right_val) { + | + For more information about this error, try `rustc --explain E0277`. error: could not compile `deref-example` (bin "deref-example") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index cc96baed1d..850e4ddbd6 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -1,28 +1,34 @@ $ cargo run Compiling shared-state v0.1.0 (file:///projects/shared-state) error[E0277]: `Rc>` cannot be sent between threads safely - --> src/main.rs:11:36 - | -11 | let handle = thread::spawn(move || { - | ------------- ^------ - | | | - | ______________________|_____________within this `{closure@src/main.rs:11:36: 11:43}` - | | | - | | required by a bound introduced by this call -12 | | let mut num = counter.lock().unwrap(); -13 | | -14 | | *num += 1; -15 | | }); - | |_________^ `Rc>` cannot be sent between threads safely - | - = help: within `{closure@src/main.rs:11:36: 11:43}`, the trait `Send` is not implemented for `Rc>`, which is required by `{closure@src/main.rs:11:36: 11:43}: Send` + --> src/main.rs:11:36 + | +11 | let handle = thread::spawn(move || { + | ------------- ^------ + | | | + | ______________________|_____________within this `{closure@src/main.rs:11:36: 11:43}` + | | | + | | required by a bound introduced by this call +12 | | let mut num = counter.lock().unwrap(); +13 | | +14 | | *num += 1; +15 | | }); + | |_________^ `Rc>` cannot be sent between threads safely + | + = help: within `{closure@src/main.rs:11:36: 11:43}`, the trait `Send` is not implemented for `Rc>`, which is required by `{closure@src/main.rs:11:36: 11:43}: Send` note: required because it's used within this closure - --> src/main.rs:11:36 - | -11 | let handle = thread::spawn(move || { - | ^^^^^^^ + --> src/main.rs:11:36 + | +11 | let handle = thread::spawn(move || { + | ^^^^^^^ note: required by a bound in `spawn` - --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:688:1 + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:691:8 + | +688 | pub fn spawn(f: F) -> JoinHandle + | ----- required by a bound in this function +... +691 | F: Send + 'static, + | ^^^^ required by this bound in `spawn` 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/listings/ch17-async-await/listing-17-04/output.txt b/listings/ch17-async-await/listing-17-04/output.txt deleted file mode 100644 index a9b7a86ff3..0000000000 --- a/listings/ch17-async-await/listing-17-04/output.txt +++ /dev/null @@ -1,3 +0,0 @@ -$ cargo run "http://www.rust-lang.org" -The title for http://www.rust-lang.org was - Rust Programming Language diff --git a/listings/ch17-async-await/listing-17-19/output.txt b/listings/ch17-async-await/listing-17-19/output.txt deleted file mode 100644 index f6a657d5ae..0000000000 --- a/listings/ch17-async-await/listing-17-19/output.txt +++ /dev/null @@ -1,14 +0,0 @@ -$ cargo run -error: failed to get `trpl` as a dependency of package `async_await v0.1.0 (/Users/chris/dev/rust-lang/book/tmp/listings/ch17-async-await/listing-17-18)` - -Caused by: - failed to load source for dependency `trpl` - -Caused by: - Unable to update /Users/chris/dev/rust-lang/book/tmp/packages/trpl - -Caused by: - failed to read `/Users/chris/dev/rust-lang/book/tmp/packages/trpl/Cargo.toml` - -Caused by: - No such file or directory (os error 2) diff --git a/listings/ch19-patterns-and-matching/listing-19-08/output.txt b/listings/ch19-patterns-and-matching/listing-19-08/output.txt index 0ed34b7164..6ce3dfc582 100644 --- a/listings/ch19-patterns-and-matching/listing-19-08/output.txt +++ b/listings/ch19-patterns-and-matching/listing-19-08/output.txt @@ -7,7 +7,7 @@ error[E0005]: refutable pattern in local binding | ^^^^^^^ pattern `None` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant - = note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html + = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `Option` help: you might want to use `let else` to handle the variant that isn't matched | diff --git a/listings/ch21-web-server/listing-21-22/output.txt b/listings/ch21-web-server/listing-21-22/output.txt index 554bfd8591..189f5bd0e2 100644 --- a/listings/ch21-web-server/listing-21-22/output.txt +++ b/listings/ch21-web-server/listing-21-22/output.txt @@ -1,15 +1,18 @@ $ cargo check Checking hello v0.1.0 (file:///projects/hello) error[E0507]: cannot move out of `worker.thread` which is behind a mutable reference - --> src/lib.rs:52:13 - | -52 | worker.thread.join().unwrap(); - | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this method call - | | - | move occurs because `worker.thread` has type `JoinHandle<()>`, which does not implement the `Copy` trait - | + --> src/lib.rs:52:13 + | +52 | worker.thread.join().unwrap(); + | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this method call + | | + | 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/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:1778:17 + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:1778:17 + | +1778 | pub fn join(self) -> Result { + | ^^^^ For more information about this error, try `rustc --explain E0507`. error: could not compile `hello` (lib) due to 1 previous error diff --git a/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt index 6867dcbcaf..3042df208b 100644 --- a/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt @@ -1,17 +1,20 @@ $ cargo check Checking hello v0.1.0 (file:///projects/hello) error[E0599]: no method named `join` found for enum `Option` in the current scope - --> src/lib.rs:52:27 - | -52 | worker.thread.join().unwrap(); - | ^^^^ method not found in `Option>` - | + --> src/lib.rs:52:27 + | +52 | worker.thread.join().unwrap(); + | ^^^^ method not found in `Option>` + | note: the method `join` exists on the type `JoinHandle<()>` - --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:1778:5 + --> /Users/chris/.rustup/toolchains/1.81-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1778:5 + | +1778 | pub fn join(self) -> Result { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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(); - | +++++++++++++++++ + | +52 | worker.thread.expect("REASON").join().unwrap(); + | +++++++++++++++++ error[E0308]: mismatched types --> src/lib.rs:72:22 diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 8d58f7aa0d..c1b223cc8b 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -259,7 +259,7 @@ await the result of calling `page_title`, as in Listing 17-4. - + ```rust,should_panic,noplayground {{#rustdoc_include ../listings/ch17-async-await/listing-17-04/src/main.rs:run}} @@ -269,8 +269,18 @@ await the result of calling `page_title`, as in Listing 17-4. When we run this, we get the behavior we might have expected initially: + + ```console -{{#include ../listings/ch17-async-await/listing-17-04/output.txt}} +$ cargo run https://www.rust-lang.org +The title for https://www.rust-lang.org was +Rust Programming Language ``` Phew: we finally have some working async code! This now compiles, and we can run From effecb884e14461d02e0cf697eb79d2d84049a89 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 5 Nov 2024 14:48:19 -0700 Subject: [PATCH 664/720] infra: rewrite rustup toolchain paths in update-rustc.sh As with project paths, we do not want these to have the paths from the user who runs `update-rustc.sh`, but some totally generic path. --- tools/update-rustc.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/update-rustc.sh b/tools/update-rustc.sh index 72d8d89177..8e674e0569 100755 --- a/tools/update-rustc.sh +++ b/tools/update-rustc.sh @@ -8,8 +8,9 @@ echo 'Building book dependencies in tmp/packages...' mkdir -p tmp/packages cp -r packages/trpl tmp/packages/trpl cd tmp/packages/trpl -cargo clean > /dev/null -cargo build > /dev/null + # hide the output; if it fails, debug then. +cargo clean > /dev/null 2>&1 +cargo build > /dev/null 2>&1 cd - > /dev/null # Build the book before making any changes for comparison of the output. @@ -73,6 +74,16 @@ find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do # instead of a path to the computer of whoever is running this sed -i '' -E -e 's@(Compiling|Checking) ([^\)]*) v0.1.0 (.*)@\1 \2 v0.1.0 (file:///projects/\2)@' "${full_output_path}" + # Likewise, use a "default" installation directory for rustup's install + # location so the version of the source is not a path on the computer of + # whoever is doing the update. This does two substitutions: + # + # - Replaces the path up to `.rustup/toolchains` with `file:///home`, while + # preserving leading spaces and the `-->`. + # - Replaces the version-and-architecture-tripl with just the version, so + # e.g. `1.82-aarch64-apple-darwin` becomes `1.82`. + sed -i '' -E -e 's@^([[:space:]]*-->[[:space:]]+).*(\.rustup/toolchains/[[:digit:]]+\.[[:digit:]]+)([^/]*)@\1file:///home/\2@' "${full_output_path}" + # Restore the previous compile time, if there is one if [ -n "${compile_time}" ]; then sed -i '' -E -e "s/Finished \`(dev|test)\` profile \[unoptimized \+ debuginfo] target\(s\) in [0-9.]*/Finished \`\1\` profile [unoptimized + debuginfo] target(s) in ${compile_time}/" "${full_output_path}" From c913659d62c1f89f2e68ef26cc8c6cde0fb8f556 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 5 Nov 2024 14:48:19 -0700 Subject: [PATCH 665/720] infra: correctly report skipped paths in listings --- packages/tools/src/bin/release_listings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tools/src/bin/release_listings.rs b/packages/tools/src/bin/release_listings.rs index 09fb209761..468c4637dd 100644 --- a/packages/tools/src/bin/release_listings.rs +++ b/packages/tools/src/bin/release_listings.rs @@ -64,7 +64,7 @@ fn main() -> Result<(), Box> { if !listing_path.is_dir() { eprintln!( "'{}' is not a directory, skipping", - chapter_path.display() + listing_path.display(), ); continue; } From 96501370c28899e0362f0b3134f4cbb758f75e26 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 17 Oct 2024 14:41:03 -0600 Subject: [PATCH 666/720] Update to Rust 1.82 --- .github/workflows/main.yml | 8 ++++---- .../ch02-guessing-game-tutorial/listing-02-04/output.txt | 4 ++-- .../no-listing-10-non-exhaustive-match/output.txt | 6 +++--- listings/ch09-error-handling/listing-09-10/output.txt | 4 +--- .../output-only-01-comparing-to-reference/output.txt | 4 ++-- .../ch16-fearless-concurrency/listing-16-14/output.txt | 6 +++--- listings/ch21-web-server/listing-21-22/output.txt | 4 ++-- .../no-listing-04-update-worker-definition/output.txt | 4 ++-- rust-toolchain | 2 +- src/title-page.md | 2 +- 10 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d17b7286a9..727f1d1312 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.81 -c rust-docs - rustup default 1.81 + rustup toolchain install 1.82 -c rust-docs + rustup default 1.82 - name: Install mdbook run: | mkdir bin @@ -47,8 +47,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.81 -c rust-docs - rustup default 1.81 + rustup toolchain install 1.82 -c rust-docs + rustup default 1.82 - name: Run `tools` package tests run: | cargo test diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 8ecc695804..35e21b0a25 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -18,9 +18,9 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/cmp.rs:839:8 + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/core/src/cmp.rs:838:8 | -839 | fn cmp(&self, other: &Self) -> Ordering; +838 | fn cmp(&self, other: &Self) -> Ordering; | ^^^ For more information about this error, try `rustc --explain E0308`. diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 0b50c4273f..8cf3aa0749 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -7,12 +7,12 @@ error[E0004]: non-exhaustive patterns: `None` not covered | ^ pattern `None` not covered | note: `Option` defined here - --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:574:1 + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/core/src/option.rs:571:1 | -574 | pub enum Option { +571 | pub enum Option { | ^^^^^^^^^^^^^^^^^^ ... -578 | None, +575 | None, | ---- not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown diff --git a/listings/ch09-error-handling/listing-09-10/output.txt b/listings/ch09-error-handling/listing-09-10/output.txt index f3c1641b24..9e9b206fee 100644 --- a/listings/ch09-error-handling/listing-09-10/output.txt +++ b/listings/ch09-error-handling/listing-09-10/output.txt @@ -13,9 +13,7 @@ help: consider adding return type | 3 ~ fn main() -> Result<(), Box> { 4 | let greeting_file = File::open("hello.txt")?; -5 + -6 + Ok(()) -7 + } +5 + Ok(()) | For more information about this error, try `rustc --explain E0277`. diff --git a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt index 12664a815b..75ad91a0b3 100644 --- a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt +++ b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt @@ -9,9 +9,9 @@ error[E0277]: can't compare `{integer}` with `&{integer}` = help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}` = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider dereferencing here - --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/macros/mod.rs:40:35 + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/core/src/macros/mod.rs:46:35 | -40| if !(*left_val == **right_val) { +46| if !(*left_val == **right_val) { | + For more information about this error, try `rustc --explain E0277`. diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index 850e4ddbd6..a0adbc6190 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -22,12 +22,12 @@ note: required because it's used within this closure 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` - --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:691:8 + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/std/src/thread/mod.rs:675:8 | -688 | pub fn spawn(f: F) -> JoinHandle +672 | pub fn spawn(f: F) -> JoinHandle | ----- required by a bound in this function ... -691 | F: Send + 'static, +675 | F: Send + 'static, | ^^^^ required by this bound in `spawn` For more information about this error, try `rustc --explain E0277`. diff --git a/listings/ch21-web-server/listing-21-22/output.txt b/listings/ch21-web-server/listing-21-22/output.txt index 189f5bd0e2..c0165dbb80 100644 --- a/listings/ch21-web-server/listing-21-22/output.txt +++ b/listings/ch21-web-server/listing-21-22/output.txt @@ -9,9 +9,9 @@ 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/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:1778:17 + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1763:17 | -1778 | pub fn join(self) -> Result { +1763 | pub fn join(self) -> Result { | ^^^^ For more information about this error, try `rustc --explain E0507`. diff --git a/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt index 3042df208b..1ac14a444b 100644 --- a/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch21-web-server/no-listing-04-update-worker-definition/output.txt @@ -7,9 +7,9 @@ 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<()>` - --> /Users/chris/.rustup/toolchains/1.81-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1778:5 + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/std/src/thread/mod.rs:1763:5 | -1778 | pub fn join(self) -> Result { +1763 | pub fn join(self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `Option::expect` to unwrap the `JoinHandle<()>` value, panicking if the value is an `Option::None` | diff --git a/rust-toolchain b/rust-toolchain index ea3769f296..a92432a8ab 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.81 +1.82 diff --git a/src/title-page.md b/src/title-page.md index ff45326fd4..daaf01a3d7 100644 --- a/src/title-page.md +++ b/src/title-page.md @@ -3,7 +3,7 @@ *by Steve Klabnik, Carol Nichols, and Chris Krycho, with contributions from the Rust Community* -This version of the text assumes you’re using Rust 1.81.0 (released 2024-09-04) +This version of the text assumes you’re using Rust 1.82.0 (released 2024-10-17) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. From f04d20fe8d1a49c3bffa10a3086c58e527ff0a90 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 5 Nov 2024 16:57:28 -0700 Subject: [PATCH 667/720] Rust 1.82: also update all cases of manual regeneration --- .../listing-02-02/Cargo.lock | 77 +++++++++- .../no-listing-01-cargo-new/Cargo.lock | 7 - .../no-listing-01-cargo-new/Cargo.toml | 2 - .../no-listing-01-cargo-new/output.txt | 5 +- .../listing-11-01/Cargo.lock | 7 - .../listing-11-01/Cargo.toml | 2 - .../listing-11-01/output.txt | 3 +- .../listing-11-01/src/lib.rs | 2 +- .../listing-14-07/add/Cargo.toml | 7 +- .../add/Cargo.lock | 6 - .../add/Cargo.toml | 5 - .../add/adder/Cargo.toml | 6 - .../add/adder/src/main.rs | 3 - .../no-listing-01-workspace/add/Cargo.toml | 2 + .../add/Cargo.toml | 7 +- .../add/Cargo.toml | 7 +- .../add/Cargo.toml | 7 +- .../output-only-01-adder-crate/add/Cargo.toml | 6 +- .../output-only-02-add-one/add/Cargo.toml | 7 +- .../add/add_one/Cargo.toml | 2 - .../add/add_one/src/lib.rs | 2 +- .../output-only-03-use-rand/add/Cargo.toml | 7 +- src/ch02-00-guessing-game-tutorial.md | 46 +++--- src/ch03-05-control-flow.md | 2 +- ...ch09-01-unrecoverable-errors-with-panic.md | 14 +- src/ch14-01-release-profiles.md | 4 +- src/ch14-02-publishing-to-crates-io.md | 4 +- src/ch14-03-cargo-workspaces.md | 34 +++-- src/ch14-04-installing-binaries.md | 2 +- src/ch17-01-futures-and-syntax.md | 7 +- src/ch17-03-more-futures.md | 134 +++++++++++------- src/ch17-04-streams.md | 49 +++---- src/ch17-05-traits-for-async.md | 21 ++- src/ch21-02-multithreaded.md | 22 +-- src/ch21-03-graceful-shutdown-and-cleanup.md | 2 +- 35 files changed, 288 insertions(+), 232 deletions(-) delete mode 100644 listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock delete mode 100644 listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock delete mode 100644 listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.lock delete mode 100644 listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.toml delete mode 100644 listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/Cargo.toml delete mode 100644 listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/src/main.rs create mode 100644 listings/ch14-more-about-cargo/no-listing-01-workspace/add/Cargo.toml diff --git a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock index 0fb52b33cb..2aa1298037 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock +++ b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "cfg-if" version = "1.0.0" @@ -10,9 +16,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -28,15 +34,36 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] [[package]] name = "rand" @@ -68,8 +95,46 @@ dependencies = [ "getrandom", ] +[[package]] +name = "syn" +version = "2.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock deleted file mode 100644 index ee5d79095f..0000000000 --- a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "guessing_game" -version = "0.1.0" diff --git a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.toml b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.toml index 78c94fef95..4e348c8d26 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.toml @@ -3,6 +3,4 @@ name = "guessing_game" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] diff --git a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt index 33409e38cf..32ed12b639 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt @@ -1,5 +1,4 @@ -$ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.50s - Running `target/debug/guessing_game` + Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.80s + Running `file:///projects/guessing_game/target/debug/guessing_game` Hello, world! diff --git a/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock b/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock deleted file mode 100644 index 8b8c69d33a..0000000000 --- a/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "adder" -version = "0.1.0" diff --git a/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml b/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml index b7d36d44cb..e61cb12e3e 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml +++ b/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml @@ -3,6 +3,4 @@ name = "adder" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] diff --git a/listings/ch11-writing-automated-tests/listing-11-01/output.txt b/listings/ch11-writing-automated-tests/listing-11-01/output.txt index 128309c129..3b09a15ece 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-01/output.txt @@ -1,7 +1,7 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) Finished `test` profile [unoptimized + debuginfo] target(s) in 0.57s - Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) + Running unittests src/lib.rs (file:///projects/adder/target/debug/deps/adder-7acb243c25ffd9dc) running 1 test test tests::it_works ... ok @@ -13,4 +13,3 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - diff --git a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs index 7d12d9af81..b93cf3ffd9 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add(left: usize, right: usize) -> usize { +pub fn add(left: u64, right: u64) -> u64 { left + right } diff --git a/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml b/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.lock b/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.lock deleted file mode 100644 index d37189b337..0000000000 --- a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.lock +++ /dev/null @@ -1,6 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "adder" -version = "0.1.0" - diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.toml deleted file mode 100644 index c5ea8e510b..0000000000 --- a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.toml +++ /dev/null @@ -1,5 +0,0 @@ -[workspace] - -members = [ - "adder", -] diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/Cargo.toml deleted file mode 100644 index e61cb12e3e..0000000000 --- a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "adder" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/src/main.rs b/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/src/main.rs deleted file mode 100644 index e7a11a969c..0000000000 --- a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-01-workspace/add/Cargo.toml new file mode 100644 index 0000000000..61bdb9cbf2 --- /dev/null +++ b/listings/ch14-more-about-cargo/no-listing-01-workspace/add/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +resolver = "2" diff --git a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml b/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml index c5ea8e510b..38ea3f5655 100644 --- a/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml @@ -1,5 +1,3 @@ [workspace] - -members = [ - "adder", -] +resolver = "2" +members = ["adder"] diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml b/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml index 1448801d5b..8c9ab0e120 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = [ "add_one","adder"] diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/Cargo.toml b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/Cargo.toml index 9000184707..8af4ab8166 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/Cargo.toml @@ -3,6 +3,4 @@ name = "add_one" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs index 7d12d9af81..b93cf3ffd9 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs @@ -1,4 +1,4 @@ -pub fn add(left: usize, right: usize) -> usize { +pub fn add(left: u64, right: u64) -> u64 { left + right } diff --git a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index d0d27f2b1b..848ce75fbe 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -305,7 +305,7 @@ input 6 --> ```console $ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 6.44s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.44s Running `target/debug/guessing_game` Guess the number! Please input your guess. @@ -380,22 +380,28 @@ cargo build --> ```console $ cargo build Updating crates.io index - Downloaded rand v0.8.5 - Downloaded libc v0.2.127 - Downloaded getrandom v0.2.7 - Downloaded cfg-if v1.0.0 - Downloaded ppv-lite86 v0.2.16 - Downloaded rand_chacha v0.3.1 - Downloaded rand_core v0.6.3 - Compiling libc v0.2.127 - Compiling getrandom v0.2.7 + Locking 16 packages to latest compatible versions + Adding wasi v0.11.0+wasi-snapshot-preview1 (latest: v0.13.3+wasi-0.2.2) + Adding zerocopy v0.7.35 (latest: v0.8.9) + Adding zerocopy-derive v0.7.35 (latest: v0.8.9) + Downloaded syn v2.0.87 + Downloaded 1 crate (278.1 KB) in 0.16s + Compiling proc-macro2 v1.0.89 + Compiling unicode-ident v1.0.13 + Compiling libc v0.2.161 Compiling cfg-if v1.0.0 - Compiling ppv-lite86 v0.2.16 - Compiling rand_core v0.6.3 + Compiling byteorder v1.5.0 + Compiling getrandom v0.2.15 + Compiling rand_core v0.6.4 + Compiling quote v1.0.37 + Compiling syn v2.0.87 + Compiling zerocopy-derive v0.7.35 + Compiling zerocopy v0.7.35 + Compiling ppv-lite86 v0.2.20 Compiling rand_chacha v0.3.1 Compiling rand v0.8.5 Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 2.53s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.69s ``` @@ -433,7 +439,7 @@ cargo build --> ```console $ cargo build Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 2.53 secs + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s ``` These lines show that Cargo only updates the build with your tiny change to the @@ -557,7 +563,7 @@ cargo run ```console $ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 2.53s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s Running `target/debug/guessing_game` Guess the number! The secret number is: 7 @@ -566,7 +572,7 @@ Please input your guess. You guessed: 4 $ cargo run - Finished dev [unoptimized + debuginfo] target(s) in 0.02s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s Running `target/debug/guessing_game` Guess the number! The secret number is: 83 @@ -717,6 +723,7 @@ Let’s run the program now: @@ -724,7 +731,7 @@ cargo run ```console $ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 0.43s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.26s Running `target/debug/guessing_game` Guess the number! The secret number is: 58 @@ -767,6 +774,7 @@ advantage of that to allow the user to quit, as shown here: ```console -$ cargo run https://www.rust-lang.org +$ cargo run -- https://www.rust-lang.org + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s + Running `target/debug/async_await 'https://www.rust-lang.org'` The title for https://www.rust-lang.org was -Rust Programming Language + Rust Programming Language ``` Phew: we finally have some working async code! This now compiles, and we can run diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 5a9fea4482..cab96d1f1d 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -39,7 +39,7 @@ replace `join!` with `join_all`. Unfortunately, this doesn’t compile. Instead, we get this error: @@ -47,33 +47,21 @@ copy just the compiler error ```text error[E0308]: mismatched types - --> src/main.rs:43:37 + --> src/main.rs:45:37 | -8 | let tx1_fut = async move { - | _______________________- -9 | | let vals = vec![ -10 | | String::from("hi"), -11 | | String::from("from"), -... | -19 | | } -20 | | }; - | |_________- the expected `async` block -21 | -22 | let rx_fut = async { - | ______________________- -23 | | while let Some(value) = rx.recv().await { -24 | | println!("received '{value}'"); -25 | | } -26 | | }; - | |_________- the found `async` block +10 | let tx1_fut = async move { + | ---------- the expected `async` block ... -43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; - | ^^^^^^ expected `async` block, found a different `async` block +24 | let rx_fut = async { + | ----- the found `async` block +... +45 | let futures = vec![tx1_fut, rx_fut, tx_fut]; + | ^^^^^^ expected `async` block, found a different `async` block | - = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` - found `async` block `{async block@src/main.rs:22:22: 26:10}` + = note: expected `async` block `{async block@src/main.rs:10:23: 10:33}` + found `async` block `{async block@src/main.rs:24:22: 24:27}` = note: no two async blocks, even if identical, have the same type - = help: consider pinning your async block and and casting it to a trait object + = help: consider pinning your async block and casting it to a trait object ``` This might be surprising. After all, none of them return anything, so each @@ -135,25 +123,74 @@ the errors mentioning `Unpin`. Although there are three of them, notice that each is very similar in its contents. ```text -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:24 +error[E0308]: mismatched types + --> src/main.rs:46:46 + | +10 | let tx1_fut = async move { + | ---------- the expected `async` block +... +24 | let rx_fut = async { + | ----- the found `async` block +... +46 | vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + | -------- ^^^^^^ expected `async` block, found a different `async` block + | | + | arguments to this function are incorrect + | + = note: expected `async` block `{async block@src/main.rs:10:23: 10:33}` + found `async` block `{async block@src/main.rs:24:22: 24:27}` + = note: no two async blocks, even if identical, have the same type + = help: consider pinning your async block and casting it to a trait object +note: associated function defined here + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/alloc/src/boxed.rs:255:12 + | +255 | pub fn new(x: T) -> Self { + | ^^^ + +error[E0308]: mismatched types + --> src/main.rs:46:64 + | +10 | let tx1_fut = async move { + | ---------- the expected `async` block +... +30 | let tx_fut = async move { + | ---------- the found `async` block +... +46 | vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + | -------- ^^^^^^ expected `async` block, found a different `async` block + | | + | arguments to this function are incorrect | -46 | trpl::join_all(futures).await; - | -------------- ^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + = note: expected `async` block `{async block@src/main.rs:10:23: 10:33}` + found `async` block `{async block@src/main.rs:30:22: 30:32}` + = note: no two async blocks, even if identical, have the same type + = help: consider pinning your async block and casting it to a trait object +note: associated function defined here + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/alloc/src/boxed.rs:255:12 + | +255 | pub fn new(x: T) -> Self { + | ^^^ + +error[E0277]: `{async block@src/main.rs:10:23: 10:33}` cannot be unpinned + --> src/main.rs:48:24 + | +48 | trpl::join_all(futures).await; + | -------------- ^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:10:23: 10:33}`, which is required by `Box<{async block@src/main.rs:10:23: 10:33}>: Future` | | | required by a bound introduced by this call | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` + = note: required for `Box<{async block@src/main.rs:10:23: 10:33}>` to implement `Future` note: required by a bound in `join_all` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 + --> file:///home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 | 102 | pub fn join_all(iter: I) -> JoinAll | -------- required by a bound in this function @@ -161,17 +198,17 @@ note: required by a bound in `join_all` 105 | I::Item: Future, | ^^^^^^ required by this bound in `join_all` -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:9 +error[E0277]: `{async block@src/main.rs:10:23: 10:33}` cannot be unpinned + --> src/main.rs:48:9 | -46 | trpl::join_all(futures).await; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` +48 | trpl::join_all(futures).await; + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:10:23: 10:33}`, which is required by `Box<{async block@src/main.rs:10:23: 10:33}>: Future` | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` -note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + = note: required for `Box<{async block@src/main.rs:10:23: 10:33}>` to implement `Future` +note: required by a bound in `futures_util::future::join_all::JoinAll` + --> file:///home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll | ------- required by a bound in this struct @@ -179,26 +216,23 @@ note: required by a bound in `JoinAll` 29 | F: Future, | ^^^^^^ required by this bound in `JoinAll` -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:33 +error[E0277]: `{async block@src/main.rs:10:23: 10:33}` cannot be unpinned + --> src/main.rs:48:33 | -46 | trpl::join_all(futures).await; - | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` +48 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:10:23: 10:33}`, which is required by `Box<{async block@src/main.rs:10:23: 10:33}>: Future` | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` -note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + = note: required for `Box<{async block@src/main.rs:10:23: 10:33}>` to implement `Future` +note: required by a bound in `futures_util::future::join_all::JoinAll` + --> file:///home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll | ------- required by a bound in this struct 28 | where 29 | F: Future, | ^^^^^^ required by this bound in `JoinAll` - -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. ``` That is a *lot* to digest, so let’s pull it apart. The first part of the message @@ -369,7 +403,7 @@ a pair of futures. To begin, each future only hands control back to the runtime If you run this, you will see this output: diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 0000ac9c88..1f20e873b3 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -39,39 +39,36 @@ stream as they arrive with the `while let` loop. Unfortunately, when we try to run the code, it doesn’t compile. Instead, as we can see in the output, it reports that there is no `next` method available. - ```console error[E0599]: no method named `next` found for struct `Iter` in the current scope - --> src/main.rs:8:40 - | -8 | while let Some(value) = stream.next().await { - | ^^^^ - | - = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-30/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' - = note: consider using `--verbose` to print the full type name to the console - = help: items from traits can only be used if the trait is in scope + --> src/main.rs:10:40 + | +10 | while let Some(value) = stream.next().await { + | ^^^^ + | + = note: the full type name has been written to 'file:///projects/async_await/target/debug/deps/async_await-9de943556a6001b8.long-type-1281356139287206597.txt' + = note: consider using `--verbose` to print the full type name to the console + = help: items from traits can only be used if the trait is in scope help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them - | -1 + use futures_util::stream::stream::StreamExt; - | -1 + use std::iter::Iterator; - | -1 + use std::str::pattern::Searcher; - | -1 + use trpl::StreamExt; - | + | +1 + use crate::trpl::StreamExt; + | +1 + use futures_util::stream::stream::StreamExt; + | +1 + use std::iter::Iterator; + | +1 + use std::str::pattern::Searcher; + | help: there is a method `try_next` with a similar name - | -8 | while let Some(value) = stream.try_next().await { - | ~~~~~~~~ - -For more information about this error, try `rustc --explain E0599`. + | +10 | while let Some(value) = stream.try_next().await { + | ~~~~~~~~ ``` As the output suggests, the reason for the compiler error is that we need the @@ -231,7 +228,7 @@ Now our code has a much more interesting result! Between every other pair of messages, we see an error reported: `Problem: Elapsed(())`. @@ -395,7 +392,7 @@ This is the inherent “laziness” of Rust’s futures at work again, allowing choose our performance characteristics. diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 836c73b617..1b7b23b7d8 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -115,36 +115,33 @@ it is not yet ready. ### Pinning and the Pin and Unpin Traits -When we introduced the idea of pinning while working on Listing 17-17, we ran +When we introduced the idea of pinning while working on Listing 17-16, we ran into a very gnarly error message. Here is the relevant part of it again: ```text -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:33 +error[E0277]: `{async block@src/main.rs:10:23: 10:33}` cannot be unpinned + --> src/main.rs:48:33 | -46 | trpl::join_all(futures).await; - | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` +48 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:10:23: 10:33}`, which is required by `Box<{async block@src/main.rs:10:23: 10:33}>: Future` | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` -note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + = note: required for `Box<{async block@src/main.rs:10:23: 10:33}>` to implement `Future` +note: required by a bound in `futures_util::future::join_all::JoinAll` + --> file:///home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll | ------- required by a bound in this struct 28 | where 29 | F: Future, | ^^^^^^ required by this bound in `JoinAll` - -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. ``` When we read this error message carefully, it not only tells us that we need to diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index f8043fc30f..788ee54688 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -619,28 +619,28 @@ Can't automate because the output depends on making requests ```console $ cargo run Compiling hello v0.1.0 (file:///projects/hello) -warning: field is never read: `workers` +warning: field `workers` is never read --> src/lib.rs:7:5 | +6 | pub struct ThreadPool { + | ---------- field in this struct 7 | workers: Vec, - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ | = note: `#[warn(dead_code)]` on by default -warning: field is never read: `id` +warning: fields `id` and `thread` are never read --> src/lib.rs:48:5 | +47 | struct Worker { + | ------ fields in this struct 48 | id: usize, - | ^^^^^^^^^ - -warning: field is never read: `thread` - --> src/lib.rs:49:5 - | + | ^^ 49 | thread: thread::JoinHandle<()>, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ -warning: `hello` (lib) generated 3 warnings - Finished dev [unoptimized + debuginfo] target(s) in 1.40s +warning: `hello` (lib) generated 2 warnings + Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.91s Running `target/debug/hello` Worker 0 got a job; executing. Worker 2 got a job; executing. diff --git a/src/ch21-03-graceful-shutdown-and-cleanup.md b/src/ch21-03-graceful-shutdown-and-cleanup.md index 9d2a02e54f..b60278240a 100644 --- a/src/ch21-03-graceful-shutdown-and-cleanup.md +++ b/src/ch21-03-graceful-shutdown-and-cleanup.md @@ -182,7 +182,7 @@ Can't automate because the output depends on making requests ```console $ cargo run Compiling hello v0.1.0 (file:///projects/hello) - Finished dev [unoptimized + debuginfo] target(s) in 1.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.41s Running `target/debug/hello` Worker 0 got a job; executing. Shutting down. From 91381a1e11b29740f43652b833931ce1c75d2889 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 6 Nov 2024 11:57:23 -0700 Subject: [PATCH 668/720] Add new terms to dictionary --- ci/dictionary.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 4364dc0d61..e6dfe6225e 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -61,6 +61,7 @@ BTreeSet BufRead BufReader BuildHasher +byteorder Cacher cacher Cagain @@ -104,6 +105,7 @@ CustomSmartPointer CustomSmartPointers data's DataStruct +dbea deallocate deallocated deallocating @@ -566,6 +568,7 @@ Uncomment uncommenting unevaluated unhandled +unicode Uninstalling uninstall unittests @@ -598,6 +601,7 @@ Vlissides vscode vtable waitlist +wasi wasn weakt WeatherForecast @@ -616,4 +620,5 @@ WriteMessage xcode xpression yyyy +zerocopy ZipImpl From 7ee012f18b4fb2c6d8985880e187861ceaf49c33 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 6 Nov 2024 12:10:42 -0700 Subject: [PATCH 669/720] infra: *some* file paths can also contain `file:///home` Rust recently began printing error messages which include the full path to the source of the file with an error in it; when that path is in the standard library, that includes the user's home directory (or similar). A previous change (b9241f6) added support for those paths in the output files; this one adds support to the local file paths linter. Specifically allow exactly and only paths in the home directory which include `.rustup` or `.cargo`. --- packages/tools/src/bin/lfp.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/tools/src/bin/lfp.rs b/packages/tools/src/bin/lfp.rs index ee7f39c3c8..64bdaa99d8 100644 --- a/packages/tools/src/bin/lfp.rs +++ b/packages/tools/src/bin/lfp.rs @@ -106,6 +106,8 @@ fn is_line_of_interest(line: &str) -> bool { line.split_whitespace().any(|sub_string| { sub_string.contains("file://") && !sub_string.contains("file:///projects/") + && !sub_string.contains("file:///home/.cargo") + && !sub_string.contains("file:///home/.rustup") }) } From 2b1ddf491191e86a859794b6c21dd7b7b3d020ce Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 3 Oct 2024 08:24:47 -0600 Subject: [PATCH 670/720] Use new `&raw` feature for sound raw pointer usage. Note: this requires Rust 1.82.0, and will be easiest to merge after that version is stabilized in two weeks. Since it is blocked on that anyway, I am also basing it on top of the listing changes. --- .../listing-20-01/src/main.rs | 4 ++-- .../listing-20-03/src/main.rs | 4 ++-- src/ch20-01-unsafe-rust.md | 21 ++++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/listings/ch20-advanced-features/listing-20-01/src/main.rs b/listings/ch20-advanced-features/listing-20-01/src/main.rs index 893f578905..492b43ba3b 100644 --- a/listings/ch20-advanced-features/listing-20-01/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-01/src/main.rs @@ -2,7 +2,7 @@ fn main() { // ANCHOR: here let mut num = 5; - let r1 = &num as *const i32; - let r2 = &mut num as *mut i32; + let r1 = &raw const num; + let r2 = &raw mut num; // ANCHOR_END: here } diff --git a/listings/ch20-advanced-features/listing-20-03/src/main.rs b/listings/ch20-advanced-features/listing-20-03/src/main.rs index 02a0be6b0e..6ed8ca2afc 100644 --- a/listings/ch20-advanced-features/listing-20-03/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-03/src/main.rs @@ -2,8 +2,8 @@ fn main() { // ANCHOR: here let mut num = 5; - let r1 = &num as *const i32; - let r2 = &mut num as *mut i32; + let r1 = &raw const num; + let r2 = &raw mut num; unsafe { println!("r1 is: {}", *r1); diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index ae4e674f1e..660135cab2 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -103,19 +103,20 @@ Notice that we don’t include the `unsafe` keyword in this code. We can create raw pointers in safe code; we just can’t dereference raw pointers outside an unsafe block, as you’ll see in a bit. -We’ve created raw pointers by using `as` to cast an immutable and a mutable -reference into their corresponding raw pointer types. Because we created them -directly from references guaranteed to be valid, we know these particular raw -pointers are valid, but we can’t make that assumption about just any raw -pointer. +We’ve created raw pointers by using the raw borrow operators: `&raw const num` +creates a `*const i32` immutable raw pointer, and `&raw mut num` creates a `&mut +i32` mutable raw pointer. Because we created them directly from references +guaranteed to be valid, we know these particular raw pointers are valid, but we +can’t make that assumption about just any raw pointer. To demonstrate this, next we’ll create a raw pointer whose validity we can’t be -so certain of. Listing 20-2 shows how to create a raw pointer to an arbitrary +so certain of, using `as` to cast a value instead of using the raw reference +operators. Listing 20-2 shows how to create a raw pointer to an arbitrary location in memory. Trying to use arbitrary memory is undefined: there might be -data at that address or there might not, the compiler might optimize the code -so there is no memory access, or the program might error with a segmentation -fault. Usually, there is no good reason to write code like this, but it is -possible. +data at that address or there might not, the compiler might optimize the code so +there is no memory access, or the program might error with a segmentation fault. +Usually, there is no good reason to write code like this, especially in cases +where you can use a raw borrow operator instead, but it is possible. From 48d0b7686bf65b7325e20c817c57b559075fe629 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 3 Oct 2024 08:24:47 -0600 Subject: [PATCH 671/720] Ch. 20: Fix safety handling in the `static mut` example - Add `SAFETY` documentation on the unsafe function and comments on the unsafe invocation in the code samples. - Discuss the soundness issues in more depth and explain the idiomatic use of those `SAFETY` comments. --- .../listing-20-10/src/main.rs | 15 ++++++++------- src/ch20-01-unsafe-rust.md | 10 +++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/listings/ch20-advanced-features/listing-20-10/src/main.rs b/listings/ch20-advanced-features/listing-20-10/src/main.rs index b5559fd3a5..360e3548fc 100644 --- a/listings/ch20-advanced-features/listing-20-10/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-10/src/main.rs @@ -1,15 +1,16 @@ static mut COUNTER: u32 = 0; -fn add_to_count(inc: u32) { - unsafe { - COUNTER += inc; - } +/// SAFETY: Calling this from more than a single thread at a time is undefined +/// behavior, so you *must* guarantee you only call it from a single thread at +/// a time. +unsafe fn add_to_count(inc: u32) { + COUNTER += inc; } fn main() { - add_to_count(3); - unsafe { - println!("COUNTER: {COUNTER}"); + // SAFETY: This is only called from a single thread in `main`. + add_to_count(3); + println!("COUNTER: {}", COUNTER); } } diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 660135cab2..e559f46dc8 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -402,7 +402,15 @@ As with regular variables, we specify mutability using the `mut` keyword. Any code that reads or writes from `COUNTER` must be within an `unsafe` block. This code compiles and prints `COUNTER: 3` as we would expect because it’s single threaded. Having multiple threads access `COUNTER` would likely result in data -races. +races, so it is undefined behavior. Therefore, we need to mark the entire +function as `unsafe`, and document the safety limitation, so anyone calling the +function knows what they are and are not allowed to do safely. + +Whenever we write an unsafe function, it is idiomatic to write a comment +starting with `SAFETY` and explaining what the caller needs to do to call the +function safely. Likewise, whenever we perform an unsafe operation, it is +idiomatic to write a comment starting with `SAFETY` to explain how the safety +rules are upheld. With mutable data that is globally accessible, it’s difficult to ensure there are no data races, which is why Rust considers mutable static variables to be From 3fdb5203640e6fa3c78c2b8ec1694ad71e117173 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 3 Oct 2024 08:24:47 -0600 Subject: [PATCH 672/720] Introduce basic usage of Miri in the unsafe chapter --- .../listing-20-10/output.txt | 14 ++++++ src/ch20-01-unsafe-rust.md | 45 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 listings/ch20-advanced-features/listing-20-10/output.txt diff --git a/listings/ch20-advanced-features/listing-20-10/output.txt b/listings/ch20-advanced-features/listing-20-10/output.txt new file mode 100644 index 0000000000..ec0ec88b3c --- /dev/null +++ b/listings/ch20-advanced-features/listing-20-10/output.txt @@ -0,0 +1,14 @@ +$ cargo +nightly miri run + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s + Running `/Users/chris/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/unsafe-example` +warning: creating a shared reference to mutable static is discouraged + --> src/main.rs:14:33 + | +14 | println!("COUNTER: {}", COUNTER); + | ^^^^^^^ shared reference to mutable static + | + = note: for more information, see + = note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives + = note: `#[warn(static_mut_refs)]` on by default + +COUNTER: 3 diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index e559f46dc8..2be392c7e8 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -457,6 +457,47 @@ interface with unions in C code. Accessing union fields is unsafe because Rust can’t guarantee the type of the data currently being stored in the union instance. You can learn more about unions in [the Rust Reference][reference]. +### Using Miri to check unsafe code + +When writing unsafe code, you might want to check that what you have written +actually is safe and correct. One of the best ways to do that is to use +[Miri][miri], an official Rust tool for detecting undefined behavior. Whereas +the borrow checker is a *static* tool which works at compile time, Miri is a +*dynamic* tool which works at runtime. It checks your code by running your +program, or its test suite, and detecting when you violate the rules its +understands about how Rust should work. + +Using Miri requires a nightly build of Rust (which we talk about more in +[Appendix G: How Rust is Made and “Nightly Rust”][nightly]). You can install +both a nightly version of Rust and the Miri tool by typing `rustup +nightly +component add miri`. This does not change what version of Rust your project +uses; it only adds the tool to your system so you can use it when you want to. +You can run Miri on a project by typing `cargo +nightly miri run` or `cargo ++nightly miri test`. + +For an example of how helpful this can be, consider what happens when we run it +against Listing 20-10: + +```console +{{#include ../listings/ch20-advanced-features/listing-20-10/output.txt}} +``` + +It helpfully and correctly notices that we have shared references to mutable +data, and warns about it. In this case, it does not tell us how to fix the +problem, but it means that we know there is a possible issue and can think about +how to make sure it is safe. In other cases, it can actually tell us that some +code is *sure* to be wrong and make recommendations about how to fix it. + +Miri doesn’t catch *everything* you might get wrong when writing unsafe code. +For one thing, since it is a dynamic check, it only catches problems with code +that actually gets run. That means you will need to use it in conjunction with +good testing techniques to increase your confidence about the unsafe code you +have written. For another thing, it does not cover every possible way your code +can be unsound. If Miri *does* catch a problem, you know there’s a bug, but just +because Miri *doesn’t* catch a bug doesn’t mean there isn’t a problem. Miri can +catch a lot, though. Try running it on the other examples of unsafe code in this +chapter and see what it says! + ### When to Use Unsafe Code Using `unsafe` to take one of the five actions (superpowers) just discussed @@ -464,6 +505,8 @@ isn’t wrong or even frowned upon. But it is trickier to get `unsafe` code correct because the compiler can’t help uphold memory safety. When you have a reason to use `unsafe` code, you can do so, and having the explicit `unsafe` annotation makes it easier to track down the source of problems when they occur. +Whenever you write unsafe code, you can use Miri to help you be more confident +that the code you have written upholds Rust’s rules. [dangling-references]: ch04-02-references-and-borrowing.html#dangling-references @@ -473,3 +516,5 @@ ch03-01-variables-and-mutability.html#constants ch16-04-extensible-concurrency-sync-and-send.html#extensible-concurrency-with-the-sync-and-send-traits [the-slice-type]: ch04-03-slices.html#the-slice-type [reference]: ../reference/items/unions.html +[miri]: https://github.com/rust-lang/miri +[nightly]: appendix-07-nightly-rust.html From e934f316104971d5eb6f1e2148eeec9afbd7dbbb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 16 Oct 2024 11:07:09 -0600 Subject: [PATCH 673/720] Ch. 20: correct text about how we got raw pointers We no longer get the raw pointers from references, although we *could*, because we can now use the raw pointer operator rather than an `as` cast and thus can get them directly from a variable in scope. --- src/ch20-01-unsafe-rust.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 2be392c7e8..156c0f05ff 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -88,10 +88,9 @@ By opting out of having Rust enforce these guarantees, you can give up guaranteed safety in exchange for greater performance or the ability to interface with another language or hardware where Rust’s guarantees don’t apply. -Listing 20-1 shows how to create an immutable and a mutable raw pointer from -references. +Listing 20-1 shows how to create an immutable and a mutable raw pointer. -+ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-01/src/main.rs:here}} @@ -105,9 +104,9 @@ unsafe block, as you’ll see in a bit. We’ve created raw pointers by using the raw borrow operators: `&raw const num` creates a `*const i32` immutable raw pointer, and `&raw mut num` creates a `&mut -i32` mutable raw pointer. Because we created them directly from references -guaranteed to be valid, we know these particular raw pointers are valid, but we -can’t make that assumption about just any raw pointer. +i32` mutable raw pointer. Because we created them directly from a local +variable, we know these particular raw pointers are valid, but we can’t make +that assumption about just any raw pointer. To demonstrate this, next we’ll create a raw pointer whose validity we can’t be so certain of, using `as` to cast a value instead of using the raw reference From 3e725cdf9c0aee41a41ebac5295478bb9a19208c Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 6 Nov 2024 12:42:55 -0700 Subject: [PATCH 674/720] Add 'Miri' and 'miri' to the dictionary --- ci/dictionary.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index e6dfe6225e..ccca2b04cd 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -311,6 +311,8 @@ microcontroller microcontrollers millis minigrep +Miri +miri mixup mkdir MockMessenger From af61f9529c8b1dd39da30840c2c55575b39cb97b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 6 Nov 2024 12:54:51 -0700 Subject: [PATCH 675/720] Fix output paths for updates in Ch. 20 --- listings/ch20-advanced-features/listing-20-10/output.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/listings/ch20-advanced-features/listing-20-10/output.txt b/listings/ch20-advanced-features/listing-20-10/output.txt index ec0ec88b3c..f6f38f31d5 100644 --- a/listings/ch20-advanced-features/listing-20-10/output.txt +++ b/listings/ch20-advanced-features/listing-20-10/output.txt @@ -1,4 +1,6 @@ $ cargo +nightly miri run +Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done + Compiling unsafe-example v0.1.0 (file:///projects/unsafe-example) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s Running `/Users/chris/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/unsafe-example` warning: creating a shared reference to mutable static is discouraged From da611679cddab960c4b774f16180aedf0cbb12e8 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 6 Nov 2024 13:43:09 -0700 Subject: [PATCH 676/720] Correct baseline after running update-rustc.sh again --- .../no-listing-01-cargo-new/output.txt | 5 +++-- listings/ch20-advanced-features/listing-20-10/output.txt | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt index 32ed12b639..f55ab06302 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt @@ -1,4 +1,5 @@ +$ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.80s - Running `file:///projects/guessing_game/target/debug/guessing_game` + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.20s + Running `target/debug/guessing_game` Hello, world! diff --git a/listings/ch20-advanced-features/listing-20-10/output.txt b/listings/ch20-advanced-features/listing-20-10/output.txt index f6f38f31d5..abddb73627 100644 --- a/listings/ch20-advanced-features/listing-20-10/output.txt +++ b/listings/ch20-advanced-features/listing-20-10/output.txt @@ -1,5 +1,4 @@ $ cargo +nightly miri run -Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done Compiling unsafe-example v0.1.0 (file:///projects/unsafe-example) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s Running `/Users/chris/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/unsafe-example` From 77b52a82c5e32c14104e2a924d5a8fcfb36b4e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sun, 10 Nov 2024 11:37:28 +0000 Subject: [PATCH 677/720] Ch17-05: Typos --- src/ch17-05-traits-for-async.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 1b7b23b7d8..ed47948d20 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -92,9 +92,9 @@ loop { ``` If Rust compiled it to exactly that code, though, every `await` would be -blocking—exactly the opposite of what we were going for! Instead, Rust needs -makes sure that the loop can hand off control to something which can pause work -on this future and work on other futures and check this one again later. That +blocking—exactly the opposite of what we were going for! Instead, Rust makes +sure that the loop can hand off control to something which can pause work on +this future and work on other futures and check this one again later. That “something” is an async runtime, and this scheduling and coordination work is one of the main jobs for a runtime. @@ -153,10 +153,10 @@ future with `await` pins the future implicitly. That’s why we don’t need to However, we’re not directly awaiting a future here. Instead, we construct a new future, `JoinAll`, by passing a collection of futures to the `join_all` -function. The signature for `join_all` produces requires that the type of the -items in the collection all implement the `Future` trait, and `Box` only -implements `Future` if the `T` that it wraps is a future which implements the -`Unpin` trait. +function. The signature for `join_all` requires that the type of the items in +the collection all implement the `Future` trait, and `Box` only implements +`Future` if the `T` that it wraps is a future which implements the `Unpin` +trait. That’s a lot! But we can understand it, if we dive a little further into how the `Future` type actually works, in particular around *pinning*. @@ -190,7 +190,7 @@ on which the method is implemented, a reference or smart pointer to that type, or a `Pin` wrapping a reference to that type. We’ll see more on this syntax in Chapter 18. For now, it’s enough to know that if we want to poll a future (to check whether it is `Pending` or `Ready(Output)`), we need a mutable reference -to the type, which is wrapped in a `Pin`. +to the type which is wrapped in a `Pin`. `Pin` is a wrapper type. In some ways, it’s similar to the `Box`, `Rc`, and other smart pointer types we saw in Chapter 15, which also wrap other types. From a9c38c2d371246fce4050f314a1331c849f5fab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Tue, 12 Nov 2024 18:31:27 +0000 Subject: [PATCH 678/720] Drop the comma change --- src/ch17-05-traits-for-async.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index ed47948d20..e3819d9a49 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -190,7 +190,7 @@ on which the method is implemented, a reference or smart pointer to that type, or a `Pin` wrapping a reference to that type. We’ll see more on this syntax in Chapter 18. For now, it’s enough to know that if we want to poll a future (to check whether it is `Pending` or `Ready(Output)`), we need a mutable reference -to the type which is wrapped in a `Pin`. +to the type, which is wrapped in a `Pin`. `Pin` is a wrapper type. In some ways, it’s similar to the `Box`, `Rc`, and other smart pointer types we saw in Chapter 15, which also wrap other types. From c7e7f8fa13677386ef3e75f3cf22dfb661d2fda9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Mon, 18 Nov 2024 14:42:22 +0000 Subject: [PATCH 679/720] Ch20-01: Fix typos --- src/ch20-01-unsafe-rust.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 156c0f05ff..b3cbcac74c 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -103,7 +103,7 @@ raw pointers in safe code; we just can’t dereference raw pointers outside an unsafe block, as you’ll see in a bit. We’ve created raw pointers by using the raw borrow operators: `&raw const num` -creates a `*const i32` immutable raw pointer, and `&raw mut num` creates a `&mut +creates a `*const i32` immutable raw pointer, and `&raw mut num` creates a `*mut i32` mutable raw pointer. Because we created them directly from a local variable, we know these particular raw pointers are valid, but we can’t make that assumption about just any raw pointer. @@ -463,7 +463,7 @@ actually is safe and correct. One of the best ways to do that is to use [Miri][miri], an official Rust tool for detecting undefined behavior. Whereas the borrow checker is a *static* tool which works at compile time, Miri is a *dynamic* tool which works at runtime. It checks your code by running your -program, or its test suite, and detecting when you violate the rules its +program, or its test suite, and detecting when you violate the rules it understands about how Rust should work. Using Miri requires a nightly build of Rust (which we talk about more in From 93d741a77b5222096cd3f894b67cf46053d96426 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 17 Oct 2024 14:40:13 -0600 Subject: [PATCH 680/720] Rust 2024: update Ch. 20 for new `unsafe` rules - `extern` now requires `unsafe extern`, but in turn allows functions within it to be marked as `safe`. Add examples to both effects within the text, and update listing numbers accordingly. - `#[no_mangle]` now requires `#[unsafe(no_mangle)]` These are all backwards-compatible, so we can opt the chapter into using the new rules without issue. --- .../listing-20-08/src/main.rs | 2 +- .../listing-20-09/src/main.rs | 6 +- .../listing-20-10/src/main.rs | 15 +--- .../output.txt | 0 .../listing-20-11/src/main.rs | 19 ++-- .../listing-20-12/Cargo.lock | 2 +- .../listing-20-12/Cargo.toml | 2 +- .../listing-20-12/src/lib.rs | 5 -- .../listing-20-12/src/main.rs | 9 ++ .../listing-20-13/src/lib.rs | 6 +- .../listing-20-14/src/lib.rs | 3 + .../src/main.rs | 0 .../src/lib.rs | 0 .../listing-20-16/src/main.rs | 31 ------- .../listing-20-17/src/main.rs | 9 +- .../listing-20-18/src/main.rs | 2 - .../listing-20-19/output.txt | 6 +- .../listing-20-19/src/main.rs | 35 +++++--- .../listing-20-20/output.txt | 19 +--- .../listing-20-20/src/main.rs | 4 +- .../listing-20-21/output.txt | 19 +++- .../listing-20-21/src/main.rs | 2 +- .../output.txt | 6 +- .../listing-20-22/src/main.rs | 32 ++++--- .../listing-20-23/src/main.rs | 21 +++-- .../listing-20-24/Cargo.lock | 2 +- .../listing-20-24/Cargo.toml | 2 +- .../listing-20-24/src/main.rs | 22 +++-- .../listing-20-25/src/main.rs | 8 +- .../Cargo.lock | 2 +- .../Cargo.toml | 2 +- .../listing-20-26/src/main.rs | 18 ++++ .../listing-20-28/Cargo.lock | 2 +- .../listing-20-28/Cargo.toml | 2 +- .../src/main.rs | 0 .../listing-20-29/Cargo.lock | 6 ++ .../listing-20-29/Cargo.toml | 6 ++ .../src/lib.rs | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../src/main.rs | 0 .../hello_macro/Cargo.lock | 0 .../hello_macro/Cargo.toml | 0 .../hello_macro/hello_macro_derive/Cargo.lock | 0 .../hello_macro/hello_macro_derive/Cargo.toml | 0 .../hello_macro/hello_macro_derive/src/lib.rs | 0 .../hello_macro/src/lib.rs | 0 .../hello_macro/src/main.rs | 0 .../hello_macro/Cargo.lock | 0 .../hello_macro/Cargo.toml | 0 .../hello_macro/hello_macro_derive/Cargo.lock | 0 .../hello_macro/hello_macro_derive/Cargo.toml | 0 .../hello_macro/hello_macro_derive/src/lib.rs | 0 .../hello_macro/src/lib.rs | 0 .../hello_macro/src/main.rs | 0 src/ch20-01-unsafe-rust.md | 72 +++++++++------ src/ch20-03-advanced-traits.md | 88 +++++++++---------- src/ch20-04-advanced-types.md | 24 ++--- ...ch20-05-advanced-functions-and-closures.md | 6 +- src/ch20-06-macros.md | 48 +++++----- 60 files changed, 303 insertions(+), 262 deletions(-) rename listings/ch20-advanced-features/{listing-20-10 => listing-20-11}/output.txt (100%) delete mode 100644 listings/ch20-advanced-features/listing-20-12/src/lib.rs create mode 100644 listings/ch20-advanced-features/listing-20-12/src/main.rs create mode 100644 listings/ch20-advanced-features/listing-20-14/src/lib.rs rename listings/ch20-advanced-features/{listing-20-14 => listing-20-15}/src/main.rs (100%) rename listings/ch20-advanced-features/{listing-20-15 => listing-20-16}/src/lib.rs (100%) delete mode 100644 listings/ch20-advanced-features/listing-20-16/src/main.rs rename listings/ch20-advanced-features/{listing-20-18 => listing-20-22}/output.txt (73%) rename listings/ch20-advanced-features/{listing-20-27 => listing-20-26}/Cargo.lock (81%) rename listings/ch20-advanced-features/{listing-20-27 => listing-20-26}/Cargo.toml (69%) create mode 100644 listings/ch20-advanced-features/listing-20-26/src/main.rs rename listings/ch20-advanced-features/{listing-20-27 => listing-20-28}/src/main.rs (100%) create mode 100644 listings/ch20-advanced-features/listing-20-29/Cargo.lock create mode 100644 listings/ch20-advanced-features/listing-20-29/Cargo.toml rename listings/ch20-advanced-features/{listing-20-28 => listing-20-29}/src/lib.rs (100%) rename listings/ch20-advanced-features/{listing-20-30 => listing-20-31}/Cargo.lock (100%) rename listings/ch20-advanced-features/{listing-20-30 => listing-20-31}/Cargo.toml (100%) rename listings/ch20-advanced-features/{listing-20-30 => listing-20-31}/src/main.rs (100%) rename listings/ch20-advanced-features/{listing-20-31 => listing-20-32}/hello_macro/Cargo.lock (100%) rename listings/ch20-advanced-features/{listing-20-31 => listing-20-32}/hello_macro/Cargo.toml (100%) rename listings/ch20-advanced-features/{listing-20-31 => listing-20-32}/hello_macro/hello_macro_derive/Cargo.lock (100%) rename listings/ch20-advanced-features/{listing-20-31 => listing-20-32}/hello_macro/hello_macro_derive/Cargo.toml (100%) rename listings/ch20-advanced-features/{listing-20-31 => listing-20-32}/hello_macro/hello_macro_derive/src/lib.rs (100%) rename listings/ch20-advanced-features/{listing-20-31 => listing-20-32}/hello_macro/src/lib.rs (100%) rename listings/ch20-advanced-features/{listing-20-31 => listing-20-32}/hello_macro/src/main.rs (100%) rename listings/ch20-advanced-features/{listing-20-33 => listing-20-34}/hello_macro/Cargo.lock (100%) rename listings/ch20-advanced-features/{listing-20-33 => listing-20-34}/hello_macro/Cargo.toml (100%) rename listings/ch20-advanced-features/{listing-20-33 => listing-20-34}/hello_macro/hello_macro_derive/Cargo.lock (100%) rename listings/ch20-advanced-features/{listing-20-33 => listing-20-34}/hello_macro/hello_macro_derive/Cargo.toml (100%) rename listings/ch20-advanced-features/{listing-20-33 => listing-20-34}/hello_macro/hello_macro_derive/src/lib.rs (100%) rename listings/ch20-advanced-features/{listing-20-33 => listing-20-34}/hello_macro/src/lib.rs (100%) rename listings/ch20-advanced-features/{listing-20-33 => listing-20-34}/hello_macro/src/main.rs (100%) diff --git a/listings/ch20-advanced-features/listing-20-08/src/main.rs b/listings/ch20-advanced-features/listing-20-08/src/main.rs index 8b56630c95..90c183adec 100644 --- a/listings/ch20-advanced-features/listing-20-08/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-08/src/main.rs @@ -1,4 +1,4 @@ -extern "C" { +unsafe extern "C" { fn abs(input: i32) -> i32; } diff --git a/listings/ch20-advanced-features/listing-20-09/src/main.rs b/listings/ch20-advanced-features/listing-20-09/src/main.rs index fda5179af7..7d77d51e4f 100644 --- a/listings/ch20-advanced-features/listing-20-09/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-09/src/main.rs @@ -1,5 +1,7 @@ -static HELLO_WORLD: &str = "Hello, world!"; +unsafe extern "C" { + safe fn abs(input: i32) -> i32; +} fn main() { - println!("name is: {HELLO_WORLD}"); + println!("Absolute value of -3 according to C: {}", abs(-3)); } diff --git a/listings/ch20-advanced-features/listing-20-10/src/main.rs b/listings/ch20-advanced-features/listing-20-10/src/main.rs index 360e3548fc..fda5179af7 100644 --- a/listings/ch20-advanced-features/listing-20-10/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-10/src/main.rs @@ -1,16 +1,5 @@ -static mut COUNTER: u32 = 0; - -/// SAFETY: Calling this from more than a single thread at a time is undefined -/// behavior, so you *must* guarantee you only call it from a single thread at -/// a time. -unsafe fn add_to_count(inc: u32) { - COUNTER += inc; -} +static HELLO_WORLD: &str = "Hello, world!"; fn main() { - unsafe { - // SAFETY: This is only called from a single thread in `main`. - add_to_count(3); - println!("COUNTER: {}", COUNTER); - } + println!("name is: {HELLO_WORLD}"); } diff --git a/listings/ch20-advanced-features/listing-20-10/output.txt b/listings/ch20-advanced-features/listing-20-11/output.txt similarity index 100% rename from listings/ch20-advanced-features/listing-20-10/output.txt rename to listings/ch20-advanced-features/listing-20-11/output.txt diff --git a/listings/ch20-advanced-features/listing-20-11/src/main.rs b/listings/ch20-advanced-features/listing-20-11/src/main.rs index 885c1aa1d8..360e3548fc 100644 --- a/listings/ch20-advanced-features/listing-20-11/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-11/src/main.rs @@ -1,9 +1,16 @@ -unsafe trait Foo { - // methods go here -} +static mut COUNTER: u32 = 0; -unsafe impl Foo for i32 { - // method implementations go here +/// SAFETY: Calling this from more than a single thread at a time is undefined +/// behavior, so you *must* guarantee you only call it from a single thread at +/// a time. +unsafe fn add_to_count(inc: u32) { + COUNTER += inc; } -fn main() {} +fn main() { + unsafe { + // SAFETY: This is only called from a single thread in `main`. + add_to_count(3); + println!("COUNTER: {}", COUNTER); + } +} diff --git a/listings/ch20-advanced-features/listing-20-12/Cargo.lock b/listings/ch20-advanced-features/listing-20-12/Cargo.lock index b1977d01ec..497817bf27 100644 --- a/listings/ch20-advanced-features/listing-20-12/Cargo.lock +++ b/listings/ch20-advanced-features/listing-20-12/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "traits-example" +name = "unsafe-example" version = "0.1.0" diff --git a/listings/ch20-advanced-features/listing-20-12/Cargo.toml b/listings/ch20-advanced-features/listing-20-12/Cargo.toml index 52395a5873..3e8a292013 100644 --- a/listings/ch20-advanced-features/listing-20-12/Cargo.toml +++ b/listings/ch20-advanced-features/listing-20-12/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "traits-example" +name = "unsafe-example" version = "0.1.0" edition = "2021" diff --git a/listings/ch20-advanced-features/listing-20-12/src/lib.rs b/listings/ch20-advanced-features/listing-20-12/src/lib.rs deleted file mode 100644 index dbe04620ef..0000000000 --- a/listings/ch20-advanced-features/listing-20-12/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub trait Iterator { - type Item; - - fn next(&mut self) -> Option; -} diff --git a/listings/ch20-advanced-features/listing-20-12/src/main.rs b/listings/ch20-advanced-features/listing-20-12/src/main.rs new file mode 100644 index 0000000000..885c1aa1d8 --- /dev/null +++ b/listings/ch20-advanced-features/listing-20-12/src/main.rs @@ -0,0 +1,9 @@ +unsafe trait Foo { + // methods go here +} + +unsafe impl Foo for i32 { + // method implementations go here +} + +fn main() {} diff --git a/listings/ch20-advanced-features/listing-20-13/src/lib.rs b/listings/ch20-advanced-features/listing-20-13/src/lib.rs index 7c9479c5b5..dbe04620ef 100644 --- a/listings/ch20-advanced-features/listing-20-13/src/lib.rs +++ b/listings/ch20-advanced-features/listing-20-13/src/lib.rs @@ -1,3 +1,5 @@ -pub trait Iterator { - fn next(&mut self) -> Option; +pub trait Iterator { + type Item; + + fn next(&mut self) -> Option; } diff --git a/listings/ch20-advanced-features/listing-20-14/src/lib.rs b/listings/ch20-advanced-features/listing-20-14/src/lib.rs new file mode 100644 index 0000000000..7c9479c5b5 --- /dev/null +++ b/listings/ch20-advanced-features/listing-20-14/src/lib.rs @@ -0,0 +1,3 @@ +pub trait Iterator { + fn next(&mut self) -> Option; +} diff --git a/listings/ch20-advanced-features/listing-20-14/src/main.rs b/listings/ch20-advanced-features/listing-20-15/src/main.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-14/src/main.rs rename to listings/ch20-advanced-features/listing-20-15/src/main.rs diff --git a/listings/ch20-advanced-features/listing-20-15/src/lib.rs b/listings/ch20-advanced-features/listing-20-16/src/lib.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-15/src/lib.rs rename to listings/ch20-advanced-features/listing-20-16/src/lib.rs diff --git a/listings/ch20-advanced-features/listing-20-16/src/main.rs b/listings/ch20-advanced-features/listing-20-16/src/main.rs deleted file mode 100644 index d854e287df..0000000000 --- a/listings/ch20-advanced-features/listing-20-16/src/main.rs +++ /dev/null @@ -1,31 +0,0 @@ -// ANCHOR: here -trait Pilot { - fn fly(&self); -} - -trait Wizard { - fn fly(&self); -} - -struct Human; - -impl Pilot for Human { - fn fly(&self) { - println!("This is your captain speaking."); - } -} - -impl Wizard for Human { - fn fly(&self) { - println!("Up!"); - } -} - -impl Human { - fn fly(&self) { - println!("*waving arms furiously*"); - } -} -// ANCHOR_END: here - -fn main() {} diff --git a/listings/ch20-advanced-features/listing-20-17/src/main.rs b/listings/ch20-advanced-features/listing-20-17/src/main.rs index 3df65a7ce2..d854e287df 100644 --- a/listings/ch20-advanced-features/listing-20-17/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-17/src/main.rs @@ -1,3 +1,4 @@ +// ANCHOR: here trait Pilot { fn fly(&self); } @@ -25,10 +26,6 @@ impl Human { println!("*waving arms furiously*"); } } - -// ANCHOR: here -fn main() { - let person = Human; - person.fly(); -} // ANCHOR_END: here + +fn main() {} diff --git a/listings/ch20-advanced-features/listing-20-18/src/main.rs b/listings/ch20-advanced-features/listing-20-18/src/main.rs index fa01c09ccc..3df65a7ce2 100644 --- a/listings/ch20-advanced-features/listing-20-18/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-18/src/main.rs @@ -29,8 +29,6 @@ impl Human { // ANCHOR: here fn main() { let person = Human; - Pilot::fly(&person); - Wizard::fly(&person); person.fly(); } // ANCHOR_END: here diff --git a/listings/ch20-advanced-features/listing-20-19/output.txt b/listings/ch20-advanced-features/listing-20-19/output.txt index b6e283f202..d7e315bfab 100644 --- a/listings/ch20-advanced-features/listing-20-19/output.txt +++ b/listings/ch20-advanced-features/listing-20-19/output.txt @@ -1,5 +1,7 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.46s Running `target/debug/traits-example` -A baby dog is called a Spot +This is your captain speaking. +Up! +*waving arms furiously* diff --git a/listings/ch20-advanced-features/listing-20-19/src/main.rs b/listings/ch20-advanced-features/listing-20-19/src/main.rs index 44affe0ee2..fa01c09ccc 100644 --- a/listings/ch20-advanced-features/listing-20-19/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-19/src/main.rs @@ -1,21 +1,36 @@ -trait Animal { - fn baby_name() -> String; +trait Pilot { + fn fly(&self); } -struct Dog; +trait Wizard { + fn fly(&self); +} + +struct Human; + +impl Pilot for Human { + fn fly(&self) { + println!("This is your captain speaking."); + } +} -impl Dog { - fn baby_name() -> String { - String::from("Spot") +impl Wizard for Human { + fn fly(&self) { + println!("Up!"); } } -impl Animal for Dog { - fn baby_name() -> String { - String::from("puppy") +impl Human { + fn fly(&self) { + println!("*waving arms furiously*"); } } +// ANCHOR: here fn main() { - println!("A baby dog is called a {}", Dog::baby_name()); + let person = Human; + Pilot::fly(&person); + Wizard::fly(&person); + person.fly(); } +// ANCHOR_END: here diff --git a/listings/ch20-advanced-features/listing-20-20/output.txt b/listings/ch20-advanced-features/listing-20-20/output.txt index 0e78ae2d9f..b6e283f202 100644 --- a/listings/ch20-advanced-features/listing-20-20/output.txt +++ b/listings/ch20-advanced-features/listing-20-20/output.txt @@ -1,18 +1,5 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) -error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type - --> src/main.rs:20:43 - | -2 | fn baby_name() -> String; - | ------------------------- `Animal::baby_name` defined here -... -20 | println!("A baby dog is called a {}", Animal::baby_name()); - | ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait - | -help: use the fully-qualified path to the only available implementation - | -20 | println!("A baby dog is called a {}", ::baby_name()); - | +++++++ + - -For more information about this error, try `rustc --explain E0790`. -error: could not compile `traits-example` (bin "traits-example") due to 1 previous error + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s + Running `target/debug/traits-example` +A baby dog is called a Spot diff --git a/listings/ch20-advanced-features/listing-20-20/src/main.rs b/listings/ch20-advanced-features/listing-20-20/src/main.rs index 8e295c9b65..44affe0ee2 100644 --- a/listings/ch20-advanced-features/listing-20-20/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-20/src/main.rs @@ -16,8 +16,6 @@ impl Animal for Dog { } } -// ANCHOR: here fn main() { - println!("A baby dog is called a {}", Animal::baby_name()); + println!("A baby dog is called a {}", Dog::baby_name()); } -// ANCHOR_END: here diff --git a/listings/ch20-advanced-features/listing-20-21/output.txt b/listings/ch20-advanced-features/listing-20-21/output.txt index f59d0bc27d..0e78ae2d9f 100644 --- a/listings/ch20-advanced-features/listing-20-21/output.txt +++ b/listings/ch20-advanced-features/listing-20-21/output.txt @@ -1,5 +1,18 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s - Running `target/debug/traits-example` -A baby dog is called a puppy +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type + --> src/main.rs:20:43 + | +2 | fn baby_name() -> String; + | ------------------------- `Animal::baby_name` defined here +... +20 | println!("A baby dog is called a {}", Animal::baby_name()); + | ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait + | +help: use the fully-qualified path to the only available implementation + | +20 | println!("A baby dog is called a {}", ::baby_name()); + | +++++++ + + +For more information about this error, try `rustc --explain E0790`. +error: could not compile `traits-example` (bin "traits-example") due to 1 previous error diff --git a/listings/ch20-advanced-features/listing-20-21/src/main.rs b/listings/ch20-advanced-features/listing-20-21/src/main.rs index b1df728951..8e295c9b65 100644 --- a/listings/ch20-advanced-features/listing-20-21/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-21/src/main.rs @@ -18,6 +18,6 @@ impl Animal for Dog { // ANCHOR: here fn main() { - println!("A baby dog is called a {}", ::baby_name()); + println!("A baby dog is called a {}", Animal::baby_name()); } // ANCHOR_END: here diff --git a/listings/ch20-advanced-features/listing-20-18/output.txt b/listings/ch20-advanced-features/listing-20-22/output.txt similarity index 73% rename from listings/ch20-advanced-features/listing-20-18/output.txt rename to listings/ch20-advanced-features/listing-20-22/output.txt index d7e315bfab..f59d0bc27d 100644 --- a/listings/ch20-advanced-features/listing-20-18/output.txt +++ b/listings/ch20-advanced-features/listing-20-22/output.txt @@ -1,7 +1,5 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.46s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s Running `target/debug/traits-example` -This is your captain speaking. -Up! -*waving arms furiously* +A baby dog is called a puppy diff --git a/listings/ch20-advanced-features/listing-20-22/src/main.rs b/listings/ch20-advanced-features/listing-20-22/src/main.rs index 7069fef179..b1df728951 100644 --- a/listings/ch20-advanced-features/listing-20-22/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-22/src/main.rs @@ -1,17 +1,23 @@ -// ANCHOR: here -use std::fmt; +trait Animal { + fn baby_name() -> String; +} + +struct Dog; -trait OutlinePrint: fmt::Display { - fn outline_print(&self) { - let output = self.to_string(); - let len = output.len(); - println!("{}", "*".repeat(len + 4)); - println!("*{}*", " ".repeat(len + 2)); - println!("* {output} *"); - println!("*{}*", " ".repeat(len + 2)); - println!("{}", "*".repeat(len + 4)); +impl Dog { + fn baby_name() -> String { + String::from("Spot") + } +} + +impl Animal for Dog { + fn baby_name() -> String { + String::from("puppy") } } -// ANCHOR_END: here -fn main() {} +// ANCHOR: here +fn main() { + println!("A baby dog is called a {}", ::baby_name()); +} +// ANCHOR_END: here diff --git a/listings/ch20-advanced-features/listing-20-23/src/main.rs b/listings/ch20-advanced-features/listing-20-23/src/main.rs index f8c8366b4c..7069fef179 100644 --- a/listings/ch20-advanced-features/listing-20-23/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-23/src/main.rs @@ -1,14 +1,17 @@ +// ANCHOR: here use std::fmt; -struct Wrapper(Vec); - -impl fmt::Display for Wrapper { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{}]", self.0.join(", ")) +trait OutlinePrint: fmt::Display { + fn outline_print(&self) { + let output = self.to_string(); + let len = output.len(); + println!("{}", "*".repeat(len + 4)); + println!("*{}*", " ".repeat(len + 2)); + println!("* {output} *"); + println!("*{}*", " ".repeat(len + 2)); + println!("{}", "*".repeat(len + 4)); } } +// ANCHOR_END: here -fn main() { - let w = Wrapper(vec![String::from("hello"), String::from("world")]); - println!("w = {w}"); -} +fn main() {} diff --git a/listings/ch20-advanced-features/listing-20-24/Cargo.lock b/listings/ch20-advanced-features/listing-20-24/Cargo.lock index c0c98a79cf..b1977d01ec 100644 --- a/listings/ch20-advanced-features/listing-20-24/Cargo.lock +++ b/listings/ch20-advanced-features/listing-20-24/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "types-example" +name = "traits-example" version = "0.1.0" diff --git a/listings/ch20-advanced-features/listing-20-24/Cargo.toml b/listings/ch20-advanced-features/listing-20-24/Cargo.toml index a2ae20c77c..52395a5873 100644 --- a/listings/ch20-advanced-features/listing-20-24/Cargo.toml +++ b/listings/ch20-advanced-features/listing-20-24/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "types-example" +name = "traits-example" version = "0.1.0" edition = "2021" diff --git a/listings/ch20-advanced-features/listing-20-24/src/main.rs b/listings/ch20-advanced-features/listing-20-24/src/main.rs index d604ae8d6a..f8c8366b4c 100644 --- a/listings/ch20-advanced-features/listing-20-24/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-24/src/main.rs @@ -1,16 +1,14 @@ -fn main() { - // ANCHOR: here - let f: Box = Box::new(|| println!("hi")); +use std::fmt; - fn takes_long_type(f: Box) { - // --snip-- - } +struct Wrapper(Vec); - fn returns_long_type() -> Box { - // --snip-- - // ANCHOR_END: here - Box::new(|| ()) - // ANCHOR: here +impl fmt::Display for Wrapper { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "[{}]", self.0.join(", ")) } - // ANCHOR_END: here +} + +fn main() { + let w = Wrapper(vec![String::from("hello"), String::from("world")]); + println!("w = {w}"); } diff --git a/listings/ch20-advanced-features/listing-20-25/src/main.rs b/listings/ch20-advanced-features/listing-20-25/src/main.rs index af35bed2c9..d604ae8d6a 100644 --- a/listings/ch20-advanced-features/listing-20-25/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-25/src/main.rs @@ -1,14 +1,12 @@ fn main() { // ANCHOR: here - type Thunk = Box; + let f: Box = Box::new(|| println!("hi")); - let f: Thunk = Box::new(|| println!("hi")); - - fn takes_long_type(f: Thunk) { + fn takes_long_type(f: Box) { // --snip-- } - fn returns_long_type() -> Thunk { + fn returns_long_type() -> Box { // --snip-- // ANCHOR_END: here Box::new(|| ()) diff --git a/listings/ch20-advanced-features/listing-20-27/Cargo.lock b/listings/ch20-advanced-features/listing-20-26/Cargo.lock similarity index 81% rename from listings/ch20-advanced-features/listing-20-27/Cargo.lock rename to listings/ch20-advanced-features/listing-20-26/Cargo.lock index b2327c755a..c0c98a79cf 100644 --- a/listings/ch20-advanced-features/listing-20-27/Cargo.lock +++ b/listings/ch20-advanced-features/listing-20-26/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "functions-example" +name = "types-example" version = "0.1.0" diff --git a/listings/ch20-advanced-features/listing-20-27/Cargo.toml b/listings/ch20-advanced-features/listing-20-26/Cargo.toml similarity index 69% rename from listings/ch20-advanced-features/listing-20-27/Cargo.toml rename to listings/ch20-advanced-features/listing-20-26/Cargo.toml index b196f35b55..a2ae20c77c 100644 --- a/listings/ch20-advanced-features/listing-20-27/Cargo.toml +++ b/listings/ch20-advanced-features/listing-20-26/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "functions-example" +name = "types-example" version = "0.1.0" edition = "2021" diff --git a/listings/ch20-advanced-features/listing-20-26/src/main.rs b/listings/ch20-advanced-features/listing-20-26/src/main.rs new file mode 100644 index 0000000000..af35bed2c9 --- /dev/null +++ b/listings/ch20-advanced-features/listing-20-26/src/main.rs @@ -0,0 +1,18 @@ +fn main() { + // ANCHOR: here + type Thunk = Box; + + let f: Thunk = Box::new(|| println!("hi")); + + fn takes_long_type(f: Thunk) { + // --snip-- + } + + fn returns_long_type() -> Thunk { + // --snip-- + // ANCHOR_END: here + Box::new(|| ()) + // ANCHOR: here + } + // ANCHOR_END: here +} diff --git a/listings/ch20-advanced-features/listing-20-28/Cargo.lock b/listings/ch20-advanced-features/listing-20-28/Cargo.lock index b2d9257545..b2327c755a 100644 --- a/listings/ch20-advanced-features/listing-20-28/Cargo.lock +++ b/listings/ch20-advanced-features/listing-20-28/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "macros-example" +name = "functions-example" version = "0.1.0" diff --git a/listings/ch20-advanced-features/listing-20-28/Cargo.toml b/listings/ch20-advanced-features/listing-20-28/Cargo.toml index 9218091c89..b196f35b55 100644 --- a/listings/ch20-advanced-features/listing-20-28/Cargo.toml +++ b/listings/ch20-advanced-features/listing-20-28/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "macros-example" +name = "functions-example" version = "0.1.0" edition = "2021" diff --git a/listings/ch20-advanced-features/listing-20-27/src/main.rs b/listings/ch20-advanced-features/listing-20-28/src/main.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-27/src/main.rs rename to listings/ch20-advanced-features/listing-20-28/src/main.rs diff --git a/listings/ch20-advanced-features/listing-20-29/Cargo.lock b/listings/ch20-advanced-features/listing-20-29/Cargo.lock new file mode 100644 index 0000000000..b2d9257545 --- /dev/null +++ b/listings/ch20-advanced-features/listing-20-29/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "macros-example" +version = "0.1.0" + diff --git a/listings/ch20-advanced-features/listing-20-29/Cargo.toml b/listings/ch20-advanced-features/listing-20-29/Cargo.toml new file mode 100644 index 0000000000..9218091c89 --- /dev/null +++ b/listings/ch20-advanced-features/listing-20-29/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "macros-example" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/listings/ch20-advanced-features/listing-20-28/src/lib.rs b/listings/ch20-advanced-features/listing-20-29/src/lib.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-28/src/lib.rs rename to listings/ch20-advanced-features/listing-20-29/src/lib.rs diff --git a/listings/ch20-advanced-features/listing-20-30/Cargo.lock b/listings/ch20-advanced-features/listing-20-31/Cargo.lock similarity index 100% rename from listings/ch20-advanced-features/listing-20-30/Cargo.lock rename to listings/ch20-advanced-features/listing-20-31/Cargo.lock diff --git a/listings/ch20-advanced-features/listing-20-30/Cargo.toml b/listings/ch20-advanced-features/listing-20-31/Cargo.toml similarity index 100% rename from listings/ch20-advanced-features/listing-20-30/Cargo.toml rename to listings/ch20-advanced-features/listing-20-31/Cargo.toml diff --git a/listings/ch20-advanced-features/listing-20-30/src/main.rs b/listings/ch20-advanced-features/listing-20-31/src/main.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-30/src/main.rs rename to listings/ch20-advanced-features/listing-20-31/src/main.rs diff --git a/listings/ch20-advanced-features/listing-20-31/hello_macro/Cargo.lock b/listings/ch20-advanced-features/listing-20-32/hello_macro/Cargo.lock similarity index 100% rename from listings/ch20-advanced-features/listing-20-31/hello_macro/Cargo.lock rename to listings/ch20-advanced-features/listing-20-32/hello_macro/Cargo.lock diff --git a/listings/ch20-advanced-features/listing-20-31/hello_macro/Cargo.toml b/listings/ch20-advanced-features/listing-20-32/hello_macro/Cargo.toml similarity index 100% rename from listings/ch20-advanced-features/listing-20-31/hello_macro/Cargo.toml rename to listings/ch20-advanced-features/listing-20-32/hello_macro/Cargo.toml diff --git a/listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/Cargo.lock b/listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/Cargo.lock similarity index 100% rename from listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/Cargo.lock rename to listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/Cargo.lock diff --git a/listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/Cargo.toml b/listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/Cargo.toml similarity index 100% rename from listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/Cargo.toml rename to listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/Cargo.toml diff --git a/listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/src/lib.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/src/lib.rs rename to listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/src/lib.rs diff --git a/listings/ch20-advanced-features/listing-20-31/hello_macro/src/lib.rs b/listings/ch20-advanced-features/listing-20-32/hello_macro/src/lib.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-31/hello_macro/src/lib.rs rename to listings/ch20-advanced-features/listing-20-32/hello_macro/src/lib.rs diff --git a/listings/ch20-advanced-features/listing-20-31/hello_macro/src/main.rs b/listings/ch20-advanced-features/listing-20-32/hello_macro/src/main.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-31/hello_macro/src/main.rs rename to listings/ch20-advanced-features/listing-20-32/hello_macro/src/main.rs diff --git a/listings/ch20-advanced-features/listing-20-33/hello_macro/Cargo.lock b/listings/ch20-advanced-features/listing-20-34/hello_macro/Cargo.lock similarity index 100% rename from listings/ch20-advanced-features/listing-20-33/hello_macro/Cargo.lock rename to listings/ch20-advanced-features/listing-20-34/hello_macro/Cargo.lock diff --git a/listings/ch20-advanced-features/listing-20-33/hello_macro/Cargo.toml b/listings/ch20-advanced-features/listing-20-34/hello_macro/Cargo.toml similarity index 100% rename from listings/ch20-advanced-features/listing-20-33/hello_macro/Cargo.toml rename to listings/ch20-advanced-features/listing-20-34/hello_macro/Cargo.toml diff --git a/listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/Cargo.lock b/listings/ch20-advanced-features/listing-20-34/hello_macro/hello_macro_derive/Cargo.lock similarity index 100% rename from listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/Cargo.lock rename to listings/ch20-advanced-features/listing-20-34/hello_macro/hello_macro_derive/Cargo.lock diff --git a/listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/Cargo.toml b/listings/ch20-advanced-features/listing-20-34/hello_macro/hello_macro_derive/Cargo.toml similarity index 100% rename from listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/Cargo.toml rename to listings/ch20-advanced-features/listing-20-34/hello_macro/hello_macro_derive/Cargo.toml diff --git a/listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch20-advanced-features/listing-20-34/hello_macro/hello_macro_derive/src/lib.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/src/lib.rs rename to listings/ch20-advanced-features/listing-20-34/hello_macro/hello_macro_derive/src/lib.rs diff --git a/listings/ch20-advanced-features/listing-20-33/hello_macro/src/lib.rs b/listings/ch20-advanced-features/listing-20-34/hello_macro/src/lib.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-33/hello_macro/src/lib.rs rename to listings/ch20-advanced-features/listing-20-34/hello_macro/src/lib.rs diff --git a/listings/ch20-advanced-features/listing-20-33/hello_macro/src/main.rs b/listings/ch20-advanced-features/listing-20-34/hello_macro/src/main.rs similarity index 100% rename from listings/ch20-advanced-features/listing-20-33/hello_macro/src/main.rs rename to listings/ch20-advanced-features/listing-20-34/hello_macro/src/main.rs diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 156c0f05ff..b9f370786d 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -311,9 +311,10 @@ programming language to call those functions. Listing 20-8 demonstrates how to set up an integration with the `abs` function from the C standard library. Functions declared within `extern` blocks are -always unsafe to call from Rust code. The reason is that other languages don’t -enforce Rust’s rules and guarantees, and Rust can’t check them, so -responsibility falls on the programmer to ensure safety. +usually unsafe to call from Rust code, so they must also be marked `unsafe`. The +reason is that other languages don’t enforce Rust’s rules and guarantees, and +Rust can’t check them, so responsibility falls on the programmer to ensure +safety. @@ -323,30 +324,51 @@ responsibility falls on the programmer to ensure safety. -Within the `extern "C"` block, we list the names and signatures of external -functions from another language we want to call. The `"C"` part defines which -*application binary interface (ABI)* the external function uses: the ABI +Within the `unsafe extern "C"` block, we list the names and signatures of +external functions from another language we want to call. The `"C"` part defines +which *application binary interface (ABI)* the external function uses: the ABI defines how to call the function at the assembly level. The `"C"` ABI is the most common and follows the C programming language’s ABI. +This particular function does not have any memory safety considerations, though. +In fact, we know that any call to `abs` will always be safe for any `i32`, so we +can use the `safe` keyword to say that this specific function is safe to call +even though it is in an `unsafe extern` block. Once we make that change, calling +it no longer requires an `unsafe` block, as shown in Listing 20-9. + ++ +```rust +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-09/src/main.rs}} +``` + + + +Marking a function as `safe` does not inherently make it safe! Instead, it is +like a promise you are making to Rust that it *is* safe. It is still your +responsibility to make sure that promise is kept! + > #### Calling Rust Functions from Other Languages > -> We can also use `extern` to create an interface that allows other languages -> to call Rust functions. Instead of creating a whole `extern` block, we add -> the `extern` keyword and specify the ABI to use just before the `fn` keyword -> for the relevant function. We also need to add a `#[no_mangle]` annotation to -> tell the Rust compiler not to mangle the name of this function. *Mangling* is -> when a compiler changes the name we’ve given a function to a different name +> We can also use `extern` to create an interface that allows other languages to +> call Rust functions. Instead of creating a whole `extern` block, we add the +> `extern` keyword and specify the ABI to use just before the `fn` keyword for +> the relevant function. We also need to add a `#[unsafe(no_mangle)]` annotation +> to tell the Rust compiler not to mangle the name of this function. *Mangling* +> is when a compiler changes the name we’ve given a function to a different name > that contains more information for other parts of the compilation process to > consume but is less human readable. Every programming language compiler > mangles names slightly differently, so for a Rust function to be nameable by -> other languages, we must disable the Rust compiler’s name mangling. +> other languages, we must disable the Rust compiler’s name mangling. This is +> unsafe because there might be name collisions across libraries without the +> built-in mangling, so it is our responsibility to make sure the name we have +> exported is safe to export without mangling. > > In the following example, we make the `call_from_c` function accessible from > C code, after it’s compiled to a shared library and linked from C: > > ```rust -> #[no_mangle] +> #[unsafe(no_mangle)] > pub extern "C" fn call_from_c() { > println!("Just called a Rust function from C!"); > } @@ -360,14 +382,14 @@ In this book, we’ve not yet talked about *global variables*, which Rust does support but can be problematic with Rust’s ownership rules. If two threads are accessing the same mutable global variable, it can cause a data race. -In Rust, global variables are called *static* variables. Listing 20-9 shows an +In Rust, global variables are called *static* variables. Listing 20-10 shows an example declaration and use of a static variable with a string slice as a value. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-09/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-10/src/main.rs}} ``` @@ -386,13 +408,13 @@ values in a static variable have a fixed address in memory. Using the value will always access the same data. Constants, on the other hand, are allowed to duplicate their data whenever they’re used. Another difference is that static variables can be mutable. Accessing and modifying mutable static variables is -*unsafe*. Listing 20-10 shows how to declare, access, and modify a mutable +*unsafe*. Listing 20-11 shows how to declare, access, and modify a mutable static variable named `COUNTER`. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-10/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-11/src/main.rs}} ``` @@ -423,12 +445,12 @@ We can use `unsafe` to implement an unsafe trait. A trait is unsafe when at least one of its methods has some invariant that the compiler can’t verify. We declare that a trait is `unsafe` by adding the `unsafe` keyword before `trait` and marking the implementation of the trait as `unsafe` too, as shown in -Listing 20-11. +Listing 20-12. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-11/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-12/src/main.rs}} ``` @@ -475,10 +497,10 @@ You can run Miri on a project by typing `cargo +nightly miri run` or `cargo +nightly miri test`. For an example of how helpful this can be, consider what happens when we run it -against Listing 20-10: +against Listing 20-11: ```console -{{#include ../listings/ch20-advanced-features/listing-20-10/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-11/output.txt}} ``` It helpfully and correctly notices that we have shared references to mutable diff --git a/src/ch20-03-advanced-traits.md b/src/ch20-03-advanced-traits.md index e411dd57de..d95b1d9b94 100644 --- a/src/ch20-03-advanced-traits.md +++ b/src/ch20-03-advanced-traits.md @@ -23,12 +23,12 @@ One example of a trait with an associated type is the `Iterator` trait that the standard library provides. The associated type is named `Item` and stands in for the type of the values the type implementing the `Iterator` trait is iterating over. The definition of the `Iterator` trait is as shown in Listing -20-12. +20-13. -+ ```rust,noplayground -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-12/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-13/src/lib.rs}} ``` @@ -53,17 +53,17 @@ the `Item` type is `u32`: This syntax seems comparable to that of generics. So why not just define the -`Iterator` trait with generics, as shown in Listing 20-13? +`Iterator` trait with generics, as shown in Listing 20-14? -+ ```rust,noplayground -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-13/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-14/src/lib.rs}} ``` -The difference is that when using generics, as in Listing 20-13, we must +The difference is that when using generics, as in Listing 20-14, we must annotate the types in each implementation; because we can also implement `Iterator for Counter` or any other type, we could have multiple implementations of `Iterator` for `Counter`. In other words, when a trait has a @@ -73,7 +73,7 @@ the concrete types of the generic type parameters each time. When we use the indicate which implementation of `Iterator` we want to use. With associated types, we don’t need to annotate types because we can’t -implement a trait on a type multiple times. In Listing 20-12 with the +implement a trait on a type multiple times. In Listing 20-13 with the definition that uses associated types, we can only choose what the type of `Item` will be once, because there can only be one `impl Iterator for Counter`. We don’t have to specify that we want an iterator of `u32` values everywhere @@ -98,14 +98,14 @@ in particular situations. Rust doesn’t allow you to create your own operators or overload arbitrary operators. But you can overload the operations and corresponding traits listed in `std::ops` by implementing the traits associated with the operator. For -example, in Listing 20-14 we overload the `+` operator to add two `Point` +example, in Listing 20-15 we overload the `+` operator to add two `Point` instances together. We do this by implementing the `Add` trait on a `Point` struct: -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-14/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-15/src/main.rs}} ``` @@ -145,12 +145,12 @@ units. This thin wrapping of an existing type in another struct is known as the Pattern to Implement External Traits on External Types”][newtype] section. We want to add values in millimeters to values in meters and have the implementation of `Add` do the conversion correctly. We can implement `Add` -for `Millimeters` with `Meters` as the `Rhs`, as shown in Listing 20-15. +for `Millimeters` with `Meters` as the `Rhs`, as shown in Listing 20-16. -+ ```rust,noplayground -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-15/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-16/src/lib.rs}} ``` @@ -183,26 +183,26 @@ on one type. It’s also possible to implement a method directly on the type wit the same name as methods from traits. When calling methods with the same name, you’ll need to tell Rust which one you -want to use. Consider the code in Listing 20-16 where we’ve defined two traits, +want to use. Consider the code in Listing 20-17 where we’ve defined two traits, `Pilot` and `Wizard`, that both have a method called `fly`. We then implement both traits on a type `Human` that already has a method named `fly` implemented on it. Each `fly` method does something different. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-16/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-17/src/main.rs:here}} ``` When we call `fly` on an instance of `Human`, the compiler defaults to calling -the method that is directly implemented on the type, as shown in Listing 20-17. +the method that is directly implemented on the type, as shown in Listing 20-18. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-17/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-18/src/main.rs:here}} ``` @@ -212,12 +212,12 @@ called the `fly` method implemented on `Human` directly. To call the `fly` methods from either the `Pilot` trait or the `Wizard` trait, we need to use more explicit syntax to specify which `fly` method we mean. -Listing 20-18 demonstrates this syntax. +Listing 20-19 demonstrates this syntax. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-18/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-19/src/main.rs:here}} ``` @@ -225,13 +225,13 @@ Listing 20-18 demonstrates this syntax. Specifying the trait name before the method name clarifies to Rust which implementation of `fly` we want to call. We could also write `Human::fly(&person)`, which is equivalent to the `person.fly()` that we used -in Listing 20-18, but this is a bit longer to write if we don’t need to +in Listing 20-19, but this is a bit longer to write if we don’t need to disambiguate. Running this code prints the following: ```console -{{#include ../listings/ch20-advanced-features/listing-20-18/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-19/output.txt}} ``` Because the `fly` method takes a `self` parameter, if we had two *types* that @@ -241,16 +241,16 @@ trait to use based on the type of `self`. However, associated functions that are not methods don’t have a `self` parameter. When there are multiple types or traits that define non-method functions with the same function name, Rust doesn't always know which type you -mean unless you use *fully qualified syntax*. For example, in Listing 20-19 we +mean unless you use *fully qualified syntax*. For example, in Listing 20-20 we create a trait for an animal shelter that wants to name all baby dogs *Spot*. We make an `Animal` trait with an associated non-method function `baby_name`. The `Animal` trait is implemented for the struct `Dog`, on which we also provide an associated non-method function `baby_name` directly. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-19/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-20/src/main.rs}} ``` @@ -265,19 +265,19 @@ In `main`, we call the `Dog::baby_name` function, which calls the associated function defined on `Dog` directly. This code prints the following: ```console -{{#include ../listings/ch20-advanced-features/listing-20-19/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-20/output.txt}} ``` This output isn’t what we wanted. We want to call the `baby_name` function that is part of the `Animal` trait that we implemented on `Dog` so the code prints `A baby dog is called a puppy`. The technique of specifying the trait name that -we used in Listing 20-18 doesn’t help here; if we change `main` to the code in -Listing 20-20, we’ll get a compilation error. +we used in Listing 20-19 doesn’t help here; if we change `main` to the code in +Listing 20-21, we’ll get a compilation error. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-20/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-21/src/main.rs:here}} ``` @@ -287,18 +287,18 @@ other types that implement the `Animal` trait, Rust can’t figure out which implementation of `Animal::baby_name` we want. We’ll get this compiler error: ```console -{{#include ../listings/ch20-advanced-features/listing-20-20/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-21/output.txt}} ``` To disambiguate and tell Rust that we want to use the implementation of `Animal` for `Dog` as opposed to the implementation of `Animal` for some other -type, we need to use fully qualified syntax. Listing 20-21 demonstrates how to +type, we need to use fully qualified syntax. Listing 20-22 demonstrates how to use fully qualified syntax. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-21/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-22/src/main.rs:here}} ``` @@ -309,7 +309,7 @@ implemented on `Dog` by saying that we want to treat the `Dog` type as an `Animal` for this function call. This code will now print what we want: ```console -{{#include ../listings/ch20-advanced-features/listing-20-21/output.txt}} +{{#include ../listings/ch20-advanced-features/listing-20-22/output.txt}} ``` In general, fully qualified syntax is defined as follows: @@ -354,13 +354,13 @@ In the implementation of the `outline_print` method, we want to use the `OutlinePrint` trait will work only for types that also implement `Display` and provide the functionality that `OutlinePrint` needs. We can do that in the trait definition by specifying `OutlinePrint: Display`. This technique is -similar to adding a trait bound to the trait. Listing 20-22 shows an +similar to adding a trait bound to the trait. Listing 20-23 shows an implementation of the `OutlinePrint` trait. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-22/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-23/src/main.rs:here}} ``` @@ -424,12 +424,12 @@ As an example, let’s say we want to implement `Display` on `Vec`, which the orphan rule prevents us from doing directly because the `Display` trait and the `Vec` type are defined outside our crate. We can make a `Wrapper` struct that holds an instance of `Vec`; then we can implement `Display` on -`Wrapper` and use the `Vec` value, as shown in Listing 20-23. +`Wrapper` and use the `Vec` value, as shown in Listing 20-24. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-23/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-24/src/main.rs}} ``` diff --git a/src/ch20-04-advanced-types.md b/src/ch20-04-advanced-types.md index 88f2b36f65..a3f1f43207 100644 --- a/src/ch20-04-advanced-types.md +++ b/src/ch20-04-advanced-types.md @@ -15,7 +15,7 @@ the `!` type and dynamically sized types. The newtype pattern is also useful for tasks beyond those we’ve discussed so far, including statically enforcing that values are never confused and indicating the units of a value. You saw an example of using newtypes to -indicate units in Listing 20-15: recall that the `Millimeters` and `Meters` +indicate units in Listing 20-16: recall that the `Millimeters` and `Meters` structs wrapped `u32` values in a newtype. If we wrote a function with a parameter of type `Millimeters`, we couldn’t compile a program that accidentally tried to call that function with a value of type `Meters` or a @@ -47,7 +47,7 @@ the alias `Kilometers` to `i32` like so: ``` Now, the alias `Kilometers` is a *synonym* for `i32`; unlike the `Millimeters` -and `Meters` types we created in Listing 20-15, `Kilometers` is not a separate, +and `Meters` types we created in Listing 20-16, `Kilometers` is not a separate, new type. Values that have the type `Kilometers` will be treated the same as values of type `i32`: @@ -71,24 +71,24 @@ Box Writing this lengthy type in function signatures and as type annotations all over the code can be tiresome and error prone. Imagine having a project full of -code like that in Listing 20-24. +code like that in Listing 20-25. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-24/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-25/src/main.rs:here}} ``` A type alias makes this code more manageable by reducing the repetition. In -Listing 20-25, we’ve introduced an alias named `Thunk` for the verbose type and +Listing 20-26, we’ve introduced an alias named `Thunk` for the verbose type and can replace all uses of the type with the shorter alias `Thunk`. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-25/src/main.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-26/src/main.rs:here}} ``` @@ -148,9 +148,9 @@ so `bar` can never possibly return. But what use is a type you can never create values for? Recall the code from Listing 2-5, part of the number guessing game; we’ve reproduced a bit of it -here in Listing 20-26. +here in Listing 20-27. -+ ```rust,ignore {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-05/src/main.rs:ch19}} @@ -170,7 +170,7 @@ example, the following code doesn’t work: The type of `guess` in this code would have to be an integer *and* a string, and Rust requires that `guess` have only one type. So what does `continue` return? How were we allowed to return a `u32` from one arm and have another arm -that ends with `continue` in Listing 20-26? +that ends with `continue` in Listing 20-27? As you might have guessed, `continue` has a `!` value. That is, when Rust computes the type of `guess`, it looks at both match arms, the former with a @@ -191,7 +191,7 @@ this definition: {{#rustdoc_include ../listings/ch20-advanced-features/no-listing-09-unwrap-definition/src/lib.rs:here}} ``` -In this code, the same thing happens as in the `match` in Listing 20-26: Rust +In this code, the same thing happens as in the `match` in Listing 20-27: Rust sees that `val` has the type `T` and `panic!` has the type `!`, so the result of the overall `match` expression is `T`. This code works because `panic!` doesn’t produce a value; it ends the program. In the `None` case, we won’t be diff --git a/src/ch20-05-advanced-functions-and-closures.md b/src/ch20-05-advanced-functions-and-closures.md index 70385af324..618568d0d1 100644 --- a/src/ch20-05-advanced-functions-and-closures.md +++ b/src/ch20-05-advanced-functions-and-closures.md @@ -14,7 +14,7 @@ with function pointers will allow you to use functions as arguments to other functions. The syntax for specifying that a parameter is a function pointer is similar to -that of closures, as shown in Listing 20-27, where we’ve defined a function +that of closures, as shown in Listing 20-28, where we’ve defined a function `add_one` that adds one to its parameter. The function `do_twice` takes two parameters: a function pointer to any function that takes an `i32` parameter and returns an `i32`, and one `i32` value. The `do_twice` function calls the @@ -22,10 +22,10 @@ function `f` twice, passing it the `arg` value, then adds the two function call results together. The `main` function calls `do_twice` with the arguments `add_one` and `5`. -+ ```rust -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-27/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-28/src/main.rs}} ``` diff --git a/src/ch20-06-macros.md b/src/ch20-06-macros.md index 7900a015bc..cd4ded07d8 100644 --- a/src/ch20-06-macros.md +++ b/src/ch20-06-macros.md @@ -73,12 +73,12 @@ We could also use the `vec!` macro to make a vector of two integers or a vector of five string slices. We wouldn’t be able to use a function to do the same because we wouldn’t know the number or type of values up front. -Listing 20-28 shows a slightly simplified definition of the `vec!` macro. +Listing 20-29 shows a slightly simplified definition of the `vec!` macro. -+ ```rust,noplayground -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-28/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-29/src/lib.rs}} ``` @@ -106,7 +106,7 @@ one arm. Valid pattern syntax in macro definitions is different than the pattern syntax covered in Chapter 19 because macro patterns are matched against Rust code structure rather than values. Let’s walk through what the pattern pieces in -Listing 20-28 mean; for the full macro pattern syntax, see the [Rust +Listing 20-29 mean; for the full macro pattern syntax, see the [Rust Reference][ref]. First, we use a set of parentheses to encompass the whole pattern. We use a @@ -159,11 +159,11 @@ attribute-like, and function-like, and all work in a similar fashion. When creating procedural macros, the definitions must reside in their own crate with a special crate type. This is for complex technical reasons that we hope -to eliminate in the future. In Listing 20-29, we show how to define a +to eliminate in the future. In Listing 20-30, we show how to define a procedural macro, where `some_attribute` is a placeholder for using a specific macro variety. -+ ```rust,ignore use proc_macro; @@ -198,12 +198,12 @@ we’ll provide a procedural macro so users can annotate their type with function. The default implementation will print `Hello, Macro! My name is TypeName!` where `TypeName` is the name of the type on which this trait has been defined. In other words, we’ll write a crate that enables another -programmer to write code like Listing 20-30 using our crate. +programmer to write code like Listing 20-31 using our crate. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-30/src/main.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-31/src/main.rs}} ``` @@ -271,19 +271,19 @@ in a moment, so we need to add them as dependencies. Add the following to the ```toml -{{#include ../listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/Cargo.toml:6:12}} +{{#include ../listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/Cargo.toml:6:12}} ``` -To start defining the procedural macro, place the code in Listing 20-31 into +To start defining the procedural macro, place the code in Listing 20-32 into your *src/lib.rs* file for the `hello_macro_derive` crate. Note that this code won’t compile until we add a definition for the `impl_hello_macro` function. -+ ```rust,ignore,does_not_compile -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-31/hello_macro/hello_macro_derive/src/lib.rs}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/src/lib.rs}} ``` @@ -318,10 +318,10 @@ The `hello_macro_derive` function first converts the `input` from a `TokenStream` to a data structure that we can then interpret and perform operations on. This is where `syn` comes into play. The `parse` function in `syn` takes a `TokenStream` and returns a `DeriveInput` struct representing the -parsed Rust code. Listing 20-32 shows the relevant parts of the `DeriveInput` +parsed Rust code. Listing 20-33 shows the relevant parts of the `DeriveInput` struct we get from parsing the `struct Pancakes;` string: -+ ```rust,ignore DeriveInput { @@ -367,23 +367,23 @@ about what went wrong by using `panic!` or `expect`. Now that we have the code to turn the annotated Rust code from a `TokenStream` into a `DeriveInput` instance, let’s generate the code that implements the -`HelloMacro` trait on the annotated type, as shown in Listing 20-33. +`HelloMacro` trait on the annotated type, as shown in Listing 20-34. -+ ```rust,ignore -{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-33/hello_macro/hello_macro_derive/src/lib.rs:here}} +{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-34/hello_macro/hello_macro_derive/src/lib.rs:here}} ``` We get an `Ident` struct instance containing the name (identifier) of the -annotated type using `ast.ident`. The struct in Listing 20-32 shows that when -we run the `impl_hello_macro` function on the code in Listing 20-30, the +annotated type using `ast.ident`. The struct in Listing 20-33 shows that when +we run the `impl_hello_macro` function on the code in Listing 20-31, the `ident` we get will have the `ident` field with a value of `"Pancakes"`. Thus, -the `name` variable in Listing 20-33 will contain an `Ident` struct instance +the `name` variable in Listing 20-34 will contain an `Ident` struct instance that, when printed, will be the string `"Pancakes"`, the name of the struct in -Listing 20-30. +Listing 20-31. The `quote!` macro lets us define the Rust code that we want to return. The compiler expects something different to the direct result of the `quote!` @@ -412,7 +412,7 @@ saves an allocation by converting `#name` to a string literal at compile time. At this point, `cargo build` should complete successfully in both `hello_macro` and `hello_macro_derive`. Let’s hook up these crates to the code in Listing -20-30 to see the procedural macro in action! Create a new binary project in +20-31 to see the procedural macro in action! Create a new binary project in your *projects* directory using `cargo new pancakes`. We need to add `hello_macro` and `hello_macro_derive` as dependencies in the `pancakes` crate’s *Cargo.toml*. If you’re publishing your versions of `hello_macro` and @@ -423,7 +423,7 @@ dependencies; if not, you can specify them as `path` dependencies as follows: {{#include ../listings/ch20-advanced-features/no-listing-21-pancakes/pancakes/Cargo.toml:7:9}} ``` -Put the code in Listing 20-30 into *src/main.rs*, and run `cargo run`: it +Put the code in Listing 20-31 into *src/main.rs*, and run `cargo run`: it should print `Hello, Macro! My name is Pancakes!` The implementation of the `HelloMacro` trait from the procedural macro was included without the `pancakes` crate needing to implement it; the `#[derive(HelloMacro)]` added the From c4afacc2f983ecdc0441cc974247eb4a9371c84b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 26 Nov 2024 14:25:23 -0700 Subject: [PATCH 681/720] Add a short paragraph on editors and IDEs in installation Fixes #4107 --- src/ch01-01-installation.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index 64968f6bc7..f554c94b7b 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -134,7 +134,16 @@ Any time a type or function is provided by the standard library and you’re not sure what it does or how to use it, use the application programming interface (API) documentation to find out! +### Text Editors and Integrated Development Environments + +This book makes no assumptions about what tools you use to author Rust code. +Just about any text editor will get the job done! However, many text editors and +integrated development environments (IDEs) have built-in support for Rust. You +can always find a fairly current list of many editors and IDEs on [the tools +page][tools] on the Rust website. + [otherinstall]: https://forge.rust-lang.org/infra/other-installation-methods.html [install]: https://www.rust-lang.org/tools/install [msvc]: https://rust-lang.github.io/rustup/installation/windows-msvc.html [community]: https://www.rust-lang.org/community +[tools]: https://www.rust-lang.org/tools From 398eb06581e2fc855182607574261f071c9e04b7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 26 Nov 2024 15:55:15 -0700 Subject: [PATCH 682/720] Very small clarification on if let Fixes #3999 --- src/ch06-03-if-let.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch06-03-if-let.md b/src/ch06-03-if-let.md index fee6b2caf3..829d011695 100644 --- a/src/ch06-03-if-let.md +++ b/src/ch06-03-if-let.md @@ -32,8 +32,8 @@ sign. It works the same way as a `match`, where the expression is given to the `match` and the pattern is its first arm. In this case, the pattern is `Some(max)`, and the `max` binds to the value inside the `Some`. We can then use `max` in the body of the `if let` block in the same way we used `max` in -the corresponding `match` arm. The code in the `if let` block isn’t run if the -value doesn’t match the pattern. +the corresponding `match` arm. The code in the `if let` block only runs if the +value matches the pattern. Using `if let` means less typing, less indentation, and less boilerplate code. However, you lose the exhaustive checking that `match` enforces. Choosing From d119e947dfd5d479aa9a692cdbec6c1ee62bb99a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 26 Nov 2024 17:00:17 -0700 Subject: [PATCH 683/720] Drop a pedantry-triggering sentence about IEEE-754 The pedantry is accurate, but since we can just drop this entirely, it will cut the potential distraction for readers who might get hung up on it otherwise! Fixes #3818 --- src/ch03-02-data-types.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ch03-02-data-types.md b/src/ch03-02-data-types.md index 84af90e3f6..881319dbcc 100644 --- a/src/ch03-02-data-types.md +++ b/src/ch03-02-data-types.md @@ -141,8 +141,7 @@ Here’s an example that shows floating-point numbers in action: {{#rustdoc_include ../listings/ch03-common-programming-concepts/no-listing-06-floating-point/src/main.rs}} ``` -Floating-point numbers are represented according to the IEEE-754 standard. The -`f32` type is a single-precision float, and `f64` has double precision. +Floating-point numbers are represented according to the IEEE-754 standard. #### Numeric Operations From 3afd582a96f7ecc4e9c21ba0ed3dad3fda1c6421 Mon Sep 17 00:00:00 2001 From: Peteris Ledins Date: Wed, 19 Jul 2023 22:56:39 +0300 Subject: [PATCH 684/720] Refer to `--exact` for running exact one test --- src/ch11-02-running-tests.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ch11-02-running-tests.md b/src/ch11-02-running-tests.md index 406b06e681..b02bfe10c3 100644 --- a/src/ch11-02-running-tests.md +++ b/src/ch11-02-running-tests.md @@ -128,6 +128,10 @@ Only the test with the name `one_hundred` ran; the other two tests didn’t matc that name. The test output lets us know we had more tests that didn’t run by displaying `2 filtered out` at the end. +If a test name is a substring of another test, we can use `-- --exact` argument, +referring to test function with full path, for example +`cargo test tests::one_hundred -- --exact`. + We can’t specify the names of multiple tests in this way; only the first value given to `cargo test` will be used. But there is a way to run multiple tests. From 871ace83d1b8a029a5fe932b9078a88e8fc6fb55 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 27 Nov 2024 07:47:06 -0700 Subject: [PATCH 685/720] Link to the rustc book for docs about `cargo test -- ` --- src/ch11-02-running-tests.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ch11-02-running-tests.md b/src/ch11-02-running-tests.md index b02bfe10c3..1c9a1a35da 100644 --- a/src/ch11-02-running-tests.md +++ b/src/ch11-02-running-tests.md @@ -13,7 +13,12 @@ binary. To separate these two types of arguments, you list the arguments that go to `cargo test` followed by the separator `--` and then the ones that go to the test binary. Running `cargo test --help` displays the options you can use with `cargo test`, and running `cargo test -- --help` displays the options you -can use after the separator. +can use after the separator. Those options are also documented in [the “Tests” +section][tests] of the [the rustc book][rustc]. + +[tests]: https://doc.rust-lang.org/rustc/tests/index.html +[rustc]: https://doc.rust-lang.org/rustc/index.html + ### Running Tests in Parallel or Consecutively @@ -128,10 +133,6 @@ Only the test with the name `one_hundred` ran; the other two tests didn’t matc that name. The test output lets us know we had more tests that didn’t run by displaying `2 filtered out` at the end. -If a test name is a substring of another test, we can use `-- --exact` argument, -referring to test function with full path, for example -`cargo test tests::one_hundred -- --exact`. - We can’t specify the names of multiple tests in this way; only the first value given to `cargo test` will be used. But there is a way to run multiple tests. From 52b9e2a0407bbc11842b0f950c1965eeaf675c2e Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 27 Nov 2024 09:11:30 -0700 Subject: [PATCH 686/720] Match NoStarch style guide for updated Listing 4-3 comment --- listings/ch04-understanding-ownership/listing-04-03/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch04-understanding-ownership/listing-04-03/src/main.rs b/listings/ch04-understanding-ownership/listing-04-03/src/main.rs index 28f5ca62cb..0ab0171aff 100644 --- a/listings/ch04-understanding-ownership/listing-04-03/src/main.rs +++ b/listings/ch04-understanding-ownership/listing-04-03/src/main.rs @@ -6,7 +6,7 @@ fn main() { let x = 5; // x comes into scope - makes_copy(x); // since i32 implements the Copy trait, + makes_copy(x); // because i32 implements the Copy trait, // x does NOT move into the function, println!("{}", x); // so it's okay to use x afterward From 294b80dda8d625eb467f81c4d16175de947714f4 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 27 Nov 2024 10:52:49 -0700 Subject: [PATCH 687/720] Ch. 17: fix some wording issues --- src/ch17-04-streams.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 1f20e873b3..d08e40689a 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -7,13 +7,12 @@ The async `recv` method produces a sequence of items over time. This is an instance of a much more general pattern, often called a *stream*. A sequence of items is something we’ve seen before, when we looked at the -`Iterator` trait in Chapter 13, but there are two differences between iterators -and the async channel receiver. The first difference is the element of time: -iterators are synchronous, while the channel receiver is asynchronous. The -second difference is the API. When working directly with an `Iterator`, we call -its synchronous `next` method. With the `trpl::Receiver` stream in particular, -we called an asynchronous `recv` method instead, but these APIs otherwise feel -very similar. +`Iterator` trait in Chapter 13. There are two differences between iterators and +the async channel receiver, though. The first is the element of time: iterators +are synchronous, while the channel receiver is asynchronous. The second is the +API. When working directly with an `Iterator`, we call its synchronous `next` +method. With the `trpl::Receiver` stream in particular, we called an +asynchronous `recv` method instead. These APIs otherwise feel very similar. That similarity isn’t a coincidence. A stream is similar to an asynchronous form of iteration. Whereas the `trpl::Receiver` specifically waits to receive From daf8d828cc0ff7a4103b6f626591cd8845f0082a Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 27 Nov 2024 14:18:53 -0700 Subject: [PATCH 688/720] Fix confusion between variable `hello` and string `"hello"` Fixes #3803 --- src/ch08-02-strings.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index 9494fd94cb..5635263b69 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -278,8 +278,8 @@ seem that `answer` should in fact be `208`, but `208` is not a valid character on its own. Returning `208` is likely not what a user would want if they asked for the first letter of this string; however, that’s the only data that Rust has at byte index 0. Users generally don’t want the byte value returned, even -if the string contains only Latin letters: if `&"hello"[0]` were valid code -that returned the byte value, it would return `104`, not `h`. +if the string contains only Latin letters: if `&"hi"[0]` were valid code that +returned the byte value, it would return `104`, not `h`. The answer, then, is that to avoid returning an unexpected value and causing bugs that might not be discovered immediately, Rust doesn’t compile this code From e945e17d910fe59c852eedb14329a6d90cf230ee Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 2 Dec 2024 08:50:50 -0700 Subject: [PATCH 689/720] =?UTF-8?q?Fix=20a=20couple=20inverted=20uses=20of?= =?UTF-8?q?=20=E2=80=9Cshadowed=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3773. --- ...ch12-05-working-with-environment-variables.md | 16 ++++++++-------- src/ch19-01-all-the-places-for-patterns.md | 14 +++++++------- src/ch19-03-pattern-syntax.md | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ch12-05-working-with-environment-variables.md b/src/ch12-05-working-with-environment-variables.md index c56a285caa..630f98cb2f 100644 --- a/src/ch12-05-working-with-environment-variables.md +++ b/src/ch12-05-working-with-environment-variables.md @@ -55,14 +55,14 @@ they’ll be the same case when we check whether the line contains the query. -First we lowercase the `query` string and store it in a shadowed variable with -the same name. Calling `to_lowercase` on the query is necessary so that no -matter whether the user’s query is `"rust"`, `"RUST"`, `"Rust"`, or `"rUsT"`, -we’ll treat the query as if it were `"rust"` and be insensitive to the case. -While `to_lowercase` will handle basic Unicode, it won’t be 100% accurate. If -we were writing a real application, we’d want to do a bit more work here, but -this section is about environment variables, not Unicode, so we’ll leave it at -that here. +First we lowercase the `query` string and store it in a new variable with the +same name, shadowing the original. Calling `to_lowercase` on the query is +necessary so that no matter whether the user’s query is `"rust"`, `"RUST"`, +`"Rust"`, or `"rUsT"`, we’ll treat the query as if it were `"rust"` and be +insensitive to the case. While `to_lowercase` will handle basic Unicode, it +won’t be 100% accurate. If we were writing a real application, we’d want to do a +bit more work here, but this section is about environment variables, not +Unicode, so we’ll leave it at that here. Note that `query` is now a `String` rather than a string slice because calling `to_lowercase` creates new data rather than referencing existing data. Say the diff --git a/src/ch19-01-all-the-places-for-patterns.md b/src/ch19-01-all-the-places-for-patterns.md index 03d132954d..5200a01b52 100644 --- a/src/ch19-01-all-the-places-for-patterns.md +++ b/src/ch19-01-all-the-places-for-patterns.md @@ -82,13 +82,13 @@ This conditional structure lets us support complex requirements. With the hardcoded values we have here, this example will print `Using purple as the background color`. -You can see that `if let` can also introduce shadowed variables in the same way -that `match` arms can: the line `if let Ok(age) = age` introduces a new -shadowed `age` variable that contains the value inside the `Ok` variant. This -means we need to place the `if age > 30` condition within that block: we can’t -combine these two conditions into `if let Ok(age) = age && age > 30`. The -shadowed `age` we want to compare to 30 isn’t valid until the new scope starts -with the curly bracket. +You can see that `if let` can also introduce new variables which shadow existing +variables in the same way that `match` arms can: the line `if let Ok(age) = age` +introduces a new shadowed `age` variable that contains the value inside the `Ok` +variant. This means we need to place the `if age > 30` condition within that +block: we can’t combine these two conditions into `if let Ok(age) = age && age > +30`. The shadowed `age` we want to compare to 30 isn’t valid until the new scope +starts with the curly bracket. The downside of using `if let` expressions is that the compiler doesn’t check for exhaustiveness, whereas with `match` expressions it does. If we omitted the diff --git a/src/ch19-03-pattern-syntax.md b/src/ch19-03-pattern-syntax.md index 4a471bd670..4503cf77eb 100644 --- a/src/ch19-03-pattern-syntax.md +++ b/src/ch19-03-pattern-syntax.md @@ -29,7 +29,7 @@ value `Some(5)` and a variable `y` with the value `10`. We then create a `println!` at the end, and try to figure out what the code will print before running this code or reading further. -+ ```rust {{#rustdoc_include ../listings/ch19-patterns-and-matching/listing-19-11/src/main.rs:here}} @@ -60,10 +60,10 @@ When the `match` expression is done, its scope ends, and so does the scope of the inner `y`. The last `println!` produces `at the end: x = Some(5), y = 10`. To create a `match` expression that compares the values of the outer `x` and -`y`, rather than introducing a shadowed variable, we would need to use a match -guard conditional instead. We’ll talk about match guards later in the [“Extra -Conditionals with Match Guards”](#extra-conditionals-with-match-guards) section. +`y`, rather than introducing a new variable which shadows the existing `y` +variable, we would need to use a match guard conditional instead. We’ll talk +about match guards later in the [“Extra Conditionals with Match +Guards”](#extra-conditionals-with-match-guards) section. ### Multiple Patterns @@ -503,8 +503,8 @@ pattern as `Some(y)`, which would have shadowed the outer `y`, we specify `Some(n)`. This creates a new variable `n` that doesn’t shadow anything because there is no `n` variable outside the `match`. -The match guard `if n == y` is not a pattern and therefore doesn’t introduce -new variables. This `y` *is* the outer `y` rather than a new shadowed `y`, and +The match guard `if n == y` is not a pattern and therefore doesn’t introduce new +variables. This `y` *is* the outer `y` rather than a new `y` shadowing it, and we can look for a value that has the same value as the outer `y` by comparing `n` to `y`. From b2e71e88187088448ad8c4862bbdc3da63c41fe0 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 2 Dec 2024 09:08:21 -0700 Subject: [PATCH 690/720] =?UTF-8?q?Fix=20more=20inverted=20uses=20of=20?= =?UTF-8?q?=E2=80=9Cshadowed=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-on for #3773 and #4121: I missed how the rest of this paragraph also had “shadowed” inverted! --- src/ch19-01-all-the-places-for-patterns.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ch19-01-all-the-places-for-patterns.md b/src/ch19-01-all-the-places-for-patterns.md index 5200a01b52..11f5919a49 100644 --- a/src/ch19-01-all-the-places-for-patterns.md +++ b/src/ch19-01-all-the-places-for-patterns.md @@ -84,11 +84,11 @@ background color`. You can see that `if let` can also introduce new variables which shadow existing variables in the same way that `match` arms can: the line `if let Ok(age) = age` -introduces a new shadowed `age` variable that contains the value inside the `Ok` -variant. This means we need to place the `if age > 30` condition within that -block: we can’t combine these two conditions into `if let Ok(age) = age && age > -30`. The shadowed `age` we want to compare to 30 isn’t valid until the new scope -starts with the curly bracket. +introduces a new `age` variable that contains the value inside the `Ok` variant, +shadowing the existing `age` variable. This means we need to place the `if age > +30` condition within that block: we can’t combine these two conditions into `if +let Ok(age) = age && age > 30`. The new `age` we want to compare to 30 isn’t +valid until the new scope starts with the curly bracket. The downside of using `if let` expressions is that the compiler doesn’t check for exhaustiveness, whereas with `match` expressions it does. If we omitted the From f347bb5e0eae4460c3d6b7e1579135a81e269ff2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 2 Dec 2024 10:10:31 -0700 Subject: [PATCH 691/720] Ch. 2: tweak a phrase to avoid derailing some readers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Multiple people have filed or commented on issues over the past few years (at least #3782, #4101, #4090, and #3921; and possibly others I have not found) because seeing “compare” here led them to jump ahead to the conversion (in the next paragraph). The text was technically correct as it stood, but since it kept derailing/hijacking people’s train of thought, tweaking it seems helpful. --- src/ch02-00-guessing-game-tutorial.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index 848ce75fbe..b66a5c2819 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -684,8 +684,8 @@ often used when you want to convert a value from one type to another type. We bind this new variable to the expression `guess.trim().parse()`. The `guess` 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 +whitespace at the beginning and end, which we must do before we can convert the +string to a `u32`, which can only contain numerical data. The user must press enter to satisfy `read_line` and input their guess, which adds a newline character to the string. For example, if the user types 5 and presses enter, `guess` looks like this: `5\n`. The `\n` represents From 0dfa24c1fe237ec84ced7a9ac8a78e6c95922b0b Mon Sep 17 00:00:00 2001 From: Daniel Mouritzen Date: Mon, 2 Dec 2024 23:10:11 +0100 Subject: [PATCH 692/720] Correct chapter numbers in introduction --- src/ch00-00-introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 050a627818..54ee6bec25 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -103,7 +103,7 @@ the topic in a later chapter. You’ll find two kinds of chapters in this book: concept chapters and project chapters. In concept chapters, you’ll learn about an aspect of Rust. In project chapters, we’ll build small programs together, applying what you’ve learned so -far. Chapters 2, 12, and 20 are project chapters; the rest are concept chapters. +far. Chapters 2, 12, and 21 are project chapters; the rest are concept chapters. Chapter 1 explains how to install Rust, how to write a “Hello, world!” program, and how to use Cargo, Rust’s package manager and build tool. Chapter 2 is a From b1be1fe87d73930319a99415efad12218878041b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 2 Dec 2024 15:25:15 -0700 Subject: [PATCH 693/720] Ch. 18: unwrap a link split across two lines This appears to still work with pulldown-cmark, but not necessarily in all renderers, and (more to the point at present) is not compatible with dprint, which does not like the line wrapping that way! --- src/ch18-02-trait-objects.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ch18-02-trait-objects.md b/src/ch18-02-trait-objects.md index 6f05a4e0df..a167015eff 100644 --- a/src/ch18-02-trait-objects.md +++ b/src/ch18-02-trait-objects.md @@ -243,6 +243,5 @@ method’s code, which in turn prevents some optimizations. However, we did get extra flexibility in the code that we wrote in Listing 18-5 and were able to support in Listing 18-9, so it’s a trade-off to consider. -[performance-of-code-using-generics]: -ch10-01-syntax.html#performance-of-code-using-generics +[performance-of-code-using-generics]: ch10-01-syntax.html#performance-of-code-using-generics [dynamically-sized]: ch20-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait From 105d3fb51469f574b6092cba448f42d91d3df4d6 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 2 Dec 2024 15:25:15 -0700 Subject: [PATCH 694/720] infra: introduce dprint for easier formatting No more need to manually wrap lines? GREAT. --- dprint.jsonc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 dprint.jsonc diff --git a/dprint.jsonc b/dprint.jsonc new file mode 100644 index 0000000000..3d48ade517 --- /dev/null +++ b/dprint.jsonc @@ -0,0 +1,33 @@ +{ + "typescript": { + }, + "json": { + }, + "markdown": { + }, + "malva": { + }, + "excludes": [ + "**/node_modules", + "**/*-lock.json", + "**/target", + // We don’t to apply auto-formatting to this *yet*, at a minimum. It may be + // helpful as a way of replacing some of the manual formatting we do in both + // the nostarch script and the script for pulling data back over from docx, + // though, so we may *start* doing so in the future. + "nostarch", + // These should never change at this point + "2018-edition", + "first-edition", + "second-edition", + "redirects", + // has empty list items which look like headings to a formatter + ".github/ISSUE_TEMPLATE/bug_report.md" + ], + "plugins": [ + "https://plugins.dprint.dev/typescript-0.93.3.wasm", + "https://plugins.dprint.dev/json-0.19.4.wasm", + "https://plugins.dprint.dev/markdown-0.17.8.wasm", + "https://plugins.dprint.dev/g-plane/malva-v0.11.0.wasm" + ] +} From 3a30e4c1fbe641afc066b3af9eb01dcdf5ed8b24 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 2 Dec 2024 15:27:35 -0700 Subject: [PATCH 695/720] Apply dprint fmt to active files in the repo --- ADMIN_TASKS.md | 47 ++-- CONTRIBUTING.md | 3 +- README.md | 7 +- ferris.js | 68 ++--- packages/mdbook-trpl-note/README.md | 4 +- packages/trpl/CHANGELOG.md | 2 +- packages/trpl/README.md | 2 +- src/SUMMARY.md | 172 ++++++------ src/appendix-01-keywords.md | 106 +++---- src/appendix-02-operators.md | 260 +++++++++--------- src/appendix-03-derivable-traits.md | 21 +- src/appendix-04-useful-development-tools.md | 2 +- src/appendix-05-editions.md | 15 +- src/appendix-07-nightly-rust.md | 25 +- src/ch00-00-introduction.md | 14 +- src/ch01-00-getting-started.md | 6 +- src/ch01-01-installation.md | 4 +- src/ch01-02-hello-world.md | 34 +-- src/ch01-03-hello-cargo.md | 72 ++--- src/ch02-00-guessing-game-tutorial.md | 81 +++--- src/ch03-00-common-programming-concepts.md | 2 +- src/ch03-01-variables-and-mutability.md | 24 +- src/ch03-02-data-types.md | 55 ++-- src/ch03-03-how-functions-work.md | 26 +- src/ch03-04-comments.md | 2 +- src/ch03-05-control-flow.md | 30 +- src/ch04-01-what-is-ownership.md | 70 ++--- src/ch04-02-references-and-borrowing.md | 32 +-- src/ch04-03-slices.md | 11 +- src/ch05-00-structs.md | 6 +- src/ch05-01-defining-structs.md | 19 +- src/ch05-02-example-structs.md | 12 +- src/ch05-03-method-syntax.md | 11 +- src/ch06-00-enums.md | 4 +- src/ch06-01-defining-an-enum.md | 18 +- src/ch06-02-match.md | 7 +- src/ch06-03-if-let.md | 1 - ...ojects-with-packages-crates-and-modules.md | 12 +- src/ch07-01-packages-and-crates.md | 32 +-- ...ng-modules-to-control-scope-and-privacy.md | 44 +-- ...referring-to-an-item-in-the-module-tree.md | 12 +- ...g-paths-into-scope-with-the-use-keyword.md | 17 +- ...separating-modules-into-different-files.md | 38 +-- src/ch08-00-common-collections.md | 10 +- src/ch08-01-vectors.md | 2 +- src/ch08-02-strings.md | 18 +- src/ch08-03-hash-maps.md | 28 +- src/ch09-00-error-handling.md | 4 +- ...ch09-01-unrecoverable-errors-with-panic.md | 22 +- src/ch09-02-recoverable-errors-with-result.md | 8 +- src/ch09-03-to-panic-or-not-to-panic.md | 20 +- src/ch10-00-generics.md | 6 +- src/ch10-01-syntax.md | 8 +- src/ch10-02-traits.md | 15 +- src/ch10-03-lifetime-syntax.md | 26 +- src/ch11-00-testing.md | 2 +- src/ch11-01-writing-tests.md | 29 +- src/ch11-02-running-tests.md | 3 +- src/ch11-03-test-organization.md | 71 +++-- src/ch12-00-an-io-project.md | 10 +- src/ch12-02-reading-a-file.md | 6 +- ...improving-error-handling-and-modularity.md | 68 ++--- ...2-04-testing-the-librarys-functionality.md | 19 +- ...2-05-working-with-environment-variables.md | 20 +- ...-06-writing-to-stderr-instead-of-stdout.md | 15 +- src/ch13-00-functional-features.md | 10 +- src/ch13-01-closures.md | 7 +- src/ch13-02-iterators.md | 10 +- src/ch13-03-improving-our-io-project.md | 4 +- src/ch13-04-performance.md | 12 +- src/ch14-00-more-about-cargo.md | 13 +- src/ch14-01-release-profiles.md | 8 +- src/ch14-02-publishing-to-crates-io.md | 47 ++-- src/ch14-03-cargo-workspaces.md | 66 ++--- src/ch14-04-installing-binaries.md | 12 +- src/ch15-00-smart-pointers.md | 18 +- src/ch15-01-box.md | 18 +- src/ch15-02-deref.md | 17 +- src/ch15-03-drop.md | 10 +- src/ch15-04-rc.md | 2 +- src/ch15-05-interior-mutability.md | 22 +- src/ch15-06-reference-cycles.md | 6 +- src/ch16-00-concurrency.md | 26 +- src/ch16-01-threads.md | 19 +- src/ch16-02-message-passing.md | 27 +- src/ch16-03-shared-state.md | 24 +- ...04-extensible-concurrency-sync-and-send.md | 5 +- src/ch17-00-async-await.md | 24 +- src/ch17-01-futures-and-syntax.md | 48 ++-- src/ch17-02-concurrency-with-async.md | 54 ++-- src/ch17-03-more-futures.md | 68 +++-- src/ch17-04-streams.md | 16 +- src/ch17-05-traits-for-async.md | 36 +-- src/ch17-06-futures-tasks-threads.md | 21 +- src/ch18-00-oop.md | 2 +- src/ch18-01-what-is-oo.md | 18 +- src/ch18-02-trait-objects.md | 14 +- src/ch18-03-oo-design-patterns.md | 11 +- src/ch19-00-patterns.md | 12 +- src/ch19-01-all-the-places-for-patterns.md | 5 +- src/ch19-02-refutability.md | 4 +- src/ch19-03-pattern-syntax.md | 16 +- src/ch20-00-advanced-features.md | 10 +- src/ch20-01-unsafe-rust.md | 67 +++-- src/ch20-03-advanced-traits.md | 36 ++- src/ch20-04-advanced-types.md | 29 +- ...ch20-05-advanced-functions-and-closures.md | 8 +- src/ch20-06-macros.md | 36 +-- src/ch21-01-single-threaded.md | 80 +++--- src/ch21-02-multithreaded.md | 59 ++-- src/ch21-03-graceful-shutdown-and-cleanup.md | 10 +- src/foreword.md | 2 +- src/title-page.md | 4 +- style-guide.md | 26 +- theme/2018-edition.css | 8 +- theme/listing.css | 6 +- theme/semantic-notes.css | 12 +- 117 files changed, 1473 insertions(+), 1492 deletions(-) diff --git a/ADMIN_TASKS.md b/ADMIN_TASKS.md index c493a335ce..b91b2ef96c 100644 --- a/ADMIN_TASKS.md +++ b/ADMIN_TASKS.md @@ -14,7 +14,7 @@ occasional maintenance tasks. does) - Inspect the changes (by looking at the files changed according to git) and their effects (by looking at the files in `tmp/book-before` and - `tmp/book-after`) and commit them if they look good + `tmp/book-after`) and commit them if they look good - Grep for `manual-regeneration` and follow the instructions in those places to update output that cannot be generated by a script @@ -36,9 +36,8 @@ create a new release artifact, for example if there have been code changes due to edits or due to updating Rust and `rustfmt`, do the following: - Create a git tag for the release and push it to GitHub, or create a new tag - by going to the GitHub UI, [drafting a new - release](https://github.com/rust-lang/book/releases/new), and entering a new - tag instead of selecting an existing tag + by going to the GitHub UI, [drafting a new release](https://github.com/rust-lang/book/releases/new), and entering a new + tag instead of selecting an existing tag - Run `cargo run --bin release_listings`, which will generate `tmp/listings.tar.gz` - Upload `tmp/listings.tar.gz` in the GitHub UI for the draft release @@ -54,50 +53,50 @@ extracted into a file. To do that: - Find where the new listing should go in the `listings` directory. - There is one subdirectory for each chapter - Numbered listings should use `listing-[chapter num]-[listing num]` for - their directory names. + their directory names. - Listings without a number should start with `no-listing-` followed by a - number that indicates its position in the chapter relative to the other - listings without numbers in the chapter, then a short description that - someone could read to find the code they're looking for. + number that indicates its position in the chapter relative to the other + listings without numbers in the chapter, then a short description that + someone could read to find the code they're looking for. - Listings used only for displaying the output of the code (for example, when - we say "if we had written x instead of y, we would get this compiler - error:" but we don't actually show code x) should be named with - `output-only-` followed by a number that indicates its position in the - chapter relative to the other listings used only for output, then a short - description that authors or contributors could read to find the code - they're looking for. + we say "if we had written x instead of y, we would get this compiler + error:" but we don't actually show code x) should be named with + `output-only-` followed by a number that indicates its position in the + chapter relative to the other listings used only for output, then a short + description that authors or contributors could read to find the code + they're looking for. - **Remember to adjust surrounding listing numbers as appropriate!** - Create a full Cargo project in that directory, either by using `cargo new` or copying another listing as a starting point. - Add the code and any surrounding code needed to create a full working example. - If you only want to show part of the code in the file, use anchor comments (`// ANCHOR: some_tag` and `// ANCHOR_END: some_tag`) to mark the parts of - the file you want to show. + the file you want to show. - For Rust code, use the `{{#rustdoc_include [filename:some_tag]}}` directive within the code blocks in the text. The `rustdoc_include` directive gives the - code that doesn't get displayed to `rustdoc` for `mdbook test` purposes. + code that doesn't get displayed to `rustdoc` for `mdbook test` purposes. - For anything else, use the `{{#include [filename:some_tag]}}` directive. - If you want to display the output of a command in the text as well, create an `output.txt` file in the listing's directory as follows: - Run the command, like `cargo run` or `cargo test`, and copy all of the - output. + output. - Create a new `output.txt` file with the first line `$ [the command you ran]`. - Paste the output you just copied. - Run `./tools/update-rustc.sh`, which should perform some normalization on - the compiler output. + the compiler output. - Include the output in the text with the `{{#include [filename]}}` directive. - Add and commit output.txt. - If you want to display output but for some reason it can't be generated by a script (say, because of user input or external events like making a web - request), keep the output inline but make a comment that contains - `manual-regeneration` and instructions for manually updating the inline - output. + request), keep the output inline but make a comment that contains + `manual-regeneration` and instructions for manually updating the inline + output. - If you don't want this example to even be attempted to be formatted by `rustfmt` (for example because the example doesn't parse on purpose), add a - `rustfmt-ignore` file in the listing's directory and the reason it's not - being formatted as the contents of that file (in case it's a rustfmt bug that - might get fixed someday). + `rustfmt-ignore` file in the listing's directory and the reason it's not + being formatted as the contents of that file (in case it's a rustfmt bug that + might get fixed someday). ## See the effect of some change on the rendered book diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a20cb58501..bba1a19a22 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,8 +45,7 @@ or pull request. [nostarch]: https://nostarch.com/rust-programming-language-2nd-edition -So far, we've been doing a larger revision to coincide with [Rust -Editions](https://doc.rust-lang.org/edition-guide/). Between those larger +So far, we've been doing a larger revision to coincide with [Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger revisions, we will only be correcting errors. If your issue or pull request isn't strictly fixing an error, it might sit until the next time that we're working on a large revision: expect on the order of months or years. Thank you diff --git a/README.md b/README.md index b4426bd492..9935bd46f7 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ $ 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, +look right, but you _will_ still be able to build the book. To use the plugins, you should run: ```bash @@ -55,6 +55,7 @@ The output will be in the `book` subdirectory. To check it out, open it in your web browser. _Firefox:_ + ```bash $ firefox book/index.html # Linux $ open -a "Firefox" book/index.html # OS X @@ -63,6 +64,7 @@ $ start firefox.exe .\book\index.html # Windows (Cmd) ``` _Chrome:_ + ```bash $ google-chrome book/index.html # Linux $ open -a "Google Chrome" book/index.html # OS X @@ -89,8 +91,7 @@ to keep the online version of the book close to the print version when possible, it may take longer than you're used to for us to address your issue or pull request. -So far, we've been doing a larger revision to coincide with [Rust -Editions](https://doc.rust-lang.org/edition-guide/). Between those larger +So far, we've been doing a larger revision to coincide with [Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger revisions, we will only be correcting errors. If your issue or pull request isn't strictly fixing an error, it might sit until the next time that we're working on a large revision: expect on the order of months or years. Thank you diff --git a/ferris.js b/ferris.js index 51e5b12a99..08f3292816 100644 --- a/ferris.js +++ b/ferris.js @@ -7,50 +7,50 @@ /** @type {Array} */ const FERRIS_TYPES = [ { - attr: 'does_not_compile', - title: 'This code does not compile!' + attr: "does_not_compile", + title: "This code does not compile!", }, { - attr: 'panics', - title: 'This code panics!' + attr: "panics", + title: "This code panics!", }, { - attr: 'not_desired_behavior', - title: 'This code does not produce the desired behavior.' - } -] + attr: "not_desired_behavior", + title: "This code does not produce the desired behavior.", + }, +]; -document.addEventListener('DOMContentLoaded', () => { +document.addEventListener("DOMContentLoaded", () => { for (let ferrisType of FERRIS_TYPES) { - attachFerrises(ferrisType) + attachFerrises(ferrisType); } -}) +}); /** * @param {FerrisType} type */ function attachFerrises(type) { - let elements = document.getElementsByClassName(type.attr) + let elements = document.getElementsByClassName(type.attr); for (let codeBlock of elements) { // Skip SVG etc.: in principle, these should never be attached to those, but // this means if someone happens to have a browser extension which *is* // attaching them, it will not break the code. if (!(codeBlock instanceof HTMLElement)) { - continue + continue; } - let lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length + let lines = codeBlock.innerText.replace(/\n$/, "").split(/\n/).length; /** @type {'small' | 'large'} */ - let size = lines < 4 ? 'small' : 'large' + let size = lines < 4 ? "small" : "large"; - let container = prepareFerrisContainer(codeBlock, size == 'small') + let container = prepareFerrisContainer(codeBlock, size == "small"); if (!container) { - continue + continue; } - container.appendChild(createFerris(type, size)) + container.appendChild(createFerris(type, size)); } } @@ -60,22 +60,22 @@ function attachFerrises(type) { * @returns {Element | null} - The container element to use. */ function prepareFerrisContainer(element, useButtons) { - let foundButtons = element.parentElement?.querySelector('.buttons') + let foundButtons = element.parentElement?.querySelector(".buttons"); if (useButtons && foundButtons) { - return foundButtons + return foundButtons; } - let div = document.createElement('div') - div.classList.add('ferris-container') + let div = document.createElement("div"); + div.classList.add("ferris-container"); if (!element.parentElement) { console.error(`Could not install Ferris on ${element}, which is missing a parent`); return null; } - element.parentElement.insertBefore(div, element) + element.parentElement.insertBefore(div, element); - return div + return div; } /** @@ -84,17 +84,17 @@ function prepareFerrisContainer(element, useButtons) { * @returns {HTMLAnchorElement} - The generated anchor element. */ function createFerris(type, size) { - let a = document.createElement('a') - a.setAttribute('href', 'ch00-00-introduction.html#ferris') - a.setAttribute('target', '_blank') + let a = document.createElement("a"); + a.setAttribute("href", "ch00-00-introduction.html#ferris"); + a.setAttribute("target", "_blank"); - let img = document.createElement('img') - img.setAttribute('src', 'img/ferris/' + type.attr + '.svg') - img.setAttribute('title', type.title) - img.classList.add('ferris') - img.classList.add('ferris-' + size) + let img = document.createElement("img"); + img.setAttribute("src", "img/ferris/" + type.attr + ".svg"); + img.setAttribute("title", type.title); + img.classList.add("ferris"); + img.classList.add("ferris-" + size); - a.appendChild(img) + a.appendChild(img); - return a + return a; } diff --git a/packages/mdbook-trpl-note/README.md b/packages/mdbook-trpl-note/README.md index 1ef5e64788..3e54ae7fd1 100644 --- a/packages/mdbook-trpl-note/README.md +++ b/packages/mdbook-trpl-note/README.md @@ -1,6 +1,6 @@ # mdbook-trpl-note -This is a *very* simple [preprocessor][pre] for [mdBook][mdbook], focused specifically on the content of _The Rust Programming Language_ book. This preprocessor takes Markdown like this— +This is a _very_ simple [preprocessor][pre] for [mdBook][mdbook], focused specifically on the content of _The Rust Programming Language_ book. This preprocessor takes Markdown like this— ```markdown > Note: This is some material we want to provide more emphasis for, because it @@ -37,7 +37,7 @@ Here is all the important things to know about that particular subject. This allows using the relatively standard Markdown convention of (incorrectly!) using blockquotes for “callouts” or “notes” like this, while still producing semantic HTML which conveys the actual intent. > [!NOTE] -> This is *not* a full “admonition” preprocessor, and it is not remotely compliant with [the GitHub “alert” syntax][alerts]. It exists almost entirely for the sake of providing better semantic HTML for _The Rust Programming Language_ book with a minimum of disruption to existing workflows! +> This is _not_ a full “admonition” preprocessor, and it is not remotely compliant with [the GitHub “alert” syntax][alerts]. It exists almost entirely for the sake of providing better semantic HTML for _The Rust Programming Language_ book with a minimum of disruption to existing workflows! > > You are probably better off using one of the other existing alert/admonition preprocessors: > diff --git a/packages/trpl/CHANGELOG.md b/packages/trpl/CHANGELOG.md index e579745ea9..5555b3ee64 100644 --- a/packages/trpl/CHANGELOG.md +++ b/packages/trpl/CHANGELOG.md @@ -2,4 +2,4 @@ ## 0.1.0 -Initial release! Adds support code for the first draft of the new async chapter of the book. \ No newline at end of file +Initial release! Adds support code for the first draft of the new async chapter of the book. diff --git a/packages/trpl/README.md b/packages/trpl/README.md index 7d22504888..3e97ac9b3b 100644 --- a/packages/trpl/README.md +++ b/packages/trpl/README.md @@ -5,7 +5,7 @@ This repository is the home of the `trpl` crate used in _The Rust Programming Language_ book materials. -This crate mostly just re-exports items from *other* crates. It exists for two +This crate mostly just re-exports items from _other_ crates. It exists for two main reasons: 1. So that as you read along in _The Rust Programming Language_, you can add diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 40f5c22424..a157cd05af 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -7,137 +7,137 @@ ## Getting started - [Getting Started](ch01-00-getting-started.md) - - [Installation](ch01-01-installation.md) - - [Hello, World!](ch01-02-hello-world.md) - - [Hello, Cargo!](ch01-03-hello-cargo.md) + - [Installation](ch01-01-installation.md) + - [Hello, World!](ch01-02-hello-world.md) + - [Hello, Cargo!](ch01-03-hello-cargo.md) - [Programming a Guessing Game](ch02-00-guessing-game-tutorial.md) - [Common Programming Concepts](ch03-00-common-programming-concepts.md) - - [Variables and Mutability](ch03-01-variables-and-mutability.md) - - [Data Types](ch03-02-data-types.md) - - [Functions](ch03-03-how-functions-work.md) - - [Comments](ch03-04-comments.md) - - [Control Flow](ch03-05-control-flow.md) + - [Variables and Mutability](ch03-01-variables-and-mutability.md) + - [Data Types](ch03-02-data-types.md) + - [Functions](ch03-03-how-functions-work.md) + - [Comments](ch03-04-comments.md) + - [Control Flow](ch03-05-control-flow.md) - [Understanding Ownership](ch04-00-understanding-ownership.md) - - [What is Ownership?](ch04-01-what-is-ownership.md) - - [References and Borrowing](ch04-02-references-and-borrowing.md) - - [The Slice Type](ch04-03-slices.md) + - [What is Ownership?](ch04-01-what-is-ownership.md) + - [References and Borrowing](ch04-02-references-and-borrowing.md) + - [The Slice Type](ch04-03-slices.md) - [Using Structs to Structure Related Data](ch05-00-structs.md) - - [Defining and Instantiating Structs](ch05-01-defining-structs.md) - - [An Example Program Using Structs](ch05-02-example-structs.md) - - [Method Syntax](ch05-03-method-syntax.md) + - [Defining and Instantiating Structs](ch05-01-defining-structs.md) + - [An Example Program Using Structs](ch05-02-example-structs.md) + - [Method Syntax](ch05-03-method-syntax.md) - [Enums and Pattern Matching](ch06-00-enums.md) - - [Defining an Enum](ch06-01-defining-an-enum.md) - - [The `match` Control Flow Construct](ch06-02-match.md) - - [Concise Control Flow with `if let`](ch06-03-if-let.md) + - [Defining an Enum](ch06-01-defining-an-enum.md) + - [The `match` Control Flow Construct](ch06-02-match.md) + - [Concise Control Flow with `if let`](ch06-03-if-let.md) ## Basic Rust Literacy - [Managing Growing Projects with Packages, Crates, and Modules](ch07-00-managing-growing-projects-with-packages-crates-and-modules.md) - - [Packages and Crates](ch07-01-packages-and-crates.md) - - [Defining Modules to Control Scope and Privacy](ch07-02-defining-modules-to-control-scope-and-privacy.md) - - [Paths for Referring to an Item in the Module Tree](ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md) - - [Bringing Paths Into Scope with the `use` Keyword](ch07-04-bringing-paths-into-scope-with-the-use-keyword.md) - - [Separating Modules into Different Files](ch07-05-separating-modules-into-different-files.md) + - [Packages and Crates](ch07-01-packages-and-crates.md) + - [Defining Modules to Control Scope and Privacy](ch07-02-defining-modules-to-control-scope-and-privacy.md) + - [Paths for Referring to an Item in the Module Tree](ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md) + - [Bringing Paths Into Scope with the `use` Keyword](ch07-04-bringing-paths-into-scope-with-the-use-keyword.md) + - [Separating Modules into Different Files](ch07-05-separating-modules-into-different-files.md) - [Common Collections](ch08-00-common-collections.md) - - [Storing Lists of Values with Vectors](ch08-01-vectors.md) - - [Storing UTF-8 Encoded Text with Strings](ch08-02-strings.md) - - [Storing Keys with Associated Values in Hash Maps](ch08-03-hash-maps.md) + - [Storing Lists of Values with Vectors](ch08-01-vectors.md) + - [Storing UTF-8 Encoded Text with Strings](ch08-02-strings.md) + - [Storing Keys with Associated Values in Hash Maps](ch08-03-hash-maps.md) - [Error Handling](ch09-00-error-handling.md) - - [Unrecoverable Errors with `panic!`](ch09-01-unrecoverable-errors-with-panic.md) - - [Recoverable Errors with `Result`](ch09-02-recoverable-errors-with-result.md) - - [To `panic!` or Not to `panic!`](ch09-03-to-panic-or-not-to-panic.md) + - [Unrecoverable Errors with `panic!`](ch09-01-unrecoverable-errors-with-panic.md) + - [Recoverable Errors with `Result`](ch09-02-recoverable-errors-with-result.md) + - [To `panic!` or Not to `panic!`](ch09-03-to-panic-or-not-to-panic.md) - [Generic Types, Traits, and Lifetimes](ch10-00-generics.md) - - [Generic Data Types](ch10-01-syntax.md) - - [Traits: Defining Shared Behavior](ch10-02-traits.md) - - [Validating References with Lifetimes](ch10-03-lifetime-syntax.md) + - [Generic Data Types](ch10-01-syntax.md) + - [Traits: Defining Shared Behavior](ch10-02-traits.md) + - [Validating References with Lifetimes](ch10-03-lifetime-syntax.md) - [Writing Automated Tests](ch11-00-testing.md) - - [How to Write Tests](ch11-01-writing-tests.md) - - [Controlling How Tests Are Run](ch11-02-running-tests.md) - - [Test Organization](ch11-03-test-organization.md) + - [How to Write Tests](ch11-01-writing-tests.md) + - [Controlling How Tests Are Run](ch11-02-running-tests.md) + - [Test Organization](ch11-03-test-organization.md) - [An I/O Project: Building a Command Line Program](ch12-00-an-io-project.md) - - [Accepting Command Line Arguments](ch12-01-accepting-command-line-arguments.md) - - [Reading a File](ch12-02-reading-a-file.md) - - [Refactoring to Improve Modularity and Error Handling](ch12-03-improving-error-handling-and-modularity.md) - - [Developing the Library’s Functionality with Test Driven Development](ch12-04-testing-the-librarys-functionality.md) - - [Working with Environment Variables](ch12-05-working-with-environment-variables.md) - - [Writing Error Messages to Standard Error Instead of Standard Output](ch12-06-writing-to-stderr-instead-of-stdout.md) + - [Accepting Command Line Arguments](ch12-01-accepting-command-line-arguments.md) + - [Reading a File](ch12-02-reading-a-file.md) + - [Refactoring to Improve Modularity and Error Handling](ch12-03-improving-error-handling-and-modularity.md) + - [Developing the Library’s Functionality with Test Driven Development](ch12-04-testing-the-librarys-functionality.md) + - [Working with Environment Variables](ch12-05-working-with-environment-variables.md) + - [Writing Error Messages to Standard Error Instead of Standard Output](ch12-06-writing-to-stderr-instead-of-stdout.md) ## Thinking in Rust - [Functional Language Features: Iterators and Closures](ch13-00-functional-features.md) - - [Closures: Anonymous Functions that Capture Their Environment](ch13-01-closures.md) - - [Processing a Series of Items with Iterators](ch13-02-iterators.md) - - [Improving Our I/O Project](ch13-03-improving-our-io-project.md) - - [Comparing Performance: Loops vs. Iterators](ch13-04-performance.md) + - [Closures: Anonymous Functions that Capture Their Environment](ch13-01-closures.md) + - [Processing a Series of Items with Iterators](ch13-02-iterators.md) + - [Improving Our I/O Project](ch13-03-improving-our-io-project.md) + - [Comparing Performance: Loops vs. Iterators](ch13-04-performance.md) - [More about Cargo and Crates.io](ch14-00-more-about-cargo.md) - - [Customizing Builds with Release Profiles](ch14-01-release-profiles.md) - - [Publishing a Crate to Crates.io](ch14-02-publishing-to-crates-io.md) - - [Cargo Workspaces](ch14-03-cargo-workspaces.md) - - [Installing Binaries from Crates.io with `cargo install`](ch14-04-installing-binaries.md) - - [Extending Cargo with Custom Commands](ch14-05-extending-cargo.md) + - [Customizing Builds with Release Profiles](ch14-01-release-profiles.md) + - [Publishing a Crate to Crates.io](ch14-02-publishing-to-crates-io.md) + - [Cargo Workspaces](ch14-03-cargo-workspaces.md) + - [Installing Binaries from Crates.io with `cargo install`](ch14-04-installing-binaries.md) + - [Extending Cargo with Custom Commands](ch14-05-extending-cargo.md) - [Smart Pointers](ch15-00-smart-pointers.md) - - [Using `Box` to Point to Data on the Heap](ch15-01-box.md) - - [Treating Smart Pointers Like Regular References with the `Deref` Trait](ch15-02-deref.md) - - [Running Code on Cleanup with the `Drop` Trait](ch15-03-drop.md) - - [`Rc`, the Reference Counted Smart Pointer](ch15-04-rc.md) - - [`RefCell` and the Interior Mutability Pattern](ch15-05-interior-mutability.md) - - [Reference Cycles Can Leak Memory](ch15-06-reference-cycles.md) + - [Using `Box` to Point to Data on the Heap](ch15-01-box.md) + - [Treating Smart Pointers Like Regular References with the `Deref` Trait](ch15-02-deref.md) + - [Running Code on Cleanup with the `Drop` Trait](ch15-03-drop.md) + - [`Rc`, the Reference Counted Smart Pointer](ch15-04-rc.md) + - [`RefCell` and the Interior Mutability Pattern](ch15-05-interior-mutability.md) + - [Reference Cycles Can Leak Memory](ch15-06-reference-cycles.md) - [Fearless Concurrency](ch16-00-concurrency.md) - - [Using Threads to Run Code Simultaneously](ch16-01-threads.md) - - [Using Message Passing to Transfer Data Between Threads](ch16-02-message-passing.md) - - [Shared-State Concurrency](ch16-03-shared-state.md) - - [Extensible Concurrency with the `Sync` and `Send` Traits](ch16-04-extensible-concurrency-sync-and-send.md) + - [Using Threads to Run Code Simultaneously](ch16-01-threads.md) + - [Using Message Passing to Transfer Data Between Threads](ch16-02-message-passing.md) + - [Shared-State Concurrency](ch16-03-shared-state.md) + - [Extensible Concurrency with the `Sync` and `Send` Traits](ch16-04-extensible-concurrency-sync-and-send.md) - [Async and Await](ch17-00-async-await.md) - - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) - - [Concurrency With Async](ch17-02-concurrency-with-async.md) - - [Working With Any Number of Futures](ch17-03-more-futures.md) - - [Streams](ch17-04-streams.md) - - [Digging Into the Traits for Async](ch17-05-traits-for-async.md) - - [Futures, Tasks, and Threads](ch17-06-futures-tasks-threads.md) + - [Futures and the Async Syntax](ch17-01-futures-and-syntax.md) + - [Concurrency With Async](ch17-02-concurrency-with-async.md) + - [Working With Any Number of Futures](ch17-03-more-futures.md) + - [Streams](ch17-04-streams.md) + - [Digging Into the Traits for Async](ch17-05-traits-for-async.md) + - [Futures, Tasks, and Threads](ch17-06-futures-tasks-threads.md) - [Object Oriented Programming Features of Rust](ch18-00-oop.md) - - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) - - [Using Trait Objects That Allow for Values of Different Types](ch18-02-trait-objects.md) - - [Implementing an Object-Oriented Design Pattern](ch18-03-oo-design-patterns.md) + - [Characteristics of Object-Oriented Languages](ch18-01-what-is-oo.md) + - [Using Trait Objects That Allow for Values of Different Types](ch18-02-trait-objects.md) + - [Implementing an Object-Oriented Design Pattern](ch18-03-oo-design-patterns.md) ## Advanced Topics - [Patterns and Matching](ch19-00-patterns.md) - - [All the Places Patterns Can Be Used](ch19-01-all-the-places-for-patterns.md) - - [Refutability: Whether a Pattern Might Fail to Match](ch19-02-refutability.md) - - [Pattern Syntax](ch19-03-pattern-syntax.md) + - [All the Places Patterns Can Be Used](ch19-01-all-the-places-for-patterns.md) + - [Refutability: Whether a Pattern Might Fail to Match](ch19-02-refutability.md) + - [Pattern Syntax](ch19-03-pattern-syntax.md) - [Advanced Features](ch20-00-advanced-features.md) - - [Unsafe Rust](ch20-01-unsafe-rust.md) - - [Advanced Traits](ch20-03-advanced-traits.md) - - [Advanced Types](ch20-04-advanced-types.md) - - [Advanced Functions and Closures](ch20-05-advanced-functions-and-closures.md) - - [Macros](ch20-06-macros.md) + - [Unsafe Rust](ch20-01-unsafe-rust.md) + - [Advanced Traits](ch20-03-advanced-traits.md) + - [Advanced Types](ch20-04-advanced-types.md) + - [Advanced Functions and Closures](ch20-05-advanced-functions-and-closures.md) + - [Macros](ch20-06-macros.md) - [Final Project: Building a Multithreaded Web Server](ch21-00-final-project-a-web-server.md) - - [Building a Single-Threaded Web Server](ch21-01-single-threaded.md) - - [Turning Our Single-Threaded Server into a Multithreaded Server](ch21-02-multithreaded.md) - - [Graceful Shutdown and Cleanup](ch21-03-graceful-shutdown-and-cleanup.md) + - [Building a Single-Threaded Web Server](ch21-01-single-threaded.md) + - [Turning Our Single-Threaded Server into a Multithreaded Server](ch21-02-multithreaded.md) + - [Graceful Shutdown and Cleanup](ch21-03-graceful-shutdown-and-cleanup.md) - [Appendix](appendix-00.md) - - [A - Keywords](appendix-01-keywords.md) - - [B - Operators and Symbols](appendix-02-operators.md) - - [C - Derivable Traits](appendix-03-derivable-traits.md) - - [D - Useful Development Tools](appendix-04-useful-development-tools.md) - - [E - Editions](appendix-05-editions.md) - - [F - Translations of the Book](appendix-06-translation.md) - - [G - How Rust is Made and “Nightly Rust”](appendix-07-nightly-rust.md) + - [A - Keywords](appendix-01-keywords.md) + - [B - Operators and Symbols](appendix-02-operators.md) + - [C - Derivable Traits](appendix-03-derivable-traits.md) + - [D - Useful Development Tools](appendix-04-useful-development-tools.md) + - [E - Editions](appendix-05-editions.md) + - [F - Translations of the Book](appendix-06-translation.md) + - [G - How Rust is Made and “Nightly Rust”](appendix-07-nightly-rust.md) diff --git a/src/appendix-01-keywords.md b/src/appendix-01-keywords.md index b848945915..1df1691174 100644 --- a/src/appendix-01-keywords.md +++ b/src/appendix-01-keywords.md @@ -14,48 +14,48 @@ macros, static values, attributes, types, traits, or lifetimes. The following is a list of keywords currently in use, with their functionality described. -* `as` - perform primitive casting, disambiguate the specific trait containing +- `as` - perform primitive casting, disambiguate the specific trait containing an item, or rename items in `use` statements -* `async` - return a `Future` instead of blocking the current thread -* `await` - suspend execution until the result of a `Future` is ready -* `break` - exit a loop immediately -* `const` - define constant items or constant raw pointers -* `continue` - continue to the next loop iteration -* `crate` - in a module path, refers to the crate root -* `dyn` - dynamic dispatch to a trait object -* `else` - fallback for `if` and `if let` control flow constructs -* `enum` - define an enumeration -* `extern` - link an external function or variable -* `false` - Boolean false literal -* `fn` - define a function or the function pointer type -* `for` - loop over items from an iterator, implement a trait, or specify a +- `async` - return a `Future` instead of blocking the current thread +- `await` - suspend execution until the result of a `Future` is ready +- `break` - exit a loop immediately +- `const` - define constant items or constant raw pointers +- `continue` - continue to the next loop iteration +- `crate` - in a module path, refers to the crate root +- `dyn` - dynamic dispatch to a trait object +- `else` - fallback for `if` and `if let` control flow constructs +- `enum` - define an enumeration +- `extern` - link an external function or variable +- `false` - Boolean false literal +- `fn` - define a function or the function pointer type +- `for` - loop over items from an iterator, implement a trait, or specify a higher-ranked lifetime -* `if` - branch based on the result of a conditional expression -* `impl` - implement inherent or trait functionality -* `in` - part of `for` loop syntax -* `let` - bind a variable -* `loop` - loop unconditionally -* `match` - match a value to patterns -* `mod` - define a module -* `move` - make a closure take ownership of all its captures -* `mut` - denote mutability in references, raw pointers, or pattern bindings -* `pub` - denote public visibility in struct fields, `impl` blocks, or modules -* `ref` - bind by reference -* `return` - return from function -* `Self` - a type alias for the type we are defining or implementing -* `self` - method subject or current module -* `static` - global variable or lifetime lasting the entire program execution -* `struct` - define a structure -* `super` - parent module of the current module -* `trait` - define a trait -* `true` - Boolean true literal -* `type` - define a type alias or associated type -* `union` - define a [union][union]; is only a keyword when used +- `if` - branch based on the result of a conditional expression +- `impl` - implement inherent or trait functionality +- `in` - part of `for` loop syntax +- `let` - bind a variable +- `loop` - loop unconditionally +- `match` - match a value to patterns +- `mod` - define a module +- `move` - make a closure take ownership of all its captures +- `mut` - denote mutability in references, raw pointers, or pattern bindings +- `pub` - denote public visibility in struct fields, `impl` blocks, or modules +- `ref` - bind by reference +- `return` - return from function +- `Self` - a type alias for the type we are defining or implementing +- `self` - method subject or current module +- `static` - global variable or lifetime lasting the entire program execution +- `struct` - define a structure +- `super` - parent module of the current module +- `trait` - define a trait +- `true` - Boolean true literal +- `type` - define a type alias or associated type +- `union` - define a [union][union]; is only a keyword when used in a union declaration -* `unsafe` - denote unsafe code, functions, traits, or implementations -* `use` - bring symbols into scope -* `where` - denote clauses that constrain a type -* `while` - loop conditionally based on the result of an expression +- `unsafe` - denote unsafe code, functions, traits, or implementations +- `use` - bring symbols into scope +- `where` - denote clauses that constrain a type +- `while` - loop conditionally based on the result of an expression [union]: ../reference/items/unions.html @@ -64,23 +64,23 @@ described. The following keywords do not yet have any functionality but are reserved by Rust for potential future use. -* `abstract` -* `become` -* `box` -* `do` -* `final` -* `macro` -* `override` -* `priv` -* `try` -* `typeof` -* `unsized` -* `virtual` -* `yield` +- `abstract` +- `become` +- `box` +- `do` +- `final` +- `macro` +- `override` +- `priv` +- `try` +- `typeof` +- `unsized` +- `virtual` +- `yield` ### Raw Identifiers -*Raw identifiers* are the syntax that lets you use keywords where they wouldn’t +_Raw identifiers_ are the syntax that lets you use keywords where they wouldn’t normally be allowed. You use a raw identifier by prefixing a keyword with `r#`. For example, `match` is a keyword. If you try to compile the following function diff --git a/src/appendix-02-operators.md b/src/appendix-02-operators.md index 45de3e56aa..6c8b8d89db 100644 --- a/src/appendix-02-operators.md +++ b/src/appendix-02-operators.md @@ -13,62 +13,62 @@ overload that operator is listed. Table B-1: Operators -| Operator | Example | Explanation | Overloadable? | -|----------|---------|-------------|---------------| -| `!` | `ident!(...)`, `ident!{...}`, `ident![...]` | Macro expansion | | -| `!` | `!expr` | Bitwise or logical complement | `Not` | -| `!=` | `expr != expr` | Nonequality comparison | `PartialEq` | -| `%` | `expr % expr` | Arithmetic remainder | `Rem` | -| `%=` | `var %= expr` | Arithmetic remainder and assignment | `RemAssign` | -| `&` | `&expr`, `&mut expr` | Borrow | | -| `&` | `&type`, `&mut type`, `&'a type`, `&'a mut type` | Borrowed pointer type | | -| `&` | `expr & expr` | Bitwise AND | `BitAnd` | -| `&=` | `var &= expr` | Bitwise AND and assignment | `BitAndAssign` | -| `&&` | `expr && expr` | Short-circuiting logical AND | | -| `*` | `expr * expr` | Arithmetic multiplication | `Mul` | -| `*=` | `var *= expr` | Arithmetic multiplication and assignment | `MulAssign` | -| `*` | `*expr` | Dereference | `Deref` | -| `*` | `*const type`, `*mut type` | Raw pointer | | -| `+` | `trait + trait`, `'a + trait` | Compound type constraint | | -| `+` | `expr + expr` | Arithmetic addition | `Add` | -| `+=` | `var += expr` | Arithmetic addition and assignment | `AddAssign` | -| `,` | `expr, expr` | Argument and element separator | | -| `-` | `- expr` | Arithmetic negation | `Neg` | -| `-` | `expr - expr` | Arithmetic subtraction | `Sub` | -| `-=` | `var -= expr` | Arithmetic subtraction and assignment | `SubAssign` | -| `->` | `fn(...) -> type`, |...| -> type | Function and closure return type | | -| `.` | `expr.ident` | Member access | | -| `..` | `..`, `expr..`, `..expr`, `expr..expr` | Right-exclusive range literal | `PartialOrd` | -| `..=` | `..=expr`, `expr..=expr` | Right-inclusive range literal | `PartialOrd` | -| `..` | `..expr` | Struct literal update syntax | | -| `..` | `variant(x, ..)`, `struct_type { x, .. }` | “And the rest” pattern binding | | -| `...` | `expr...expr` | (Deprecated, use `..=` instead) In a pattern: inclusive range pattern | | -| `/` | `expr / expr` | Arithmetic division | `Div` | -| `/=` | `var /= expr` | Arithmetic division and assignment | `DivAssign` | -| `:` | `pat: type`, `ident: type` | Constraints | | -| `:` | `ident: expr` | Struct field initializer | | -| `:` | `'a: loop {...}` | Loop label | | -| `;` | `expr;` | Statement and item terminator | | -| `;` | `[...; len]` | Part of fixed-size array syntax | | -| `<<` | `expr << expr` | Left-shift | `Shl` | -| `<<=` | `var <<= expr` | Left-shift and assignment | `ShlAssign` | -| `<` | `expr < expr` | Less than comparison | `PartialOrd` | -| `<=` | `expr <= expr` | Less than or equal to comparison | `PartialOrd` | -| `=` | `var = expr`, `ident = type` | Assignment/equivalence | | -| `==` | `expr == expr` | Equality comparison | `PartialEq` | -| `=>` | `pat => expr` | Part of match arm syntax | | -| `>` | `expr > expr` | Greater than comparison | `PartialOrd` | -| `>=` | `expr >= expr` | Greater than or equal to comparison | `PartialOrd` | -| `>>` | `expr >> expr` | Right-shift | `Shr` | -| `>>=` | `var >>= expr` | Right-shift and assignment | `ShrAssign` | -| `@` | `ident @ pat` | Pattern binding | | -| `^` | `expr ^ expr` | Bitwise exclusive OR | `BitXor` | -| `^=` | `var ^= expr` | Bitwise exclusive OR and assignment | `BitXorAssign` | -| | | pat | pat | Pattern alternatives | | -| | | expr | expr | Bitwise OR | `BitOr` | -| |= | var |= expr | Bitwise OR and assignment | `BitOrAssign` | -| || | expr || expr | Short-circuiting logical OR | | -| `?` | `expr?` | Error propagation | | +| Operator | Example | Explanation | Overloadable? | +| ------------------------- | ------------------------------------------------------- | --------------------------------------------------------------------- | -------------- | +| `!` | `ident!(...)`, `ident!{...}`, `ident![...]` | Macro expansion | | +| `!` | `!expr` | Bitwise or logical complement | `Not` | +| `!=` | `expr != expr` | Nonequality comparison | `PartialEq` | +| `%` | `expr % expr` | Arithmetic remainder | `Rem` | +| `%=` | `var %= expr` | Arithmetic remainder and assignment | `RemAssign` | +| `&` | `&expr`, `&mut expr` | Borrow | | +| `&` | `&type`, `&mut type`, `&'a type`, `&'a mut type` | Borrowed pointer type | | +| `&` | `expr & expr` | Bitwise AND | `BitAnd` | +| `&=` | `var &= expr` | Bitwise AND and assignment | `BitAndAssign` | +| `&&` | `expr && expr` | Short-circuiting logical AND | | +| `*` | `expr * expr` | Arithmetic multiplication | `Mul` | +| `*=` | `var *= expr` | Arithmetic multiplication and assignment | `MulAssign` | +| `*` | `*expr` | Dereference | `Deref` | +| `*` | `*const type`, `*mut type` | Raw pointer | | +| `+` | `trait + trait`, `'a + trait` | Compound type constraint | | +| `+` | `expr + expr` | Arithmetic addition | `Add` | +| `+=` | `var += expr` | Arithmetic addition and assignment | `AddAssign` | +| `,` | `expr, expr` | Argument and element separator | | +| `-` | `- expr` | Arithmetic negation | `Neg` | +| `-` | `expr - expr` | Arithmetic subtraction | `Sub` | +| `-=` | `var -= expr` | Arithmetic subtraction and assignment | `SubAssign` | +| `->` | `fn(...) -> type`, |...| -> type | Function and closure return type | | +| `.` | `expr.ident` | Member access | | +| `..` | `..`, `expr..`, `..expr`, `expr..expr` | Right-exclusive range literal | `PartialOrd` | +| `..=` | `..=expr`, `expr..=expr` | Right-inclusive range literal | `PartialOrd` | +| `..` | `..expr` | Struct literal update syntax | | +| `..` | `variant(x, ..)`, `struct_type { x, .. }` | “And the rest” pattern binding | | +| `...` | `expr...expr` | (Deprecated, use `..=` instead) In a pattern: inclusive range pattern | | +| `/` | `expr / expr` | Arithmetic division | `Div` | +| `/=` | `var /= expr` | Arithmetic division and assignment | `DivAssign` | +| `:` | `pat: type`, `ident: type` | Constraints | | +| `:` | `ident: expr` | Struct field initializer | | +| `:` | `'a: loop {...}` | Loop label | | +| `;` | `expr;` | Statement and item terminator | | +| `;` | `[...; len]` | Part of fixed-size array syntax | | +| `<<` | `expr << expr` | Left-shift | `Shl` | +| `<<=` | `var <<= expr` | Left-shift and assignment | `ShlAssign` | +| `<` | `expr < expr` | Less than comparison | `PartialOrd` | +| `<=` | `expr <= expr` | Less than or equal to comparison | `PartialOrd` | +| `=` | `var = expr`, `ident = type` | Assignment/equivalence | | +| `==` | `expr == expr` | Equality comparison | `PartialEq` | +| `=>` | `pat => expr` | Part of match arm syntax | | +| `>` | `expr > expr` | Greater than comparison | `PartialOrd` | +| `>=` | `expr >= expr` | Greater than or equal to comparison | `PartialOrd` | +| `>>` | `expr >> expr` | Right-shift | `Shr` | +| `>>=` | `var >>= expr` | Right-shift and assignment | `ShrAssign` | +| `@` | `ident @ pat` | Pattern binding | | +| `^` | `expr ^ expr` | Bitwise exclusive OR | `BitXor` | +| `^=` | `var ^= expr` | Bitwise exclusive OR and assignment | `BitXorAssign` | +| | | pat | pat | Pattern alternatives | | +| | | expr | expr | Bitwise OR | `BitOr` | +| |= | var |= expr | Bitwise OR and assignment | `BitOrAssign` | +| || | expr || expr | Short-circuiting logical OR | | +| `?` | `expr?` | Error propagation | | ### Non-operator Symbols @@ -80,91 +80,91 @@ locations. Table B-2: Stand-Alone Syntax -| Symbol | Explanation | -|--------|-------------| -| `'ident` | Named lifetime or loop label | -| `...u8`, `...i32`, `...f64`, `...usize`, etc. | Numeric literal of specific type | -| `"..."` | String literal | -| `r"..."`, `r#"..."#`, `r##"..."##`, etc. | Raw string literal, escape characters not processed | -| `b"..."` | Byte string literal; constructs an array of bytes instead of a string | -| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, combination of raw and byte string literal | -| `'...'` | Character literal | -| `b'...'` | ASCII byte literal | -| |...| expr | Closure | -| `!` | Always empty bottom type for diverging functions | -| `_` | “Ignored” pattern binding; also used to make integer literals readable | +| Symbol | Explanation | +| --------------------------------------------- | ---------------------------------------------------------------------- | +| `'ident` | Named lifetime or loop label | +| `...u8`, `...i32`, `...f64`, `...usize`, etc. | Numeric literal of specific type | +| `"..."` | String literal | +| `r"..."`, `r#"..."#`, `r##"..."##`, etc. | Raw string literal, escape characters not processed | +| `b"..."` | Byte string literal; constructs an array of bytes instead of a string | +| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, combination of raw and byte string literal | +| `'...'` | Character literal | +| `b'...'` | ASCII byte literal | +| |...| expr | Closure | +| `!` | Always empty bottom type for diverging functions | +| `_` | “Ignored” pattern binding; also used to make integer literals readable | Table B-3 shows symbols that appear in the context of a path through the module hierarchy to an item. Table B-3: Path-Related Syntax -| Symbol | Explanation | -|--------|-------------| -| `ident::ident` | Namespace path | -| `::path` | Path relative to the extern prelude, where all other crates are rooted (i.e., an explicitly absolute path including crate name) | -| `self::path` | Path relative to the current module (i.e., an explicitly relative path). | -| `super::path` | Path relative to the parent of the current module | -| `type::ident`, `::ident` | Associated constants, functions, and types | -| `::...` | Associated item for a type that cannot be directly named (e.g., `<&T>::...`, `<[T]>::...`, etc.) | -| `trait::method(...)` | Disambiguating a method call by naming the trait that defines it | -| `type::method(...)` | Disambiguating a method call by naming the type for which it’s defined | -| `::method(...)` | Disambiguating a method call by naming the trait and type | +| Symbol | Explanation | +| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | +| `ident::ident` | Namespace path | +| `::path` | Path relative to the extern prelude, where all other crates are rooted (i.e., an explicitly absolute path including crate name) | +| `self::path` | Path relative to the current module (i.e., an explicitly relative path). | +| `super::path` | Path relative to the parent of the current module | +| `type::ident`, `::ident` | Associated constants, functions, and types | +| `::...` | Associated item for a type that cannot be directly named (e.g., `<&T>::...`, `<[T]>::...`, etc.) | +| `trait::method(...)` | Disambiguating a method call by naming the trait that defines it | +| `type::method(...)` | Disambiguating a method call by naming the type for which it’s defined | +| `::method(...)` | Disambiguating a method call by naming the trait and type | Table B-4 shows symbols that appear in the context of using generic type parameters. Table B-4: Generics -| Symbol | Explanation | -|--------|-------------| -| `path<...>` | Specifies parameters to generic type in a type (e.g., `Vec`) | +| Symbol | Explanation | +| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- | +| `path<...>` | Specifies parameters to generic type in a type (e.g., `Vec`) | | `path::<...>`, `method::<...>` | Specifies parameters to generic type, function, or method in an expression; often referred to as turbofish (e.g., `"42".parse::()`) | -| `fn ident<...> ...` | Define generic function | -| `struct ident<...> ...` | Define generic structure | -| `enum ident<...> ...` | Define generic enumeration | -| `impl<...> ...` | Define generic implementation | -| `for<...> type` | Higher-ranked lifetime bounds | -| `type` | A generic type where one or more associated types have specific assignments (e.g., `Iterator`) | +| `fn ident<...> ...` | Define generic function | +| `struct ident<...> ...` | Define generic structure | +| `enum ident<...> ...` | Define generic enumeration | +| `impl<...> ...` | Define generic implementation | +| `for<...> type` | Higher-ranked lifetime bounds | +| `type` | A generic type where one or more associated types have specific assignments (e.g., `Iterator`) | Table B-5 shows symbols that appear in the context of constraining generic type parameters with trait bounds. Table B-5: Trait Bound Constraints -| Symbol | Explanation | -|--------|-------------| -| `T: U` | Generic parameter `T` constrained to types that implement `U` | -| `T: 'a` | Generic type `T` must outlive lifetime `'a` (meaning the type cannot transitively contain any references with lifetimes shorter than `'a`) | -| `T: 'static` | Generic type `T` contains no borrowed references other than `'static` ones | -| `'b: 'a` | Generic lifetime `'b` must outlive lifetime `'a` | -| `T: ?Sized` | Allow generic type parameter to be a dynamically sized type | -| `'a + trait`, `trait + trait` | Compound type constraint | +| Symbol | Explanation | +| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | +| `T: U` | Generic parameter `T` constrained to types that implement `U` | +| `T: 'a` | Generic type `T` must outlive lifetime `'a` (meaning the type cannot transitively contain any references with lifetimes shorter than `'a`) | +| `T: 'static` | Generic type `T` contains no borrowed references other than `'static` ones | +| `'b: 'a` | Generic lifetime `'b` must outlive lifetime `'a` | +| `T: ?Sized` | Allow generic type parameter to be a dynamically sized type | +| `'a + trait`, `trait + trait` | Compound type constraint | Table B-6 shows symbols that appear in the context of calling or defining macros and specifying attributes on an item. Table B-6: Macros and Attributes -| Symbol | Explanation | -|--------|-------------| -| `#[meta]` | Outer attribute | -| `#![meta]` | Inner attribute | -| `$ident` | Macro substitution | -| `$ident:kind` | Macro capture | -| `$(…)…` | Macro repetition | -| `ident!(...)`, `ident!{...}`, `ident![...]` | Macro invocation | +| Symbol | Explanation | +| ------------------------------------------- | ------------------ | +| `#[meta]` | Outer attribute | +| `#![meta]` | Inner attribute | +| `$ident` | Macro substitution | +| `$ident:kind` | Macro capture | +| `$(…)…` | Macro repetition | +| `ident!(...)`, `ident!{...}`, `ident![...]` | Macro invocation | Table B-7 shows symbols that create comments. Table B-7: Comments -| Symbol | Explanation | -|--------|-------------| -| `//` | Line comment | -| `//!` | Inner line doc comment | -| `///` | Outer line doc comment | -| `/*...*/` | Block comment | +| Symbol | Explanation | +| ---------- | ----------------------- | +| `//` | Line comment | +| `//!` | Inner line doc comment | +| `///` | Outer line doc comment | +| `/*...*/` | Block comment | | `/*!...*/` | Inner block doc comment | | `/**...*/` | Outer block doc comment | @@ -172,34 +172,34 @@ Table B-8 shows symbols that appear in the context of using tuples. Table B-8: Tuples -| Symbol | Explanation | -|--------|-------------| -| `()` | Empty tuple (aka unit), both literal and type | -| `(expr)` | Parenthesized expression | -| `(expr,)` | Single-element tuple expression | -| `(type,)` | Single-element tuple type | -| `(expr, ...)` | Tuple expression | -| `(type, ...)` | Tuple type | -| `expr(expr, ...)` | Function call expression; also used to initialize tuple `struct`s and tuple `enum` variants | -| `expr.0`, `expr.1`, etc. | Tuple indexing | +| Symbol | Explanation | +| ------------------------ | ------------------------------------------------------------------------------------------- | +| `()` | Empty tuple (aka unit), both literal and type | +| `(expr)` | Parenthesized expression | +| `(expr,)` | Single-element tuple expression | +| `(type,)` | Single-element tuple type | +| `(expr, ...)` | Tuple expression | +| `(type, ...)` | Tuple type | +| `expr(expr, ...)` | Function call expression; also used to initialize tuple `struct`s and tuple `enum` variants | +| `expr.0`, `expr.1`, etc. | Tuple indexing | Table B-9 shows the contexts in which curly braces are used. Table B-9: Curly Brackets -| Context | Explanation | -|---------|-------------| -| `{...}` | Block expression | +| Context | Explanation | +| ------------ | ---------------- | +| `{...}` | Block expression | | `Type {...}` | `struct` literal | Table B-10 shows the contexts in which square brackets are used. Table B-10: Square Brackets -| Context | Explanation | -|---------|-------------| -| `[...]` | Array literal | -| `[expr; len]` | Array literal containing `len` copies of `expr` | -| `[type; len]` | Array type containing `len` instances of `type` | -| `expr[expr]` | Collection indexing. Overloadable (`Index`, `IndexMut`) | +| Context | Explanation | +| -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | +| `[...]` | Array literal | +| `[expr; len]` | Array literal containing `len` copies of `expr` | +| `[type; len]` | Array type containing `len` instances of `type` | +| `expr[expr]` | Collection indexing. Overloadable (`Index`, `IndexMut`) | | `expr[..]`, `expr[a..]`, `expr[..b]`, `expr[a..b]` | Collection indexing pretending to be collection slicing, using `Range`, `RangeFrom`, `RangeTo`, or `RangeFull` as the “index” | diff --git a/src/appendix-03-derivable-traits.md b/src/appendix-03-derivable-traits.md index 4214f091b9..2365ade130 100644 --- a/src/appendix-03-derivable-traits.md +++ b/src/appendix-03-derivable-traits.md @@ -8,11 +8,11 @@ type you’ve annotated with the `derive` syntax. In this appendix, we provide a reference of all the traits in the standard library that you can use with `derive`. Each section covers: -* What operators and methods deriving this trait will enable -* What the implementation of the trait provided by `derive` does -* What implementing the trait signifies about the type -* The conditions in which you’re allowed or not allowed to implement the trait -* Examples of operations that require the trait +- What operators and methods deriving this trait will enable +- What the implementation of the trait provided by `derive` does +- What implementing the trait signifies about the type +- The conditions in which you’re allowed or not allowed to implement the trait +- Examples of operations that require the trait If you want different behavior from that provided by the `derive` attribute, consult the [standard library documentation](../std/index.html) @@ -55,7 +55,7 @@ The `PartialEq` trait allows you to compare instances of a type to check for equality and enables use of the `==` and `!=` operators. Deriving `PartialEq` implements the `eq` method. When `PartialEq` is derived on -structs, two instances are equal only if *all* fields are equal, and the +structs, two instances are equal only if _all_ fields are equal, and the instances are not equal if any fields are not equal. When derived on enums, each variant is equal to itself and not equal to the other variants. @@ -178,10 +178,7 @@ The `Default` trait is required when you use the method `unwrap_or_default` on `unwrap_or_default` will return the result of `Default::default` for the type `T` stored in the `Option`. -[creating-instances-from-other-instances-with-struct-update-syntax]: -ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax -[stack-only-data-copy]: -ch04-01-what-is-ownership.html#stack-only-data-copy -[ways-variables-and-data-interact-clone]: -ch04-01-what-is-ownership.html#ways-variables-and-data-interact-clone +[creating-instances-from-other-instances-with-struct-update-syntax]: ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax +[stack-only-data-copy]: ch04-01-what-is-ownership.html#stack-only-data-copy +[ways-variables-and-data-interact-clone]: ch04-01-what-is-ownership.html#ways-variables-and-data-interact-clone [macros]: ch20-06-macros.html#macros diff --git a/src/appendix-04-useful-development-tools.md b/src/appendix-04-useful-development-tools.md index 30249ed578..75e0c871b5 100644 --- a/src/appendix-04-useful-development-tools.md +++ b/src/appendix-04-useful-development-tools.md @@ -77,7 +77,7 @@ $ cargo fix Finished dev [unoptimized + debuginfo] target(s) in 0.59s ``` -When we look at *src/main.rs* again, we’ll see that `cargo fix` has changed the +When we look at _src/main.rs_ again, we’ll see that `cargo fix` has changed the code: Filename: src/main.rs diff --git a/src/appendix-05-editions.md b/src/appendix-05-editions.md index 90828ebbaf..ea9758ffa7 100644 --- a/src/appendix-05-editions.md +++ b/src/appendix-05-editions.md @@ -1,7 +1,7 @@ ## Appendix E - Editions In Chapter 1, you saw that `cargo new` adds a bit of metadata to your -*Cargo.toml* file about an edition. This appendix talks about what that means! +_Cargo.toml_ file about an edition. This appendix talks about what that means! The Rust language and compiler have a six-week release cycle, meaning users get a constant stream of new features. Other programming languages release larger @@ -10,24 +10,24 @@ while, all of these tiny changes add up. But from release to release, it can be difficult to look back and say, “Wow, between Rust 1.10 and Rust 1.31, Rust has changed a lot!” -Every two or three years, the Rust team produces a new Rust *edition*. Each +Every two or three years, the Rust team produces a new Rust _edition_. Each edition brings together the features that have landed into a clear package with fully updated documentation and tooling. New editions ship as part of the usual six-week release process. Editions serve different purposes for different people: -* For active Rust users, a new edition brings together incremental changes into +- For active Rust users, a new edition brings together incremental changes into an easy-to-understand package. -* For non-users, a new edition signals that some major advancements have +- For non-users, a new edition signals that some major advancements have landed, which might make Rust worth another look. -* For those developing Rust, a new edition provides a rallying point for the +- For those developing Rust, a new edition provides a rallying point for the project as a whole. At the time of this writing, three Rust editions are available: Rust 2015, Rust 2018, and Rust 2021. This book is written using Rust 2021 edition idioms. -The `edition` key in *Cargo.toml* indicates which edition the compiler should +The `edition` key in _Cargo.toml_ indicates which edition the compiler should use for your code. If the key doesn’t exist, Rust uses `2015` as the edition value for backward compatibility reasons. @@ -51,7 +51,6 @@ made. However, in some cases, mainly when new keywords are added, some new features might only be available in later editions. You will need to switch editions if you want to take advantage of such features. -For more details, the [*Edition -Guide*](https://doc.rust-lang.org/stable/edition-guide/) is a complete book +For more details, the [_Edition Guide_](https://doc.rust-lang.org/stable/edition-guide/) is a complete book about editions that enumerates the differences between editions and explains how to automatically upgrade your code to a new edition via `cargo fix`. diff --git a/src/appendix-07-nightly-rust.md b/src/appendix-07-nightly-rust.md index ac3fbb9df9..5246d72825 100644 --- a/src/appendix-07-nightly-rust.md +++ b/src/appendix-07-nightly-rust.md @@ -5,7 +5,7 @@ developer. ### Stability Without Stagnation -As a language, Rust cares a *lot* about the stability of your code. We want +As a language, Rust cares a _lot_ about the stability of your code. We want Rust to be a rock-solid foundation you can build on, and if things were constantly changing, that would be impossible. At the same time, if we can’t experiment with new features, we may not find out important flaws until after @@ -18,14 +18,14 @@ bring you new features, fewer bugs, and faster compile times. ### Choo, Choo! Release Channels and Riding the Trains -Rust development operates on a *train schedule*. That is, all development is +Rust development operates on a _train schedule_. That is, all development is done on the `master` branch of the Rust repository. Releases follow a software release train model, which has been used by Cisco IOS and other software -projects. There are three *release channels* for Rust: +projects. There are three _release channels_ for Rust: -* Nightly -* Beta -* Stable +- Nightly +- Beta +- Stable Most Rust developers primarily use the stable channel, but those who want to try out experimental new features may use nightly or beta. @@ -85,7 +85,7 @@ stable: * ``` Hooray! Rust 1.5 is done! However, we’ve forgotten one thing: because the six -weeks have gone by, we also need a new beta of the *next* version of Rust, 1.6. +weeks have gone by, we also need a new beta of the _next_ version of Rust, 1.6. So after `stable` branches off of `beta`, the next version of `beta` branches off of `nightly` again: @@ -125,7 +125,7 @@ each version is supported for six weeks. There’s one more catch with this release model: unstable features. Rust uses a technique called “feature flags” to determine what features are enabled in a given release. If a new feature is under active development, it lands on -`master`, and therefore, in nightly, but behind a *feature flag*. If you, as a +`master`, and therefore, in nightly, but behind a _feature flag_. If you, as a user, wish to try out the work-in-progress feature, you can, but you must be using a nightly release of Rust and annotate your source code with the appropriate flag to opt in. @@ -151,7 +151,7 @@ install nightly, for example: $ rustup toolchain install nightly ``` -You can see all of the *toolchains* (releases of Rust and associated +You can see all of the _toolchains_ (releases of Rust and associated components) you have installed with `rustup` as well. Here’s an example on one of your authors’ Windows computer: @@ -174,20 +174,19 @@ $ rustup override set nightly ``` Now, every time you call `rustc` or `cargo` inside of -*~/projects/needs-nightly*, `rustup` will make sure that you are using nightly +_~/projects/needs-nightly_, `rustup` will make sure that you are using nightly Rust, rather than your default of stable Rust. This comes in handy when you have a lot of Rust projects! ### The RFC Process and Teams So how do you learn about these new features? Rust’s development model follows -a *Request For Comments (RFC) process*. If you’d like an improvement in Rust, +a _Request For Comments (RFC) process_. If you’d like an improvement in Rust, you can write up a proposal, called an RFC. Anyone can write RFCs to improve Rust, and the proposals are reviewed and discussed by the Rust team, which is comprised of many topic subteams. There’s -a full list of the teams [on Rust’s -website](https://www.rust-lang.org/governance), which includes teams for +a full list of the teams [on Rust’s website](https://www.rust-lang.org/governance), which includes teams for each area of the project: language design, compiler implementation, infrastructure, documentation, and more. The appropriate team reads the proposal and the comments, writes some comments of their own, and eventually, diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 050a627818..ce4ca17ba4 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -7,7 +7,7 @@ [nsprust]: https://nostarch.com/rust-programming-language-2nd-edition [nsp]: https://nostarch.com/ -Welcome to *The Rust Programming Language*, an introductory book about Rust. +Welcome to _The Rust Programming Language_, an introductory book about Rust. The Rust programming language helps you write faster, more reliable software. High-level ergonomics and low-level control are often at odds in programming language design; Rust challenges that conflict. Through balancing powerful @@ -33,12 +33,12 @@ logic rather than chasing down bugs. Rust also brings contemporary developer tools to the systems programming world: -* Cargo, the included dependency manager and build tool, makes adding, +- Cargo, the included dependency manager and build tool, makes adding, compiling, and managing dependencies painless and consistent across the Rust ecosystem. -* The Rustfmt formatting tool ensures a consistent coding style across +- The Rustfmt formatting tool ensures a consistent coding style across developers. -* The rust-analyzer powers Integrated Development Environment (IDE) +- The rust-analyzer powers Integrated Development Environment (IDE) integration for code completion and inline error messages. By using these and other tools in the Rust ecosystem, developers can be @@ -81,7 +81,7 @@ code be fast code as well. The Rust language hopes to support many other users as well; those mentioned here are merely some of the biggest stakeholders. Overall, Rust’s greatest ambition is to eliminate the trade-offs that programmers have accepted for -decades by providing safety *and* productivity, speed *and* ergonomics. Give +decades by providing safety _and_ productivity, speed _and_ ergonomics. Give Rust a try and see if its choices work for you. ## Who This Book Is For @@ -89,7 +89,7 @@ Rust a try and see if its choices work for you. This book assumes that you’ve written code in another programming language but doesn’t make any assumptions about which one. We’ve tried to make the material broadly accessible to those from a wide variety of programming backgrounds. We -don’t spend a lot of time talking about what programming *is* or how to think +don’t spend a lot of time talking about what programming _is_ or how to think about it. If you’re entirely new to programming, you would be better served by reading a book that specifically provides an introduction to programming. @@ -180,7 +180,7 @@ surrounding text to see whether the example you’re trying to run is meant to error. Ferris will also help you distinguish code that isn’t meant to work: | Ferris | Meaning | -|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------| +| ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | | Ferris with a question mark | This code does not compile! | | Ferris throwing up their hands | This code panics! | | Ferris with one claw up, shrugging | This code does not produce the desired behavior. | diff --git a/src/ch01-00-getting-started.md b/src/ch01-00-getting-started.md index ff5e324f7a..ccb10e884e 100644 --- a/src/ch01-00-getting-started.md +++ b/src/ch01-00-getting-started.md @@ -3,6 +3,6 @@ Let’s start your Rust journey! There’s a lot to learn, but every journey starts somewhere. In this chapter, we’ll discuss: -* Installing Rust on Linux, macOS, and Windows -* Writing a program that prints `Hello, world!` -* Using `cargo`, Rust’s package manager and build system +- Installing Rust on Linux, macOS, and Windows +- Writing a program that prints `Hello, world!` +- Using `cargo`, Rust’s package manager and build system diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index f554c94b7b..55636c09b3 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -39,7 +39,7 @@ for your password. If the install is successful, the following line will appear: Rust is installed now. Great! ``` -You will also need a *linker*, which is a program that Rust uses to join its +You will also need a _linker_, which is a program that Rust uses to join its compiled outputs into one file. It is likely you already have one. If you get linker errors, you should install a C compiler, which will typically include a linker. A C compiler is also useful because some common Rust packages depend on @@ -63,7 +63,7 @@ be prompted to install Visual Studio. This provides a linker and the native libraries needed to compile programs. If you need more help with this step, see [https://rust-lang.github.io/rustup/installation/windows-msvc.html][msvc] -The rest of this book uses commands that work in both *cmd.exe* and PowerShell. +The rest of this book uses commands that work in both _cmd.exe_ and PowerShell. If there are specific differences, we’ll explain which to use. ### Troubleshooting diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index 7efd5726e0..600401d4d8 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -16,11 +16,11 @@ prints the text `Hello, world!` to the screen, so we’ll do the same here! You’ll start by making a directory to store your Rust code. It doesn’t matter to Rust where your code lives, but for the exercises and projects in this book, -we suggest making a *projects* directory in your home directory and keeping all +we suggest making a _projects_ directory in your home directory and keeping all your projects there. -Open a terminal and enter the following commands to make a *projects* directory -and a directory for the “Hello, world!” project within the *projects* directory. +Open a terminal and enter the following commands to make a _projects_ directory +and a directory for the “Hello, world!” project within the _projects_ directory. For Linux, macOS, and PowerShell on Windows, enter this: @@ -42,12 +42,12 @@ For Windows CMD, enter this: ### Writing and Running a Rust Program -Next, make a new source file and call it *main.rs*. Rust files always end with -the *.rs* extension. If you’re using more than one word in your filename, the +Next, make a new source file and call it _main.rs_. Rust files always end with +the _.rs_ extension. If you’re using more than one word in your filename, the convention is to use an underscore to separate them. For example, use -*hello_world.rs* rather than *helloworld.rs*. +_hello_world.rs_ rather than _helloworld.rs_. -Now open the *main.rs* file you just created and enter the code in Listing 1-1. +Now open the _main.rs_ file you just created and enter the code in Listing 1-1. @@ -60,7 +60,7 @@ fn main() { Save the file and go back to your terminal window in the -*~/projects/hello_world* directory. On Linux or macOS, enter the following +_~/projects/hello_world_ directory. On Linux or macOS, enter the following commands to compile and run the file: ```console @@ -115,7 +115,7 @@ line as the function declaration, adding one space in between. The body of the `main` function holds the following code: ```rust - println!("Hello, world!"); +println!("Hello, world!"); ``` This line does all the work in this little program: it prints text to the @@ -171,24 +171,24 @@ main.pdb main.rs ``` -This shows the source code file with the *.rs* extension, the executable file -(*main.exe* on Windows, but *main* on all other platforms), and, when using -Windows, a file containing debugging information with the *.pdb* extension. -From here, you run the *main* or *main.exe* file, like this: +This shows the source code file with the _.rs_ extension, the executable file +(_main.exe_ on Windows, but _main_ on all other platforms), and, when using +Windows, a file containing debugging information with the _.pdb_ extension. +From here, you run the _main_ or _main.exe_ file, like this: ```console $ ./main # or .\main.exe on Windows ``` -If your *main.rs* is your “Hello, world!” program, this line prints `Hello, +If your _main.rs_ is your “Hello, world!” program, this line prints `Hello, world!` to your terminal. If you’re more familiar with a dynamic language, such as Ruby, Python, or JavaScript, you might not be used to compiling and running a program as -separate steps. Rust is an *ahead-of-time compiled* language, meaning you can +separate steps. Rust is an _ahead-of-time compiled_ language, meaning you can compile a program and give the executable to someone else, and they can run it -even without having Rust installed. If you give someone a *.rb*, *.py*, or -*.js* file, they need to have a Ruby, Python, or JavaScript implementation +even without having Rust installed. If you give someone a _.rb_, _.py_, or +_.js_ file, they need to have a Ruby, Python, or JavaScript implementation installed (respectively). But in those languages, you only need one command to compile and run your program. Everything is a trade-off in language design. diff --git a/src/ch01-03-hello-cargo.md b/src/ch01-03-hello-cargo.md index dea721d38c..048ee864c5 100644 --- a/src/ch01-03-hello-cargo.md +++ b/src/ch01-03-hello-cargo.md @@ -4,7 +4,7 @@ Cargo is Rust’s build system and package manager. Most Rustaceans use this too to manage their Rust projects because Cargo handles a lot of tasks for you, such as building your code, downloading the libraries your code depends on, and building those libraries. (We call the libraries that your code needs -*dependencies*.) +_dependencies_.) The simplest Rust programs, like the one we’ve written so far, don’t have any dependencies. If we had built the “Hello, world!” project with Cargo, it would @@ -30,7 +30,7 @@ determine how to install Cargo separately. ### Creating a Project with Cargo Let’s create a new project using Cargo and look at how it differs from our -original “Hello, world!” project. Navigate back to your *projects* directory +original “Hello, world!” project. Navigate back to your _projects_ directory (or wherever you decided to store your code). Then, on any operating system, run the following: @@ -39,15 +39,15 @@ $ cargo new hello_cargo $ cd hello_cargo ``` -The first command creates a new directory and project called *hello_cargo*. -We’ve named our project *hello_cargo*, and Cargo creates its files in a +The first command creates a new directory and project called _hello_cargo_. +We’ve named our project _hello_cargo_, and Cargo creates its files in a directory of the same name. -Go into the *hello_cargo* directory and list the files. You’ll see that Cargo -has generated two files and one directory for us: a *Cargo.toml* file and a -*src* directory with a *main.rs* file inside. +Go into the _hello_cargo_ directory and list the files. You’ll see that Cargo +has generated two files and one directory for us: a _Cargo.toml_ file and a +_src_ directory with a _main.rs_ file inside. -It has also initialized a new Git repository along with a *.gitignore* file. +It has also initialized a new Git repository along with a _.gitignore_ file. Git files won’t be generated if you run `cargo new` within an existing Git repository; you can override this behavior by using `cargo new --vcs=git`. @@ -55,7 +55,7 @@ repository; you can override this behavior by using `cargo new --vcs=git`. > use a different version control system or no version control system by using > the `--vcs` flag. Run `cargo new --help` to see the available options. -Open *Cargo.toml* in your text editor of choice. It should look similar to the +Open _Cargo.toml_ in your text editor of choice. It should look similar to the code in Listing 1-2. @@ -73,8 +73,8 @@ edition = "2021" -This file is in the [*TOML*][toml] (*Tom’s Obvious, Minimal -Language*) format, which is Cargo’s configuration format. +This file is in the [_TOML_][toml] (_Tom’s Obvious, Minimal +Language_) format, which is Cargo’s configuration format. The first line, `[package]`, is a section heading that indicates that the following statements are configuring a package. As we add more information to @@ -86,10 +86,10 @@ about the `edition` key in [Appendix E][appendix-e]. The last line, `[dependencies]`, is the start of a section for you to list any of your project’s dependencies. In Rust, packages of code are referred to as -*crates*. We won’t need any other crates for this project, but we will in the +_crates_. We won’t need any other crates for this project, but we will in the first project in Chapter 2, so we’ll use this dependencies section then. -Now open *src/main.rs* and take a look: +Now open _src/main.rs_ and take a look: Filename: src/main.rs @@ -101,10 +101,10 @@ fn main() { Cargo has generated a “Hello, world!” program for you, just like the one we wrote in Listing 1-1! So far, the differences between our project and the -project Cargo generated are that Cargo placed the code in the *src* directory -and we have a *Cargo.toml* configuration file in the top directory. +project Cargo generated are that Cargo placed the code in the _src_ directory +and we have a _Cargo.toml_ configuration file in the top directory. -Cargo expects your source files to live inside the *src* directory. The +Cargo expects your source files to live inside the _src_ directory. The top-level project directory is just for README files, license information, configuration files, and anything else not related to your code. Using Cargo helps you organize your projects. There’s a place for everything, and @@ -112,14 +112,14 @@ 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. One easy way to get that *Cargo.toml* file is to run `cargo init`, which +project code into the _src_ directory and create an appropriate _Cargo.toml_ +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 Now let’s look at what’s different when we build and run the “Hello, world!” -program with Cargo! From your *hello_cargo* directory, build your project by +program with Cargo! From your _hello_cargo_ directory, build your project by entering the following command: ```console @@ -128,10 +128,10 @@ $ cargo build Finished dev [unoptimized + debuginfo] target(s) in 2.85 secs ``` -This command creates an executable file in *target/debug/hello_cargo* (or -*target\debug\hello_cargo.exe* on Windows) rather than in your current +This command creates an executable file in _target/debug/hello_cargo_ (or +_target\debug\hello_cargo.exe_ on Windows) rather than in your current directory. Because the default build is a debug build, Cargo puts the binary in -a directory named *debug*. You can run the executable with this command: +a directory named _debug_. You can run the executable with this command: ```console $ ./target/debug/hello_cargo # or .\target\debug\hello_cargo.exe on Windows @@ -140,7 +140,7 @@ Hello, world! If all goes well, `Hello, world!` should print to the terminal. Running `cargo build` for the first time also causes Cargo to create a new file at the top -level: *Cargo.lock*. This file keeps track of the exact versions of +level: _Cargo.lock_. This file keeps track of the exact versions of dependencies in your project. This project doesn’t have dependencies, so the file is a bit sparse. You won’t ever need to change this file manually; Cargo manages its contents for you. @@ -193,13 +193,13 @@ ready to use the executable. Let’s recap what we’ve learned so far about Cargo: -* We can create a project using `cargo new`. -* We can build a project using `cargo build`. -* We can build and run a project in one step using `cargo run`. -* We can build a project without producing a binary to check for errors using +- We can create a project using `cargo new`. +- We can build a project using `cargo build`. +- We can build and run a project in one step using `cargo run`. +- We can build a project without producing a binary to check for errors using `cargo check`. -* Instead of saving the result of the build in the same directory as our code, - Cargo stores it in the *target/debug* directory. +- Instead of saving the result of the build in the same directory as our code, + Cargo stores it in the _target/debug_ directory. An additional advantage of using Cargo is that the commands are the same no matter which operating system you’re working on. So, at this point, we’ll no @@ -209,14 +209,14 @@ longer provide specific instructions for Linux and macOS versus Windows. When your project is finally ready for release, you can use `cargo build --release` to compile it with optimizations. This command will create an -executable in *target/release* instead of *target/debug*. The optimizations +executable in _target/release_ instead of _target/debug_. The optimizations make your Rust code run faster, but turning them on lengthens the time it takes for your program to compile. This is why there are two different profiles: one for development, when you want to rebuild quickly and often, and another for building the final program you’ll give to a user that won’t be rebuilt repeatedly and that will run as fast as possible. If you’re benchmarking your code’s running time, be sure to run `cargo build --release` and benchmark with -the executable in *target/release*. +the executable in _target/release_. ### Cargo as Convention @@ -243,11 +243,11 @@ For more information about Cargo, check out [its documentation][cargo]. You’re already off to a great start on your Rust journey! In this chapter, you’ve learned how to: -* Install the latest stable version of Rust using `rustup` -* Update to a newer Rust version -* Open locally installed documentation -* Write and run a “Hello, world!” program using `rustc` directly -* Create and run a new project using the conventions of Cargo +- Install the latest stable version of Rust using `rustup` +- Update to a newer Rust version +- Open locally installed documentation +- Write and run a “Hello, world!” program using `rustc` directly +- Create and run a new project using the conventions of Cargo This is a great time to build a more substantial program to get used to reading and writing Rust code. So, in Chapter 2, we’ll build a guessing game program. diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index b66a5c2819..e2e7054d83 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -15,7 +15,7 @@ correct, the game will print a congratulatory message and exit. ## Setting Up a New Project -To set up a new project, go to the *projects* directory that you created in +To set up a new project, go to the _projects_ directory that you created in Chapter 1 and make a new project using Cargo, like so: ```console @@ -27,7 +27,7 @@ The first command, `cargo new`, takes the name of the project (`guessing_game`) as the first argument. The second command changes to the new project’s directory. -Look at the generated *Cargo.toml* file: +Look at the generated _Cargo.toml_ file: + ### Handling Potential Failure with `Result` @@ -229,9 +230,9 @@ discuss what this line does. As mentioned earlier, `read_line` puts whatever the user enters into the string we pass to it, but it also returns a `Result` value. [`Result`][result] is an [*enumeration*][enums], often called an *enum*, +ignore --> is an [_enumeration_][enums], often called an _enum_, which is a type that can be in one of multiple possible states. We call each -possible state a *variant*. +possible state a _variant_. [Chapter 6][enums] will cover enums in more detail. The purpose of these `Result` types is to encode error-handling information. @@ -328,12 +329,12 @@ said functionality. ### Using a Crate to Get More Functionality Remember that a crate is a collection of Rust source code files. The project -we’ve been building is a *binary crate*, which is an executable. The `rand` -crate is a *library crate*, which contains code that is intended to be used in +we’ve been building is a _binary crate_, which is an executable. The `rand` +crate is a _library crate_, which contains code that is intended to be used in other programs and can’t be executed on its own. Cargo’s coordination of external crates is where Cargo really shines. Before we -can write code that uses `rand`, we need to modify the *Cargo.toml* file to +can write code that uses `rand`, we need to modify the _Cargo.toml_ file to include the `rand` crate as a dependency. Open that file now and add the following line to the bottom, beneath the `[dependencies]` section header that Cargo created for you. Be sure to specify `rand` exactly as we have here, with @@ -351,12 +352,12 @@ this version number, or the code examples in this tutorial may not work: {{#include ../listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml:8:}} ``` -In the *Cargo.toml* file, everything that follows a header is part of that +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 -Versioning][semver] (sometimes called *SemVer*), which is a +Versioning][semver] (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. @@ -411,7 +412,7 @@ code, thanks to SemVer!) and different lines (depending on the operating system), and the lines may be in a different order. When we include an external dependency, Cargo fetches the latest versions of -everything that dependency needs from the *registry*, which is a copy of data +everything that dependency needs from the _registry_, which is a copy of data from [Crates.io][cratesio]. Crates.io is where people in the Rust ecosystem post their open source Rust projects for others to use. @@ -424,11 +425,11 @@ them and then compiles the project with the dependencies available. If you immediately run `cargo build` again without making any changes, you won’t get any output aside from the `Finished` line. Cargo knows it has already downloaded and compiled the dependencies, and you haven’t changed anything -about them in your *Cargo.toml* file. Cargo also knows that you haven’t changed +about them in your _Cargo.toml_ file. Cargo also knows that you haven’t changed anything about your code, so it doesn’t recompile that either. With nothing to do, it simply exits. -If you open the *src/main.rs* file, make a trivial change, and then save it and +If you open the _src/main.rs_ file, make a trivial change, and then save it and build again, you’ll only see two lines of output: , but for now, know that this feature is @@ -852,7 +853,7 @@ match the first arm’s pattern, and the `match` expression will just return the `num` value that `parse` produced and put inside the `Ok` value. That number will end up right where we want it in the new `guess` variable we’re creating. -If `parse` is *not* able to turn the string into a number, it will return an +If `parse` is _not_ able to turn the string into a number, it will return an `Err` value that contains more information about the error. The `Err` value does not match the `Ok(num)` pattern in the first `match` arm, but it does match the `Err(_)` pattern in the second arm. The underscore, `_`, is a diff --git a/src/ch03-00-common-programming-concepts.md b/src/ch03-00-common-programming-concepts.md index 2e37fad02c..21ca8c58da 100644 --- a/src/ch03-00-common-programming-concepts.md +++ b/src/ch03-00-common-programming-concepts.md @@ -12,7 +12,7 @@ them early will give you a strong core to start from. > #### Keywords > -> The Rust language has a set of *keywords* that are reserved for use by the +> The Rust language has a set of _keywords_ that are reserved for use by the > language only, much as in other languages. Keep in mind that you cannot use > these words as names of variables or functions. Most of the keywords have > special meanings, and you’ll be using them to do various tasks in your Rust diff --git a/src/ch03-01-variables-and-mutability.md b/src/ch03-01-variables-and-mutability.md index 058f7bb5c4..e5d599c030 100644 --- a/src/ch03-01-variables-and-mutability.md +++ b/src/ch03-01-variables-and-mutability.md @@ -9,10 +9,10 @@ Let’s explore how and why Rust encourages you to favor immutability and why sometimes you might want to opt out. When a variable is immutable, once a value is bound to a name, you can’t change -that value. To illustrate this, generate a new project called *variables* in -your *projects* directory by using `cargo new variables`. +that value. To illustrate this, generate a new project called _variables_ in +your _projects_ directory by using `cargo new variables`. -Then, in your new *variables* directory, open *src/main.rs* and replace its +Then, in your new _variables_ directory, open _src/main.rs_ and replace its code with the following code, which won’t compile just yet: Filename: src/main.rs @@ -30,11 +30,10 @@ regarding an immutability error, as shown in this output: This example shows how the compiler helps you find errors in your programs. Compiler errors can be frustrating, but really they only mean your program -isn’t safely doing what you want it to do yet; they do *not* mean that you’re +isn’t safely doing what you want it to do yet; they do _not_ mean that you’re not a good programmer! Experienced Rustaceans still get compiler errors. -You received the error message `` cannot assign twice to immutable variable `x` -`` because you tried to assign a second value to the immutable `x` variable. +You received the error message `` cannot assign twice to immutable variable `x` `` because you tried to assign a second value to the immutable `x` variable. It’s important that we get compile-time errors when we attempt to change a value that’s designated as immutable because this very situation can lead to @@ -42,7 +41,7 @@ bugs. If one part of our code operates on the assumption that a value will never change and another part of our code changes that value, it’s possible that the first part of the code won’t do what it was designed to do. The cause of this kind of bug can be difficult to track down after the fact, especially -when the second piece of code changes the value only *sometimes*. The Rust +when the second piece of code changes the value only _sometimes_. The Rust compiler guarantees that when you state that a value won’t change, it really won’t change, so you don’t have to keep track of it yourself. Your code is thus easier to reason through. @@ -54,7 +53,7 @@ adding `mut` in front of the variable name as you did in [Chapter intent to future readers of the code by indicating that other parts of the code will be changing this variable’s value. -For example, let’s change *src/main.rs* to the following: +For example, let’s change _src/main.rs_ to the following: Filename: src/main.rs @@ -74,13 +73,13 @@ depends on what you think is clearest in that particular situation. ### Constants -Like immutable variables, *constants* are values that are bound to a name and +Like immutable variables, _constants_ are values that are bound to a name and are not allowed to change, but there are a few differences between constants and variables. First, you aren’t allowed to use `mut` with constants. Constants aren’t just immutable by default—they’re always immutable. You declare constants using the -`const` keyword instead of the `let` keyword, and the type of the value *must* +`const` keyword instead of the `let` keyword, and the type of the value _must_ be annotated. We’ll cover types and type annotations in the next section, [“Data Types”][data-types], so don’t worry about the details right now. Just know that you must always annotate the type. @@ -124,7 +123,7 @@ hardcoded value needed to be updated in the future. As you saw in the guessing game tutorial in [Chapter 2][comparing-the-guess-to-the-secret-number], you can declare a new variable with the same name as a previous variable. Rustaceans say that the -first variable is *shadowed* by the second, which means that the second +first variable is _shadowed_ by the second, which means that the second variable is what the compiler will see when you use the name of the variable. In effect, the second variable overshadows the first, taking any uses of the variable name to itself until either it itself is shadowed or the scope ends. @@ -184,8 +183,7 @@ The error says we’re not allowed to mutate a variable’s type: Now that we’ve explored how variables work, let’s look at more data types they can have. -[comparing-the-guess-to-the-secret-number]: -ch02-00-guessing-game-tutorial.html#comparing-the-guess-to-the-secret-number +[comparing-the-guess-to-the-secret-number]: ch02-00-guessing-game-tutorial.html#comparing-the-guess-to-the-secret-number [data-types]: ch03-02-data-types.html#data-types [storing-values-with-variables]: ch02-00-guessing-game-tutorial.html#storing-values-with-variables [const-eval]: ../reference/const_eval.html diff --git a/src/ch03-02-data-types.md b/src/ch03-02-data-types.md index 881319dbcc..e6d88fbb1d 100644 --- a/src/ch03-02-data-types.md +++ b/src/ch03-02-data-types.md @@ -1,10 +1,10 @@ ## Data Types -Every value in Rust is of a certain *data type*, which tells Rust what kind of +Every value in Rust is of a certain _data type_, which tells Rust what kind of data is being specified so it knows how to work with that data. We’ll look at two data type subsets: scalar and compound. -Keep in mind that Rust is a *statically typed* language, which means that it +Keep in mind that Rust is a _statically typed_ language, which means that it must know the types of all variables at compile time. The compiler can usually infer what type we want to use based on the value and how we use it. In cases when many types are possible, such as when we converted a `String` to a numeric @@ -28,13 +28,13 @@ You’ll see different type annotations for other data types. ### Scalar Types -A *scalar* type represents a single value. Rust has four primary scalar types: +A _scalar_ type represents a single value. Rust has four primary scalar types: integers, floating-point numbers, Booleans, and characters. You may recognize these from other programming languages. Let’s jump into how they work in Rust. #### Integer Types -An *integer* is a number without a fractional component. We used one integer +An _integer_ is a number without a fractional component. We used one integer type in Chapter 2, the `u32` type. This type declaration indicates that the value it’s associated with should be an unsigned integer (signed integer types start with `i` instead of `u`) that takes up 32 bits of space. Table 3-1 shows @@ -44,7 +44,7 @@ the type of an integer value. Table 3-1: Integer Types in Rust | Length | Signed | Unsigned | -|---------|---------|----------| +| ------- | ------- | -------- | | 8-bit | `i8` | `u8` | | 16-bit | `i16` | `u16` | | 32-bit | `i32` | `u32` | @@ -53,7 +53,7 @@ the type of an integer value. | arch | `isize` | `usize` | Each variant can be either signed or unsigned and has an explicit size. -*Signed* and *unsigned* refer to whether it’s possible for the number to be +_Signed_ and _unsigned_ refer to whether it’s possible for the number to be negative—in other words, whether the number needs to have a sign with it (signed) or whether it will only ever be positive and can therefore be represented without a sign (unsigned). It’s like writing numbers on paper: when @@ -63,7 +63,7 @@ Signed numbers are stored using [two’s complement][twos-complement] representation. Each signed variant can store numbers from -(2n - 1) to 2n - -1 - 1 inclusive, where *n* is the number of bits that variant uses. So an +1 - 1 inclusive, where _n_ is the number of bits that variant uses. So an `i8` can store numbers from -(27) to 27 - 1, which equals -128 to 127. Unsigned variants can store numbers from 0 to 2n - 1, so a `u8` can store numbers from 0 to 28 - 1, which equals 0 to 255. @@ -82,7 +82,7 @@ have the same value as if you had specified `1000`. Table 3-2: Integer Literals in Rust | Number literals | Example | -|------------------|---------------| +| ---------------- | ------------- | | Decimal | `98_222` | | Hex | `0xff` | | Octal | `0o77` | @@ -98,17 +98,17 @@ some sort of collection. > > Let’s say you have a variable of type `u8` that can hold values between 0 and > 255. If you try to change the variable to a value outside that range, such as -> 256, *integer overflow* will occur, which can result in one of two behaviors. +> 256, _integer overflow_ will occur, which can result in one of two behaviors. > When you’re compiling in debug mode, Rust includes checks for integer overflow -> that cause your program to *panic* at runtime if this behavior occurs. Rust -> uses the term *panicking* when a program exits with an error; we’ll discuss +> that cause your program to _panic_ at runtime if this behavior occurs. Rust +> uses the term _panicking_ when a program exits with an error; we’ll discuss > panics in more depth in the [“Unrecoverable Errors with > `panic!`”][unrecoverable-errors-with-panic] section in Chapter > 9. > > When you’re compiling in release mode with the `--release` flag, Rust does -> *not* include checks for integer overflow that cause panics. Instead, if -> overflow occurs, Rust performs *two’s complement wrapping*. In short, values +> _not_ include checks for integer overflow that cause panics. Instead, if +> overflow occurs, Rust performs _two’s complement wrapping_. In short, values > greater than the maximum value the type can hold “wrap around” to the minimum > of the values the type can hold. In the case of a `u8`, the value 256 becomes > 0, the value 257 becomes 1, and so on. The program won’t panic, but the @@ -118,16 +118,16 @@ some sort of collection. > To explicitly handle the possibility of overflow, you can use these families > of methods provided by the standard library for primitive numeric types: > -> * Wrap in all modes with the `wrapping_*` methods, such as `wrapping_add`. -> * Return the `None` value if there is overflow with the `checked_*` methods. -> * Return the value and a boolean indicating whether there was overflow with +> - Wrap in all modes with the `wrapping_*` methods, such as `wrapping_add`. +> - Return the `None` value if there is overflow with the `checked_*` methods. +> - Return the value and a boolean indicating whether there was overflow with > the `overflowing_*` methods. -> * Saturate at the value’s minimum or maximum values with the `saturating_*` +> - Saturate at the value’s minimum or maximum values with the `saturating_*` > methods. #### Floating-Point Types -Rust also has two primitive types for *floating-point numbers*, which are +Rust also has two primitive types for _floating-point numbers_, which are numbers with decimal points. Rust’s floating-point types are `f32` and `f64`, which are 32 bits and 64 bits in size, respectively. The default type is `f64` because on modern CPUs, it’s roughly the same speed as `f32` but is capable of @@ -201,12 +201,12 @@ Strings”][strings] in Chapter 8. ### Compound Types -*Compound types* can group multiple values into one type. Rust has two +_Compound types_ can group multiple values into one type. Rust has two primitive compound types: tuples and arrays. #### The Tuple Type -A *tuple* is a general way of grouping together a number of values with a +A _tuple_ is a general way of grouping together a number of values with a variety of types into one compound type. Tuples have a fixed length: once declared, they cannot grow or shrink in size. @@ -233,7 +233,7 @@ use pattern matching to destructure a tuple value, like this: This program first creates a tuple and binds it to the variable `tup`. It then uses a pattern with `let` to take `tup` and turn it into three separate -variables, `x`, `y`, and `z`. This is called *destructuring* because it breaks +variables, `x`, `y`, and `z`. This is called _destructuring_ because it breaks the single tuple into three parts. Finally, the program prints the value of `y`, which is `6.4`. @@ -250,14 +250,14 @@ This program creates the tuple `x` and then accesses each element of the tuple using their respective indices. As with most programming languages, the first index in a tuple is 0. -The tuple without any values has a special name, *unit*. This value and its +The tuple without any values has a special name, _unit_. This value and its corresponding type are both written `()` and represent an empty value or an empty return type. Expressions implicitly return the unit value if they don’t return any other value. #### The Array Type -Another way to have a collection of multiple values is with an *array*. Unlike +Another way to have a collection of multiple values is with an _array_. Unlike a tuple, every element of an array must have the same type. Unlike arrays in some other languages, arrays in Rust have a fixed length. @@ -274,8 +274,8 @@ Arrays are useful when you want your data allocated on the stack, the same as the other types we have seen so far, rather than the heap (we will discuss the stack and the heap more in [Chapter 4][stack-and-heap]) or when you want to ensure you always have a fixed number of elements. An array isn’t as -flexible as the vector type, though. A *vector* is a similar collection type -provided by the standard library that *is* allowed to grow or shrink in size. If +flexible as the vector type, though. A _vector_ is a similar collection type +provided by the standard library that _is_ allowed to grow or shrink in size. If you’re unsure whether to use an array or a vector, chances are you should use a vector. [Chapter 8][vectors] discusses vectors in more detail. @@ -356,7 +356,7 @@ index out of bounds: the len is 5 but the index is 10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` -The program resulted in a *runtime* error at the point of using an invalid +The program resulted in a _runtime_ error at the point of using an invalid value in the indexing operation. The program exited with an error message and didn’t execute the final `println!` statement. When you attempt to access an element using indexing, Rust will check that the index you’ve specified is less @@ -372,8 +372,7 @@ kind of error by immediately exiting instead of allowing the memory access and continuing. Chapter 9 discusses more of Rust’s error handling and how you can write readable, safe code that neither panics nor allows invalid memory access. -[comparing-the-guess-to-the-secret-number]: -ch02-00-guessing-game-tutorial.html#comparing-the-guess-to-the-secret-number +[comparing-the-guess-to-the-secret-number]: ch02-00-guessing-game-tutorial.html#comparing-the-guess-to-the-secret-number [twos-complement]: https://en.wikipedia.org/wiki/Two%27s_complement [control-flow]: ch03-05-control-flow.html#control-flow [strings]: ch08-02-strings.html#storing-utf-8-encoded-text-with-strings diff --git a/src/ch03-03-how-functions-work.md b/src/ch03-03-how-functions-work.md index bb8c73a62f..8442825ab1 100644 --- a/src/ch03-03-how-functions-work.md +++ b/src/ch03-03-how-functions-work.md @@ -5,7 +5,7 @@ important functions in the language: the `main` function, which is the entry point of many programs. You’ve also seen the `fn` keyword, which allows you to declare new functions. -Rust code uses *snake case* as the conventional style for function and variable +Rust code uses _snake case_ as the conventional style for function and variable names, in which all letters are lowercase and underscores separate words. Here’s a program that contains an example function definition: @@ -22,12 +22,12 @@ body begins and ends. We can call any function we’ve defined by entering its name followed by a set of parentheses. Because `another_function` is defined in the program, it can be called from inside the `main` function. Note that we defined `another_function` -*after* the `main` function in the source code; we could have defined it before +_after_ the `main` function in the source code; we could have defined it before as well. Rust doesn’t care where you define your functions, only that they’re defined somewhere in a scope that can be seen by the caller. -Let’s start a new binary project named *functions* to explore functions -further. Place the `another_function` example in *src/main.rs* and run it. You +Let’s start a new binary project named _functions_ to explore functions +further. Place the `another_function` example in _src/main.rs_ and run it. You should see the following output: ```console @@ -40,11 +40,11 @@ and its message is printed. ### Parameters -We can define functions to have *parameters*, which are special variables that +We can define functions to have _parameters_, which are special variables that are part of a function’s signature. When a function has parameters, you can provide it with concrete values for those parameters. Technically, the concrete -values are called *arguments*, but in casual conversation, people tend to use -the words *parameter* and *argument* interchangeably for either the variables +values are called _arguments_, but in casual conversation, people tend to use +the words _parameter_ and _argument_ interchangeably for either the variables in a function’s definition or the concrete values passed in when you call a function. @@ -67,7 +67,7 @@ The declaration of `another_function` has one parameter named `x`. The type of `println!` macro puts `5` where the pair of curly brackets containing `x` was in the format string. -In function signatures, you *must* declare the type of each parameter. This is +In function signatures, you _must_ declare the type of each parameter. This is a deliberate decision in Rust’s design: requiring type annotations in function definitions means the compiler almost never needs you to use them elsewhere in the code to figure out what type you mean. The compiler is also able to give @@ -87,8 +87,8 @@ parameters. The first parameter is named `value` and is an `i32`. The second is named `unit_label` and is type `char`. The function then prints text containing both the `value` and the `unit_label`. -Let’s try running this code. Replace the program currently in your *functions* -project’s *src/main.rs* file with the preceding example and run it using `cargo +Let’s try running this code. Replace the program currently in your _functions_ +project’s _src/main.rs_ file with the preceding example and run it using `cargo run`: ```console @@ -108,9 +108,9 @@ understand. Other languages don’t have the same distinctions, so let’s look what statements and expressions are and how their differences affect the bodies of functions. -* **Statements** are instructions that perform some action and do not return +- **Statements** are instructions that perform some action and do not return a value. -* **Expressions** evaluate to a resultant value. Let’s look at some examples. +- **Expressions** evaluate to a resultant value. Let’s look at some examples. We’ve actually already used statements and expressions. Creating a variable and assigning a value to it with the `let` keyword is a statement. In Listing 3-1, @@ -125,7 +125,7 @@ assigning a value to it with the `let` keyword is a statement. In Listing 3-1, Function definitions are also statements; the entire preceding example is a -statement in itself. (As we will see below, *calling* a function is not a +statement in itself. (As we will see below, _calling_ a function is not a statement.) Statements do not return values. Therefore, you can’t assign a `let` statement diff --git a/src/ch03-04-comments.md b/src/ch03-04-comments.md index bfb0cfe177..01978d605f 100644 --- a/src/ch03-04-comments.md +++ b/src/ch03-04-comments.md @@ -1,7 +1,7 @@ ## Comments All programmers strive to make their code easy to understand, but sometimes -extra explanation is warranted. In these cases, programmers leave *comments* in +extra explanation is warranted. In these cases, programmers leave _comments_ in their source code that the compiler will ignore but people reading the source code may find useful. diff --git a/src/ch03-05-control-flow.md b/src/ch03-05-control-flow.md index be93b275e9..ac89726fde 100644 --- a/src/ch03-05-control-flow.md +++ b/src/ch03-05-control-flow.md @@ -11,8 +11,8 @@ An `if` expression allows you to branch your code depending on conditions. You provide a condition and then state, “If this condition is met, run this block of code. If the condition is not met, do not run this block of code.” -Create a new project called *branches* in your *projects* directory to explore -the `if` expression. In the *src/main.rs* file, input the following: +Create a new project called _branches_ in your _projects_ directory to explore +the `if` expression. In the _src/main.rs_ file, input the following: Filename: src/main.rs @@ -24,7 +24,7 @@ All `if` expressions start with the keyword `if`, followed by a condition. In this case, the condition checks whether or not the variable `number` has a value less than 5. We place the block of code to execute if the condition is `true` immediately after the condition inside curly brackets. Blocks of code -associated with the conditions in `if` expressions are sometimes called *arms*, +associated with the conditions in `if` expressions are sometimes called _arms_, just like the arms in `match` expressions that we discussed in the [“Comparing the Guess to the Secret Number”][comparing-the-guess-to-the-secret-number] section of Chapter 2. @@ -54,7 +54,7 @@ Run the program again, and look at the output: {{#include ../listings/ch03-common-programming-concepts/no-listing-27-if-false/output.txt}} ``` -It’s also worth noting that the condition in this code *must* be a `bool`. If +It’s also worth noting that the condition in this code _must_ be a `bool`. If the condition isn’t a `bool`, we’ll get an error. For example, try running the following code: @@ -169,9 +169,9 @@ if it had to keep track of multiple hypothetical types for any variable. ### Repetition with Loops It’s often useful to execute a block of code more than once. For this task, -Rust provides several *loops*, which will run through the code inside the loop +Rust provides several _loops_, which will run through the code inside the loop body to the end and then start immediately back at the beginning. To experiment -with loops, let’s make a new project called *loops*. +with loops, let’s make a new project called _loops_. Rust has three kinds of loops: `loop`, `while`, and `for`. Let’s try each one. @@ -180,7 +180,7 @@ Rust has three kinds of loops: `loop`, `while`, and `for`. Let’s try each one. The `loop` keyword tells Rust to execute a block of code over and over again forever or until you explicitly tell it to stop. -As an example, change the *src/main.rs* file in your *loops* directory to look +As an example, change the _src/main.rs_ file in your _loops_ directory to look like this: Filename: src/main.rs @@ -254,7 +254,7 @@ loop, `return` always exits the current function. #### Loop Labels to Disambiguate Between Multiple Loops If you have loops within loops, `break` and `continue` apply to the innermost -loop at that point. You can optionally specify a *loop label* on a loop that +loop at that point. You can optionally specify a _loop label_ on a loop that you can then use with `break` or `continue` to specify that those keywords apply to the labeled loop instead of the innermost loop. Loop labels must begin with a single quote. Here’s an example with two nested loops: @@ -375,15 +375,13 @@ and compound data types, functions, comments, `if` expressions, and loops! To practice with the concepts discussed in this chapter, try building programs to do the following: -* Convert temperatures between Fahrenheit and Celsius. -* Generate the *n*th Fibonacci number. -* Print the lyrics to the Christmas carol “The Twelve Days of Christmas,” +- Convert temperatures between Fahrenheit and Celsius. +- Generate the *n*th Fibonacci number. +- Print the lyrics to the Christmas carol “The Twelve Days of Christmas,” taking advantage of the repetition in the song. -When you’re ready to move on, we’ll talk about a concept in Rust that *doesn’t* +When you’re ready to move on, we’ll talk about a concept in Rust that _doesn’t_ commonly exist in other programming languages: ownership. -[comparing-the-guess-to-the-secret-number]: -ch02-00-guessing-game-tutorial.html#comparing-the-guess-to-the-secret-number -[quitting-after-a-correct-guess]: -ch02-00-guessing-game-tutorial.html#quitting-after-a-correct-guess +[comparing-the-guess-to-the-secret-number]: ch02-00-guessing-game-tutorial.html#comparing-the-guess-to-the-secret-number +[quitting-after-a-correct-guess]: ch02-00-guessing-game-tutorial.html#quitting-after-a-correct-guess diff --git a/src/ch04-01-what-is-ownership.md b/src/ch04-01-what-is-ownership.md index 5ef7b5f97f..60d4cb4ea9 100644 --- a/src/ch04-01-what-is-ownership.md +++ b/src/ch04-01-what-is-ownership.md @@ -1,6 +1,6 @@ ## What Is Ownership? -*Ownership* is a set of rules that govern how a Rust program manages memory. +_Ownership_ is a set of rules that govern how a Rust program manages memory. All programs have to manage the way they use a computer’s memory while running. Some languages have garbage collection that regularly looks for no-longer-used memory as the program runs; in other languages, the programmer must explicitly @@ -31,20 +31,20 @@ strings. > Both the stack and the heap are parts of memory available to your code to use > at runtime, but they are structured in different ways. The stack stores > values in the order it gets them and removes the values in the opposite -> order. This is referred to as *last in, first out*. Think of a stack of +> order. This is referred to as _last in, first out_. Think of a stack of > plates: when you add more plates, you put them on top of the pile, and when > you need a plate, you take one off the top. Adding or removing plates from -> the middle or bottom wouldn’t work as well! Adding data is called *pushing -> onto the stack*, and removing data is called *popping off the stack*. All +> the middle or bottom wouldn’t work as well! Adding data is called _pushing +> onto the stack_, and removing data is called _popping off the stack_. All > data stored on the stack must have a known, fixed size. Data with an unknown > size at compile time or a size that might change must be stored on the heap > instead. > > The heap is less organized: when you put data on the heap, you request a > certain amount of space. The memory allocator finds an empty spot in the heap -> that is big enough, marks it as being in use, and returns a *pointer*, which -> is the address of that location. This process is called *allocating on the -> heap* and is sometimes abbreviated as just *allocating* (pushing values onto +> that is big enough, marks it as being in use, and returns a _pointer_, which +> is the address of that location. This process is called _allocating on the +> heap_ and is sometimes abbreviated as just _allocating_ (pushing values onto > the stack is not considered allocating). Because the pointer to the heap is a > known, fixed size, you can store the pointer on the stack, but when you want > the actual data, you must follow the pointer. Think of being seated at a @@ -88,9 +88,9 @@ strings. First, let’s take a look at the ownership rules. Keep these rules in mind as we work through the examples that illustrate them: -* Each value in Rust has an *owner*. -* There can only be one owner at a time. -* When the owner goes out of scope, the value will be dropped. +- Each value in Rust has an _owner_. +- There can only be one owner at a time. +- When the owner goes out of scope, the value will be dropped. ### Variable Scope @@ -100,7 +100,7 @@ examples inside a `main` function manually. As a result, our examples will be a bit more concise, letting us focus on the actual details rather than boilerplate code. -As a first example of ownership, we’ll look at the *scope* of some variables. A +As a first example of ownership, we’ll look at the _scope_ of some variables. A scope is the range within a program for which an item is valid. Take the following variable: @@ -110,7 +110,7 @@ let s = "hello"; The variable `s` refers to a string literal, where the value of the string is hardcoded into the text of our program. The variable is valid from the point at -which it’s declared until the end of the current *scope*. Listing 4-1 shows a +which it’s declared until the end of the current _scope_. Listing 4-1 shows a program with comments annotating where the variable `s` would be valid. @@ -123,8 +123,8 @@ program with comments annotating where the variable `s` would be valid. In other words, there are two important points in time here: -* When `s` comes *into* scope, it is valid. -* It remains valid until it goes *out of* scope. +- When `s` comes _into_ scope, it is valid. +- It remains valid until it goes _out of_ scope. At this point, the relationship between scopes and when variables are valid is similar to that in other programming languages. Now we’ll build on top of this @@ -167,7 +167,7 @@ Syntax”][method-syntax] section of Chapter 5, and when we talk about namespacing with modules in [“Paths for Referring to an Item in the Module Tree”][paths-module-tree] in Chapter 7. -This kind of string *can* be mutated: +This kind of string _can_ be mutated: ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-01-can-mutate-string/src/main.rs:here}} @@ -189,16 +189,16 @@ With the `String` type, in order to support a mutable, growable piece of text, we need to allocate an amount of memory on the heap, unknown at compile time, to hold the contents. This means: -* The memory must be requested from the memory allocator at runtime. -* We need a way of returning this memory to the allocator when we’re done with +- The memory must be requested from the memory allocator at runtime. +- We need a way of returning this memory to the allocator when we’re done with our `String`. That first part is done by us: when we call `String::from`, its implementation requests the memory it needs. This is pretty much universal in programming languages. -However, the second part is different. In languages with a *garbage collector -(GC)*, the GC keeps track of and cleans up memory that isn’t being used +However, the second part is different. In languages with a _garbage collector +(GC)_, the GC keeps track of and cleans up memory that isn’t being used anymore, and we don’t need to think about it. In most languages without a GC, it’s our responsibility to identify when memory is no longer being used and to call code to explicitly free it, just as we did to request it. Doing this @@ -223,7 +223,7 @@ the code to return the memory. Rust calls `drop` automatically at the closing curly bracket. > Note: In C++, this pattern of deallocating resources at the end of an item’s -> lifetime is sometimes called *Resource Acquisition Is Initialization (RAII)*. +> lifetime is sometimes called _Resource Acquisition Is Initialization (RAII)_. > The `drop` function in Rust will be familiar to you if you’ve used RAII > patterns. @@ -233,6 +233,7 @@ complicated situations when we want to have multiple variables use the data we’ve allocated on the heap. Let’s explore some of those situations now. + #### Variables and Data Interacting with Move @@ -297,7 +298,7 @@ src="img/trpl04-02.svg" class="center" style="width: 50%;" /> Figure 4-2: Representation in memory of the variable `s2` that has a copy of the pointer, length, and capacity of `s1` -The representation does *not* look like Figure 4-3, which is what memory would +The representation does _not_ look like Figure 4-3, which is what memory would look like if Rust instead copied the heap data as well. If Rust did this, the operation `s2 = s1` could be very expensive in terms of runtime performance if the data on the heap were large. @@ -313,7 +314,7 @@ Earlier, we said that when a variable goes out of scope, Rust automatically calls the `drop` function and cleans up the heap memory for that variable. But Figure 4-2 shows both data pointers pointing to the same location. This is a problem: when `s2` and `s1` go out of scope, they will both try to free the -same memory. This is known as a *double free* error and is one of the memory +same memory. This is known as a _double free_ error and is one of the memory safety bugs we mentioned previously. Freeing memory twice can lead to memory corruption, which can potentially lead to security vulnerabilities. @@ -333,12 +334,12 @@ invalidated reference: {{#include ../listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt}} ``` -If you’ve heard the terms *shallow copy* and *deep copy* while working with +If you’ve heard the terms _shallow copy_ and _deep copy_ while working with other languages, the concept of copying the pointer, length, and capacity without copying the data probably sounds like making a shallow copy. But because Rust also invalidates the first variable, instead of being called a -shallow copy, it’s known as a *move*. In this example, we would say that `s1` -was *moved* into `s2`. So, what actually happens is shown in Figure 4-4. +shallow copy, it’s known as a _move_. In this example, we would say that `s1` +was _moved_ into `s2`. So, what actually happens is shown in Figure 4-4. Three tables: tables s1 and s2 representing those strings on the
 stack, respectively, and both pointing to the same string data on the heap.
@@ -353,7 +354,7 @@ That solves our problem! With only `s2` valid, when it goes out of scope it
 alone will free the memory, and we’re done.
 
 In addition, there’s a design choice that’s implied by this: Rust will never
-automatically create “deep” copies of your data. Therefore, any *automatic*
+automatically create “deep” copies of your data. Therefore, any _automatic_
 copying can be assumed to be inexpensive in terms of runtime performance.
 
 #### Scope and Assignment
@@ -388,11 +389,12 @@ function on it and its memory will be freed right away. When we print the value
 at the end, it will be ` + #### Variables and Data Interacting with Clone -If we *do* want to deeply copy the heap data of the `String`, not just the +If we _do_ want to deeply copy the heap data of the `String`, not just the stack data, we can use a common method called `clone`. We’ll discuss method syntax in Chapter 5, but because methods are a common feature in many programming languages, you’ve probably seen them before. @@ -404,7 +406,7 @@ Here’s an example of the `clone` method in action: ``` This works just fine and explicitly produces the behavior shown in Figure 4-3, -where the heap data *does* get copied. +where the heap data _does_ get copied. When you see a call to `clone`, you know that some arbitrary code is being executed and that code may be expensive. It’s a visual indicator that something @@ -448,11 +450,11 @@ values can implement `Copy`, and nothing that requires allocation or is some form of resource can implement `Copy`. Here are some of the types that implement `Copy`: -* All the integer types, such as `u32`. -* The Boolean type, `bool`, with values `true` and `false`. -* All the floating-point types, such as `f64`. -* The character type, `char`. -* Tuples, if they only contain types that also implement `Copy`. For example, +- All the integer types, such as `u32`. +- The Boolean type, `bool`, with values `true` and `false`. +- All the floating-point types, such as `f64`. +- The character type, `char`. +- Tuples, if they only contain types that also implement `Copy`. For example, `(i32, i32)` implements `Copy`, but `(i32, String)` does not. ### Ownership and Functions @@ -512,7 +514,7 @@ Rust does let us return multiple values using a tuple, as shown in Listing 4-5. But this is too much ceremony and a lot of work for a concept that should be common. Luckily for us, Rust has a feature for using a value without -transferring ownership, called *references*. +transferring ownership, called _references_. [data-types]: ch03-02-data-types.html#data-types [ch8]: ch08-02-strings.html diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 055001571a..cb4d172e85 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -4,7 +4,7 @@ The issue with the tuple code in Listing 4-5 is that we have to return the `String` to the calling function so we can still use the `String` after the call to `calculate_length`, because the `String` was moved into `calculate_length`. Instead, we can provide a reference to the `String` value. -A *reference* is like a pointer in that it’s an address we can follow to access +A _reference_ is like a pointer in that it’s an address we can follow to access the data stored at that address; that data is owned by some other variable. Unlike a pointer, a reference is guaranteed to point to a valid value of a particular type for the life of that reference. @@ -23,7 +23,7 @@ reference to an object as a parameter instead of taking ownership of the value: First, notice that all the tuple code in the variable declaration and the function return value is gone. Second, note that we pass `&s1` into `calculate_length` and, in its definition, we take `&String` rather than -`String`. These ampersands represent *references*, and they allow you to refer +`String`. These ampersands represent _references_, and they allow you to refer to some value without taking ownership of it. Figure 4-6 depicts this concept. Three tables: the table for s contains only a pointer to the table
@@ -33,7 +33,7 @@ string data on the heap. Figure 4-6: A diagram of `&String s` pointing at `String s1` -> Note: The opposite of referencing by using `&` is *dereferencing*, which is +> Note: The opposite of referencing by using `&` is _dereferencing_, which is > accomplished with the dereference operator, `*`. We’ll see some uses of the > dereference operator in Chapter 8 and discuss details of dereferencing in > Chapter 15. @@ -44,7 +44,7 @@ Let’s take a closer look at the function call here: {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs:here}} ``` -The `&s1` syntax lets us create a reference that *refers* to the value of `s1` +The `&s1` syntax lets us create a reference that _refers_ to the value of `s1` but does not own it. Because it does not own it, the value it points to will not be dropped when the reference stops being used. @@ -62,7 +62,7 @@ have references as parameters instead of the actual values, we won’t need to return the values in order to give back ownership, because we never had ownership. -We call the action of creating a reference *borrowing*. As in real life, if a +We call the action of creating a reference _borrowing_. As in real life, if a person owns something, you can borrow it from them. When you’re done, you have to give it back. You don’t own it. @@ -89,7 +89,7 @@ allowed to modify something we have a reference to. ### Mutable References We can fix the code from Listing 4-6 to allow us to modify a borrowed value -with just a few small tweaks that use, instead, a *mutable reference*: +with just a few small tweaks that use, instead, a _mutable reference_: @@ -132,19 +132,19 @@ The restriction preventing multiple mutable references to the same data at the same time allows for mutation but in a very controlled fashion. It’s something that new Rustaceans struggle with because most languages let you mutate whenever you’d like. The benefit of having this restriction is that Rust can -prevent data races at compile time. A *data race* is similar to a race +prevent data races at compile time. A _data race_ is similar to a race condition and happens when these three behaviors occur: -* Two or more pointers access the same data at the same time. -* At least one of the pointers is being used to write to the data. -* There’s no mechanism being used to synchronize access to the data. +- Two or more pointers access the same data at the same time. +- At least one of the pointers is being used to write to the data. +- There’s no mechanism being used to synchronize access to the data. Data races cause undefined behavior and can be difficult to diagnose and fix when you’re trying to track them down at runtime; Rust prevents this problem by refusing to compile code with data races! As always, we can use curly brackets to create a new scope, allowing for -multiple mutable references, just not *simultaneous* ones: +multiple mutable references, just not _simultaneous_ ones: ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-11-muts-in-separate-scopes/src/main.rs:here}} @@ -163,7 +163,7 @@ Here’s the error: {{#include ../listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt}} ``` -Whew! We *also* cannot have a mutable reference while we have an immutable one +Whew! We _also_ cannot have a mutable reference while we have an immutable one to the same value. Users of an immutable reference don’t expect the value to suddenly change out @@ -193,8 +193,8 @@ have to track down why your data isn’t what you thought it was. ### Dangling References -In languages with pointers, it’s easy to erroneously create a *dangling -pointer*—a pointer that references a location in memory that may have been +In languages with pointers, it’s easy to erroneously create a _dangling +pointer_—a pointer that references a location in memory that may have been given to someone else—by freeing some memory while preserving a pointer to that memory. In Rust, by contrast, the compiler guarantees that references will never be dangling references: if you have a reference to some data, the @@ -256,8 +256,8 @@ deallocated. Let’s recap what we’ve discussed about references: -* At any given time, you can have *either* one mutable reference *or* any +- At any given time, you can have _either_ one mutable reference _or_ any number of immutable references. -* References must always be valid. +- References must always be valid. Next, we’ll look at a different kind of reference: slices. diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index d01d905021..6a0bb0815d 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -1,6 +1,6 @@ ## The Slice Type -*Slices* let you reference a contiguous sequence of elements in a +_Slices_ let you reference a contiguous sequence of elements in a [collection](ch08-00-common-collections.md) rather than the whole collection. A slice is a kind of reference, so it does not have ownership. @@ -18,7 +18,7 @@ fn first_word(s: &String) -> ? The `first_word` function has a `&String` as a parameter. We don’t want ownership, so this is fine. But what should we return? We don’t really have a -way to talk about *part* of a string. However, we could return the index of the +way to talk about _part_ of a string. However, we could return the index of the end of the word, indicated by a space. Let’s try that, as shown in Listing 4-7. @@ -94,7 +94,7 @@ we write a `second_word` function. Its signature would have to look like this: fn second_word(s: &String) -> (usize, usize) { ``` -Now we’re tracking a starting *and* an ending index, and we have even more +Now we’re tracking a starting _and_ an ending index, and we have even more values that were calculated from data in a particular state but aren’t tied to that state at all. We have three unrelated variables floating around that need to be kept in sync. @@ -103,7 +103,7 @@ Luckily, Rust has a solution to this problem: string slices. ### String Slices -A *string slice* is a reference to part of a `String`, and it looks like this: +A _string slice_ is a reference to part of a `String`, and it looks like this: ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-17-slice/src/main.rs:here}} @@ -231,6 +231,7 @@ same time, and compilation fails. Not only has Rust made our API easier to use, but it has also eliminated an entire class of errors at compile time! + #### String Literals as Slices @@ -269,7 +270,7 @@ and `&str` values. If we have a string slice, we can pass that directly. If we have a `String`, we can pass a slice of the `String` or a reference to the `String`. This -flexibility takes advantage of *deref coercions*, a feature we will cover in the +flexibility takes advantage of _deref coercions_, a feature we will cover in the [“Implicit Deref Coercions with Functions and Methods”][deref-coercions] section of Chapter 15. diff --git a/src/ch05-00-structs.md b/src/ch05-00-structs.md index d41482579a..ee064224d9 100644 --- a/src/ch05-00-structs.md +++ b/src/ch05-00-structs.md @@ -1,14 +1,14 @@ # Using Structs to Structure Related Data -A *struct*, or *structure*, is a custom data type that lets you package +A _struct_, or _structure_, is a custom data type that lets you package together and name multiple related values that make up a meaningful group. If -you’re familiar with an object-oriented language, a *struct* is like an +you’re familiar with an object-oriented language, a _struct_ is like an object’s data attributes. In this chapter, we’ll compare and contrast tuples with structs to build on what you already know and demonstrate when structs are a better way to group data. We’ll demonstrate how to define and instantiate structs. We’ll discuss how to define associated functions, especially the kind of associated functions called -*methods*, to specify behavior associated with a struct type. Structs and enums +_methods_, to specify behavior associated with a struct type. Structs and enums (discussed in Chapter 6) are the building blocks for creating new types in your program’s domain to take full advantage of Rust’s compile-time type checking. diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index e1325c63ec..91a9392436 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -10,7 +10,7 @@ on the order of the data to specify or access the values of an instance. To define a struct, we enter the keyword `struct` and name the entire struct. A struct’s name should describe the significance of the pieces of data being grouped together. Then, inside curly brackets, we define the names and types of -the pieces of data, which we call *fields*. For example, Listing 5-1 shows a +the pieces of data, which we call _fields_. For example, Listing 5-1 shows a struct that stores information about a user account. @@ -21,10 +21,10 @@ struct that stores information about a user account. -To use a struct after we’ve defined it, we create an *instance* of that struct +To use a struct after we’ve defined it, we create an _instance_ of that struct by specifying concrete values for each of the fields. We create an instance by -stating the name of the struct and then add curly brackets containing *key: -value* pairs, where the keys are the names of the fields and the values are the +stating the name of the struct and then add curly brackets containing _key: +value_ pairs, where the keys are the names of the fields and the values are the data we want to store in those fields. We don’t have to specify the fields in the same order in which we declared them in the struct. In other words, the struct definition is like a general template for the type, and instances fill @@ -76,12 +76,13 @@ variables is a bit tedious. If the struct had more fields, repeating each name would get even more annoying. Luckily, there’s a convenient shorthand! + ### Using the Field Init Shorthand Because the parameter names and the struct field names are exactly the same in -Listing 5-4, we can use the *field init shorthand* syntax to rewrite +Listing 5-4, we can use the _field init shorthand_ syntax to rewrite `build_user` so it behaves exactly the same but doesn’t have the repetition of `username` and `email`, as shown in Listing 5-5. @@ -103,7 +104,7 @@ than `email: email`. It’s often useful to create a new instance of a struct that includes most of the values from another instance, but changes some. You can do this using -*struct update syntax*. +_struct update syntax_. First, in Listing 5-6 we show how to create a new `User` instance in `user2` regularly, without the update syntax. We set a new value for `email` but @@ -151,7 +152,7 @@ Data: Copy”][copy] section would apply. We can still use ### Using Tuple Structs Without Named Fields to Create Different Types -Rust also supports structs that look similar to tuples, called *tuple structs*. +Rust also supports structs that look similar to tuples, called _tuple structs_. Tuple structs have the added meaning the struct name provides but don’t have names associated with their fields; rather, they just have the types of the fields. Tuple structs are useful when you want to give the whole tuple a name @@ -184,7 +185,7 @@ example, we would write `let Point(x, y, z) = point`. ### Unit-Like Structs Without Any Fields You can also define structs that don’t have any fields! These are called -*unit-like structs* because they behave similarly to `()`, the unit type that +_unit-like structs_ because they behave similarly to `()`, the unit type that we mentioned in [“The Tuple Type”][tuples] section. Unit-like structs can be useful when you need to implement a trait on some type but don’t have any data that you want to store in the type itself. We’ll discuss traits @@ -217,7 +218,7 @@ implement them on any type, including unit-like structs. > that data to be valid for as long as the entire struct is valid. > > It’s also possible for structs to store references to data owned by something -> else, but to do so requires the use of *lifetimes*, a Rust feature that we’ll +> else, but to do so requires the use of _lifetimes_, a Rust feature that we’ll > discuss in Chapter 10. Lifetimes ensure that the data referenced by a struct > is valid for as long as the struct is. Let’s say you try to store a reference > in a struct without specifying lifetimes, like the following; this won’t work: diff --git a/src/ch05-02-example-structs.md b/src/ch05-02-example-structs.md index 392f1bd3bd..49a109c6cf 100644 --- a/src/ch05-02-example-structs.md +++ b/src/ch05-02-example-structs.md @@ -4,10 +4,10 @@ To understand when we might want to use structs, let’s write a program that calculates the area of a rectangle. We’ll start by using single variables, and then refactor the program until we’re using structs instead. -Let’s make a new binary project with Cargo called *rectangles* that will take +Let’s make a new binary project with Cargo called _rectangles_ that will take the width and height of a rectangle specified in pixels and calculate the area of the rectangle. Listing 5-8 shows a short program with one way of doing -exactly that in our project’s *src/main.rs*. +exactly that in our project’s _src/main.rs_. @@ -155,7 +155,7 @@ But again, the compiler gives us a helpful note: {{#include ../listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt:9:10}} ``` -Rust *does* include functionality to print out debugging information, but we +Rust _does_ include functionality to print out debugging information, but we have to explicitly opt in to make that functionality available for our struct. To do that, we add the outer attribute `#[derive(Debug)]` just before the struct definition, as shown in Listing 5-12. @@ -214,10 +214,10 @@ Here’s what the output of this example looks like: {{#include ../listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt}} ``` -We can see the first bit of output came from *src/main.rs* line 10 where we’re +We can see the first bit of output came from _src/main.rs_ line 10 where we’re debugging the expression `30 * scale`, and its resultant value is `60` (the `Debug` formatting implemented for integers is to print only their value). The -`dbg!` call on line 14 of *src/main.rs* outputs the value of `&rect1`, which is +`dbg!` call on line 14 of _src/main.rs_ outputs the value of `&rect1`, which is the `Rectangle` struct. This output uses the pretty `Debug` formatting of the `Rectangle` type. The `dbg!` macro can be really helpful when you’re trying to figure out what your code is doing! @@ -233,7 +233,7 @@ section of the Rust Reference][attributes]. Our `area` function is very specific: it only computes the area of rectangles. It would be helpful to tie this behavior more closely to our `Rectangle` struct because it won’t work with any other type. Let’s look at how we can continue to -refactor this code by turning the `area` function into an `area` *method* +refactor this code by turning the `area` function into an `area` _method_ defined on our `Rectangle` type. [the-tuple-type]: ch03-02-data-types.html#the-tuple-type diff --git a/src/ch05-03-method-syntax.md b/src/ch05-03-method-syntax.md index 1ea896b38e..542f07d517 100644 --- a/src/ch05-03-method-syntax.md +++ b/src/ch05-03-method-syntax.md @@ -1,6 +1,6 @@ ## Method Syntax -*Methods* are similar to functions: we declare them with the `fn` keyword and a +_Methods_ are similar to functions: we declare them with the `fn` keyword and a name, they can have parameters and a return value, and they contain some code that’s run when the method is called from somewhere else. Unlike functions, methods are defined within the context of a struct (or an enum or a trait @@ -29,7 +29,7 @@ will be associated with the `Rectangle` type. Then we move the `area` function within the `impl` curly brackets and change the first (and in this case, only) parameter to be `self` in the signature and everywhere within the body. In `main`, where we called the `area` function and passed `rect1` as an argument, -we can instead use *method syntax* to call the `area` method on our `Rectangle` +we can instead use _method syntax_ to call the `area` method on our `Rectangle` instance. The method syntax goes after an instance: we add a dot followed by the method name, parentheses, and any arguments. @@ -81,7 +81,7 @@ method `width`. When we don’t use parentheses, Rust knows we mean the field Often, but not always, when we give a method the same name as a field we want it to only return the value in the field and do nothing else. Methods like this -are called *getters*, and Rust does not implement them automatically for struct +are called _getters_, and Rust does not implement them automatically for struct fields as some other languages do. Getters are useful because you can make the field private but the method public, and thus enable read-only access to that field as part of the type’s public API. We will discuss what public and private @@ -97,7 +97,7 @@ are and how to designate a field or method as public or private in [Chapter > `object->something()` is similar to `(*object).something()`. > > Rust doesn’t have an equivalent to the `->` operator; instead, Rust has a -> feature called *automatic referencing and dereferencing*. Calling methods is +> feature called _automatic referencing and dereferencing_. Calling methods is > one of the few places in Rust that has this behavior. > > Here’s how it works: when you call a method with `object.something()`, Rust @@ -105,6 +105,7 @@ are and how to designate a field or method as public or private in [Chapter > the method. In other words, the following are the same: > > +> > ```rust > # #[derive(Debug,Copy,Clone)] > # struct Point { @@ -188,7 +189,7 @@ parameters in functions. ### Associated Functions -All functions defined within an `impl` block are called *associated functions* +All functions defined within an `impl` block are called _associated functions_ because they’re associated with the type named after the `impl`. We can define associated functions that don’t have `self` as their first parameter (and thus are not methods) because they don’t need an instance of the type to work with. diff --git a/src/ch06-00-enums.md b/src/ch06-00-enums.md index 8a7faa9f30..0b9fc7806c 100644 --- a/src/ch06-00-enums.md +++ b/src/ch06-00-enums.md @@ -1,7 +1,7 @@ # Enums and Pattern Matching -In this chapter, we’ll look at *enumerations*, also referred to as *enums*. -Enums allow you to define a type by enumerating its possible *variants*. First +In this chapter, we’ll look at _enumerations_, also referred to as _enums_. +Enums allow you to define a type by enumerating its possible _variants_. First we’ll define and use an enum to show how an enum can encode meaning along with data. Next, we’ll explore a particularly useful enum, called `Option`, which expresses that a value can be either something or nothing. Then we’ll look at diff --git a/src/ch06-01-defining-an-enum.md b/src/ch06-01-defining-an-enum.md index 3462f38917..d61578777e 100644 --- a/src/ch06-01-defining-an-enum.md +++ b/src/ch06-01-defining-an-enum.md @@ -10,7 +10,7 @@ Let’s look at a situation we might want to express in code and see why enums are useful and more appropriate than structs in this case. Say we need to work with IP addresses. Currently, two major standards are used for IP addresses: version four and version six. Because these are the only possibilities for an -IP address that our program will come across, we can *enumerate* all possible +IP address that our program will come across, we can _enumerate_ all possible variants, which is where enumeration gets its name. Any IP address can be either a version four or a version six address, but not @@ -54,8 +54,8 @@ And we can call this function with either variant: ``` Using enums has even more advantages. Thinking more about our IP address type, -at the moment we don’t have a way to store the actual IP address *data*; we -only know what *kind* it is. Given that you just learned about structs in +at the moment we don’t have a way to store the actual IP address _data_; we +only know what _kind_ it is. Given that you just learned about structs in Chapter 5, you might be tempted to tackle this problem with structs as shown in Listing 6-1. @@ -151,10 +151,10 @@ variety of types embedded in its variants. This enum has four variants with different types: -* `Quit` has no data associated with it at all. -* `Move` has named fields, like a struct does. -* `Write` includes a single `String`. -* `ChangeColor` includes three `i32` values. +- `Quit` has no data associated with it at all. +- `Move` has named fields, like a struct does. +- `Write` includes a single `String`. +- `ChangeColor` includes three `i32` values. Defining an enum with variants such as the ones in Listing 6-2 is similar to defining different kinds of struct definitions, except the enum doesn’t use the @@ -201,7 +201,7 @@ languages. Programming language design is often thought of in terms of which features you include, but the features you exclude are important too. Rust doesn’t have the -null feature that many other languages have. *Null* is a value that means there +null feature that many other languages have. _Null_ is a value that means there is no value there. In languages with null, variables can always be in one of two states: null or not-null. @@ -301,7 +301,7 @@ more confident in your code. In order to have a value that can possibly be null, you must explicitly opt in by making the type of that value `Option`. Then, when you use that value, you are required to explicitly handle the case when the value is null. Everywhere that a value has a type that isn’t an -`Option`, you *can* safely assume that the value isn’t null. This was a +`Option`, you _can_ safely assume that the value isn’t null. This was a deliberate design decision for Rust to limit null’s pervasiveness and increase the safety of Rust code. diff --git a/src/ch06-02-match.md b/src/ch06-02-match.md index f81907c9ee..7cbae3edf9 100644 --- a/src/ch06-02-match.md +++ b/src/ch06-02-match.md @@ -1,5 +1,7 @@ + + ## The `match` Control Flow Construct Rust has an extremely powerful control flow construct called `match` that @@ -185,7 +187,7 @@ error: ``` Rust knows that we didn’t cover every possible case, and even knows which -pattern we forgot! Matches in Rust are *exhaustive*: we must exhaust every last +pattern we forgot! Matches in Rust are _exhaustive_: we must exhaust every last possibility in order for the code to be valid. Especially in the case of `Option`, when Rust prevents us from forgetting to explicitly handle the `None` case, it protects us from assuming that we have a value when we might @@ -220,7 +222,7 @@ patterns are evaluated in order. If we put the catch-all arm earlier, the other arms would never run, so Rust will warn us if we add arms after a catch-all! Rust also has a pattern we can use when we want a catch-all but don’t want to -*use* the value in the catch-all pattern: `_` is a special pattern that matches +_use_ the value in the catch-all pattern: `_` is a special pattern that matches any value and does not bind to that value. This tells Rust we aren’t going to use the value, so Rust won’t warn us about an unused variable. @@ -254,5 +256,4 @@ There’s more about patterns and matching that we’ll cover in [Chapter is a bit wordy. [tuples]: ch03-02-data-types.html#the-tuple-type - [ch19-00-patterns]: ch19-00-patterns.html diff --git a/src/ch06-03-if-let.md b/src/ch06-03-if-let.md index 829d011695..50ad9321f9 100644 --- a/src/ch06-03-if-let.md +++ b/src/ch06-03-if-let.md @@ -81,4 +81,3 @@ function expects. In order to provide a well-organized API to your users that is straightforward to use and only exposes exactly what your users will need, let’s now turn to Rust’s modules. - diff --git a/src/ch07-00-managing-growing-projects-with-packages-crates-and-modules.md b/src/ch07-00-managing-growing-projects-with-packages-crates-and-modules.md index 0f7abf51e3..1786711d8d 100644 --- a/src/ch07-00-managing-growing-projects-with-packages-crates-and-modules.md +++ b/src/ch07-00-managing-growing-projects-with-packages-crates-and-modules.md @@ -11,7 +11,7 @@ and then multiple files. A package can contain multiple binary crates and optionally one library crate. As a package grows, you can extract parts into separate crates that become external dependencies. This chapter covers all these techniques. For very large projects comprising a set of interrelated -packages that evolve together, Cargo provides *workspaces*, which we’ll cover +packages that evolve together, Cargo provides _workspaces_, which we’ll cover in the [“Cargo Workspaces”][workspaces] section in Chapter 14. We’ll also discuss encapsulating implementation details, which lets you reuse @@ -33,13 +33,13 @@ same name in the same scope; tools are available to resolve name conflicts. Rust has a number of features that allow you to manage your code’s organization, including which details are exposed, which details are private, and what names are in each scope in your programs. These features, sometimes -collectively referred to as the *module system*, include: +collectively referred to as the _module system_, include: -* **Packages:** A Cargo feature that lets you build, test, and share crates -* **Crates:** A tree of modules that produces a library or executable -* **Modules** and **use:** Let you control the organization, scope, and +- **Packages:** A Cargo feature that lets you build, test, and share crates +- **Crates:** A tree of modules that produces a library or executable +- **Modules** and **use:** Let you control the organization, scope, and privacy of paths -* **Paths:** A way of naming an item, such as a struct, function, or module +- **Paths:** A way of naming an item, such as a struct, function, or module In this chapter, we’ll cover all these features, discuss how they interact, and explain how to use them to manage scope. By the end, you should have a solid diff --git a/src/ch07-01-packages-and-crates.md b/src/ch07-01-packages-and-crates.md index e9bf645f34..281f27b7b6 100644 --- a/src/ch07-01-packages-and-crates.md +++ b/src/ch07-01-packages-and-crates.md @@ -2,7 +2,7 @@ The first parts of the module system we’ll cover are packages and crates. -A *crate* is the smallest amount of code that the Rust compiler considers at a +A _crate_ is the smallest amount of code that the Rust compiler considers at a time. Even if you run `rustc` rather than `cargo` and pass a single source code file (as we did all the way back in the “Writing and Running a Rust Program” section of Chapter 1), the compiler considers that file to be a crate. Crates @@ -10,25 +10,25 @@ can contain modules, and the modules may be defined in other files that get compiled with the crate, as we’ll see in the coming sections. A crate can come in one of two forms: a binary crate or a library crate. -*Binary crates* are programs you can compile to an executable that you can run, +_Binary crates_ are programs you can compile to an executable that you can run, such as a command-line program or a server. Each must have a function called `main` that defines what happens when the executable runs. All the crates we’ve created so far have been binary crates. -*Library crates* don’t have a `main` function, and they don’t compile to an +_Library crates_ don’t have a `main` function, and they don’t compile to an executable. Instead, they define functionality intended to be shared with multiple projects. For example, the `rand` crate we used in [Chapter 2][rand] provides functionality that generates random numbers. Most of the time when Rustaceans say “crate”, they mean library crate, and they use “crate” interchangeably with the general programming concept of a “library”. -The *crate root* is a source file that the Rust compiler starts from and makes +The _crate root_ is a source file that the Rust compiler starts from and makes up the root module of your crate (we’ll explain modules in depth in the [“Defining Modules to Control Scope and Privacy”][modules] section). -A *package* is a bundle of one or more crates that provides a set of -functionality. A package contains a *Cargo.toml* file that describes how to +A _package_ is a bundle of one or more crates that provides a set of +functionality. A package contains a _Cargo.toml_ file that describes how to build those crates. Cargo is actually a package that contains the binary crate for the command-line tool you’ve been using to build your code. The Cargo package also contains a library crate that the binary crate depends on. Other @@ -51,20 +51,20 @@ main.rs ``` After we run `cargo new my-project`, we use `ls` to see what Cargo creates. In -the project directory, there’s a *Cargo.toml* file, giving us a package. -There’s also a *src* directory that contains *main.rs*. Open *Cargo.toml* in -your text editor, and note there’s no mention of *src/main.rs*. Cargo follows a -convention that *src/main.rs* is the crate root of a binary crate with the same +the project directory, there’s a _Cargo.toml_ file, giving us a package. +There’s also a _src_ directory that contains _main.rs_. Open _Cargo.toml_ in +your text editor, and note there’s no mention of _src/main.rs_. Cargo follows a +convention that _src/main.rs_ is the crate root of a binary crate with the same name as the package. Likewise, Cargo knows that if the package directory -contains *src/lib.rs*, the package contains a library crate with the same name -as the package, and *src/lib.rs* is its crate root. Cargo passes the crate root +contains _src/lib.rs_, the package contains a library crate with the same name +as the package, and _src/lib.rs_ is its crate root. Cargo passes the crate root files to `rustc` to build the library or binary. -Here, we have a package that only contains *src/main.rs*, meaning it only -contains a binary crate named `my-project`. If a package contains *src/main.rs* -and *src/lib.rs*, it has two crates: a binary and a library, both with the same +Here, we have a package that only contains _src/main.rs_, meaning it only +contains a binary crate named `my-project`. If a package contains _src/main.rs_ +and _src/lib.rs_, it has two crates: a binary and a library, both with the same name as the package. A package can have multiple binary crates by placing files -in the *src/bin* directory: each file will be a separate binary crate. +in the _src/bin_ directory: each file will be a separate binary crate. [modules]: ch07-02-defining-modules-to-control-scope-and-privacy.html [rand]: ch02-00-guessing-game-tutorial.html#generating-a-random-number diff --git a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md index c1afe4c15a..29924e6fe2 100644 --- a/src/ch07-02-defining-modules-to-control-scope-and-privacy.md +++ b/src/ch07-02-defining-modules-to-control-scope-and-privacy.md @@ -1,7 +1,7 @@ ## Defining Modules to Control Scope and Privacy In this section, we’ll talk about modules and other parts of the module system, -namely *paths*, which allow you to name items; the `use` keyword that brings a +namely _paths_, which allow you to name items; the `use` keyword that brings a path into scope; and the `pub` keyword to make items public. We’ll also discuss the `as` keyword, external packages, and the glob operator. @@ -14,23 +14,23 @@ through examples of each of these rules throughout this chapter, but this is a great place to refer to as a reminder of how modules work. - **Start from the crate root**: When compiling a crate, the compiler first - looks in the crate root file (usually *src/lib.rs* for a library crate or - *src/main.rs* for a binary crate) for code to compile. + looks in the crate root file (usually _src/lib.rs_ for a library crate or + _src/main.rs_ for a binary crate) for code to compile. - **Declaring modules**: In the crate root file, you can declare new modules; -say you declare a “garden” module with `mod garden;`. The compiler will look -for the module’s code in these places: + say you declare a “garden” module with `mod garden;`. The compiler will look + for the module’s code in these places: - Inline, within curly brackets that replace the semicolon following `mod garden` - - In the file *src/garden.rs* - - In the file *src/garden/mod.rs* + - In the file _src/garden.rs_ + - In the file _src/garden/mod.rs_ - **Declaring submodules**: In any file other than the crate root, you can declare submodules. For example, you might declare `mod vegetables;` in - *src/garden.rs*. The compiler will look for the submodule’s code within the + _src/garden.rs_. The compiler will look for the submodule’s code within the directory named for the parent module in these places: - Inline, directly following `mod vegetables`, within curly brackets instead of the semicolon - - In the file *src/garden/vegetables.rs* - - In the file *src/garden/vegetables/mod.rs* + - In the file _src/garden/vegetables.rs_ + - In the file _src/garden/vegetables/mod.rs_ - **Paths to code in modules**: Once a module is part of your crate, you can refer to code in that module from anywhere else in that same crate, as long as the privacy rules allow, using the path to the code. For example, an @@ -61,7 +61,7 @@ backyard └── main.rs ``` -The crate root file in this case is *src/main.rs*, and it contains: +The crate root file in this case is _src/main.rs_, and it contains: @@ -72,7 +72,7 @@ The crate root file in this case is *src/main.rs*, and it contains: The `pub mod garden;` line tells the compiler to include the code it finds in -*src/garden.rs*, which is: +_src/garden.rs_, which is: @@ -82,7 +82,7 @@ The `pub mod garden;` line tells the compiler to include the code it finds in -Here, `pub mod vegetables;` means the code in *src/garden/vegetables.rs* is +Here, `pub mod vegetables;` means the code in _src/garden/vegetables.rs_ is included too. That code is: ```rust,noplayground,ignore @@ -93,8 +93,8 @@ Now let’s get into the details of these rules and demonstrate them in action! ### Grouping Related Code in Modules -*Modules* let us organize code within a crate for readability and easy reuse. -Modules also allow us to control the *privacy* of items because code within a +_Modules_ let us organize code within a crate for readability and easy reuse. +Modules also allow us to control the _privacy_ of items because code within a module is private by default. Private items are internal implementation details not available for outside use. We can choose to make modules and the items within them public, which exposes them to allow external code to use and depend @@ -106,7 +106,7 @@ empty to concentrate on the organization of the code rather than the implementation of a restaurant. In the restaurant industry, some parts of a restaurant are referred to as -*front of house* and others as *back of house*. Front of house is where +_front of house_ and others as _back of house_. Front of house is where customers are; this encompasses where the hosts seat customers, servers take orders and payment, and bartenders make drinks. Back of house is where the chefs and cooks work in the kitchen, dishwashers clean up, and managers do @@ -114,7 +114,7 @@ administrative work. To structure our crate in this way, we can organize its functions into nested modules. Create a new library named `restaurant` by running `cargo new -restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to +restaurant --lib`. Then enter the code in Listing 7-1 into _src/lib.rs_ to define some modules and function signatures; this code is the front of house section. @@ -139,10 +139,10 @@ groups rather than having to read through all the definitions, making it easier to find the definitions relevant to them. Programmers adding new functionality to this code would know where to place the code to keep the program organized. -Earlier, we mentioned that *src/main.rs* and *src/lib.rs* are called crate +Earlier, we mentioned that _src/main.rs_ and _src/lib.rs_ are called crate roots. The reason for their name is that the contents of either of these two files form a module named `crate` at the root of the crate’s module structure, -known as the *module tree*. +known as the _module tree_. Listing 7-2 shows the module tree for the structure in Listing 7-1. @@ -164,10 +164,10 @@ crate This tree shows how some of the modules nest inside other modules; for example, `hosting` nests inside `front_of_house`. The tree also shows that some modules -are *siblings*, meaning they’re defined in the same module; `hosting` and +are _siblings_, meaning they’re defined in the same module; `hosting` and `serving` are siblings defined within `front_of_house`. If module A is -contained inside module B, we say that module A is the *child* of module B and -that module B is the *parent* of module A. Notice that the entire module tree +contained inside module B, we say that module A is the _child_ of module B and +that module B is the _parent_ of module A. Notice that the entire module tree is rooted under the implicit module named `crate`. The module tree might remind you of the filesystem’s directory tree on your diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index da07d9fd83..a336f94a69 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -6,10 +6,10 @@ know its path. A path can take two forms: -* An *absolute path* is the full path starting from a crate root; for code +- An _absolute path_ is the full path starting from a crate root; for code from an external crate, the absolute path begins with the crate name, and for code from the current crate, it starts with the literal `crate`. -* A *relative path* starts from the current module and uses `self`, `super`, or +- A _relative path_ starts from the current module and uses `self`, `super`, or an identifier in the current module. Both absolute and relative paths are followed by one or more identifiers @@ -126,7 +126,7 @@ shown in Listing 7-6. What happened? Adding the `pub` keyword in front of `mod hosting` makes the module public. With this change, if we can access `front_of_house`, we can -access `hosting`. But the *contents* of `hosting` are still private; making the +access `hosting`. But the _contents_ of `hosting` are still private; making the module public doesn’t make its contents public. The `pub` keyword on a module only lets code in its ancestor modules refer to it, not access its inner code. Because modules are containers, there’s not much we can do by only making the @@ -179,15 +179,15 @@ interested in this topic, see [The Rust API Guidelines][api-guidelines]. > #### Best Practices for Packages with a Binary and a Library > -> We mentioned that a package can contain both a *src/main.rs* binary crate -> root as well as a *src/lib.rs* library crate root, and both crates will have +> We mentioned that a package can contain both a _src/main.rs_ binary crate +> root as well as a _src/lib.rs_ library crate root, and both crates will have > the package name by default. Typically, packages with this pattern of > containing both a library and a binary crate will have just enough code in the > binary crate to start an executable that calls code within the library crate. > This lets other projects benefit from most of the functionality that the > package provides because the library crate’s code can be shared. > -> The module tree should be defined in *src/lib.rs*. Then, any public items can +> The module tree should be defined in _src/lib.rs_. Then, any public items can > be used in the binary crate by starting paths with the name of the package. > The binary crate becomes a user of the library crate just like a completely > external crate would use the library crate: it can only use the public API. diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index aaf7713e95..97b2b656a8 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -112,7 +112,7 @@ meant when we used `Result`. There’s another solution to the problem of bringing two types of the same name into the same scope with `use`: after the path, we can specify `as` and a new -local name, or *alias*, for the type. Listing 7-16 shows another way to write +local name, or _alias_, for the type. Listing 7-16 shows another way to write the code in Listing 7-15 by renaming one of the two `Result` types using `as`. @@ -133,7 +133,7 @@ considered idiomatic, so the choice is up to you! When we bring a name into scope with the `use` keyword, the name available in the new scope is private. To enable the code that calls our code to refer to that name as if it had been defined in that code’s scope, we can combine `pub` -and `use`. This technique is called *re-exporting* because we’re bringing an +and `use`. This technique is called _re-exporting_ because we’re bringing an item into scope but also making that item available for others to bring into their scope. @@ -171,7 +171,7 @@ Chapter 14. In Chapter 2, we programmed a guessing game project that used an external package called `rand` to get random numbers. To use `rand` in our project, we -added this line to *Cargo.toml*: +added this line to _Cargo.toml_: section in Chapter 11. The glob operator -is also sometimes used as part of the prelude pattern: see [the standard -library documentation](../std/prelude/index.html#other-preludes) +is also sometimes used as part of the prelude pattern: see [the standard library documentation](../std/prelude/index.html#other-preludes) for more information on that pattern. [ch14-pub-use]: ch14-02-publishing-to-crates-io.html#exporting-a-convenient-public-api-with-pub-use diff --git a/src/ch07-05-separating-modules-into-different-files.md b/src/ch07-05-separating-modules-into-different-files.md index 2952e4b156..4de9b6908f 100644 --- a/src/ch07-05-separating-modules-into-different-files.md +++ b/src/ch07-05-separating-modules-into-different-files.md @@ -7,14 +7,14 @@ file to make the code easier to navigate. For example, let’s start from the code in Listing 7-17 that had multiple restaurant modules. We’ll extract modules into files instead of having all the modules defined in the crate root file. In this case, the crate root file is -*src/lib.rs*, but this procedure also works with binary crates whose crate root -file is *src/main.rs*. +_src/lib.rs_, but this procedure also works with binary crates whose crate root +file is _src/main.rs_. First we’ll extract the `front_of_house` module to its own file. Remove the code inside the curly brackets for the `front_of_house` module, leaving only -the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code +the `mod front_of_house;` declaration, so that _src/lib.rs_ contains the code shown in Listing 7-21. Note that this won’t compile until we create the -*src/front_of_house.rs* file in Listing 7-22. +_src/front_of_house.rs_ file in Listing 7-22. @@ -25,7 +25,7 @@ shown in Listing 7-21. Note that this won’t compile until we create the Next, place the code that was in the curly brackets into a new file named -*src/front_of_house.rs*, as shown in Listing 7-22. The compiler knows to look +_src/front_of_house.rs_, as shown in Listing 7-22. The compiler knows to look in this file because it came across the module declaration in the crate root with the name `front_of_house`. @@ -37,21 +37,21 @@ with the name `front_of_house`. -Note that you only need to load a file using a `mod` declaration *once* in your +Note that you only need to load a file using a `mod` declaration _once_ in your module tree. Once the compiler knows the file is part of the project (and knows where in the module tree the code resides because of where you’ve put the `mod` statement), other files in your project should refer to the loaded file’s code using a path to where it was declared, as covered in the [“Paths for Referring to an Item in the Module Tree”][paths] section. In other words, -`mod` is *not* an “include” operation that you may have seen in other +`mod` is _not_ an “include” operation that you may have seen in other programming languages. Next, we’ll extract the `hosting` module to its own file. The process is a bit different because `hosting` is a child module of `front_of_house`, not of the root module. We’ll place the file for `hosting` in a new directory that will be -named for its ancestors in the module tree, in this case *src/front_of_house*. +named for its ancestors in the module tree, in this case _src/front_of_house_. -To start moving `hosting`, we change *src/front_of_house.rs* to contain only +To start moving `hosting`, we change _src/front_of_house.rs_ to contain only the declaration of the `hosting` module: @@ -62,7 +62,7 @@ the declaration of the `hosting` module: -Then we create a *src/front_of_house* directory and a *hosting.rs* file to +Then we create a _src/front_of_house_ directory and a _hosting.rs_ file to contain the definitions made in the `hosting` module: @@ -73,8 +73,8 @@ contain the definitions made in the `hosting` module: -If we instead put *hosting.rs* in the *src* directory, the compiler would -expect the *hosting.rs* code to be in a `hosting` module declared in the crate +If we instead put _hosting.rs_ in the _src_ directory, the compiler would +expect the _hosting.rs_ code to be in a `hosting` module declared in the crate root, and not declared as a child of the `front_of_house` module. The compiler’s rules for which files to check for which modules’ code mean the directories and files more closely match the module tree. @@ -86,21 +86,21 @@ directories and files more closely match the module tree. > `front_of_house` declared in the crate root, the compiler will look for the > module’s code in: > -> * *src/front_of_house.rs* (what we covered) -> * *src/front_of_house/mod.rs* (older style, still supported path) +> - _src/front_of_house.rs_ (what we covered) +> - _src/front_of_house/mod.rs_ (older style, still supported path) > > For a module named `hosting` that is a submodule of `front_of_house`, the > compiler will look for the module’s code in: > -> * *src/front_of_house/hosting.rs* (what we covered) -> * *src/front_of_house/hosting/mod.rs* (older style, still supported path) +> - _src/front_of_house/hosting.rs_ (what we covered) +> - _src/front_of_house/hosting/mod.rs_ (older style, still supported path) > > If you use both styles for the same module, you’ll get a compiler error. > Using a mix of both styles for different modules in the same project is > allowed, but might be confusing for people navigating your project. > -> The main downside to the style that uses files named *mod.rs* is that your -> project can end up with many files named *mod.rs*, which can get confusing +> The main downside to the style that uses files named _mod.rs_ is that your +> project can end up with many files named _mod.rs_, which can get confusing > when you have them open in your editor at the same time. We’ve moved each module’s code to a separate file, and the module tree remains @@ -109,7 +109,7 @@ modification, even though the definitions live in different files. This technique lets you move modules to new files as they grow in size. Note that the `pub use crate::front_of_house::hosting` statement in -*src/lib.rs* also hasn’t changed, nor does `use` have any impact on what files +_src/lib.rs_ also hasn’t changed, nor does `use` have any impact on what files are compiled as part of the crate. The `mod` keyword declares modules, and Rust looks in a file with the same name as the module for the code that goes into that module. diff --git a/src/ch08-00-common-collections.md b/src/ch08-00-common-collections.md index c9de36be1d..7cc5c424b8 100644 --- a/src/ch08-00-common-collections.md +++ b/src/ch08-00-common-collections.md @@ -1,7 +1,7 @@ # Common Collections Rust’s standard library includes a number of very useful data structures called -*collections*. Most other data types represent one specific value, but +_collections_. Most other data types represent one specific value, but collections can contain multiple values. Unlike the built-in array and tuple types, the data these collections point to is stored on the heap, which means the amount of data does not need to be known at compile time and can grow or @@ -10,11 +10,11 @@ and costs, and choosing an appropriate one for your current situation is a skill you’ll develop over time. In this chapter, we’ll discuss three collections that are used very often in Rust programs: -* A *vector* allows you to store a variable number of values next to each other. -* A *string* is a collection of characters. We’ve mentioned the `String` type +- A _vector_ allows you to store a variable number of values next to each other. +- A _string_ is a collection of characters. We’ve mentioned the `String` type previously, but in this chapter we’ll talk about it in depth. -* A *hash map* allows you to associate a value with a specific key. It’s a - particular implementation of the more general data structure called a *map*. +- A _hash map_ allows you to associate a value with a specific key. It’s a + particular implementation of the more general data structure called a _map_. To learn about the other kinds of collections provided by the standard library, see [the documentation][collections]. diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index c29728a7a2..d711c9904e 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -1,6 +1,6 @@ ## Storing Lists of Values with Vectors -The first collection type we’ll look at is `Vec`, also known as a *vector*. +The first collection type we’ll look at is `Vec`, also known as a _vector_. Vectors allow you to store more than one value in a single data structure that puts all the values next to each other in memory. Vectors can only store values of the same type. They are useful when you have a list of items, such as the diff --git a/src/ch08-02-strings.md b/src/ch08-02-strings.md index 5635263b69..6df7dd83cb 100644 --- a/src/ch08-02-strings.md +++ b/src/ch08-02-strings.md @@ -18,9 +18,9 @@ complicated by the differences between how people and computers interpret ### What Is a String? -We’ll first define what we mean by the term *string*. Rust has only one string +We’ll first define what we mean by the term _string_. Rust has only one string type in the core language, which is the string slice `str` that is usually seen -in its borrowed form `&str`. In Chapter 4, we talked about *string slices*, +in its borrowed form `&str`. In Chapter 4, we talked about _string slices_, which are references to some UTF-8 encoded string data stored elsewhere. String literals, for example, are stored in the program’s binary and are therefore string slices. @@ -132,7 +132,7 @@ If the `push_str` method took ownership of `s2`, we wouldn’t be able to print its value on the last line. However, this code works as we’d expect! The `push` method takes a single character as a parameter and adds it to the -`String`. Listing 8-17 adds the letter *l* to a `String` using the `push` +`String`. Listing 8-17 adds the letter _l_ to a `String` using the `push` method. @@ -174,21 +174,21 @@ call this method with `String` values. We’ll discuss generics in Chapter 10. This signature gives us the clues we need in order to understand the tricky bits of the `+` operator. -First, `s2` has an `&`, meaning that we’re adding a *reference* of the second +First, `s2` has an `&`, meaning that we’re adding a _reference_ of the second string to the first string. This is because of the `s` parameter in the `add` function: we can only add a `&str` to a `String`; we can’t add two `String` values together. But wait—the type of `&s2` is `&String`, not `&str`, as specified in the second parameter to `add`. So why does Listing 8-18 compile? The reason we’re able to use `&s2` in the call to `add` is that the compiler -can *coerce* the `&String` argument into a `&str`. When we call the `add` -method, Rust uses a *deref coercion*, which here turns `&s2` into `&s2[..]`. +can _coerce_ the `&String` argument into a `&str`. When we call the `add` +method, Rust uses a _deref coercion_, which here turns `&s2` into `&s2[..]`. We’ll discuss deref coercion in more depth in Chapter 15. Because `add` does not take ownership of the `s` parameter, `s2` will still be a valid `String` after this operation. Second, we can see in the signature that `add` takes ownership of `self` -because `self` does *not* have an `&`. This means `s1` in Listing 8-18 will be +because `self` does _not_ have an `&`. This means `s1` in Listing 8-18 will be moved into the `add` call and will no longer be valid after that. So, although `let s3 = s1 + &s2;` looks like it will copy both strings and create a new one, this statement actually takes ownership of `s1`, appends a copy of the contents @@ -254,7 +254,7 @@ encoded UTF-8 example strings from Listing 8-14. First, this one: In this case, `len` will be `4`, which means the vector storing the string `"Hola"` is 4 bytes long. Each of these letters takes one byte when encoded in UTF-8. The following line, however, may surprise you (note that this string -begins with the capital Cyrillic letter *Ze*, not the number 3): +begins with the capital Cyrillic letter _Ze_, not the number 3): ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-14/src/main.rs:russian}} @@ -289,7 +289,7 @@ at all and prevents misunderstandings early in the development process. Another point about UTF-8 is that there are actually three relevant ways to look at strings from Rust’s perspective: as bytes, scalar values, and grapheme -clusters (the closest thing to what we would call *letters*). +clusters (the closest thing to what we would call _letters_). If we look at the Hindi word “नमस्ते” written in the Devanagari script, it is stored as a vector of `u8` values that looks like this: diff --git a/src/ch08-03-hash-maps.md b/src/ch08-03-hash-maps.md index 057501415a..3db150419b 100644 --- a/src/ch08-03-hash-maps.md +++ b/src/ch08-03-hash-maps.md @@ -1,11 +1,11 @@ ## Storing Keys with Associated Values in Hash Maps -The last of our common collections is the *hash map*. The type `HashMap` -stores a mapping of keys of type `K` to values of type `V` using a *hashing -function*, which determines how it places these keys and values into memory. +The last of our common collections is the _hash map_. The type `HashMap` +stores a mapping of keys of type `K` to values of type `V` using a _hashing +function_, which determines how it places these keys and values into memory. Many programming languages support this kind of data structure, but they often -use a different name, such as *hash*, *map*, *object*, *hash table*, -*dictionary*, or *associative array*, just to name a few. +use a different name, such as _hash_, _map_, _object_, _hash table_, +_dictionary_, or _associative array_, just to name a few. Hash maps are useful when you want to look up data not by using an index, as you can with vectors, but by using a key that can be of any type. For example, @@ -21,7 +21,7 @@ As always, check the standard library documentation for more information. One way to create an empty hash map is to use `new` and to add elements with `insert`. In Listing 8-20, we’re keeping track of the scores of two teams whose -names are *Blue* and *Yellow*. The Blue team starts with 10 points, and the +names are _Blue_ and _Yellow_. The Blue team starts with 10 points, and the Yellow team starts with 50. @@ -112,7 +112,7 @@ When you want to change the data in a hash map, you have to decide how to handle the case when a key already has a value assigned. You could replace the old value with the new value, completely disregarding the old value. You could keep the old value and ignore the new value, only adding the new value if the -key *doesn’t* already have a value. Or you could combine the old value and the +key _doesn’t_ already have a value. Or you could combine the old value and the new value. Let’s look at how to do each of these! #### Overwriting a Value @@ -135,6 +135,7 @@ This code will print `{"Blue": 25}`. The original value of `10` has been overwritten. + #### Adding a Key and Value Only If a Key Isn’t Present @@ -203,13 +204,13 @@ changes are safe and allowed by the borrowing rules. ### Hashing Functions -By default, `HashMap` uses a hashing function called *SipHash* that can provide +By default, `HashMap` uses a hashing function called _SipHash_ that can provide resistance to denial-of-service (DoS) attacks involving hash tables[^siphash]. This is not the fastest hashing algorithm available, but the trade-off for better security that comes with the drop in performance is worth it. If you profile your code and find that the default hash function is too slow for your purposes, you can switch to another function -by specifying a different hasher. A *hasher* is a type that implements the +by specifying a different hasher. A _hasher_ is a type that implements the `BuildHasher` trait. We’ll talk about traits and how to implement them in [Chapter 10][traits]. You don’t necessarily have to implement your own hasher from scratch; [crates.io](https://crates.io/) @@ -228,9 +229,9 @@ some exercises you should now be equipped to solve: the value in the middle position) and mode (the value that occurs most often; a hash map will be helpful here) of the list. 1. Convert strings to pig latin. The first consonant of each word is moved to - the end of the word and *ay* is added, so *first* becomes *irst-fay*. Words - that start with a vowel have *hay* added to the end instead (*apple* becomes - *apple-hay*). Keep in mind the details about UTF-8 encoding! + the end of the word and _ay_ is added, so _first_ becomes _irst-fay_. Words + that start with a vowel have _hay_ added to the end instead (_apple_ becomes + _apple-hay_). Keep in mind the details about UTF-8 encoding! 1. Using a hash map and vectors, create a text interface to allow a user to add employee names to a department in a company; for example, “Add Sally to Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all @@ -243,7 +244,6 @@ and hash maps have that will be helpful for these exercises! We’re getting into more complex programs in which operations can fail, so it’s a perfect time to discuss error handling. We’ll do that next! -[validating-references-with-lifetimes]: -ch10-03-lifetime-syntax.html#validating-references-with-lifetimes +[validating-references-with-lifetimes]: ch10-03-lifetime-syntax.html#validating-references-with-lifetimes [access]: #accessing-values-in-a-hash-map [traits]: ch10-02-traits.html diff --git a/src/ch09-00-error-handling.md b/src/ch09-00-error-handling.md index cf997d91b9..a5240b1997 100644 --- a/src/ch09-00-error-handling.md +++ b/src/ch09-00-error-handling.md @@ -7,8 +7,8 @@ code will compile. This requirement makes your program more robust by ensuring that you’ll discover errors and handle them appropriately before you’ve deployed your code to production! -Rust groups errors into two major categories: *recoverable* and *unrecoverable* -errors. For a recoverable error, such as a *file not found* error, we most +Rust groups errors into two major categories: _recoverable_ and _unrecoverable_ +errors. For a recoverable error, such as a _file not found_ error, we most likely just want to report the problem to the user and retry the operation. Unrecoverable errors are always symptoms of bugs, such as trying to access a location beyond the end of an array, and so we want to immediately stop the diff --git a/src/ch09-01-unrecoverable-errors-with-panic.md b/src/ch09-01-unrecoverable-errors-with-panic.md index bb3b8ed1f5..792932f5f4 100644 --- a/src/ch09-01-unrecoverable-errors-with-panic.md +++ b/src/ch09-01-unrecoverable-errors-with-panic.md @@ -11,17 +11,17 @@ panic occurs to make it easier to track down the source of the panic. > ### Unwinding the Stack or Aborting in Response to a Panic > -> By default, when a panic occurs the program starts *unwinding*, which means +> By default, when a panic occurs the program starts _unwinding_, which means > Rust walks back up the stack and cleans up the data from each function it > encounters. However, walking back and cleaning up is a lot of work. Rust, -> therefore, allows you to choose the alternative of immediately *aborting*, +> therefore, allows you to choose the alternative of immediately _aborting_, > which ends the program without cleaning up. > > Memory that the program was using will then need to be cleaned up by the > operating system. If in your project you need to make the resultant binary as > small as possible, you can switch from unwinding to aborting upon a panic by > adding `panic = 'abort'` to the appropriate `[profile]` sections in your -> *Cargo.toml* file. For example, if you want to abort on panic in release mode, +> _Cargo.toml_ file. For example, if you want to abort on panic in release mode, > add this: > > ```toml @@ -47,8 +47,8 @@ When you run the program, you’ll see something like this: The call to `panic!` causes the error message contained in the last two lines. The first line shows our panic message and the place in our source code where -the panic occurred: *src/main.rs:2:5* indicates that it’s the second line, -fifth character of our *src/main.rs* file. +the panic occurred: _src/main.rs:2:5_ indicates that it’s the second line, +fifth character of our _src/main.rs_ file. In this case, the line indicated is part of our code, and if we go to that line, we see the `panic!` macro call. In other cases, the `panic!` call might @@ -57,6 +57,7 @@ the error message will be someone else’s code where the `panic!` macro is called, not the line of our code that eventually led to the `panic!` call. + We can use the backtrace of the functions the `panic!` call came from to figure @@ -83,7 +84,7 @@ could return here that would be correct. In C, attempting to read beyond the end of a data structure is undefined behavior. You might get whatever is at the location in memory that would correspond to that element in the data structure, even though the memory -doesn’t belong to that structure. This is called a *buffer overread* and can +doesn’t belong to that structure. This is called a _buffer overread_ and can lead to security vulnerabilities if an attacker is able to manipulate the index in such a way as to read data they shouldn’t be allowed to that is stored after the data structure. @@ -96,12 +97,12 @@ continue. Let’s try it and see: {{#include ../listings/ch09-error-handling/listing-09-01/output.txt}} ``` -This error points at line 4 of our *main.rs* where we attempt to access index +This error points at line 4 of our _main.rs_ where we attempt to access index `99` of the vector in `v`. The `note:` line tells us that we can set the `RUST_BACKTRACE` environment variable to get a backtrace of exactly what happened to cause the error. A -*backtrace* is a list of all the functions that have been called to get to this +_backtrace_ is a list of all the functions that have been called to get to this point. Backtraces in Rust work as they do in other languages: the key to reading the backtrace is to start from the top and read until you see files you wrote. That’s the spot where the problem originated. The lines above that spot @@ -153,7 +154,7 @@ default when using `cargo build` or `cargo run` without the `--release` flag, as we have here. In the output in Listing 9-2, line 6 of the backtrace points to the line in our -project that’s causing the problem: line 4 of *src/main.rs*. If we don’t want +project that’s causing the problem: line 4 of _src/main.rs_. If we don’t want our program to panic, we should start our investigation at the location pointed to by the first line mentioning a file we wrote. In Listing 9-1, where we deliberately wrote code that would panic, the way to fix the panic is to not @@ -166,5 +167,4 @@ handle error conditions in the [“To `panic!` or Not to `panic!`”][to-panic-or-not-to-panic] section later in this chapter. Next, we’ll look at how to recover from an error using `Result`. -[to-panic-or-not-to-panic]: -ch09-03-to-panic-or-not-to-panic.html#to-panic-or-not-to-panic +[to-panic-or-not-to-panic]: ch09-03-to-panic-or-not-to-panic.html#to-panic-or-not-to-panic diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 81f6281925..13117d7dfb 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -78,7 +78,7 @@ writing. The other arm of the `match` handles the case where we get an `Err` value from `File::open`. In this example, we’ve chosen to call the `panic!` macro. If -there’s no file named *hello.txt* in our current directory and we run this +there’s no file named _hello.txt_ in our current directory and we run this code, we’ll see the following output from the `panic!` macro: ```console @@ -178,7 +178,7 @@ call the `panic!` macro for us. Here is an example of `unwrap` in action: -If we run this code without a *hello.txt* file, we’ll see an error message from +If we run this code without a _hello.txt_ file, we’ll see an error message from the `panic!` call that the `unwrap` method makes: section in Chapter 18. For now, you can read `Box` to mean “any kind of error.” Using `?` on a `Result` diff --git a/src/ch09-03-to-panic-or-not-to-panic.md b/src/ch09-03-to-panic-or-not-to-panic.md index 9b7850ca93..90d9eacfd4 100644 --- a/src/ch09-03-to-panic-or-not-to-panic.md +++ b/src/ch09-03-to-panic-or-not-to-panic.md @@ -57,7 +57,7 @@ of the `parse` method: we still get a `Result` value, and the compiler will still make us handle the `Result` as if the `Err` variant is a possibility because the compiler isn’t smart enough to see that this string is always a valid IP address. If the IP address string came from a user rather than being -hardcoded into the program and therefore *did* have a possibility of failure, +hardcoded into the program and therefore _did_ have a possibility of failure, we’d definitely want to handle the `Result` in a more robust way instead. Mentioning the assumption that this IP address is hardcoded will prompt us to change `expect` to better error-handling code if, in the future, we need to get @@ -66,17 +66,17 @@ the IP address from some other source instead. ### Guidelines for Error Handling It’s advisable to have your code panic when it’s possible that your code could -end up in a bad state. In this context, a *bad state* is when some assumption, +end up in a bad state. In this context, a _bad state_ is when some assumption, guarantee, contract, or invariant has been broken, such as when invalid values, contradictory values, or missing values are passed to your code—plus one or more of the following: -* The bad state is something that is unexpected, as opposed to something that +- The bad state is something that is unexpected, as opposed to something that will likely happen occasionally, like a user entering data in the wrong format. -* Your code after this point needs to rely on not being in this bad state, +- Your code after this point needs to rely on not being in this bad state, rather than checking for the problem at every step. -* There’s not a good way to encode this information in the types you use. We’ll +- There’s not a good way to encode this information in the types you use. We’ll work through an example of what we mean in the [“Encoding States and Behavior as Types”][encoding] section of Chapter 18. @@ -102,11 +102,11 @@ attempting to operate on invalid data can expose your code to vulnerabilities. This is the main reason the standard library will call `panic!` if you attempt an out-of-bounds memory access: trying to access memory that doesn’t belong to the current data structure is a common security problem. Functions often have -*contracts*: their behavior is only guaranteed if the inputs meet particular +_contracts_: their behavior is only guaranteed if the inputs meet particular requirements. Panicking when the contract is violated makes sense because a contract violation always indicates a caller-side bug, and it’s not a kind of error you want the calling code to have to explicitly handle. In fact, there’s -no reasonable way for calling code to recover; the calling *programmers* need +no reasonable way for calling code to recover; the calling _programmers_ need to fix the code. Contracts for a function, especially when a violation will cause a panic, should be explained in the API documentation for the function. @@ -116,7 +116,7 @@ checking done by the compiler) to do many of the checks for you. If your function has a particular type as a parameter, you can proceed with your code’s logic knowing that the compiler has already ensured you have a valid value. For example, if you have a type rather than an `Option`, your program expects to -have *something* rather than *nothing*. Your code then doesn’t have to handle +have _something_ rather than _nothing_. Your code then doesn’t have to handle two cases for the `Some` and `None` variants: it will only have one case for definitely having a value. Code trying to pass nothing to your function won’t even compile, so your function doesn’t have to check for that case at runtime. @@ -193,11 +193,11 @@ to the `value` parameter and return the `Guess`. Next, we implement a method named `value` that borrows `self`, doesn’t have any other parameters, and returns an `i32`. This kind of method is sometimes called -a *getter* because its purpose is to get some data from its fields and return +a _getter_ because its purpose is to get some data from its fields and return it. This public method is necessary because the `value` field of the `Guess` struct is private. It’s important that the `value` field be private so code using the `Guess` struct is not allowed to set `value` directly: code outside -the module *must* use the `Guess::new` function to create an instance of +the module _must_ use the `Guess::new` function to create an instance of `Guess`, thereby ensuring there’s no way for a `Guess` to have a `value` that hasn’t been checked by the conditions in the `Guess::new` function. diff --git a/src/ch10-00-generics.md b/src/ch10-00-generics.md index 2e68384e11..20289557f1 100644 --- a/src/ch10-00-generics.md +++ b/src/ch10-00-generics.md @@ -1,7 +1,7 @@ # Generic Types, Traits, and Lifetimes Every programming language has tools for effectively handling the duplication -of concepts. In Rust, one such tool is *generics*: abstract stand-ins for +of concepts. In Rust, one such tool is _generics_: abstract stand-ins for concrete types or other properties. We can express the behavior of generics or how they relate to other generics without knowing what will be in their place when compiling and running the code. @@ -18,11 +18,11 @@ then use the same technique to make a generic function from two functions that differ only in the types of their parameters. We’ll also explain how to use generic types in struct and enum definitions. -Then you’ll learn how to use *traits* to define behavior in a generic way. You +Then you’ll learn how to use _traits_ to define behavior in a generic way. You can combine traits with generic types to constrain a generic type to accept only those types that have a particular behavior, as opposed to just any type. -Finally, we’ll discuss *lifetimes*: a variety of generics that give the +Finally, we’ll discuss _lifetimes_: a variety of generics that give the compiler information about how references relate to each other. Lifetimes allow us to give the compiler enough information about borrowed values so that it can ensure references will be valid in more situations than it could without our diff --git a/src/ch10-01-syntax.md b/src/ch10-01-syntax.md index 2a22baf581..00e813978e 100644 --- a/src/ch10-01-syntax.md +++ b/src/ch10-01-syntax.md @@ -33,7 +33,7 @@ To parameterize the types in a new single function, we need to name the type parameter, just as we do for the value parameters to a function. You can use any identifier as a type parameter name. But we’ll use `T` because, by convention, type parameter names in Rust are short, often just one letter, and -Rust’s type-naming convention is UpperCamelCase. Short for *type*, `T` is the +Rust’s type-naming convention is UpperCamelCase. Short for _type_, `T` is the default choice of most Rust programmers. When we use a parameter in the body of the function, we have to declare the @@ -71,7 +71,7 @@ If we compile this code right now, we’ll get this error: {{#include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt}} ``` -The help text mentions `std::cmp::PartialOrd`, which is a *trait*, and we’re +The help text mentions `std::cmp::PartialOrd`, which is a _trait_, and we’re going to talk about traits in the next section. For now, know that this error states that the body of `largest` won’t work for all possible types that `T` could be. Because we want to compare values of type `T` in the body, we can @@ -104,7 +104,7 @@ types. Note that because we’ve used only one generic type to define `Point`, this definition says that the `Point` struct is generic over some type `T`, and -the fields `x` and `y` are *both* that same type, whatever that type may be. If +the fields `x` and `y` are _both_ that same type, whatever that type may be. If we create an instance of a `Point` that has values of different types, as in Listing 10-7, our code won’t compile. @@ -270,7 +270,7 @@ parameters. The good news is that using generic types won’t make your program run any slower than it would with concrete types. Rust accomplishes this by performing monomorphization of the code using -generics at compile time. *Monomorphization* is the process of turning generic +generics at compile time. _Monomorphization_ is the process of turning generic code into specific code by filling in the concrete types that are used when compiled. In this process, the compiler does the opposite of the steps we used to create the generic function in Listing 10-5: the compiler looks at all the diff --git a/src/ch10-02-traits.md b/src/ch10-02-traits.md index d9c40518ef..5628eef64b 100644 --- a/src/ch10-02-traits.md +++ b/src/ch10-02-traits.md @@ -1,11 +1,11 @@ ## Traits: Defining Shared Behavior -A *trait* defines the functionality a particular type has and can share with +A _trait_ defines the functionality a particular type has and can share with other types. We can use traits to define shared behavior in an abstract way. We -can use *trait bounds* to specify that a generic type can be any type that has +can use _trait bounds_ to specify that a generic type can be any type that has certain behavior. -> Note: Traits are similar to a feature often called *interfaces* in other +> Note: Traits are similar to a feature often called _interfaces_ in other > languages, although with some differences. ### Defining a Trait @@ -105,7 +105,7 @@ But we can’t implement external traits on external types. For example, we can implement the `Display` trait on `Vec` within our `aggregator` crate because `Display` and `Vec` are both defined in the standard library and aren’t local to our `aggregator` crate. This restriction is part of a property called -*coherence*, and more specifically the *orphan rule*, so named because the +_coherence_, and more specifically the _orphan rule_, so named because the parent type is not present. This rule ensures that other people’s code can’t break your code and vice versa. Without the rule, two crates could implement the same trait for the same type, and Rust wouldn’t know which implementation @@ -206,12 +206,13 @@ function with any other type, such as a `String` or an `i32`, won’t compile because those types don’t implement `Summary`. + #### Trait Bound Syntax The `impl Trait` syntax works for straightforward cases but is actually syntax -sugar for a longer form known as a *trait bound*; it looks like this: +sugar for a longer form known as a _trait bound_; it looks like this: ```rust,ignore pub fn notify(item: &T) { @@ -334,7 +335,7 @@ traits. For example, the type `Pair` in Listing 10-15 always implements the is a type alias for the type of the `impl` block, which in this case is `Pair`). But in the next `impl` block, `Pair` only implements the `cmp_display` method if its inner type `T` implements the `PartialOrd` trait -that enables comparison *and* the `Display` trait that enables printing. +that enables comparison _and_ the `Display` trait that enables printing. @@ -346,7 +347,7 @@ that enables comparison *and* the `Display` trait that enables printing. We can also conditionally implement a trait for any type that implements another trait. Implementations of a trait on any type that satisfies the trait -bounds are called *blanket implementations* and are used extensively in the +bounds are called _blanket implementations_ and are used extensively in the Rust standard library. For example, the standard library implements the `ToString` trait on any type that implements the `Display` trait. The `impl` block in the standard library looks similar to this code: diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index d9922d38ad..0a356ec641 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -6,7 +6,7 @@ references are valid as long as we need them to be. One detail we didn’t discuss in the [“References and Borrowing”][references-and-borrowing] section in Chapter 4 is -that every reference in Rust has a *lifetime*, which is the scope for which +that every reference in Rust has a _lifetime_, which is the scope for which that reference is valid. Most of the time, lifetimes are implicit and inferred, just like most of the time, types are inferred. We must annotate types only when multiple types are possible. In a similar way, we must annotate lifetimes @@ -21,7 +21,7 @@ lifetime syntax so you can get comfortable with the concept. ### Preventing Dangling References with Lifetimes -The main aim of lifetimes is to prevent *dangling references*, which cause a +The main aim of lifetimes is to prevent _dangling references_, which cause a program to reference data other than the data it’s intended to reference. Consider the program in Listing 10-16, which has an outer scope and an inner scope. @@ -62,7 +62,7 @@ determine that this code is invalid? It uses a borrow checker. ### The Borrow Checker -The Rust compiler has a *borrow checker* that compares scopes to determine +The Rust compiler has a _borrow checker_ that compares scopes to determine whether all borrows are valid. Listing 10-17 shows the same code as Listing 10-16 but with annotations showing the lifetimes of the variables. @@ -188,8 +188,8 @@ relate to each other in the context of the `longest` function. ### Lifetime Annotations in Function Signatures To use lifetime annotations in function signatures, we need to declare the -generic *lifetime* parameters inside angle brackets between the function name -and the parameter list, just as we did with generic *type* parameters. +generic _lifetime_ parameters inside angle brackets between the function name +and the parameter list, just as we did with generic _type_ parameters. We want the signature to express the following constraint: the returned reference will be valid as long as both the parameters are valid. This is the @@ -324,7 +324,7 @@ any relationship with the lifetime of `x` or the return value. When returning a reference from a function, the lifetime parameter for the return type needs to match the lifetime parameter for one of the parameters. If -the reference returned does *not* refer to one of the parameters, it must refer +the reference returned does _not_ refer to one of the parameters, it must refer to a value created within this function. However, this would be a dangling reference because the value will go out of scope at the end of the function. Consider this attempted implementation of the `longest` function that won’t @@ -425,7 +425,7 @@ deterministic patterns will emerge and be added to the compiler. In the future, even fewer lifetime annotations might be required. The patterns programmed into Rust’s analysis of references are called the -*lifetime elision rules*. These aren’t rules for programmers to follow; they’re +_lifetime elision rules_. These aren’t rules for programmers to follow; they’re a set of particular cases that the compiler will consider, and if your code fits these cases, you don’t need to write the lifetimes explicitly. @@ -435,8 +435,8 @@ compiler won’t guess what the lifetime of the remaining references should be. Instead of guessing, the compiler will give you an error that you can resolve by adding the lifetime annotations. -Lifetimes on function or method parameters are called *input lifetimes*, and -lifetimes on return values are called *output lifetimes*. +Lifetimes on function or method parameters are called _input lifetimes_, and +lifetimes on return values are called _output lifetimes_. The compiler uses three rules to figure out the lifetimes of the references when there aren’t explicit annotations. The first rule applies to input @@ -557,7 +557,7 @@ and all lifetimes have been accounted for. ### The Static Lifetime One special lifetime we need to discuss is `'static`, which denotes that the -affected reference *can* live for the entire duration of the program. All +affected reference _can_ live for the entire duration of the program. All string literals have the `'static` lifetime, which we can annotate as follows: ```rust @@ -611,8 +611,6 @@ that you will only need in very advanced scenarios; for those, you should read the [Rust Reference][reference]. But next, you’ll learn how to write tests in Rust so you can make sure your code is working the way it should. -[references-and-borrowing]: -ch04-02-references-and-borrowing.html#references-and-borrowing -[string-slices-as-parameters]: -ch04-03-slices.html#string-slices-as-parameters +[references-and-borrowing]: ch04-02-references-and-borrowing.html#references-and-borrowing +[string-slices-as-parameters]: ch04-03-slices.html#string-slices-as-parameters [reference]: ../reference/index.html diff --git a/src/ch11-00-testing.md b/src/ch11-00-testing.md index ea85a14101..f6e799d581 100644 --- a/src/ch11-00-testing.md +++ b/src/ch11-00-testing.md @@ -16,7 +16,7 @@ it. This function’s signature accepts an integer as a parameter and returns an integer as a result. When we implement and compile that function, Rust does all the type checking and borrow checking that you’ve learned so far to ensure that, for instance, we aren’t passing a `String` value or an invalid reference -to this function. But Rust *can’t* check that this function will do precisely +to this function. But Rust _can’t_ check that this function will do precisely what we intend, which is return the parameter plus 2 rather than, say, the parameter plus 10 or the parameter minus 50! That’s where tests come in. diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index 5c6452a7bd..93009f4d09 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -4,9 +4,9 @@ Tests are Rust functions that verify that the non-test code is functioning in the expected manner. The bodies of test functions typically perform these three actions: -* Set up any needed data or state. -* Run the code you want to test. -* Assert that the results are what you expect. +- Set up any needed data or state. +- Run the code you want to test. +- Assert that the results are what you expect. Let’s look at the features Rust provides specifically for writing tests that take these actions, which include the `test` attribute, a few macros, and the @@ -40,7 +40,7 @@ $ cargo new adder --lib $ cd adder ``` -The contents of the *src/lib.rs* file in your `adder` library should look like +The contents of the _src/lib.rs_ file in your `adder` library should look like Listing 11-1. @@ -100,7 +100,7 @@ Benchmark tests are, as of this writing, only available in nightly Rust. See [the documentation about benchmark tests][bench] to learn more. We can pass an argument to the `cargo test` command to run only tests whose -name matches a string; this is called *filtering* and we’ll cover that in the +name matches a string; this is called _filtering_ and we’ll cover that in the [“Running a Subset of Tests by Name”][subset] section. Here we haven’t filtered the tests being run, so the end of the summary shows `0 filtered out`. @@ -134,7 +134,7 @@ fail when something in the test function panics. Each test is run in a new thread, and when the main thread sees that a test thread has died, the test is marked as failed. In Chapter 9, we talked about how the simplest way to panic is to call the `panic!` macro. Enter the new test as a function named -`another`, so your *src/lib.rs* file looks like Listing 11-3. +`another`, so your _src/lib.rs_ file looks like Listing 11-3. @@ -164,7 +164,7 @@ Instead of `ok`, the line `test tests::another` shows `FAILED`. Two new sections appear between the individual results and the summary: the first displays the detailed reason for each test failure. In this case, we get the details that `another` failed because it `panicked at 'Make this test fail'` on -line 17 in the *src/lib.rs* file. The next section lists just the names of all +line 17 in the _src/lib.rs_ file. The next section lists just the names of all the failing tests, which is useful when there are lots of tests and lots of detailed failing test output. We can use the name of a failing test to run just that test to more easily debug it; we’ll talk more about ways to run tests in @@ -188,7 +188,7 @@ macro helps us check that our code is functioning in the way we intend. In Chapter 5, Listing 5-15, we used a `Rectangle` struct and a `can_hold` method, which are repeated here in Listing 11-5. Let’s put this code in the -*src/lib.rs* file, then write some tests for it using the `assert!` macro. +_src/lib.rs_ file, then write some tests for it using the `assert!` macro. @@ -275,7 +275,7 @@ do this by using the `assert!` macro and passing it an expression using the provides a pair of macros—`assert_eq!` and `assert_ne!`—to perform this test more conveniently. These macros compare two arguments for equality or inequality, respectively. They’ll also print the two values if the assertion -fails, which makes it easier to see *why* the test failed; conversely, the +fails, which makes it easier to see _why_ the test failed; conversely, the `assert!` macro only indicates that it got a `false` value for the `==` expression, without printing the values that led to the `false` value. @@ -331,7 +331,7 @@ that displays `` assertion failed: `(left == right)` ``. The `assert_ne!` macro will pass if the two values we give it are not equal and fail if they’re equal. This macro is most useful for cases when we’re not sure -what a value *will* be, but we know what the value definitely *shouldn’t* be. +what a value _will_ be, but we know what the value definitely _shouldn’t_ be. For example, if we’re testing a function that is guaranteed to change its input in some way, but the way in which the input is changed depends on the day of the week that we run our tests, the best thing to assert might be that the @@ -367,6 +367,7 @@ For example, let’s say we have a function that greets people by name and we want to test that the name we pass into the function appears in the output: Filename: src/lib.rs + ```rust,noplayground {{#rustdoc_include ../listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs}} ``` @@ -525,7 +526,7 @@ mark operator in the body of tests, which can be a convenient way to write tests that should fail if any operation within them returns an `Err` variant. You can’t use the `#[should_panic]` annotation on tests that use `Result`. To assert that an operation returns an `Err` variant, *don’t* use the +E>`. To assert that an operation returns an `Err` variant, _don’t_ use the question mark operator on the `Result` value. Instead, use `assert!(value.is_err())`. @@ -533,13 +534,11 @@ Now that you know several ways to write tests, let’s look at what is happening when we run our tests and explore the different options we can use with `cargo test`. -[concatenation-with-the--operator-or-the-format-macro]: -ch08-02-strings.html#concatenation-with-the--operator-or-the-format-macro +[concatenation-with-the--operator-or-the-format-macro]: ch08-02-strings.html#concatenation-with-the--operator-or-the-format-macro [bench]: ../unstable-book/library-features/test.html [ignoring]: ch11-02-running-tests.html#ignoring-some-tests-unless-specifically-requested [subset]: ch11-02-running-tests.html#running-a-subset-of-tests-by-name -[controlling-how-tests-are-run]: -ch11-02-running-tests.html#controlling-how-tests-are-run +[controlling-how-tests-are-run]: ch11-02-running-tests.html#controlling-how-tests-are-run [derivable-traits]: appendix-03-derivable-traits.html [doc-comments]: ch14-02-publishing-to-crates-io.html#documentation-comments-as-tests [paths-for-referring-to-an-item-in-the-module-tree]: ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html diff --git a/src/ch11-02-running-tests.md b/src/ch11-02-running-tests.md index 1c9a1a35da..dc4afc2af6 100644 --- a/src/ch11-02-running-tests.md +++ b/src/ch11-02-running-tests.md @@ -19,7 +19,6 @@ section][tests] of the [the rustc book][rustc]. [tests]: https://doc.rust-lang.org/rustc/tests/index.html [rustc]: https://doc.rust-lang.org/rustc/index.html - ### Running Tests in Parallel or Consecutively When you run multiple tests, by default they run in parallel using threads, @@ -29,7 +28,7 @@ on each other or on any shared state, including a shared environment, such as the current working directory or environment variables. For example, say each of your tests runs some code that creates a file on disk -named *test-output.txt* and writes some data to that file. Then each test reads +named _test-output.txt_ and writes some data to that file. Then each test reads the data in that file and asserts that the file contains a particular value, which is different in each test. Because the tests run at the same time, one test might overwrite the file in the time between another test writing and diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index 323f01a74a..d0c6ef3003 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -3,8 +3,8 @@ As mentioned at the start of the chapter, testing is a complex discipline, and different people use different terminology and organization. The Rust community thinks about tests in terms of two main categories: unit tests and integration -tests. *Unit tests* are small and more focused, testing one module in isolation -at a time, and can test private interfaces. *Integration tests* are entirely +tests. _Unit tests_ are small and more focused, testing one module in isolation +at a time, and can test private interfaces. _Integration tests_ are entirely external to your library and use your code in the same way any other external code would, using only the public interface and potentially exercising multiple modules per test. @@ -16,7 +16,7 @@ library are doing what you expect them to, separately and together. The purpose of unit tests is to test each unit of code in isolation from the rest of the code to quickly pinpoint where code is and isn’t working as -expected. You’ll put unit tests in the *src* directory in each file with the +expected. You’ll put unit tests in the _src_ directory in each file with the code that they’re testing. The convention is to create a module named `tests` in each file to contain the test functions and to annotate the module with `cfg(test)`. @@ -42,7 +42,7 @@ this chapter, Cargo generated this code for us: ``` On the automatically generated `tests` module, the attribute `cfg` stands for -*configuration* and tells Rust that the following item should only be included +_configuration_ and tells Rust that the following item should only be included given a certain configuration option. In this case, the configuration option is `test`, which is provided by Rust for compiling and running tests. By using the `cfg` attribute, Cargo compiles our test code only if we actively run the tests @@ -82,18 +82,18 @@ functions that are part of your library’s public API. Their purpose is to test whether many parts of your library work together correctly. Units of code that work correctly on their own could have problems when integrated, so test coverage of the integrated code is important as well. To create integration -tests, you first need a *tests* directory. +tests, you first need a _tests_ directory. -#### The *tests* Directory +#### The _tests_ Directory -We create a *tests* directory at the top level of our project directory, next -to *src*. Cargo knows to look for integration test files in this directory. We +We create a _tests_ directory at the top level of our project directory, next +to _src_. Cargo knows to look for integration test files in this directory. We can then make as many test files as we want, and Cargo will compile each of the files as an individual crate. Let’s create an integration test. With the code in Listing 11-12 still in the -*src/lib.rs* file, make a *tests* directory, and create a new file named -*tests/integration_test.rs*. Your directory structure should look like this: +_src/lib.rs_ file, make a _tests_ directory, and create a new file named +_tests/integration_test.rs_. Your directory structure should look like this: ```text adder @@ -105,7 +105,7 @@ adder └── integration_test.rs ``` -Enter the code in Listing 11-13 into the *tests/integration_test.rs* file. +Enter the code in Listing 11-13 into the _tests/integration_test.rs_ file. @@ -115,12 +115,12 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file. -Each file in the *tests* directory is a separate crate, so we need to bring our +Each file in the _tests_ directory is a separate crate, so we need to bring our library into each test crate’s scope. For that reason we add `use adder::add_two;` at the top of the code, which we didn’t need in the unit tests. -We don’t need to annotate any code in *tests/integration_test.rs* with -`#[cfg(test)]`. Cargo treats the *tests* directory specially and compiles files +We don’t need to annotate any code in _tests/integration_test.rs_ with +`#[cfg(test)]`. Cargo treats the _tests_ directory specially and compiles files in this directory only when we run `cargo test`. Run `cargo test` now: ```console @@ -143,7 +143,7 @@ that integration test and a summary line for the results of the integration test just before the `Doc-tests adder` section starts. Each integration test file has its own section, so if we add more files in the -*tests* directory, there will be more integration test sections. +_tests_ directory, there will be more integration test sections. We can still run a particular integration test function by specifying the test function’s name as an argument to `cargo test`. To run all the tests in a @@ -154,24 +154,24 @@ followed by the name of the file: {{#include ../listings/ch11-writing-automated-tests/output-only-05-single-integration/output.txt}} ``` -This command runs only the tests in the *tests/integration_test.rs* file. +This command runs only the tests in the _tests/integration_test.rs_ file. #### Submodules in Integration Tests As you add more integration tests, you might want to make more files in the -*tests* directory to help organize them; for example, you can group the test +_tests_ directory to help organize them; for example, you can group the test functions by the functionality they’re testing. As mentioned earlier, each file -in the *tests* directory is compiled as its own separate crate, which is useful +in the _tests_ directory is compiled as its own separate crate, which is useful for creating separate scopes to more closely imitate the way end users will be -using your crate. However, this means files in the *tests* directory don’t -share the same behavior as files in *src* do, as you learned in Chapter 7 +using your crate. However, this means files in the _tests_ directory don’t +share the same behavior as files in _src_ do, as you learned in Chapter 7 regarding how to separate code into modules and files. -The different behavior of *tests* directory files is most noticeable when you +The different behavior of _tests_ directory files is most noticeable when you have a set of helper functions to use in multiple integration test files and you try to follow the steps in the [“Separating Modules into Different Files”][separating-modules-into-files] section of Chapter 7 to -extract them into a common module. For example, if we create *tests/common.rs* +extract them into a common module. For example, if we create _tests/common.rs_ and place a function named `setup` in it, we can add some code to `setup` that we want to call from multiple test functions in multiple test files: @@ -182,7 +182,7 @@ we want to call from multiple test functions in multiple test files: ``` When we run the tests again, we’ll see a new section in the test output for the -*common.rs* file, even though this file doesn’t contain any test functions nor +_common.rs_ file, even though this file doesn’t contain any test functions nor did we call the `setup` function from anywhere: ```console @@ -192,7 +192,7 @@ did we call the `setup` function from anywhere: Having `common` appear in the test results with `running 0 tests` displayed for it is not what we wanted. We just wanted to share some code with the other integration test files. To avoid having `common` appear in the test output, -instead of creating *tests/common.rs*, we’ll create *tests/common/mod.rs*. The +instead of creating _tests/common.rs_, we’ll create _tests/common/mod.rs_. The project directory now looks like this: ```text @@ -210,14 +210,14 @@ This is the older naming convention that Rust also understands that we mentioned in the [“Alternate File Paths”][alt-paths] section of Chapter 7. Naming the file this way tells Rust not to treat the `common` module as an integration test file. When we move the `setup` function code into -*tests/common/mod.rs* and delete the *tests/common.rs* file, the section in the -test output will no longer appear. Files in subdirectories of the *tests* +_tests/common/mod.rs_ and delete the _tests/common.rs_ file, the section in the +test output will no longer appear. Files in subdirectories of the _tests_ directory don’t get compiled as separate crates or have sections in the test output. -After we’ve created *tests/common/mod.rs*, we can use it from any of the +After we’ve created _tests/common/mod.rs_, we can use it from any of the integration test files as a module. Here’s an example of calling the `setup` -function from the `it_adds_two` test in *tests/integration_test.rs*: +function from the `it_adds_two` test in _tests/integration_test.rs_: Filename: tests/integration_test.rs @@ -231,17 +231,17 @@ we demonstrated in Listing 7-21. Then, in the test function, we can call the #### Integration Tests for Binary Crates -If our project is a binary crate that only contains a *src/main.rs* file and -doesn’t have a *src/lib.rs* file, we can’t create integration tests in the -*tests* directory and bring functions defined in the *src/main.rs* file into +If our project is a binary crate that only contains a _src/main.rs_ file and +doesn’t have a _src/lib.rs_ file, we can’t create integration tests in the +_tests_ directory and bring functions defined in the _src/main.rs_ file into scope with a `use` statement. Only library crates expose functions that other crates can use; binary crates are meant to be run on their own. This is one of the reasons Rust projects that provide a binary have a -straightforward *src/main.rs* file that calls logic that lives in the -*src/lib.rs* file. Using that structure, integration tests *can* test the +straightforward _src/main.rs_ file that calls logic that lives in the +_src/lib.rs_ file. Using that structure, integration tests _can_ test the library crate with `use` to make the important functionality available. If the -important functionality works, the small amount of code in the *src/main.rs* +important functionality works, the small amount of code in the _src/main.rs_ file will work as well, and that small amount of code doesn’t need to be tested. ## Summary @@ -259,6 +259,5 @@ Let’s combine the knowledge you learned in this chapter and in previous chapters to work on a project! [paths]: ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html -[separating-modules-into-files]: -ch07-05-separating-modules-into-different-files.html +[separating-modules-into-files]: ch07-05-separating-modules-into-different-files.html [alt-paths]: ch07-05-separating-modules-into-different-files.html#alternate-file-paths diff --git a/src/ch12-00-an-io-project.md b/src/ch12-00-an-io-project.md index e179e11800..e421cc12f0 100644 --- a/src/ch12-00-an-io-project.md +++ b/src/ch12-00-an-io-project.md @@ -29,11 +29,11 @@ background knowledge you need to understand a real-world project such as Our `grep` project will combine a number of concepts you’ve learned so far: -* Organizing code ([Chapter 7][ch7]) -* Using vectors and strings ([Chapter 8][ch8]) -* Handling errors ([Chapter 9][ch9]) -* Using traits and lifetimes where appropriate ([Chapter 10][ch10]) -* Writing tests ([Chapter 11][ch11]) +- Organizing code ([Chapter 7][ch7]) +- Using vectors and strings ([Chapter 8][ch8]) +- Handling errors ([Chapter 9][ch9]) +- Using traits and lifetimes where appropriate ([Chapter 10][ch10]) +- Writing tests ([Chapter 11][ch11]) We’ll also briefly introduce closures, iterators, and trait objects, which [Chapter 13][ch13] and [Chapter 18][ch18] will diff --git a/src/ch12-02-reading-a-file.md b/src/ch12-02-reading-a-file.md index 804683d50d..bc6d79139b 100644 --- a/src/ch12-02-reading-a-file.md +++ b/src/ch12-02-reading-a-file.md @@ -4,7 +4,7 @@ Now we’ll add functionality to read the file specified in the `file_path` argument. First we need a sample file to test it with: we’ll use a file with a small amount of text over multiple lines with some repeated words. Listing 12-3 has an Emily Dickinson poem that will work well! Create a file called -*poem.txt* at the root level of your project, and enter the poem “I’m Nobody! +_poem.txt_ at the root level of your project, and enter the poem “I’m Nobody! Who are you?” @@ -15,7 +15,7 @@ Who are you?” -With the text in place, edit *src/main.rs* and add code to read the file, as +With the text in place, edit _src/main.rs_ and add code to read the file, as shown in Listing 12-4. @@ -38,7 +38,7 @@ of `contents` after the file is read, so we can check that the program is working so far. Let’s run this code with any string as the first command line argument (because -we haven’t implemented the searching part yet) and the *poem.txt* file as the +we haven’t implemented the searching part yet) and the _poem.txt_ file as the second argument: ```console diff --git a/src/ch12-03-improving-error-handling-and-modularity.md b/src/ch12-03-improving-error-handling-and-modularity.md index bf2b7c35bd..0bf85bdd61 100644 --- a/src/ch12-03-improving-error-handling-and-modularity.md +++ b/src/ch12-03-improving-error-handling-and-modularity.md @@ -41,34 +41,34 @@ community has developed guidelines for splitting the separate concerns of a binary program when `main` starts getting large. This process has the following steps: -* Split your program into a *main.rs* file and a *lib.rs* file and move your - program’s logic to *lib.rs*. -* As long as your command line parsing logic is small, it can remain in - *main.rs*. -* When the command line parsing logic starts getting complicated, extract it - from *main.rs* and move it to *lib.rs*. +- Split your program into a _main.rs_ file and a _lib.rs_ file and move your + program’s logic to _lib.rs_. +- As long as your command line parsing logic is small, it can remain in + _main.rs_. +- When the command line parsing logic starts getting complicated, extract it + from _main.rs_ and move it to _lib.rs_. The responsibilities that remain in the `main` function after this process should be limited to the following: -* Calling the command line parsing logic with the argument values -* Setting up any other configuration -* Calling a `run` function in *lib.rs* -* Handling the error if `run` returns an error +- Calling the command line parsing logic with the argument values +- Setting up any other configuration +- Calling a `run` function in _lib.rs_ +- Handling the error if `run` returns an error -This pattern is about separating concerns: *main.rs* handles running the -program and *lib.rs* handles all the logic of the task at hand. Because you +This pattern is about separating concerns: _main.rs_ handles running the +program and _lib.rs_ handles all the logic of the task at hand. Because you can’t test the `main` function directly, this structure lets you test all of -your program’s logic by moving it into functions in *lib.rs*. The code that -remains in *main.rs* will be small enough to verify its correctness by reading +your program’s logic by moving it into functions in _lib.rs_. The code that +remains in _main.rs_ will be small enough to verify its correctness by reading it. Let’s rework our program by following this process. #### Extracting the Argument Parser We’ll extract the functionality for parsing arguments into a function that `main` will call to prepare for moving the command line parsing logic to -*src/lib.rs*. Listing 12-5 shows the new start of `main` that calls a new -function `parse_config`, which we’ll define in *src/main.rs* for the moment. +_src/lib.rs_. Listing 12-5 shows the new start of `main` that calls a new +function `parse_config`, which we’ll define in _src/main.rs_ for the moment. @@ -243,6 +243,7 @@ we’ll use the other technique you learned about in Chapter 9—[returning a `Result`][ch9-result] that indicates either success or an error. + #### Returning a `Result` Instead of Calling `panic!` @@ -283,6 +284,7 @@ handle the `Result` value returned from the `build` function and exit the process more cleanly in the error case. + #### Calling `Config::build` and Handling Errors @@ -307,7 +309,7 @@ In this listing, we’ve used a method we haven’t covered in detail yet: Using `unwrap_or_else` allows us to define some custom, non-`panic!` error handling. If the `Result` is an `Ok` value, this method’s behavior is similar to `unwrap`: it returns the inner value that `Ok` is wrapping. However, if the -value is an `Err` value, this method calls the code in the *closure*, which is +value is an `Err` value, this method calls the code in the _closure_, which is an anonymous function we define and pass as an argument to `unwrap_or_else`. We’ll cover closures in more detail in [Chapter 13][ch13]. For now, you just need to know that `unwrap_or_else` will pass the inner value of @@ -342,7 +344,7 @@ inspection, and we’ll be able to write tests for all the other logic. Listing 12-11 shows the extracted `run` function. For now, we’re just making the small, incremental improvement of extracting the function. We’re still -defining the function in *src/main.rs*. +defining the function in _src/main.rs_. @@ -379,14 +381,14 @@ the `run` function to `Result<(), Box>`. This function previously returned the unit type, `()`, and we keep that as the value returned in the `Ok` case. -For the error type, we used the *trait object* `Box` (and we’ve +For the error type, we used the _trait object_ `Box` (and we’ve brought `std::error::Error` into scope with a `use` statement at the top). We’ll cover trait objects in [Chapter 18][ch18]. For now, just know that `Box` means the function will return a type that implements the `Error` trait, but we don’t have to specify what particular type the return value will be. This gives us flexibility to return error values that may be of different types in different error cases. The `dyn` keyword is short -for *dynamic*. +for _dynamic_. Second, we’ve removed the call to `expect` in favor of the `?` operator, as we talked about in [Chapter 9][ch9-question-mark]. Rather than @@ -435,20 +437,20 @@ both cases: we print the error and exit. ### Splitting Code into a Library Crate Our `minigrep` project is looking good so far! Now we’ll split the -*src/main.rs* file and put some code into the *src/lib.rs* file. That way, we -can test the code and have a *src/main.rs* file with fewer responsibilities. +_src/main.rs_ file and put some code into the _src/lib.rs_ file. That way, we +can test the code and have a _src/main.rs_ file with fewer responsibilities. -Let’s move all the code that isn’t in the `main` function from *src/main.rs* to -*src/lib.rs*: +Let’s move all the code that isn’t in the `main` function from _src/main.rs_ to +_src/lib.rs_: -* The `run` function definition -* The relevant `use` statements -* The definition of `Config` -* The `Config::build` function definition +- The `run` function definition +- The relevant `use` statements +- The definition of `Config` +- The `Config::build` function definition -The contents of *src/lib.rs* should have the signatures shown in Listing 12-13 +The contents of _src/lib.rs_ should have the signatures shown in Listing 12-13 (we’ve omitted the bodies of the functions for brevity). Note that this won’t -compile until we modify *src/main.rs* in Listing 12-14. +compile until we modify _src/main.rs_ in Listing 12-14. @@ -462,8 +464,8 @@ We’ve made liberal use of the `pub` keyword: on `Config`, on its fields and it `build` method, and on the `run` function. We now have a library crate that has a public API we can test! -Now we need to bring the code we moved to *src/lib.rs* into the scope of the -binary crate in *src/main.rs*, as shown in Listing 12-14. +Now we need to bring the code we moved to _src/lib.rs_ into the scope of the +binary crate in _src/main.rs_, as shown in Listing 12-14. @@ -480,7 +482,7 @@ work. Run the program with `cargo run` and make sure everything works correctly. Whew! That was a lot of work, but we’ve set ourselves up for success in the future. Now it’s much easier to handle errors, and we’ve made the code more -modular. Almost all of our work will be done in *src/lib.rs* from here on out. +modular. Almost all of our work will be done in _src/lib.rs_ from here on out. Let’s take advantage of this newfound modularity by doing something that would have been difficult with the old code but is easy with the new code: we’ll diff --git a/src/ch12-04-testing-the-librarys-functionality.md b/src/ch12-04-testing-the-librarys-functionality.md index 7034783d7c..92dac84aaf 100644 --- a/src/ch12-04-testing-the-librarys-functionality.md +++ b/src/ch12-04-testing-the-librarys-functionality.md @@ -1,7 +1,7 @@ ## Developing the Library’s Functionality with Test-Driven Development -Now that we’ve extracted the logic into *src/lib.rs* and left the argument -collecting and error handling in *src/main.rs*, it’s much easier to write tests +Now that we’ve extracted the logic into _src/lib.rs_ and left the argument +collecting and error handling in _src/main.rs_, it’s much easier to write tests for the core functionality of our code. We can call functions directly with various arguments and check return values without having to call our binary from the command line. @@ -28,8 +28,8 @@ lines that match the query. We’ll add this functionality in a function called ### Writing a Failing Test Because we don’t need them anymore, let’s remove the `println!` statements from -*src/lib.rs* and *src/main.rs* that we used to check the program’s behavior. -Then, in *src/lib.rs*, we’ll add a `tests` module with a test function, as we +_src/lib.rs_ and _src/main.rs_ that we used to check the program’s behavior. +Then, in _src/lib.rs_, we’ll add a `tests` module with a test function, as we did in [Chapter 11][ch11-anatomy]. The test function specifies the behavior we want the `search` function to have: it will take a query and the text to search, and it will return only the lines from the text that @@ -75,7 +75,7 @@ argument `query`). In other words, we tell Rust that the data returned by the `search` function will live as long as the data passed into the `search` function in the -`contents` argument. This is important! The data referenced *by* a slice needs +`contents` argument. This is important! The data referenced _by_ a slice needs to be valid for the reference to be valid; if the compiler assumes we’re making string slices of `query` rather than `contents`, it will do its safety checking incorrectly. @@ -205,20 +205,20 @@ will print each line returned from `search`: We’re still using a `for` loop to return each line from `search` and print it. Now the entire program should work! Let’s try it out, first with a word that -should return exactly one line from the Emily Dickinson poem: *frog*. +should return exactly one line from the Emily Dickinson poem: _frog_. ```console {{#include ../listings/ch12-an-io-project/no-listing-02-using-search-in-run/output.txt}} ``` -Cool! Now let’s try a word that will match multiple lines, like *body*: +Cool! Now let’s try a word that will match multiple lines, like _body_: ```console {{#include ../listings/ch12-an-io-project/output-only-03-multiple-matches/output.txt}} ``` And finally, let’s make sure that we don’t get any lines when we search for a -word that isn’t anywhere in the poem, such as *monomorphization*: +word that isn’t anywhere in the poem, such as _monomorphization_: ```console {{#include ../listings/ch12-an-io-project/output-only-04-no-matches/output.txt}} @@ -232,8 +232,7 @@ To round out this project, we’ll briefly demonstrate how to work with environment variables and how to print to standard error, both of which are useful when you’re writing command line programs. -[validating-references-with-lifetimes]: -ch10-03-lifetime-syntax.html#validating-references-with-lifetimes +[validating-references-with-lifetimes]: ch10-03-lifetime-syntax.html#validating-references-with-lifetimes [ch11-anatomy]: ch11-01-writing-tests.html#the-anatomy-of-a-test-function [ch10-lifetimes]: ch10-03-lifetime-syntax.html [ch3-iter]: ch03-05-control-flow.html#looping-through-a-collection-with-for diff --git a/src/ch12-05-working-with-environment-variables.md b/src/ch12-05-working-with-environment-variables.md index 630f98cb2f..b91b00ba8a 100644 --- a/src/ch12-05-working-with-environment-variables.md +++ b/src/ch12-05-working-with-environment-variables.md @@ -25,15 +25,15 @@ tests, as shown in Listing 12-20. Note that we’ve edited the old test’s `contents` too. We’ve added a new line -with the text `"Duct tape."` using a capital *D* that shouldn’t match the query +with the text `"Duct tape."` using a capital _D_ that shouldn’t match the query `"duct"` when we’re searching in a case-sensitive manner. Changing the old test in this way helps ensure that we don’t accidentally break the case-sensitive search functionality that we’ve already implemented. This test should pass now and should continue to pass as we work on the case-insensitive search. -The new test for the case-*insensitive* search uses `"rUsT"` as its query. In +The new test for the case-_insensitive_ search uses `"rUsT"` as its query. In the `search_case_insensitive` function we’re about to add, the query `"rUsT"` -should match the line containing `"Rust:"` with a capital *R* and match the +should match the line containing `"Rust:"` with a capital _R_ and match the line `"Trust me."` even though both have different casing from the query. This is our failing test, and it will fail to compile because we haven’t yet defined the `search_case_insensitive` function. Feel free to add a skeleton @@ -109,7 +109,7 @@ function, as shown in Listing 12-22. This still won’t compile yet. Finally, we need to check for the environment variable. The functions for working with environment variables are in the `env` module in the standard -library, so we bring that module into scope at the top of *src/lib.rs*. Then +library, so we bring that module into scope at the top of _src/lib.rs_. Then we’ll use the `var` function from the `env` module to check to see if any value has been set for an environment variable named `IGNORE_CASE`, as shown in Listing 12-23. @@ -133,7 +133,7 @@ We’re using the `is_ok` method on the `Result` to check whether the environmen variable is set, which means the program should do a case-insensitive search. If the `IGNORE_CASE` environment variable isn’t set to anything, `is_ok` will return `false` and the program will perform a case-sensitive search. We don’t -care about the *value* of the environment variable, just whether it’s set or +care about the _value_ of the environment variable, just whether it’s set or unset, so we’re checking `is_ok` rather than using `unwrap`, `expect`, or any of the other methods we’ve seen on `Result`. @@ -143,14 +143,14 @@ We pass the value in the `ignore_case` variable to the `Config` instance so the Let’s give it a try! First we’ll run our program without the environment variable set and with the query `to`, which should match any line that contains -the word *to* in all lowercase: +the word _to_ in all lowercase: ```console {{#include ../listings/ch12-an-io-project/listing-12-23/output.txt}} ``` Looks like that still works! Now let’s run the program with `IGNORE_CASE` set -to `1` but with the same query *to*: +to `1` but with the same query _to_: ```console $ IGNORE_CASE=1 cargo run -- to poem.txt @@ -170,7 +170,7 @@ It can be unset with the `Remove-Item` cmdlet: PS> Remove-Item Env:IGNORE_CASE ``` -We should get lines that contain *to* that might have uppercase letters: +We should get lines that contain _to_ that might have uppercase letters: + ## Closures: Anonymous Functions that Capture Their Environment @@ -11,6 +12,7 @@ We’ll demonstrate how these closure features allow for code reuse and behavior customization. + @@ -258,6 +260,7 @@ in the main thread after the closure is defined to see what compiler errors you get! + @@ -266,9 +269,9 @@ get! Once a closure has captured a reference or captured ownership of a value from the environment where the closure is defined (thus affecting what, if anything, -is moved *into* the closure), the code in the body of the closure defines what +is moved _into_ the closure), the code in the body of the closure defines what happens to the references or values when the closure is evaluated later (thus -affecting what, if anything, is moved *out of* the closure). A closure body can +affecting what, if anything, is moved _out of_ the closure). A closure body can do any of the following: move a captured value out of the closure, mutate the captured value, neither move nor mutate the value, or capture nothing from the environment to begin with. diff --git a/src/ch13-02-iterators.md b/src/ch13-02-iterators.md index 5942a62c5a..65573f114c 100644 --- a/src/ch13-02-iterators.md +++ b/src/ch13-02-iterators.md @@ -5,7 +5,7 @@ turn. An iterator is responsible for the logic of iterating over each item and determining when the sequence has finished. When you use iterators, you don’t have to reimplement that logic yourself. -In Rust, iterators are *lazy*, meaning they have no effect until you call +In Rust, iterators are _lazy_, meaning they have no effect until you call methods that consume the iterator to use it up. For example, the code in Listing 13-10 creates an iterator over the items in the vector `v1` by calling the `iter` method defined on `Vec`. This code by itself doesn’t do anything @@ -65,7 +65,7 @@ pub trait Iterator { ``` Notice this definition uses some new syntax: `type Item` and `Self::Item`, -which are defining an *associated type* with this trait. We’ll talk about +which are defining an _associated type_ with this trait. We’ll talk about associated types in depth in Chapter 20. For now, all you need to know is that this code says implementing the `Iterator` trait requires that you also define an `Item` type, and this `Item` type is used in the return type of the `next` @@ -90,7 +90,7 @@ from the vector. Note that we needed to make `v1_iter` mutable: calling the `next` method on an iterator changes internal state that the iterator uses to keep track of where -it is in the sequence. In other words, this code *consumes*, or uses up, the +it is in the sequence. In other words, this code _consumes_, or uses up, the iterator. Each call to `next` eats up an item from the iterator. We didn’t need to make `v1_iter` mutable when we used a `for` loop because the loop took ownership of `v1_iter` and made it mutable behind the scenes. @@ -111,7 +111,7 @@ trait. Some of these methods call the `next` method in their definition, which is why you’re required to implement the `next` method when implementing the `Iterator` trait. -Methods that call `next` are called *consuming adapters*, because calling them +Methods that call `next` are called _consuming adapters_, because calling them uses up the iterator. One example is the `sum` method, which takes ownership of the iterator and iterates through the items by repeatedly calling `next`, thus consuming the iterator. As it iterates through, it adds each item to a running @@ -131,7 +131,7 @@ ownership of the iterator we call it on. ### Methods that Produce Other Iterators -*Iterator adapters* are methods defined on the `Iterator` trait that don’t +_Iterator adapters_ are methods defined on the `Iterator` trait that don’t consume the iterator. Instead, they produce different iterators by changing some aspect of the original iterator. diff --git a/src/ch13-03-improving-our-io-project.md b/src/ch13-03-improving-our-io-project.md index c560bc1124..489bdc10fa 100644 --- a/src/ch13-03-improving-our-io-project.md +++ b/src/ch13-03-improving-our-io-project.md @@ -41,7 +41,7 @@ operations that borrow, we can move the `String` values from the iterator into #### Using the Returned Iterator Directly -Open your I/O project’s *src/main.rs* file, which should look like this: +Open your I/O project’s _src/main.rs_ file, which should look like this: Filename: src/main.rs @@ -67,7 +67,7 @@ we’re passing ownership of the iterator returned from `env::args` to `Config::build` directly. Next, we need to update the definition of `Config::build`. In your I/O -project’s *src/lib.rs* file, let’s change the signature of `Config::build` to +project’s _src/lib.rs_ file, let’s change the signature of `Config::build` to look like Listing 13-19. This still won’t compile because we need to update the function body. diff --git a/src/ch13-04-performance.md b/src/ch13-04-performance.md index 0dbc7420a0..d9cc06f99b 100644 --- a/src/ch13-04-performance.md +++ b/src/ch13-04-performance.md @@ -4,9 +4,9 @@ To determine whether to use loops or iterators, you need to know which implementation is faster: the version of the `search` function with an explicit `for` loop or the version with iterators. -We ran a benchmark by loading the entire contents of *The Adventures of -Sherlock Holmes* by Sir Arthur Conan Doyle into a `String` and looking for the -word *the* in the contents. Here are the results of the benchmark on the +We ran a benchmark by loading the entire contents of _The Adventures of +Sherlock Holmes_ by Sir Arthur Conan Doyle into a `String` and looking for the +word _the_ in the contents. Here are the results of the benchmark on the version of `search` using the `for` loop and the version using iterators: ```text @@ -24,10 +24,10 @@ various sizes as the `contents`, different words and words of different lengths as the `query`, and all kinds of other variations. The point is this: iterators, although a high-level abstraction, get compiled down to roughly the same code as if you’d written the lower-level code yourself. Iterators are one -of Rust’s *zero-cost abstractions*, by which we mean using the abstraction +of Rust’s _zero-cost abstractions_, by which we mean using the abstraction imposes no additional runtime overhead. This is analogous to how Bjarne Stroustrup, the original designer and implementor of C++, defines -*zero-overhead* in “Foundations of C++” (2012): +_zero-overhead_ in “Foundations of C++” (2012): > In general, C++ implementations obey the zero-overhead principle: What you > don’t use, you don’t pay for. And further: What you do use, you couldn’t hand @@ -70,7 +70,7 @@ consuming the value. What assembly code would this Rust code compile to? Well, as of this writing, it compiles down to the same assembly you’d write by hand. There’s no loop at all corresponding to the iteration over the values in `coefficients`: Rust knows that there are 12 iterations, so it “unrolls” the -loop. *Unrolling* is an optimization that removes the overhead of the loop +loop. _Unrolling_ is an optimization that removes the overhead of the loop controlling code and instead generates repetitive code for each iteration of the loop. diff --git a/src/ch14-00-more-about-cargo.md b/src/ch14-00-more-about-cargo.md index 8f8b8e51c7..a6d0d91549 100644 --- a/src/ch14-00-more-about-cargo.md +++ b/src/ch14-00-more-about-cargo.md @@ -4,12 +4,11 @@ So far we’ve used only the most basic features of Cargo to build, run, and tes our code, but it can do a lot more. In this chapter, we’ll discuss some of its other, more advanced features to show you how to do the following: -* Customize your build through release profiles -* Publish libraries on [crates.io](https://crates.io/) -* Organize large projects with workspaces -* Install binaries from [crates.io](https://crates.io/) -* Extend Cargo using custom commands +- Customize your build through release profiles +- Publish libraries on [crates.io](https://crates.io/) +- Organize large projects with workspaces +- Install binaries from [crates.io](https://crates.io/) +- Extend Cargo using custom commands Cargo can do even more than the functionality we cover in this chapter, so for -a full explanation of all its features, see [its -documentation](https://doc.rust-lang.org/cargo/). +a full explanation of all its features, see [its documentation](https://doc.rust-lang.org/cargo/). diff --git a/src/ch14-01-release-profiles.md b/src/ch14-01-release-profiles.md index 5038cf6972..6dd52c6425 100644 --- a/src/ch14-01-release-profiles.md +++ b/src/ch14-01-release-profiles.md @@ -1,6 +1,6 @@ ## Customizing Builds with Release Profiles -In Rust, *release profiles* are predefined and customizable profiles with +In Rust, _release profiles_ are predefined and customizable profiles with different configurations that allow a programmer to have more control over various options for compiling code. Each profile is configured independently of the others. @@ -29,7 +29,7 @@ $ cargo build --release The `dev` and `release` are these different profiles used by the compiler. Cargo has default settings for each of the profiles that apply when you haven't -explicitly added any `[profile.*]` sections in the project’s *Cargo.toml* file. +explicitly added any `[profile.*]` sections in the project’s _Cargo.toml_ file. By adding `[profile.*]` sections for any profile you want to customize, you override any subset of the default settings. For example, here are the default values for the `opt-level` setting for the `dev` and `release` profiles: @@ -55,8 +55,8 @@ so release mode trades longer compile time for code that runs faster. That is why the default `opt-level` for the `release` profile is `3`. You can override a default setting by adding a different value for it in -*Cargo.toml*. For example, if we want to use optimization level 1 in the -development profile, we can add these two lines to our project’s *Cargo.toml* +_Cargo.toml_. For example, if we want to use optimization level 1 in the +development profile, we can add these two lines to our project’s _Cargo.toml_ file: Filename: Cargo.toml diff --git a/src/ch14-02-publishing-to-crates-io.md b/src/ch14-02-publishing-to-crates-io.md index 0a72279cbf..5b9b36d321 100644 --- a/src/ch14-02-publishing-to-crates-io.md +++ b/src/ch14-02-publishing-to-crates-io.md @@ -16,10 +16,10 @@ Accurately documenting your packages will help other users know how and when to use them, so it’s worth investing the time to write documentation. In Chapter 3, we discussed how to comment Rust code using two slashes, `//`. Rust also has a particular kind of comment for documentation, known conveniently as a -*documentation comment*, that will generate HTML documentation. The HTML +_documentation comment_, that will generate HTML documentation. The HTML displays the contents of documentation comments for public API items intended -for programmers interested in knowing how to *use* your crate as opposed to how -your crate is *implemented*. +for programmers interested in knowing how to _use_ your crate as opposed to how +your crate is _implemented_. Documentation comments use three slashes, `///`, instead of two and support Markdown notation for formatting the text. Place documentation comments just @@ -39,7 +39,7 @@ section with the heading `Examples`, and then provide code that demonstrates how to use the `add_one` function. We can generate the HTML documentation from this documentation comment by running `cargo doc`. This command runs the `rustdoc` tool distributed with Rust and puts the generated HTML documentation -in the *target/doc* directory. +in the _target/doc_ directory. For convenience, running `cargo doc --open` will build the HTML for your current crate’s documentation (as well as the documentation for all of your @@ -58,14 +58,14 @@ We used the `# Examples` Markdown heading in Listing 14-1 to create a section in the HTML with the title “Examples.” Here are some other sections that crate authors commonly use in their documentation: -* **Panics**: The scenarios in which the function being documented could +- **Panics**: The scenarios in which the function being documented could panic. Callers of the function who don’t want their programs to panic should make sure they don’t call the function in these situations. -* **Errors**: If the function returns a `Result`, describing the kinds of +- **Errors**: If the function returns a `Result`, describing the kinds of errors that might occur and what conditions might cause those errors to be returned can be helpful to callers so they can write code to handle the different kinds of errors in different ways. -* **Safety**: If the function is `unsafe` to call (we discuss unsafety in +- **Safety**: If the function is `unsafe` to call (we discuss unsafety in Chapter 20), there should be a section explaining why the function is unsafe and covering the invariants that the function expects callers to uphold. @@ -106,12 +106,12 @@ that the example and the code are out of sync with each other! The style of doc comment `//!` adds documentation to the item that contains the comments rather than to the items following the comments. We typically use -these doc comments inside the crate root file (*src/lib.rs* by convention) or +these doc comments inside the crate root file (_src/lib.rs_ by convention) or inside a module to document the crate or the module as a whole. For example, to add documentation that describes the purpose of the `my_crate` crate that contains the `add_one` function, we add documentation comments that -start with `//!` to the beginning of the *src/lib.rs* file, as shown in Listing +start with `//!` to the beginning of the _src/lib.rs_ file, as shown in Listing 14-2: @@ -125,7 +125,7 @@ start with `//!` to the beginning of the *src/lib.rs* file, as shown in Listing Notice there isn’t any code after the last line that begins with `//!`. Because we started the comments with `//!` instead of `///`, we’re documenting the item that contains this comment rather than an item that follows this comment. In -this case, that item is the *src/lib.rs* file, which is the crate root. These +this case, that item is the _src/lib.rs_ file, which is the crate root. These comments describe the entire crate. When we run `cargo doc --open`, these comments will display on the front @@ -158,7 +158,7 @@ They might also be annoyed at having to enter `use` `my_crate::some_module::another_module::UsefulType;` rather than `use` `my_crate::UsefulType;`. -The good news is that if the structure *isn’t* convenient for others to use +The good news is that if the structure _isn’t_ convenient for others to use from another library, you don’t have to rearrange your internal organization: instead, you can re-export items to make a public structure that’s different from your private structure by using `pub use`. Re-exporting takes a public @@ -275,7 +275,7 @@ abcdefghijklmnopqrstuvwxyz012345 ``` This command will inform Cargo of your API token and store it locally in -*~/.cargo/credentials*. Note that this token is a *secret*: do not share it +_~/.cargo/credentials_. Note that this token is a _secret_: do not share it with anyone else. If you do share it with anyone for any reason, you should revoke it and generate a new token on [crates.io](https://crates.io/). @@ -283,7 +283,7 @@ revoke it and generate a new token on [crates.io](https://crates.io/) for others to use. -Be careful, because a publish is *permanent*. The version can never be +Be careful, because a publish is _permanent_. The version can never be overwritten, and the code cannot be deleted. One major goal of [crates.io](https://crates.io/) is to act as a permanent archive of code so that builds of all projects that depend on crates from @@ -411,12 +411,13 @@ anyone can easily add your crate as a dependency of their project. ### Publishing a New Version of an Existing Crate When you’ve made changes to your crate and are ready to release a new version, -you change the `version` value specified in your *Cargo.toml* file and +you change the `version` value specified in your _Cargo.toml_ file and republish. Use the [Semantic Versioning rules][semver] to decide what an appropriate next version number is based on the kinds of changes you’ve made. Then run `cargo publish` to upload the new version. + ### Deprecating Versions from Crates.io with `cargo yank` @@ -424,12 +425,12 @@ Then run `cargo publish` to upload the new version. Although you can’t remove previous versions of a crate, you can prevent any future projects from adding them as a new dependency. This is useful when a crate version is broken for one reason or another. In such situations, Cargo -supports *yanking* a crate version. +supports _yanking_ a crate version. Yanking a version prevents new projects from depending on that version while allowing all existing projects that depend on it to continue. Essentially, a -yank means that all projects with a *Cargo.lock* will not break, and any future -*Cargo.lock* files generated will not use the yanked version. +yank means that all projects with a _Cargo.lock_ will not break, and any future +_Cargo.lock_ files generated will not use the yanked version. To yank a version of a crate, in the directory of the crate that you’ve previously published, run `cargo yank` and specify which version you want to @@ -457,7 +458,7 @@ $ cargo yank --vers 1.0.1 --undo Unyank guessing_game@1.0.1 ``` -A yank *does not* delete any code. It cannot, for example, delete accidentally +A yank _does not_ delete any code. It cannot, for example, delete accidentally uploaded secrets. If that happens, you must reset those secrets immediately. [spdx]: http://spdx.org/licenses/ diff --git a/src/ch14-03-cargo-workspaces.md b/src/ch14-03-cargo-workspaces.md index 04bf2d6e7f..8f257b5849 100644 --- a/src/ch14-03-cargo-workspaces.md +++ b/src/ch14-03-cargo-workspaces.md @@ -3,12 +3,12 @@ In Chapter 12, we built a package that included a binary crate and a library crate. As your project develops, you might find that the library crate continues to get bigger and you want to split your package further into -multiple library crates. Cargo offers a feature called *workspaces* that can +multiple library crates. Cargo offers a feature called _workspaces_ that can help manage multiple related packages that are developed in tandem. ### Creating a Workspace -A *workspace* is a set of packages that share the same *Cargo.lock* and output +A _workspace_ is a set of packages that share the same _Cargo.lock_ and output directory. Let’s make a project using a workspace—we’ll use trivial code so we can concentrate on the structure of the workspace. There are multiple ways to structure a workspace, so we'll just show one common way. We’ll have a @@ -23,7 +23,7 @@ $ mkdir add $ cd add ``` -Next, in the *add* directory, we create the *Cargo.toml* file that will +Next, in the _add_ directory, we create the _Cargo.toml_ file that will configure the entire workspace. This file won’t have a `[package]` section. Instead, it will start with a `[workspace]` section that will allow us to add members to the workspace. We also make a point to use the latest and greatest @@ -31,7 +31,7 @@ version of Cargo’s resolver algorithm in our workspace by setting the `resolver` to `"2"`. by specifying the path to the package with our binary -crate; in this case, that path is *adder*: +crate; in this case, that path is _adder_: Filename: Cargo.toml @@ -40,7 +40,7 @@ crate; in this case, that path is *adder*: ``` Next, we’ll create the `adder` binary crate by running `cargo new` within the -*add* directory: +_add_ directory: + ## Installing Binaries with `cargo install` @@ -7,18 +8,17 @@ The `cargo install` command allows you to install and use binary crates locally. This isn’t intended to replace system packages; it’s meant to be a convenient way for Rust developers to install tools that others have shared on [crates.io](https://crates.io/). Note that you can only install -packages that have binary targets. A *binary target* is the runnable program -that is created if the crate has a *src/main.rs* file or another file specified +packages that have binary targets. A _binary target_ is the runnable program +that is created if the crate has a _src/main.rs_ file or another file specified as a binary, as opposed to a library target that isn’t runnable on its own but is suitable for including within other programs. Usually, crates have -information in the *README* file about whether a crate is a library, has a +information in the _README_ file about whether a crate is a library, has a binary target, or both. All binaries installed with `cargo install` are stored in the installation -root’s *bin* folder. If you installed Rust using *rustup.rs* and don’t have any +root’s _bin_ folder. If you installed Rust using _rustup.rs_ and don’t have any custom configurations, this directory will be *$HOME/.cargo/bin*. Ensure that -directory is in your `$PATH` to be able to run programs you’ve installed with -`cargo install`. +directory is in your `$PATH`to be able to run programs you’ve installed with`cargo install`. For example, in Chapter 12 we mentioned that there’s a Rust implementation of the `grep` tool called `ripgrep` for searching files. To install `ripgrep`, we diff --git a/src/ch15-00-smart-pointers.md b/src/ch15-00-smart-pointers.md index 9ecdcc8350..323463bf40 100644 --- a/src/ch15-00-smart-pointers.md +++ b/src/ch15-00-smart-pointers.md @@ -1,25 +1,25 @@ # Smart Pointers -A *pointer* is a general concept for a variable that contains an address in +A _pointer_ is a general concept for a variable that contains an address in memory. This address refers to, or “points at,” some other data. The most common kind of pointer in Rust is a reference, which you learned about in Chapter 4. References are indicated by the `&` symbol and borrow the value they point to. They don’t have any special capabilities other than referring to data, and have no overhead. -*Smart pointers*, on the other hand, are data structures that act like a +_Smart pointers_, on the other hand, are data structures that act like a pointer but also have additional metadata and capabilities. The concept of smart pointers isn’t unique to Rust: smart pointers originated in C++ and exist in other languages as well. Rust has a variety of smart pointers defined in the standard library that provide functionality beyond that provided by references. To explore the general concept, we’ll look at a couple of different examples of -smart pointers, including a *reference counting* smart pointer type. This +smart pointers, including a _reference counting_ smart pointer type. This pointer enables you to allow data to have multiple owners by keeping track of the number of owners and, when no owners remain, cleaning up the data. Rust, with its concept of ownership and borrowing, has an additional difference between references and smart pointers: while references only borrow data, in -many cases, smart pointers *own* the data they point to. +many cases, smart pointers _own_ the data they point to. Though we didn’t call them as such at the time, we’ve already encountered a few smart pointers in this book, including `String` and `Vec` in Chapter 8. Both @@ -41,13 +41,13 @@ frequently in Rust, this chapter won’t cover every existing smart pointer. Man libraries have their own smart pointers, and you can even write your own. We’ll cover the most common smart pointers in the standard library: -* `Box` for allocating values on the heap -* `Rc`, a reference counting type that enables multiple ownership -* `Ref` and `RefMut`, accessed through `RefCell`, a type that enforces +- `Box` for allocating values on the heap +- `Rc`, a reference counting type that enables multiple ownership +- `Ref` and `RefMut`, accessed through `RefCell`, a type that enforces the borrowing rules at runtime instead of compile time -In addition, we’ll cover the *interior mutability* pattern where an immutable +In addition, we’ll cover the _interior mutability_ pattern where an immutable type exposes an API for mutating an interior value. We’ll also discuss -*reference cycles*: how they can leak memory and how to prevent them. +_reference cycles_: how they can leak memory and how to prevent them. Let’s dive in! diff --git a/src/ch15-01-box.md b/src/ch15-01-box.md index 548152b5ca..f53ee6aaa7 100644 --- a/src/ch15-01-box.md +++ b/src/ch15-01-box.md @@ -1,6 +1,6 @@ ## Using `Box` to Point to Data on the Heap -The most straightforward smart pointer is a *box*, whose type is written +The most straightforward smart pointer is a _box_, whose type is written `Box`. Boxes allow you to store data on the heap rather than the stack. What remains on the stack is the pointer to the heap data. Refer to Chapter 4 to review the difference between the stack and the heap. @@ -9,11 +9,11 @@ Boxes don’t have performance overhead, other than storing their data on the heap instead of on the stack. But they don’t have many extra capabilities either. You’ll use them most often in these situations: -* When you have a type whose size can’t be known at compile time and you want +- When you have a type whose size can’t be known at compile time and you want to use a value of that type in a context that requires an exact size -* When you have a large amount of data and you want to transfer ownership but +- When you have a large amount of data and you want to transfer ownership but ensure the data won’t be copied when you do so -* When you want to own a value and you care only that it’s a type that +- When you want to own a value and you care only that it’s a type that implements a particular trait rather than being of a specific type We’ll demonstrate the first situation in the [“Enabling Recursive Types with @@ -23,7 +23,7 @@ time because the data is copied around on the stack. To improve performance in this situation, we can store the large amount of data on the heap in a box. Then, only the small amount of pointer data is copied around on the stack, while the data it references stays in one place on the heap. The third case is -known as a *trait object*, and Chapter 18 devotes an entire section, [“Using +known as a _trait object_, and Chapter 18 devotes an entire section, [“Using Trait Objects That Allow for Values of Different Types,”][trait-objects] just to that topic. So what you learn here you’ll apply again in Chapter 18! @@ -59,14 +59,14 @@ wouldn’t be allowed to if we didn’t have boxes. ### Enabling Recursive Types with Boxes -A value of *recursive type* can have another value of the same type as part of +A value of _recursive type_ can have another value of the same type as part of itself. Recursive types pose an issue because at compile time Rust needs to know how much space a type takes up. However, the nesting of values of recursive types could theoretically continue infinitely, so Rust can’t know how much space the value needs. Because boxes have a known size, we can enable recursive types by inserting a box in the recursive type definition. -As an example of a recursive type, let’s explore the *cons list*. This is a data +As an example of a recursive type, let’s explore the _cons list_. This is a data type commonly found in functional programming languages. The cons list type we’ll define is straightforward except for the recursion; therefore, the concepts in the example we’ll work with will be useful any time you get into @@ -74,7 +74,7 @@ more complex situations involving recursive types. #### More Information About the Cons List -A *cons list* is a data structure that comes from the Lisp programming language +A _cons list_ is a data structure that comes from the Lisp programming language and its dialects and is made up of nested pairs, and is the Lisp version of a linked list. Its name comes from the `cons` function (short for “construct function”) in Lisp that constructs a new pair from its two arguments. By @@ -97,7 +97,7 @@ which is an invalid or absent value. The cons list isn’t a commonly used data structure in Rust. Most of the time when you have a list of items in Rust, `Vec` is a better choice to use. -Other, more complex recursive data types *are* useful in various situations, +Other, more complex recursive data types _are_ useful in various situations, but by starting with the cons list in this chapter, we can explore how boxes let us define a recursive data type without much distraction. diff --git a/src/ch15-02-deref.md b/src/ch15-02-deref.md index 449e472dcd..a0b00e1a7e 100644 --- a/src/ch15-02-deref.md +++ b/src/ch15-02-deref.md @@ -1,7 +1,7 @@ ## Treating Smart Pointers Like Regular References with the `Deref` Trait Implementing the `Deref` trait allows you to customize the behavior of the -*dereference operator* `*` (not to be confused with the multiplication or glob +_dereference operator_ `*` (not to be confused with the multiplication or glob operator). By implementing `Deref` in such a way that a smart pointer can be treated like a regular reference, you can write code that operates on references and use that code with smart pointers too. @@ -11,7 +11,7 @@ Then we’ll try to define a custom type that behaves like `Box`, and see why the dereference operator doesn’t work like a reference on our newly defined type. We’ll explore how implementing the `Deref` trait makes it possible for 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 +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` type we’re about to @@ -20,6 +20,7 @@ or smart pointers. > is less important than the pointer-like behavior. + ### Following the Pointer to the Value @@ -40,7 +41,7 @@ reference to the value: The variable `x` holds an `i32` value `5`. We set `y` equal to a reference to `x`. We can assert that `x` is equal to `5`. However, if we want to make an assertion about the value in `y`, we have to use `*y` to follow the reference -to the value it’s pointing to (hence *dereference*) so the compiler can compare +to the value it’s pointing to (hence _dereference_) so the compiler can compare the actual value. Once we dereference `y`, we have access to the integer value `y` is pointing to that we can compare with `5`. @@ -187,7 +188,7 @@ Listing 15-9. ### Implicit Deref Coercions with Functions and Methods -*Deref coercion* converts a reference to a type that implements the `Deref` +_Deref coercion_ converts a reference to a type that implements the `Deref` trait into a reference to another type. For example, deref coercion can convert `&String` to `&str` because `String` implements the `Deref` trait such that it returns `&str`. Deref coercion is a convenience Rust performs on arguments to @@ -268,9 +269,9 @@ operator on mutable references. Rust does deref coercion when it finds types and trait implementations in three cases: -* From `&T` to `&U` when `T: Deref` -* From `&mut T` to `&mut U` when `T: DerefMut` -* From `&mut T` to `&U` when `T: Deref` +- From `&T` to `&U` when `T: Deref` +- From `&mut T` to `&mut U` when `T: DerefMut` +- From `&mut T` to `&U` when `T: Deref` The first two cases are the same as each other except that the second implements mutability. The first case states that if you have a `&T`, and `T` @@ -278,7 +279,7 @@ implements `Deref` to some type `U`, you can get a `&U` transparently. The second case states that the same deref coercion happens for mutable references. The third case is trickier: Rust will also coerce a mutable reference to an -immutable one. But the reverse is *not* possible: immutable references will +immutable one. But the reverse is _not_ possible: immutable references will never coerce to mutable references. Because of the borrowing rules, if you have a mutable reference, that mutable reference must be the only reference to that data (otherwise, the program wouldn’t compile). Converting one mutable diff --git a/src/ch15-03-drop.md b/src/ch15-03-drop.md index 8c402f408f..4f0b96bd97 100644 --- a/src/ch15-03-drop.md +++ b/src/ch15-03-drop.md @@ -93,14 +93,14 @@ When we try to compile this code, we’ll get this error: ``` This error message states that we’re not allowed to explicitly call `drop`. The -error message uses the term *destructor*, which is the general programming term -for a function that cleans up an instance. A *destructor* is analogous to a -*constructor*, which creates an instance. The `drop` function in Rust is one +error message uses the term _destructor_, which is the general programming term +for a function that cleans up an instance. A _destructor_ is analogous to a +_constructor_, which creates an instance. The `drop` function in Rust is one particular destructor. Rust doesn’t let us call `drop` explicitly because Rust would still automatically call `drop` on the value at the end of `main`. This would cause a -*double free* error because Rust would be trying to clean up the same value +_double free_ error because Rust would be trying to clean up the same value twice. We can’t disable the automatic insertion of `drop` when a value goes out of @@ -126,7 +126,7 @@ Running this code will print the following: {{#include ../listings/ch15-smart-pointers/listing-15-16/output.txt}} ``` -The text ```Dropping CustomSmartPointer with data `some data`!``` is printed +The text ``Dropping CustomSmartPointer with data `some data`!`` is printed between the `CustomSmartPointer created.` and `CustomSmartPointer dropped before the end of main.` text, showing that the `drop` method code is called to drop `c` at that point. diff --git a/src/ch15-04-rc.md b/src/ch15-04-rc.md index c5bf9a4897..6d1b243fc3 100644 --- a/src/ch15-04-rc.md +++ b/src/ch15-04-rc.md @@ -8,7 +8,7 @@ that point to it. A node shouldn’t be cleaned up unless it doesn’t have any edges pointing to it and so has no owners. You have to enable multiple ownership explicitly by using the Rust type -`Rc`, which is an abbreviation for *reference counting*. The `Rc` type +`Rc`, which is an abbreviation for _reference counting_. The `Rc` type keeps track of the number of references to a value to determine whether or not the value is still in use. If there are zero references to a value, the value can be cleaned up without any references becoming invalid. diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index 5b103dc0bf..f1d5547c7e 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -1,6 +1,6 @@ ## `RefCell` and the Interior Mutability Pattern -*Interior mutability* is a design pattern in Rust that allows you to mutate +_Interior mutability_ is a design pattern in Rust that allows you to mutate data even when there are immutable references to that data; normally, this action is disallowed by the borrowing rules. To mutate data, the pattern uses `unsafe` code inside a data structure to bend Rust’s usual rules that govern @@ -22,12 +22,12 @@ Unlike `Rc`, the `RefCell` type represents single ownership over the data it holds. So, what makes `RefCell` different from a type like `Box`? Recall the borrowing rules you learned in Chapter 4: -* At any given time, you can have *either* (but not both) one mutable reference +- At any given time, you can have _either_ (but not both) one mutable reference or any number of immutable references. -* References must always be valid. +- References must always be valid. With references and `Box`, the borrowing rules’ invariants are enforced at -compile time. With `RefCell`, these invariants are enforced *at runtime*. +compile time. With `RefCell`, these invariants are enforced _at runtime_. With references, if you break these rules, you’ll get a compiler error. With `RefCell`, if you break these rules, your program will panic and exit. @@ -60,16 +60,16 @@ multithreaded program in Chapter 16. Here is a recap of the reasons to choose `Box`, `Rc`, or `RefCell`: -* `Rc` enables multiple owners of the same data; `Box` and `RefCell` +- `Rc` enables multiple owners of the same data; `Box` and `RefCell` have single owners. -* `Box` allows immutable or mutable borrows checked at compile time; `Rc` +- `Box` allows immutable or mutable borrows checked at compile time; `Rc` allows only immutable borrows checked at compile time; `RefCell` allows immutable or mutable borrows checked at runtime. -* Because `RefCell` allows mutable borrows checked at runtime, you can +- Because `RefCell` allows mutable borrows checked at runtime, you can mutate the value inside the `RefCell` even when the `RefCell` is immutable. -Mutating the value inside an immutable value is the *interior mutability* +Mutating the value inside an immutable value is the _interior mutability_ pattern. Let’s look at a situation in which interior mutability is useful and examine how it’s possible. @@ -104,10 +104,10 @@ an immutable value and see why that is useful. Sometimes during testing a programmer will use a type in place of another type, in order to observe particular behavior and assert it’s implemented correctly. -This placeholder type is called a *test double*. Think of it in the sense of a +This placeholder type is called a _test double_. Think of it in the sense of a “stunt double” in filmmaking, where a person steps in and substitutes for an actor to do a particular tricky scene. Test doubles stand in for other types -when we’re running tests. *Mock objects* are specific types of test doubles +when we’re running tests. _Mock objects_ are specific types of test doubles that record what happens during a test so you can assert that the correct actions took place. @@ -284,7 +284,7 @@ provide. A common way to use `RefCell` is in combination with `Rc`. Recall that `Rc` lets you have multiple owners of some data, but it only gives immutable access to that data. If you have an `Rc` that holds a `RefCell`, you can -get a value that can have multiple owners *and* that you can mutate! +get a value that can have multiple owners _and_ that you can mutate! For example, recall the cons list example in Listing 15-18 where we used `Rc` to allow multiple lists to share ownership of another list. Because diff --git a/src/ch15-06-reference-cycles.md b/src/ch15-06-reference-cycles.md index 2ea12edb6f..a28df64386 100644 --- a/src/ch15-06-reference-cycles.md +++ b/src/ch15-06-reference-cycles.md @@ -1,7 +1,7 @@ ## Reference Cycles Can Leak Memory Rust’s memory safety guarantees make it difficult, but not impossible, to -accidentally create memory that is never cleaned up (known as a *memory leak*). +accidentally create memory that is never cleaned up (known as a _memory leak_). Preventing memory leaks entirely is not one of Rust’s guarantees, meaning memory leaks are memory safe in Rust. We can see that Rust allows memory leaks by using `Rc` and `RefCell`: it’s possible to create references where @@ -111,7 +111,7 @@ reference cycles. So far, we’ve demonstrated that calling `Rc::clone` increases the `strong_count` of an `Rc` instance, and an `Rc` instance is only cleaned -up if its `strong_count` is 0. You can also create a *weak reference* to the +up if its `strong_count` is 0. You can also create a _weak reference_ to the value within an `Rc` instance by calling `Rc::downgrade` and passing a reference to the `Rc`. Strong references are how you can share ownership of an `Rc` instance. Weak references don’t express an ownership relationship, @@ -136,7 +136,7 @@ Rust will ensure that the `Some` case and the `None` case are handled, and there won’t be an invalid pointer. As an example, rather than using a list whose items know only about the next -item, we’ll create a tree whose items know about their children items *and* +item, we’ll create a tree whose items know about their children items _and_ their parent items. #### Creating a Tree Data Structure: a `Node` with Child Nodes diff --git a/src/ch16-00-concurrency.md b/src/ch16-00-concurrency.md index 410f3e40da..27293fd239 100644 --- a/src/ch16-00-concurrency.md +++ b/src/ch16-00-concurrency.md @@ -1,8 +1,8 @@ # Fearless Concurrency Handling concurrent programming safely and efficiently is another of Rust’s -major goals. *Concurrent programming*, where different parts of a program -execute independently, and *parallel programming*, where different parts of a +major goals. _Concurrent programming_, where different parts of a program +execute independently, and _parallel programming_, where different parts of a program execute at the same time, are becoming increasingly important as more computers take advantage of their multiple processors. Historically, programming in these contexts has been difficult and error prone: Rust hopes to @@ -11,22 +11,22 @@ change that. Initially, the Rust team thought that ensuring memory safety and preventing concurrency problems were two separate challenges to be solved with different methods. Over time, the team discovered that the ownership and type systems are -a powerful set of tools to help manage memory safety *and* concurrency +a powerful set of tools to help manage memory safety _and_ concurrency problems! By leveraging ownership and type checking, many concurrency errors are compile-time errors in Rust rather than runtime errors. Therefore, rather than making you spend lots of time trying to reproduce the exact circumstances under which a runtime concurrency bug occurs, incorrect code will refuse to compile and present an error explaining the problem. As a result, you can fix your code while you’re working on it rather than potentially after it has been -shipped to production. We’ve nicknamed this aspect of Rust *fearless* -*concurrency*. Fearless concurrency allows you to write code that is free of +shipped to production. We’ve nicknamed this aspect of Rust _fearless_ +_concurrency_. Fearless concurrency allows you to write code that is free of subtle bugs and is easy to refactor without introducing new bugs. > Note: For simplicity’s sake, we’ll refer to many of the problems as -> *concurrent* rather than being more precise by saying *concurrent and/or -> parallel*. If this book were about concurrency and/or parallelism, we’d be -> more specific. For this chapter, please mentally substitute *concurrent -> and/or parallel* whenever we use *concurrent*. +> _concurrent_ rather than being more precise by saying _concurrent and/or +> parallel_. If this book were about concurrency and/or parallelism, we’d be +> more specific. For this chapter, please mentally substitute _concurrent +> and/or parallel_ whenever we use _concurrent_. Many languages are dogmatic about the solutions they offer for handling concurrent problems. For example, Erlang has elegant functionality for @@ -41,9 +41,9 @@ for your situation and requirements. Here are the topics we’ll cover in this chapter: -* How to create threads to run multiple pieces of code at the same time -* *Message-passing* concurrency, where channels send messages between threads -* *Shared-state* concurrency, where multiple threads have access to some piece +- How to create threads to run multiple pieces of code at the same time +- _Message-passing_ concurrency, where channels send messages between threads +- _Shared-state_ concurrency, where multiple threads have access to some piece of data -* The `Sync` and `Send` traits, which extend Rust’s concurrency guarantees to +- The `Sync` and `Send` traits, which extend Rust’s concurrency guarantees to user-defined types as well as types provided by the standard library diff --git a/src/ch16-01-threads.md b/src/ch16-01-threads.md index cc64664047..17d56ef7b5 100644 --- a/src/ch16-01-threads.md +++ b/src/ch16-01-threads.md @@ -1,9 +1,9 @@ ## Using Threads to Run Code Simultaneously In most current operating systems, an executed program’s code is run in a -*process*, and the operating system will manage multiple processes at once. +_process_, and the operating system will manage multiple processes at once. Within a program, you can also have independent parts that run simultaneously. -The features that run these independent parts are called *threads*. For +The features that run these independent parts are called _threads_. For example, a web server could have multiple threads so that it could respond to more than one request at the same time. @@ -13,11 +13,11 @@ Because threads can run simultaneously, there’s no inherent guarantee about th order in which parts of your code on different threads will run. This can lead to problems, such as: -* Race conditions, where threads are accessing data or resources in an +- Race conditions, where threads are accessing data or resources in an inconsistent order -* Deadlocks, where two threads are waiting for each other, preventing both +- Deadlocks, where two threads are waiting for each other, preventing both threads from continuing -* Bugs that happen only in certain situations and are hard to reproduce and fix +- Bugs that happen only in certain situations and are hard to reproduce and fix reliably Rust attempts to mitigate the negative effects of using threads, but @@ -27,7 +27,7 @@ thread. Programming languages implement threads in a few different ways, and many operating systems provide an API the language can call for creating new threads. -The Rust standard library uses a *1:1* model of thread implementation, whereby a +The Rust standard library uses a _1:1_ model of thread implementation, whereby a program uses one operating system thread per one language thread. There are crates that implement other models of threading that make different tradeoffs to the 1:1 model. (Rust’s async system, which we will see in the next chapter, @@ -104,7 +104,7 @@ call `join` to make sure the spawned thread finishes before `main` exits: Calling `join` on the handle blocks the thread currently running until the -thread represented by the handle terminates. *Blocking* a thread means that +thread represented by the handle terminates. _Blocking_ a thread means that thread is prevented from performing work or exiting. Because we’ve put the call to `join` after the main thread’s `for` loop, running Listing 16-2 should produce output similar to this: @@ -202,7 +202,7 @@ example, we get the following error: {{#include ../listings/ch16-fearless-concurrency/listing-16-03/output.txt}} ``` -Rust *infers* how to capture `v`, and because `println!` only needs a reference +Rust _infers_ how to capture `v`, and because `println!` only needs a reference to `v`, the closure tries to borrow `v`. However, there’s a problem: Rust can’t tell how long the spawned thread will run, so it doesn’t know if the reference to `v` will always be valid. @@ -246,7 +246,6 @@ should borrow the values. The modification to Listing 16-3 shown in Listing - ```rust {{#rustdoc_include ../listings/ch16-fearless-concurrency/listing-16-05/src/main.rs}} ``` @@ -275,6 +274,6 @@ Rust’s conservative default of borrowing; it doesn’t let us violate the ownership rules. With a basic understanding of threads and the thread API, let’s look at what we -can *do* with threads. +can _do_ with threads. [capture]: ch13-01-closures.html#capturing-references-or-moving-ownership diff --git a/src/ch16-02-message-passing.md b/src/ch16-02-message-passing.md index f2d396bfaa..d5b3c91ec1 100644 --- a/src/ch16-02-message-passing.md +++ b/src/ch16-02-message-passing.md @@ -1,13 +1,12 @@ ## Using Message Passing to Transfer Data Between Threads -One increasingly popular approach to ensuring safe concurrency is *message -passing*, where threads or actors communicate by sending each other messages -containing data. Here’s the idea in a slogan from [the Go language -documentation](https://golang.org/doc/effective_go.html#concurrency): +One increasingly popular approach to ensuring safe concurrency is _message +passing_, where threads or actors communicate by sending each other messages +containing data. Here’s the idea in a slogan from [the Go language documentation](https://golang.org/doc/effective_go.html#concurrency): “Do not communicate by sharing memory; instead, share memory by communicating.” To accomplish message-sending concurrency, Rust's standard library provides an -implementation of *channels*. A channel is a general programming concept by +implementation of _channels_. A channel is a general programming concept by which data is sent from one thread to another. You can imagine a channel in programming as being like a directional channel of @@ -19,7 +18,7 @@ the upstream location where you put rubber ducks into the river, and the receiver half is where the rubber duck ends up downstream. One part of your code calls methods on the transmitter with the data you want to send, and another part checks the receiving end for arriving messages. A channel is said -to be *closed* if either the transmitter or receiver half is dropped. +to be _closed_ if either the transmitter or receiver half is dropped. Here, we’ll work up to a program that has one thread to generate values and send them down a channel, and another thread that will receive the values and @@ -43,9 +42,9 @@ want to send over the channel. halves to `tx` and `rx` We create a new channel using the `mpsc::channel` function; `mpsc` stands for -*multiple producer, single consumer*. In short, the way Rust’s standard library -implements channels means a channel can have multiple *sending* ends that -produce values but only one *receiving* end that consumes those values. Imagine +_multiple producer, single consumer_. In short, the way Rust’s standard library +implements channels means a channel can have multiple _sending_ ends that +produce values but only one _receiving_ end that consumes those values. Imagine multiple streams flowing together into one big river: everything sent down any of the streams will end up in one river at the end. We’ll start with a single producer for now, but we’ll add multiple producers when we get this example @@ -54,7 +53,7 @@ working. The `mpsc::channel` function returns a tuple, the first element of which is the sending end—the transmitter—and the second element is the receiving end—the receiver. The abbreviations `tx` and `rx` are traditionally used in many fields -for *transmitter* and *receiver* respectively, so we name our variables as such +for _transmitter_ and _receiver_ respectively, so we name our variables as such to indicate each end. We’re using a `let` statement with a pattern that destructures the tuples; we’ll discuss the use of patterns in `let` statements and destructuring in Chapter 19. For now, know that using a `let` statement @@ -97,7 +96,7 @@ receiving a chat message. The receiver has two useful methods: `recv` and `try_recv`. We’re using `recv`, -short for *receive*, which will block the main thread’s execution and wait +short for _receive_, which will block the main thread’s execution and wait until a value is sent down the channel. Once a value is sent, `recv` will return it in a `Result`. When the transmitter closes, `recv` will return an error to signal that no more values will be coming. @@ -133,7 +132,7 @@ The ownership rules play a vital role in message sending because they help you write safe, concurrent code. Preventing errors in concurrent programming is the advantage of thinking about ownership throughout your Rust programs. Let’s do an experiment to show how channels and ownership work together to prevent -problems: we’ll try to use a `val` value in the spawned thread *after* we’ve +problems: we’ll try to use a `val` value in the spawned thread _after_ we’ve sent it down the channel. Try compiling the code in Listing 16-9 to see why this code isn’t allowed: @@ -206,8 +205,8 @@ the spawned thread. ### Creating Multiple Producers by Cloning the Transmitter -Earlier we mentioned that `mpsc` was an acronym for *multiple producer, -single consumer*. Let’s put `mpsc` to use and expand the code in Listing 16-10 +Earlier we mentioned that `mpsc` was an acronym for _multiple producer, +single consumer_. Let’s put `mpsc` to use and expand the code in Listing 16-10 to create multiple threads that all send values to the same receiver. We can do so by cloning the transmitter, as shown in Listing 16-11: diff --git a/src/ch16-03-shared-state.md b/src/ch16-03-shared-state.md index d319c6d6c2..52de2fb7dc 100644 --- a/src/ch16-03-shared-state.md +++ b/src/ch16-03-shared-state.md @@ -20,18 +20,18 @@ for shared memory. ### Using Mutexes to Allow Access to Data from One Thread at a Time -*Mutex* is an abbreviation for *mutual exclusion*, as in, a mutex allows only +_Mutex_ is an abbreviation for _mutual exclusion_, as in, a mutex allows only one thread to access some data at any given time. To access the data in a mutex, a thread must first signal that it wants access by asking to acquire the -mutex’s *lock*. The lock is a data structure that is part of the mutex that +mutex’s _lock_. The lock is a data structure that is part of the mutex that keeps track of who currently has exclusive access to the data. Therefore, the -mutex is described as *guarding* the data it holds via the locking system. +mutex is described as _guarding_ the data it holds via the locking system. Mutexes have a reputation for being difficult to use because you have to remember two rules: -* You must attempt to acquire the lock before using the data. -* When you’re done with the data that the mutex guards, you must unlock the +- You must attempt to acquire the lock before using the data. +- When you’re done with the data that the mutex guards, you must unlock the data so other threads can acquire the lock. For a real-world metaphor for a mutex, imagine a panel discussion at a @@ -72,12 +72,12 @@ that case, no one would ever be able to get the lock, so we’ve chosen to After we’ve acquired the lock, we can treat the return value, named `num` in this case, as a mutable reference to the data inside. The type system ensures that we acquire a lock before using the value in `m`. The type of `m` is -`Mutex`, not `i32`, so we *must* call `lock` to be able to use the `i32` +`Mutex`, not `i32`, so we _must_ call `lock` to be able to use the `i32` value. We can’t forget; the type system won’t let us access the inner `i32` otherwise. As you might suspect, `Mutex` is a smart pointer. More accurately, the call -to `lock` *returns* a smart pointer called `MutexGuard`, wrapped in a +to `lock` _returns_ a smart pointer called `MutexGuard`, wrapped in a `LockResult` that we handled with the call to `unwrap`. The `MutexGuard` smart pointer implements `Deref` to point at our inner data; the smart pointer also has a `Drop` implementation that releases the lock automatically when a @@ -153,7 +153,7 @@ a lot. Wow, that error message is very wordy! Here’s the important part to focus on: `` `Rc>` cannot be sent between threads safely ``. The compiler is -also telling us the reason why: ``the trait `Send` is not implemented for +also telling us the reason why: `` the trait `Send` is not implemented for `Rc>` ``. We’ll talk about `Send` in the next section: it’s one of the traits that ensures the types we use with threads are meant for use in concurrent situations. @@ -169,9 +169,9 @@ to the reference count in a thread-safe way. #### Atomic Reference Counting with `Arc` -Fortunately, `Arc` *is* a type like `Rc` that is safe to use in -concurrent situations. The *a* stands for *atomic*, meaning it’s an *atomically -reference counted* type. Atomics are an additional kind of concurrency +Fortunately, `Arc` _is_ a type like `Rc` that is safe to use in +concurrent situations. The _a_ stands for _atomic_, meaning it’s an _atomically +reference counted_ type. Atomics are an additional kind of concurrency primitive that we won’t cover in detail here: see the standard library documentation for [`std::sync::atomic`][atomic] for more details. At this point, you just need to know that atomics work like primitive @@ -231,7 +231,7 @@ Another detail to note is that Rust can’t protect you from all kinds of logic errors when you use `Mutex`. Recall in Chapter 15 that using `Rc` came with the risk of creating reference cycles, where two `Rc` values refer to each other, causing memory leaks. Similarly, `Mutex` comes with the risk of -creating *deadlocks*. These occur when an operation needs to lock two resources +creating _deadlocks_. These occur when an operation needs to lock two resources and two threads have each acquired one of the locks, causing them to wait for each other forever. If you’re interested in deadlocks, try creating a Rust program that has a deadlock; then research deadlock mitigation strategies for diff --git a/src/ch16-04-extensible-concurrency-sync-and-send.md b/src/ch16-04-extensible-concurrency-sync-and-send.md index 148b68ab3d..4bae9d68c6 100644 --- a/src/ch16-04-extensible-concurrency-sync-and-send.md +++ b/src/ch16-04-extensible-concurrency-sync-and-send.md @@ -1,6 +1,6 @@ ## Extensible Concurrency with the `Sync` and `Send` Traits -Interestingly, the Rust language has *very* few concurrency features. Almost +Interestingly, the Rust language has _very_ few concurrency features. Almost every concurrency feature we’ve talked about so far in this chapter has been part of the standard library, not the language. Your options for handling concurrency are not limited to the language or the standard library; you can @@ -82,6 +82,5 @@ run on multiple threads without the kinds of hard-to-track-down bugs common in other languages. Concurrent programming is no longer a concept to be afraid of: go forth and make your programs concurrent, fearlessly! -[sharing-a-mutext-between-multiple-threads]: -ch16-03-shared-state.html#sharing-a-mutext-between-multiple-threads +[sharing-a-mutext-between-multiple-threads]: ch16-03-shared-state.html#sharing-a-mutext-between-multiple-threads [nomicon]: ../nomicon/index.html diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 5fe7020224..acd0ed3762 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -27,10 +27,10 @@ happen while the network operation is still ongoing. > Note: The video export is the kind of operation which is often described as > “CPU-bound” or “compute-bound”. It’s limited by the speed of the computer’s -> ability to process data within the *CPU* or *GPU*, and how much of that speed +> ability to process data within the _CPU_ or _GPU_, and how much of that speed > it can use. The video download is the kind of operation which is often > described as “IO-bound,” because it’s limited by the speed of the computer’s -> *input and output*. It can only go as fast as the data can be sent across the +> _input and output_. It can only go as fast as the data can be sent across the > network. In both of these examples, the operating system’s invisible interrupts provide a @@ -44,14 +44,14 @@ For example, if we’re building a tool to manage file downloads, we should be able to write our program in such a way that starting one download does not lock up the UI, and users should be able to start multiple downloads at the same time. Many operating system APIs for interacting with the network are -*blocking*, though. That is, these APIs block the program’s progress until the +_blocking_, though. That is, these APIs block the program’s progress until the data that they are processing is completely ready. -> Note: This is how *most* function calls work, if you think about it! However, +> Note: This is how _most_ function calls work, if you think about it! However, > we normally reserve the term “blocking” for function calls which interact with > files, the network, or other resources on the computer, because those are the > places where an individual program would benefit from the operation being -> *non*-blocking. +> _non_-blocking. We could avoid blocking our main thread by spawning a dedicated thread to download each file. However, we would eventually find that the overhead of those @@ -79,7 +79,7 @@ could assign a single individual multiple tasks, or we could assign one task per team member, or we could do a mix of both approaches. When an individual works on several different tasks before any of them is -complete, this is *concurrency*. Maybe you have two different projects checked +complete, this is _concurrency_. Maybe you have two different projects checked out on your computer, and when you get bored or stuck on one project, you switch to the other. You’re just one person, so you can’t make progress on both tasks at the exact same time—but you can multi-task, making progress on multiple @@ -94,7 +94,7 @@ tasks by switching between them.
When you agree to split up a group of tasks between the people on the team, with -each person taking one task and working on it alone, this is *parallelism*. Each +each person taking one task and working on it alone, this is _parallelism_. Each person on the team can make progress at the exact same time.
@@ -106,10 +106,10 @@ person on the team can make progress at the exact same time.
With both of these situations, you might have to coordinate between different -tasks. Maybe you *thought* the task that one person was working on was totally +tasks. Maybe you _thought_ the task that one person was working on was totally independent from everyone else’s work, but it actually needs something finished by another person on the team. Some of the work could be done in parallel, but -some of it was actually *serial*: it could only happen in a series, one thing +some of it was actually _serial_: it could only happen in a series, one thing after the other, as in Figure 17-3.
@@ -146,8 +146,8 @@ under the hood. Now, let’s dive into how async programming in Rust actually works! In the rest of this chapter, we will: -* see how to use Rust’s `async` and `await` syntax -* explore how to use the async model to solve some of the same challenges we +- see how to use Rust’s `async` and `await` syntax +- explore how to use the async model to solve some of the same challenges we looked at in Chapter 16 -* look at how multithreading and async provide complementary solutions, which +- look at how multithreading and async provide complementary solutions, which you can even use together in many cases diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 86d2668fa0..11089811bb 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -1,9 +1,9 @@ ## Futures and the Async Syntax -The key elements of asynchronous programming in Rust are *futures* and Rust’s +The key elements of asynchronous programming in Rust are _futures_ and Rust’s `async` and `await` keywords. -A *future* is a value which may not be ready now, but will become ready at some +A _future_ is a value which may not be ready now, but will become ready at some point in the future. (This same concept shows up in many languages, sometimes under other names such as “task” or “promise”.) Rust provides a `Future` trait as a building block so different async operations can be implemented with @@ -14,10 +14,10 @@ made and what "ready" means. The `async` keyword can be applied to blocks and functions to specify that they can be interrupted and resumed. Within an async block or async function, you can -use the `await` keyword to wait for a future to become ready, called *awaiting a -future*. Each place you await a future within an async block or function is a +use the `await` keyword to wait for a future to become ready, called _awaiting a +future_. Each place you await a future within an async block or function is a place that async block or function may get paused and resumed. The process of -checking with a future to see if its value is available yet is called *polling*. +checking with a future to see if its value is available yet is called _polling_. Some other languages also use `async` and `await` keywords for async programming. If you’re familiar with those languages, you may notice some @@ -95,11 +95,11 @@ we need to wait for the server to send back the first part of its response, which will include HTTP headers, cookies, and so on. That part of the response can be delivered separately from the body of the request. Especially if the body is very large, it can take some time for it all to arrive. Thus, we have -to wait for the *entirety* of the response to arrive, so the `text` method is +to wait for the _entirety_ of the response to arrive, so the `text` method is also async. We have to explicitly await both of these futures, because futures in Rust are -*lazy*: they don’t do anything until you ask them to with `await`. (In fact, +_lazy_: they don’t do anything until you ask them to with `await`. (In fact, Rust will show a compiler warning if you don’t use a future.) This should remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. Iterators do nothing unless you call their `next` method—whether directly, or @@ -127,7 +127,7 @@ here, but `map` is more idiomatic.) In the body of the function we supply to a `String`. When all is said and done, we have an `Option`. Notice that Rust’s `await` keyword goes after the expression you’re awaiting, -not before it. That is, it’s a *postfix keyword*. This may be different from +not before it. That is, it’s a _postfix keyword_. This may be different from what you might be used to if you have used async in other languages. Rust chose this because it makes chains of methods much nicer to work with. As a result, we can change the body of `page_url_for` to chain the `trpl::get` and `text` @@ -152,7 +152,7 @@ body is an async block. An async function’s return type is the type of the anonymous data type the compiler creates for that async block. Thus, writing `async fn` is equivalent to writing a function which returns a -*future* of the return type. When the compiler sees a function definition such +_future_ of the return type. When the compiler sees a function definition such as the `async fn page_title` in Listing 17-1, it’s equivalent to a non-async function defined like this: @@ -173,26 +173,26 @@ fn page_title(url: &str) -> impl Future> + '_ { Let’s walk through each part of the transformed version: -* It uses the `impl Trait` syntax we discussed back in the [“Traits as +- It uses the `impl Trait` syntax we discussed back in the [“Traits as Parameters”][impl-trait] section in Chapter 10. -* The returned trait is a `Future`, with an associated type of `Output`. Notice +- The returned trait is a `Future`, with an associated type of `Output`. Notice that the `Output` type is `Option`, which is the same as the the original return type from the `async fn` version of `page_title`. -* All of the code called in the body of the original function is wrapped in an +- All of the code called in the body of the original function is wrapped in an `async move` block. Remember that blocks are expressions. This whole block is the expression returned from the function. -* This async block produces a value with the type `Option`, as described +- This async block produces a value with the type `Option`, as described above. That value matches the `Output` type in the return type. This is just like other blocks you have seen. -* The new function body is an `async move` block because of how it uses the +- The new function body is an `async move` block because of how it uses the `url` parameter. (We’ll talk about `async` vs. `async move` much more later in the chapter.) -* The new version of the function has a kind of lifetime we haven’t seen before +- The new version of the function has a kind of lifetime we haven’t seen before in the output type: `'_`. Because the function returns a `Future` which refers to a reference—in this case, the reference from the `url` parameter—we need to tell Rust that we mean for that reference to be included. We don’t have to name the lifetime here, because Rust is smart enough to know there is only one - reference which could be involved, but we *do* have to be explicit that the + reference which could be involved, but we _do_ have to be explicit that the resulting `Future` is bound by that lifetime. Now we can call `page_title` in `main`. To start, we’ll just get the title @@ -228,10 +228,10 @@ error[E0752]: `main` function is not allowed to be `async` | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async` ``` -The reason `main` can’t be marked `async` is that async code needs a *runtime*: +The reason `main` can’t be marked `async` is that async code needs a _runtime_: a Rust crate which manages the details of executing asynchronous code. A -program’s `main` function can *initialize* a runtime, but it’s not a runtime -*itself*. (We’ll see more about why this is a bit later.) Every Rust program +program’s `main` function can _initialize_ a runtime, but it’s not a runtime +_itself_. (We’ll see more about why this is a bit later.) Every Rust program that executes async code has at least one place where it sets up a runtime and executes the futures. @@ -288,7 +288,7 @@ Phew: we finally have some working async code! This now compiles, and we can run it. Before we add code to race two sites against each other, let’s briefly turn our attention back to how futures work. -Each *await point*—that is, every place where the code uses the `await` +Each _await point_—that is, every place where the code uses the `await` keyword—represents a place where control gets handed back to the runtime. To make that work, Rust needs to keep track of the state involved in the async block, so that the runtime can kick off some other work and then come back when @@ -309,7 +309,7 @@ the compiler also handles checking those for us, and has good error messages. We’ll work through a few of those later in the chapter! Ultimately, something has to execute that state machine. That something is a -runtime. (This is why you may sometimes come across references to *executors* +runtime. (This is why you may sometimes come across references to _executors_ when looking into runtimes: an executor is the part of a runtime responsible for executing the async code.) @@ -320,7 +320,7 @@ but `main` is the starting point for the program! Instead, we call the `trpl::run` function in `main`, which sets up a runtime and runs the future returned by the `async` block until it returns `Ready`. -> Note: some runtimes provide macros to make it so you *can* write an async main +> Note: some runtimes provide macros to make it so you _can_ write an async main > function. Those macros rewrite `async fn main() { ... }` to be a normal `fn > main` which does the same thing we did by hand in Listing 17-5: call a > function which runs a future to completion the way `trpl::run` does. @@ -367,7 +367,7 @@ enum Either { The `race` function returns `Left` if the first argument finishes first, with that future’s output, and `Right` with the second future argument’s output if -*that* one finishes first. This matches the order the arguments appear when +_that_ one finishes first. This matches the order the arguments appear when calling the function: the first argument is to the left of the second argument. We also update `page_title` to return the same URL passed in. That way, if @@ -384,7 +384,9 @@ dig into even more of the things we can do with async. [impl-trait]: ch10-02-traits.html#traits-as-parameters [iterators-lazy]: ch13-02-iterators.html + + [crate-source]: https://github.com/rust-lang/book/tree/main/packages/trpl [futures-crate]: https://crates.io/crates/futures [tokio]: https://tokio.rs diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 22557d1b7a..522b84092b 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -7,7 +7,7 @@ threads and futures. In many cases, the APIs for working with concurrency using async are very similar to those for using threads. In other cases, they end up being shaped -quite differently. Even when the APIs *look* similar between threads and async, +quite differently. Even when the APIs _look_ similar between threads and async, they often have different behavior—and they nearly always have different performance characteristics. @@ -76,7 +76,7 @@ after awaiting it.
-This updated version runs till *both* loops finish. +This updated version runs till _both_ loops finish. @@ -297,25 +297,25 @@ With the updated code in Listing 17-11, the messages get printed at The program still never exits, though, because of the way `while let` loop interacts with `trpl::join`: -* The future returned from `trpl::join` only completes once *both* futures +- The future returned from `trpl::join` only completes once _both_ futures passed to it have completed. -* The `tx` future completes once it finishes sleeping after sending the last +- The `tx` future completes once it finishes sleeping after sending the last message in `vals`. -* The `rx` future won’t complete until the `while let` loop ends. -* The `while let` loop won’t end until awaiting `rx.recv` produces `None`. -* Awaiting `rx.recv` will only return `None` once the other end of the channel +- The `rx` future won’t complete until the `while let` loop ends. +- The `while let` loop won’t end until awaiting `rx.recv` produces `None`. +- Awaiting `rx.recv` will only return `None` once the other end of the channel is closed. -* The channel will only close if we call `rx.close` or when the sender side, +- The channel will only close if we call `rx.close` or when the sender side, `tx`, is dropped. -* We don’t call `rx.close` anywhere, and `tx` won’t be dropped until the +- We don’t call `rx.close` anywhere, and `tx` won’t be dropped until the outermost async block passed to `trpl::run` ends. -* The block can’t end because it is blocked on `trpl::join` completing, which +- The block can’t end because it is blocked on `trpl::join` completing, which takes us back to the top of this list! We could manually close `rx` by calling `rx.close` somewhere, but that doesn’t make much sense. Stopping after handling some arbitrary number of messages would make the program shut down, but we could miss messages. We need some other way -to make sure that `tx` gets dropped *before* the end of the function. +to make sure that `tx` gets dropped _before_ the end of the function. Right now, the async block where we send the messages only borrows `tx` because sending a message doesn’t require ownership, but if we could move `tx` into @@ -326,7 +326,7 @@ same basic dynamics apply to async blocks, so the `move` keyword works with async blocks just as it does with closures. In Listing 17-12, we change the async block for sending messages from a plain -`async` block to an `async move` block. When we run *this* version of the code, +`async` block to an `async move` block. When we run _this_ version of the code, it shuts down gracefully after the last message is sent and received. @@ -341,7 +341,7 @@ This async channel is also a multiple-producer channel, so we can call `clone` on `tx` if we want to send messages from multiple futures. In Listing 17-13, we clone `tx`, creating `tx1` outside the first async block. We move `tx1` into that block just as we did before with `tx`. Then, later, we move the original -`tx` into a *new* async block, where we send more messages on a slightly slower +`tx` into a _new_ async block, where we send more messages on a slightly slower delay. We happen to put this new async block after the async block for receiving messages, but it could go before it just as well. The key is the order of the futures are awaited in, not the order they are created in. diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index cab96d1f1d..aaf8e9084b 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -23,7 +23,7 @@ futures into a collection and then waiting on some or all the futures in that collection to complete is a common pattern. To check all the futures in some collection, we’ll need to iterate over and -join on *all* of them. The `trpl::join_all` function accepts any type which +join on _all_ of them. The `trpl::join_all` function accepts any type which implements the `Iterator` trait, which we learned about back in Chapter 13, so it seems like just the ticket. Let’s try putting our futures in a vector, and replace `join!` with `join_all`. @@ -44,7 +44,6 @@ cargo build copy just the compiler error --> - ```text error[E0308]: mismatched types --> src/main.rs:45:37 @@ -71,7 +70,7 @@ by the compiler for async blocks. You can’t put two different hand-written structs in a `Vec`, and the same thing applies to the different structs generated by the compiler. -To make this work, we need to use *trait objects*, just as we did in [“Returning +To make this work, we need to use _trait objects_, just as we did in [“Returning Errors from the run function”][dyn] in Chapter 12. (We’ll cover trait objects in detail in Chapter 18.) Using trait objects lets us treat each of the anonymous futures produced by these types as the same type, because all of them @@ -112,11 +111,11 @@ back to the `Unpin` errors in a moment. First, let’s fix the type errors on th The type we had to write here is a little involved, so let’s walk through it: -* The innermost type is the future itself. We note explicitly that the output of +- The innermost type is the future itself. We note explicitly that the output of the future is the unit type `()` by writing `Future`. -* Then we annotate the trait with `dyn` to mark it as dynamic. -* The entire trait reference is wrapped in a `Box`. -* Finally, we state explicitly that `futures` is a `Vec` containing these items. +- Then we annotate the trait with `dyn` to mark it as dynamic. +- The entire trait reference is wrapped in a `Box`. +- Finally, we state explicitly that `futures` is a `Vec` containing these items. That already made a big difference. Now when we run the compiler, we only have the errors mentioning `Unpin`. Although there are three of them, notice that @@ -235,7 +234,7 @@ note: required by a bound in `futures_util::future::join_all::JoinAll` | ^^^^^^ required by this bound in `JoinAll` ``` -That is a *lot* to digest, so let’s pull it apart. The first part of the message +That is a _lot_ to digest, so let’s pull it apart. The first part of the message tell us that the first async block (`src/main.rs:8:23: 20:10`) does not implement the `Unpin` trait, and suggests using `pin!` or `Box::pin` to resolve it. Later in the chapter, we’ll dig into a few more details about `Pin` and @@ -274,7 +273,7 @@ Phew! There’s a bit more we can explore here. For one thing, using `Pin>` comes with a small amount of extra overhead from putting these futures on the heap with `Box`—and we’re only doing that to get the types to line up. We don’t -actually *need* the heap allocation, after all: these futures are local to this +actually _need_ the heap allocation, after all: these futures are local to this particular function. As noted above, `Pin` is itself a wrapper type, so we can get the benefit of having a single type in the `Vec`—the original reason we reached for `Box`—without doing a heap allocation. We can use `Pin` directly @@ -308,7 +307,7 @@ types. For example, in Listing 17-20, the anonymous future for `a` implements We can use `trpl::join!` to await them, because it allows you to pass in -multiple future types and produces a tuple of those types. We *cannot* use +multiple future types and produces a tuple of those types. We _cannot_ use `trpl::join_all`, because it requires the futures passed in all to have the same type. Remember, that error is what got us started on this adventure with `Pin`! @@ -322,8 +321,8 @@ syntax for working with them, and that is a good thing. ### Racing futures When we “join” futures with the `join` family of functions and macros, we -require *all* of them to finish before we move on. Sometimes, though, we only -need *some* future from a set to finish before we move on—kind of similar to +require _all_ of them to finish before we move on. Sometimes, though, we only +need _some_ future from a set to finish before we move on—kind of similar to racing one future against another. In Listing 17-21, we once again use `trpl::race` to run two futures, `slow` and @@ -347,20 +346,20 @@ Notice that if you flip the order of the arguments to `race`, the order of the “started” messages changes, even though the `fast` future always completes first. That’s because the implementation of this particular `race` function is not fair. It always runs the futures passed as arguments in the order they’re -passed. Other implementations *are* fair, and will randomly choose which future +passed. Other implementations _are_ fair, and will randomly choose which future to poll first. Regardless of whether the implementation of race we’re using is -fair, though, *one* of the futures will run up to the first `await` in its body +fair, though, _one_ of the futures will run up to the first `await` in its body before another task can start. Recall from [Our First Async Program][async-program] that at each await point, Rust gives a runtime a chance to pause the task and switch to another one if the -future being awaited isn’t ready. The inverse is also true: Rust *only* pauses +future being awaited isn’t ready. The inverse is also true: Rust _only_ pauses async blocks and hands control back to a runtime at an await point. Everything between await points is synchronous. That means if you do a bunch of work in an async block without an await point, that future will block any other futures from making progress. You may sometimes -hear this referred to as one future *starving* other futures. In some cases, +hear this referred to as one future _starving_ other futures. In some cases, that may not be a big deal. However, if you are doing some kind of expensive setup or long-running work, or if you have a future which will keep doing some particular task indefinitely, you’ll need to think about when and where to @@ -370,7 +369,7 @@ By the same token, if you have long-running blocking operations, async can be a useful tool for providing ways for different parts of the program to relate to each other. -But *how* would you hand control back to the runtime in those cases? +But _how_ would you hand control back to the runtime in those cases? ### Yielding @@ -390,7 +389,7 @@ blocking. In Listing 17-23, we use `slow` to emulate doing this kind of CPU-bound work in a pair of futures. To begin, each future only hands control back to the runtime -*after* carrying out a bunch of slow operations. +_after_ carrying out a bunch of slow operations. @@ -431,7 +430,7 @@ means we need something we can await! We can already see this kind of handoff happening in Listing 17-23: if we removed the `trpl::sleep` at the end of the `a` future, it would complete -without the `b` future running *at all*. Maybe we could use the `sleep` function +without the `b` future running _at all_. Maybe we could use the `sleep` function as a starting point? @@ -469,7 +468,7 @@ swap back and forth each time one of them hits an await point. In this case, we have done that after every call to `slow`, but we could break up the work however makes the most sense to us. -We don’t really want to *sleep* here, though: we want to make progress as fast +We don’t really want to _sleep_ here, though: we want to make progress as fast as we can. We just need to hand back control to the runtime. We can do that directly, using the `yield_now` function. In Listing 17-25, we replace all those `sleep` calls with `yield_now`. @@ -486,7 +485,7 @@ This is both clearer about the actual intent and can be significantly faster than using `sleep`, because timers such as the one used by `sleep` often have limits to how granular they can be. The version of `sleep` we are using, for example, will always sleep for at least a millisecond, even if we pass it a -`Duration` of one nanosecond. Again, modern computers are *fast*: they can do a +`Duration` of one nanosecond. Again, modern computers are _fast_: they can do a lot in one millisecond! You can see this for yourself by setting up a little benchmark, such as the one @@ -505,23 +504,23 @@ compared to the future using `trpl::yield_now`. -The version with `yield_now` is *way* faster! +The version with `yield_now` is _way_ faster! This means that async can be useful even for compute-bound tasks, depending on what else your program is doing, because it provides a useful tool for structuring the relationships between different parts of the program. This is a -form of *cooperative multitasking*, where each future has the power to determine +form of _cooperative multitasking_, where each future has the power to determine when it hands over control via await points. Each future therefore also has the responsibility to avoid blocking for too long. In some Rust-based embedded -operating systems, this is the *only* kind of multitasking! +operating systems, this is the _only_ kind of multitasking! In real-world code, you won’t usually be alternating function calls with await points on every single line, of course. While yielding control in this way is relatively inexpensive, it’s not free! In many cases, trying to break up a compute-bound task might make it significantly slower, so sometimes it’s better -for *overall* performance to let an operation block briefly. You should always +for _overall_ performance to let an operation block briefly. You should always measure to see what your code’s actual performance bottlenecks are. The -underlying dynamic is an important one to keep in mind if you *are* seeing a +underlying dynamic is an important one to keep in mind if you _are_ seeing a lot of work happening in serial that you expected to happen concurrently, though! @@ -545,12 +544,12 @@ future. Let’s implement this! To begin, let’s think about the API for `timeout`: -* It needs to be an async function itself so we can await it. -* Its first parameter should be a future to run. We can make it generic to allow +- It needs to be an async function itself so we can await it. +- Its first parameter should be a future to run. We can make it generic to allow it to work with any future. -* Its second parameter will be the maximum time to wait. If we use a `Duration`, +- Its second parameter will be the maximum time to wait. If we use a `Duration`, that will make it easy to pass along to `trpl::sleep`. -* It should return a `Result`. If the future completes successfully, the +- It should return a `Result`. If the future completes successfully, the `Result` will be `Ok` with the value produced by the future. If the timeout elapses first, the `Result` will be `Err` with the duration that the timeout waited for. @@ -567,7 +566,7 @@ Listing 17-28 shows this declaration. -That satisfies our goals for the types. Now let’s think about the *behavior* we +That satisfies our goals for the types. Now let’s think about the _behavior_ we need: we want to race the future passed in against the duration. We can use `trpl::sleep` to make a timer future from the duration, and use `trpl::race` to run that timer with the future the caller passes in. @@ -611,19 +610,18 @@ APIs. We’ve now seen a number of ways to work with multiple futures at the same time. Up next, we’ll look at how we can work with multiple futures in a -sequence over time, with *streams*. Here are a couple more things you might want +sequence over time, with _streams_. Here are a couple more things you might want to consider first, though: -* We used a `Vec` with `join_all` to wait for all of the futures in some group +- We used a `Vec` with `join_all` to wait for all of the futures in some group to finish. How could you use a `Vec` to process a group of futures in sequence, instead? What are the tradeoffs of doing that? -* Take a look at the `futures::stream::FuturesUnordered` type from the `futures` +- Take a look at the `futures::stream::FuturesUnordered` type from the `futures` crate. How would using it be different from using a `Vec`? (Don’t worry about the fact that it is from the `stream` part of the crate; it works just fine with any collection of futures.) - [collections]: ch08-01-vectors.html#using-an-enum-to-store-multiple-types [dyn]: ch12-03-improving-error-handling-and-modularity.html [async-program]: ch17-01-futures-and-syntax.html#our-first-async-program diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index d08e40689a..11b4a04fd4 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -4,7 +4,7 @@ So far in this chapter, we have mostly stuck to individual futures. The one big exception was the async channel we used. Recall how we used the receiver for our async channel in the [“Message Passing”][17-02-messages] earlier in the chapter. The async `recv` method produces a sequence of items over time. This is an -instance of a much more general pattern, often called a *stream*. +instance of a much more general pattern, often called a _stream_. A sequence of items is something we’ve seen before, when we looked at the `Iterator` trait in Chapter 13. There are two differences between iterators and @@ -206,7 +206,7 @@ need to use async. However, we can’t make `get_messages` itself into an async function, because then we’d return a `Future>` instead of a `Stream>`. The caller would have to await `get_messages` itself to get access to the stream. But remember: everything in a -given future happens linearly; concurrency happens *between* futures. Awaiting +given future happens linearly; concurrency happens _between_ futures. Awaiting `get_messages` would require it to send all the messages, including sleeping between sending each message, before returning the receiver stream. As a result, the timeout would end up useless. There would be no delays in the stream itself: @@ -216,7 +216,7 @@ Instead, we leave `get_messages` as a regular function which returns a stream, and spawn a task to handle the async `sleep` calls. > Note: calling `spawn_task` in this way works because we already set up our -> runtime. Calling this particular implementation of `spawn_task` *without* +> runtime. Calling this particular implementation of `spawn_task` _without_ > first setting up a runtime will cause a panic. Other implementations choose > different tradeoffs: they might spawn a new runtime and so avoid the panic but > end up with a bit of extra overhead, or simply not provide a standalone way to @@ -321,7 +321,7 @@ In Listing 17-38, we rework the `intervals` stream, because `messages` is already in the basic format we want and has to handle timeout errors. First, we can use the `map` helper method to transform the `intervals` into a string. Second, we need to match the `Timeout` from `messages`. Because we don’t -actually *want* a timeout for `intervals`, though, we can just create a timeout +actually _want_ a timeout for `intervals`, though, we can just create a timeout which is longer than the other durations we are using. Here, we create a 10-second timeout with `Duration::from_secs(10)`. Finally, we need to make `stream` mutable, so that the `while let` loop’s `next` calls can iterate @@ -337,7 +337,7 @@ through the stream, and pin it so that it’s safe to do so.
-That gets us *almost* to where we need to be. Everything type checks. If you run +That gets us _almost_ to where we need to be. Everything type checks. If you run this, though, there will be two problems. First, it will never stop! You’ll need to stop it with ctrl-c. Second, the messages from the English alphabet will be buried in the midst of all the @@ -367,7 +367,7 @@ hundred milliseconds should do, because that is in the same ballpark as how often our messages arrive. To limit the number of items we will accept from a stream, we can use the `take` -method. We apply it to the *merged* stream, because we want to limit the final +method. We apply it to the _merged_ stream, because we want to limit the final output, not just one stream or the other. @@ -381,7 +381,7 @@ output, not just one stream or the other. Now when we run the program, it stops after pulling twenty items from the stream, and the intervals don’t overwhelm the messages. We also don’t get `Interval: 100` or `Interval: 200` or so on, but instead get `Interval: 1`, -`Interval: 2`, and so on—even though we have a source stream which *can* +`Interval: 2`, and so on—even though we have a source stream which _can_ produce an event every millisecond. That’s because the `throttle` call produces a new stream, wrapping the original stream, so that the original stream only gets polled at the throttle rate, not its own “native” rate. We @@ -424,7 +424,7 @@ channel-based streams, the `send` calls could fail when the other side of the channel closes—and that’s just a matter of how the runtime executes the futures which make up the stream. Up until now we have ignored this by calling `unwrap`, but in a well-behaved app, we should explicitly handle the error, at minimum by -ending the loop so we don’t try to send any more messages! Listing 17-40 shows +ending the loop so we don’t try to send any more messages! Listing 17-40 shows a simple error strategy: print the issue and then `break` from the loops. As usual, the correct way to handle a message send error will vary—just make sure you have a strategy. diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index e3819d9a49..b5cc800ce8 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -5,8 +5,8 @@ Throughout the chapter, we’ve used the `Future`, `Pin`, `Unpin`, `Stream`, and far into the details of how they work or how they fit together. Much of the time when writing Rust day to day, this is fine. Sometimes, though, you’ll hit situations where understanding a few more of these details matters. In this -section, we’ll dig down *enough* further to help with those situations—while -still leaving the *really* deep dive for other documentation! +section, we’ll dig down _enough_ further to help with those situations—while +still leaving the _really_ deep dive for other documentation! ### Future @@ -110,7 +110,7 @@ advances it when `poll` returns `Poll::Ready(Some(message))` or The exact details of how a runtime does that are more than we will cover in even this deep dive section. The key here is to see the basic mechanic of futures: a -runtime *polls* each future it is responsible for, putting it back to sleep when +runtime _polls_ each future it is responsible for, putting it back to sleep when it is not yet ready. ### Pinning and the Pin and Unpin Traits @@ -159,7 +159,7 @@ the collection all implement the `Future` trait, and `Box` only implements trait. That’s a lot! But we can understand it, if we dive a little further into how the -`Future` type actually works, in particular around *pinning*. +`Future` type actually works, in particular around _pinning_. Let’s look again at the definition of `Future`: @@ -194,7 +194,7 @@ to the type, which is wrapped in a `Pin`. `Pin` is a wrapper type. In some ways, it’s similar to the `Box`, `Rc`, and other smart pointer types we saw in Chapter 15, which also wrap other types. -Unlike those, however, `Pin` only works with *pointer types* such as references +Unlike those, however, `Pin` only works with _pointer types_ such as references (`&` and `&mut`) and smart pointers (`Box`, `Rc`, and so on). To be precise, `Pin` works with types which implement the `Deref` or `DerefMut` traits, which we covered in Chapter 15. You can think of this restriction as equivalent to @@ -262,13 +262,13 @@ In principle, the Rust compiler could try to update every reference to an object every time it gets moved. That would potentially be a lot of performance overhead, especially given there can be a whole web of references that need updating. On the other hand, if we could make sure the data structure in -question *doesn’t move in memory*, we don’t have to update any references. +question _doesn’t move in memory_, we don’t have to update any references. This is exactly what Rust’s borrow checker requires: you can’t move an item which has any active references to it using safe code. -`Pin` builds on that to give us the exact guarantee we need. When we *pin* a +`Pin` builds on that to give us the exact guarantee we need. When we _pin_ a value by wrapping a pointer to that value in `Pin`, it can no longer move. Thus, -if you have `Pin>`, you actually pin the `SomeType` value, *not* +if you have `Pin>`, you actually pin the `SomeType` value, _not_ the `Box` pointer. Figure 17-6 illustrates this:
@@ -313,19 +313,19 @@ around in cases such as these. For that, we have `Unpin`. Chapter 16. Recall that marker traits have no functionality of their own. They exist only to tell the compiler that it’s safe to use the type which implements a given trait in a particular context. `Unpin` informs the compiler that a given -type does *not* need to uphold any particular guarantees about whether the value +type does _not_ need to uphold any particular guarantees about whether the value in question can be moved. Just as with `Send` and `Sync`, the compiler implements `Unpin` automatically for all types where it can prove it is safe. The special case, again similar to -`Send` and `Sync`, is the case where `Unpin` is *not* implemented for a type. +`Send` and `Sync`, is the case where `Unpin` is _not_ implemented for a type. The notation for this is `impl !Unpin for SomeType`, where `SomeType` is the -name of a type which *does* need to uphold those guarantees to be safe whenever +name of a type which _does_ need to uphold those guarantees to be safe whenever a pointer to that type is used in a `Pin`. In other words, there are two things to keep in mind about the relationship between `Pin` and `Unpin`. First, `Unpin` is the “normal” case, and `!Unpin` is -the special case. Second, whether a type implements `Unpin` or `!Unpin` *only* +the special case. Second, whether a type implements `Unpin` or `!Unpin` _only_ matters when using a pinned pointer to that type like `Pin<&mut SomeType>`. To make that concrete, think about a `String`: it has a length and the Unicode @@ -360,7 +360,7 @@ from back in Listing 17-17. We originally tried to move the futures produced by async blocks into a `Vec>>`, but as we’ve seen, those futures may have internal references, so they don’t implement `Unpin`. They need to be pinned, and then we can pass the `Pin` type into the `Vec`, -confident that the underlying data in the futures will *not* be moved. +confident that the underlying data in the futures will _not_ be moved. `Pin` and `Unpin` are mostly important for building lower-level libraries, or when you’re building a runtime itself, rather than for day to day Rust code. @@ -369,7 +369,7 @@ idea of how to fix the code! > Note: This combination of `Pin` and `Unpin` allows a whole class of complex > types to be safe in Rust which are otherwise difficult to implement because -> they’re self-referential. Types which require `Pin` show up *most* commonly +> they’re self-referential. Types which require `Pin` show up _most_ commonly > in async Rust today, but you might—very rarely!—see it in other contexts, too. > > The specifics of how `Pin` and `Unpin` work, and the rules they’re required @@ -389,7 +389,7 @@ Now that we have a deeper grasp on the `Future`, `Pin`, and `Unpin` traits, we can turn our attention to the `Stream` trait. As described in the section introducing streams, streams are similar to asynchronous iterators. Unlike `Iterator` and `Future`, there is no definition of a `Stream` trait in the -standard library as of the time of writing, but there *is* a very common +standard library as of the time of writing, but there _is_ a very common definition from the `futures` crate used throughout the ecosystem. Let’s review the definitions of the `Iterator` and `Future` traits, so we can @@ -432,9 +432,9 @@ standard library. In the meantime, it’s part of the toolkit of most runtimes, so you can rely on it, and everything we cover below should generally apply! In the example we saw in the section on streaming, though, we didn’t use -`poll_next` *or* `Stream`, but instead used `next` and `StreamExt`. We *could* +`poll_next` _or_ `Stream`, but instead used `next` and `StreamExt`. We _could_ work directly in terms of the `poll_next` API by hand-writing our own `Stream` -state machines, of course, just as we *could* work with futures directly via +state machines, of course, just as we _could_ work with futures directly via their `poll` method. Using `await` is much nicer, though, so the `StreamExt` trait supplies the `next` method so we can do just that. @@ -468,7 +468,7 @@ APIs. In the version of `StreamExt` used in the `trpl` crate, the trait not only defines the `next` method, it also supplies an implementation of `next`, which correctly handles the details of calling `Stream::poll_next`. This means that -even when you need to write your own streaming data type, you *only* have to +even when you need to write your own streaming data type, you _only_ have to implement `Stream`, and then anyone who uses your data type can use `StreamExt` and its methods with it automatically. diff --git a/src/ch17-06-futures-tasks-threads.md b/src/ch17-06-futures-tasks-threads.md index 4569d727c0..5fa6629810 100644 --- a/src/ch17-06-futures-tasks-threads.md +++ b/src/ch17-06-futures-tasks-threads.md @@ -4,7 +4,7 @@ As we saw in the previous chapter, threads provide one approach to concurrency. We’ve seen another approach to concurrency in this chapter, using async with futures and streams. You might be wondering why you would choose one or the other. The answer is: it depends! And in many cases, the choice isn’t threads -*or* async but rather threads *and* async. +_or_ async but rather threads _and_ async. Many operating systems have supplied threading-based concurrency models for decades now, and many programming languages have support for them as a result. @@ -48,9 +48,9 @@ spawn millions of async tasks on any modern personal computer. If we tried to do that with threads, we would literally run out of memory! However, there’s a reason these APIs are so similar. Threads act as a boundary -for sets of synchronous operations; concurrency is possible *between* threads. -Tasks act as a boundary for sets of *asynchronous* operations; concurrency is -possible both *between* and *within* tasks, because a task can switch between +for sets of synchronous operations; concurrency is possible _between_ threads. +Tasks act as a boundary for sets of _asynchronous_ operations; concurrency is +possible both _between_ and _within_ tasks, because a task can switch between futures in its body. Finally, futures are Rust’s most granular unit of concurrency, and each future may represent a tree of other futures. The runtime—specifically, its executor—manages tasks, and tasks manage futures. In @@ -65,7 +65,7 @@ Concurrency with threads is in some ways a simpler programming model than concurrency with `async`. That can be a strength or a weakness. Threads are somewhat “fire and forget,” they have no native equivalent to a future, so they simply run to completion, without interruption except by the operating system -itself. That is, they have no built-in support for *intra-task concurrency* the +itself. That is, they have no built-in support for _intra-task concurrency_ the way futures do. Threads in Rust also have no mechanisms for cancellation—a subject we haven’t covered in depth in this chapter, but which is implicit in the fact that whenever we ended a future, its state got cleaned up correctly. @@ -77,22 +77,22 @@ or the `throttle` method we used with streams in [“Composing Streams”][strea The fact that futures are richer data structures means they can be composed together more naturally, as we have seen. -Tasks then give *additional* control over futures, allowing you to choose where +Tasks then give _additional_ control over futures, allowing you to choose where and how to group the futures. And it turns out that threads and tasks often work very well together, because tasks can (at least in some runtimes) be moved around between threads. We haven’t mentioned it up until now, but under the hood the `Runtime` we have been using, including the `spawn_blocking` and `spawn_task` functions, is multithreaded by default! Many runtimes use an -approach called *work stealing* to transparently move tasks around between +approach called _work stealing_ to transparently move tasks around between threads based on the current utilization of the threads, with the aim of improving the overall performance of the system. To build that actually requires -threads *and* tasks, and therefore futures. +threads _and_ tasks, and therefore futures. As a default way of thinking about which to use when: -- If the work is *very parallelizable*, such as processing a bunch of data where +- If the work is _very parallelizable_, such as processing a bunch of data where each part can be processed separately, threads are a better choice. -- If the work is *very concurrent*, such as handling messages from a bunch of +- If the work is _very concurrent_, such as handling messages from a bunch of different sources which may come in a different intervals or different rates, async is a better choice. @@ -136,6 +136,5 @@ Next, we’ll talk about idiomatic ways to model problems and structure solution as your Rust programs get bigger. In addition, we’ll discuss how Rust’s idioms relate to those you might be familiar with from object-oriented programming. - [combining-futures]: ch17-03-more-futures.html#building-our-own-async-abstractions [streams]: ch17-04-streams.html#composing-streams diff --git a/src/ch18-00-oop.md b/src/ch18-00-oop.md index e20f6583f3..adcde4c5aa 100644 --- a/src/ch18-00-oop.md +++ b/src/ch18-00-oop.md @@ -4,7 +4,7 @@ Object-oriented programming (OOP) is a way of modeling programs. Objects as a programmatic concept were introduced in the programming language Simula in the 1960s. Those objects influenced Alan Kay’s programming architecture in which objects pass messages to each other. To describe this architecture, he coined -the term *object-oriented programming* in 1967. Many competing definitions +the term _object-oriented programming_ in 1967. Many competing definitions describe what OOP is, and by some of these definitions Rust is object-oriented, but by others it is not. In this chapter, we’ll explore certain characteristics that are commonly considered object-oriented and how those characteristics diff --git a/src/ch18-01-what-is-oo.md b/src/ch18-01-what-is-oo.md index 3d977dadc2..e370757468 100644 --- a/src/ch18-01-what-is-oo.md +++ b/src/ch18-01-what-is-oo.md @@ -10,23 +10,23 @@ Rust supports it. ### Objects Contain Data and Behavior -The book *Design Patterns: Elements of Reusable Object-Oriented Software* by +The book _Design Patterns: Elements of Reusable Object-Oriented Software_ by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Addison-Wesley -Professional, 1994), colloquially referred to as *The Gang of Four* book, is a +Professional, 1994), colloquially referred to as _The Gang of Four_ book, is a catalog of object-oriented design patterns. It defines OOP this way: -> Object-oriented programs are made up of objects. An *object* packages both +> Object-oriented programs are made up of objects. An _object_ packages both > data and the procedures that operate on that data. The procedures are -> typically called *methods* or *operations*. +> typically called _methods_ or _operations_. Using this definition, Rust is object-oriented: structs and enums have data, and `impl` blocks provide methods on structs and enums. Even though structs and -enums with methods aren’t *called* objects, they provide the same +enums with methods aren’t _called_ objects, they provide the same functionality, according to the Gang of Four’s definition of objects. ### Encapsulation that Hides Implementation Details -Another aspect commonly associated with OOP is the idea of *encapsulation*, +Another aspect commonly associated with OOP is the idea of _encapsulation_, which means that the implementation details of an object aren’t accessible to code using that object. Therefore, the only way to interact with an object is through its public API; code using the object shouldn’t be able to reach into @@ -94,7 +94,7 @@ not for different parts of code enables encapsulation of implementation details. ### Inheritance as a Type System and as Code Sharing -*Inheritance* is a mechanism whereby an object can inherit elements from +_Inheritance_ is a mechanism whereby an object can inherit elements from another object’s definition, thus gaining the parent object’s data and behavior without you having to define them again. @@ -121,7 +121,7 @@ implementation of a method inherited from a parent class. The other reason to use inheritance relates to the type system: to enable a child type to be used in the same places as the parent type. This is also -called *polymorphism*, which means that you can substitute multiple objects for +called _polymorphism_, which means that you can substitute multiple objects for each other at runtime if they share certain characteristics. > ### Polymorphism @@ -132,7 +132,7 @@ each other at runtime if they share certain characteristics. > > Rust instead uses generics to abstract over different possible types and > trait bounds to impose constraints on what those types must provide. This is -> sometimes called *bounded parametric polymorphism*. +> sometimes called _bounded parametric polymorphism_. Inheritance has recently fallen out of favor as a programming design solution in many programming languages because it’s often at risk of sharing more code diff --git a/src/ch18-02-trait-objects.md b/src/ch18-02-trait-objects.md index a167015eff..4fba9656c9 100644 --- a/src/ch18-02-trait-objects.md +++ b/src/ch18-02-trait-objects.md @@ -40,7 +40,7 @@ allow users to extend it with new types. To implement the behavior we want `gui` to have, we’ll define a trait named `Draw` that will have one method named `draw`. Then we can define a vector that -takes a *trait object*. A trait object points to both an instance of a type +takes a _trait object_. A trait object points to both an instance of a type implementing our specified trait and a table used to look up trait methods on that type at runtime. We create a trait object by specifying some sort of pointer, such as a `&` reference or a `Box` smart pointer, then the `dyn` @@ -56,7 +56,7 @@ We’ve mentioned that, in Rust, we refrain from calling structs and enums “objects” to distinguish them from other languages’ objects. In a struct or enum, the data in the struct fields and the behavior in `impl` blocks are separated, whereas in other languages, the data and behavior combined into one -concept is often labeled an object. However, trait objects *are* more like +concept is often labeled an object. However, trait objects _are_ more like objects in other languages in the sense that they combine data and behavior. But trait objects differ from traditional objects in that we can’t add data to a trait object. Trait objects aren’t as generally useful as objects in other @@ -182,8 +182,8 @@ new type and draw it because `SelectBox` implements the `Draw` trait, which means it implements the `draw` method. This concept—of being concerned only with the messages a value responds to -rather than the value’s concrete type—is similar to the concept of *duck -typing* in dynamically typed languages: if it walks like a duck and quacks +rather than the value’s concrete type—is similar to the concept of _duck +typing_ in dynamically typed languages: if it walks like a duck and quacks like a duck, then it must be a duck! In the implementation of `run` on `Screen` in Listing 18-5, `run` doesn’t need to know what the concrete type of each component is. It doesn’t check whether a component is an instance of a `Button` @@ -227,9 +227,9 @@ Chapter 10 our discussion on the monomorphization process performed by the compiler when we use trait bounds on generics: the compiler generates nongeneric implementations of functions and methods for each concrete type that we use in place of a generic type parameter. The code that results from -monomorphization is doing *static dispatch*, which is when the compiler knows -what method you’re calling at compile time. This is opposed to *dynamic -dispatch*, which is when the compiler can’t tell at compile time which method +monomorphization is doing _static dispatch_, which is when the compiler knows +what method you’re calling at compile time. This is opposed to _dynamic +dispatch_, which is when the compiler can’t tell at compile time which method you’re calling. In dynamic dispatch cases, the compiler emits code that at runtime will figure out which method to call. diff --git a/src/ch18-03-oo-design-patterns.md b/src/ch18-03-oo-design-patterns.md index 29ff109017..625aef3027 100644 --- a/src/ch18-03-oo-design-patterns.md +++ b/src/ch18-03-oo-design-patterns.md @@ -1,8 +1,8 @@ ## Implementing an Object-Oriented Design Pattern -The *state pattern* is an object-oriented design pattern. The crux of the +The _state pattern_ is an object-oriented design pattern. The crux of the pattern is that we define a set of states a value can have internally. The -states are represented by a set of *state objects*, and the value’s behavior +states are represented by a set of _state objects_, and the value’s behavior changes based on its state. We’re going to work through an example of a blog post struct that has a field to hold its state, which will be a state object from the set "draft", "review", or "published". @@ -208,6 +208,7 @@ slice. We can now have a `Post` in the `PendingReview` state as well as in the Listing 18-11 now works up to line 10! + ### Adding `approve` to Change the Behavior of `content` @@ -330,10 +331,10 @@ The implementation using the state pattern is easy to extend to add more functionality. To see the simplicity of maintaining code that uses the state pattern, try a few of these suggestions: -* Add a `reject` method that changes the post’s state from `PendingReview` back +- Add a `reject` method that changes the post’s state from `PendingReview` back to `Draft`. -* Require two calls to `approve` before the state can be changed to `Published`. -* Allow users to add text content only when a post is in the `Draft` state. +- Require two calls to `approve` before the state can be changed to `Published`. +- Allow users to add text content only when a post is in the `Draft` state. Hint: have the state object responsible for what might change about the content but not responsible for modifying the `Post`. diff --git a/src/ch19-00-patterns.md b/src/ch19-00-patterns.md index dc9290e331..4574ac0b8e 100644 --- a/src/ch19-00-patterns.md +++ b/src/ch19-00-patterns.md @@ -1,15 +1,15 @@ # Patterns and Matching -*Patterns* are a special syntax in Rust for matching against the structure of +_Patterns_ are a special syntax in Rust for matching against the structure of types, both complex and simple. Using patterns in conjunction with `match` expressions and other constructs gives you more control over a program’s control flow. A pattern consists of some combination of the following: -* Literals -* Destructured arrays, enums, structs, or tuples -* Variables -* Wildcards -* Placeholders +- Literals +- Destructured arrays, enums, structs, or tuples +- Variables +- Wildcards +- Placeholders Some example patterns include `x`, `(a, 3)`, and `Some(Color::Red)`. In the contexts in which patterns are valid, these components describe the shape of diff --git a/src/ch19-01-all-the-places-for-patterns.md b/src/ch19-01-all-the-places-for-patterns.md index 11f5919a49..0db908a8a0 100644 --- a/src/ch19-01-all-the-places-for-patterns.md +++ b/src/ch19-01-all-the-places-for-patterns.md @@ -32,7 +32,7 @@ match x { The patterns in this `match` expression are the `None` and `Some(i)` on the left of each arrow. -One requirement for `match` expressions is that they need to be *exhaustive* in +One requirement for `match` expressions is that they need to be _exhaustive_ in the sense that all possibilities for the value in the `match` expression must be accounted for. One way to ensure you’ve covered every possibility is to have a catchall pattern for the last arm: for example, a variable name matching any @@ -251,5 +251,4 @@ work the same in every place we can use them. In some places, the patterns must be irrefutable; in other circumstances, they can be refutable. We’ll discuss these two concepts next. -[ignoring-values-in-a-pattern]: -ch19-03-pattern-syntax.html#ignoring-values-in-a-pattern +[ignoring-values-in-a-pattern]: ch19-03-pattern-syntax.html#ignoring-values-in-a-pattern diff --git a/src/ch19-02-refutability.md b/src/ch19-02-refutability.md index 3601f5d14f..515358879c 100644 --- a/src/ch19-02-refutability.md +++ b/src/ch19-02-refutability.md @@ -1,10 +1,10 @@ ## Refutability: Whether a Pattern Might Fail to Match Patterns come in two forms: refutable and irrefutable. Patterns that will match -for any possible value passed are *irrefutable*. An example would be `x` in the +for any possible value passed are _irrefutable_. An example would be `x` in the statement `let x = 5;` because `x` matches anything and therefore cannot fail to match. Patterns that can fail to match for some possible value are -*refutable*. An example would be `Some(x)` in the expression `if let Some(x) = +_refutable_. An example would be `Some(x)` in the expression `if let Some(x) = a_value` because if the value in the `a_value` variable is `None` rather than `Some`, the `Some(x)` pattern will not match. diff --git a/src/ch19-03-pattern-syntax.md b/src/ch19-03-pattern-syntax.md index 4503cf77eb..21c1137d95 100644 --- a/src/ch19-03-pattern-syntax.md +++ b/src/ch19-03-pattern-syntax.md @@ -68,8 +68,8 @@ Guards”](#extra-conditionals-with-match-guards) section. ### Multiple Patterns In `match` expressions, you can match multiple patterns using the `|` syntax, -which is the pattern *or* operator. For example, in the following code we match -the value of `x` against the match arms, the first of which has an *or* option, +which is the pattern _or_ operator. For example, in the following code we match +the value of `x` against the match arms, the first of which has an _or_ option, meaning if the value of `x` matches either of the values in that arm, that arm’s code will run: @@ -450,7 +450,7 @@ compiler error because using `..` in two places like this is ambiguous. ### Extra Conditionals with Match Guards -A *match guard* is an additional `if` condition, specified after the pattern in +A _match guard_ is an additional `if` condition, specified after the pattern in a `match` arm, that must also match for that arm to be chosen. Match guards are useful for expressing more complex ideas than a pattern alone allows. @@ -504,15 +504,15 @@ pattern as `Some(y)`, which would have shadowed the outer `y`, we specify there is no `n` variable outside the `match`. The match guard `if n == y` is not a pattern and therefore doesn’t introduce new -variables. This `y` *is* the outer `y` rather than a new `y` shadowing it, and +variables. This `y` _is_ the outer `y` rather than a new `y` shadowing it, and we can look for a value that has the same value as the outer `y` by comparing `n` to `y`. -You can also use the *or* operator `|` in a match guard to specify multiple +You can also use the _or_ operator `|` in a match guard to specify multiple patterns; the match guard condition will apply to all the patterns. Listing 19-28 shows the precedence when combining a pattern that uses `|` with a match guard. The important part of this example is that the `if y` match guard -applies to `4`, `5`, *and* `6`, even though it might look like `if y` only +applies to `4`, `5`, _and_ `6`, even though it might look like `if y` only applies to `6`. @@ -524,7 +524,7 @@ applies to `6`. The match condition states that the arm only matches if the value of `x` is -equal to `4`, `5`, or `6` *and* if `y` is `true`. When this code runs, the +equal to `4`, `5`, or `6` _and_ if `y` is `true`. When this code runs, the pattern of the first arm matches because `x` is `4`, but the match guard `if y` is false, so the first arm is not chosen. The code moves on to the second arm, which does match, and this program prints `no`. The reason is that the `if` @@ -549,7 +549,7 @@ were applied only to the final value in the list of values specified using the ### `@` Bindings -The *at* operator `@` lets us create a variable that holds a value at the same +The _at_ operator `@` lets us create a variable that holds a value at the same time as we’re testing that value for a pattern match. In Listing 19-29, we want to test that a `Message::Hello` `id` field is within the range `3..=7`. We also want to bind the value to the variable `id_variable` so we can use it in the diff --git a/src/ch20-00-advanced-features.md b/src/ch20-00-advanced-features.md index 3e612d2af2..049681b5da 100644 --- a/src/ch20-00-advanced-features.md +++ b/src/ch20-00-advanced-features.md @@ -10,13 +10,13 @@ grasp of all the features Rust has to offer. In this chapter, we’ll cover: -* Unsafe Rust: how to opt out of some of Rust’s guarantees and take +- Unsafe Rust: how to opt out of some of Rust’s guarantees and take responsibility for manually upholding those guarantees -* Advanced traits: associated types, default type parameters, fully qualified +- Advanced traits: associated types, default type parameters, fully qualified syntax, supertraits, and the newtype pattern in relation to traits -* Advanced types: more about the newtype pattern, type aliases, the never type, +- Advanced types: more about the newtype pattern, type aliases, the never type, and dynamically sized types -* Advanced functions and closures: function pointers and returning closures -* Macros: ways to define code that defines more code at compile time +- Advanced functions and closures: function pointers and returning closures +- Macros: ways to define code that defines more code at compile time It’s a panoply of Rust features with something for everyone! Let’s dive in! diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 935b4fe435..3e6147fe97 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -2,13 +2,13 @@ All the code we’ve discussed so far has had Rust’s memory safety guarantees enforced at compile time. However, Rust has a second language hidden inside it -that doesn’t enforce these memory safety guarantees: it’s called *unsafe Rust* +that doesn’t enforce these memory safety guarantees: it’s called _unsafe Rust_ and works just like regular Rust, but gives us extra superpowers. Unsafe Rust exists because, by nature, static analysis is conservative. When the compiler tries to determine whether or not code upholds the guarantees, it’s better for it to reject some valid programs than to accept some invalid -programs. Although the code *might* be okay, if the Rust compiler doesn’t have +programs. Although the code _might_ be okay, if the Rust compiler doesn’t have enough information to be confident, it will reject the code. In these cases, you can use unsafe code to tell the compiler, “Trust me, I know what I’m doing.” Be warned, however, that you use unsafe Rust at your own risk: if you @@ -27,14 +27,14 @@ Rust and how to do it. To switch to unsafe Rust, use the `unsafe` keyword and then start a new block that holds the unsafe code. You can take five actions in unsafe Rust that you -can’t in safe Rust, which we call *unsafe superpowers*. Those superpowers +can’t in safe Rust, which we call _unsafe superpowers_. Those superpowers include the ability to: -* Dereference a raw pointer -* Call an unsafe function or method -* Access or modify a mutable static variable -* Implement an unsafe trait -* Access fields of a `union` +- Dereference a raw pointer +- Call an unsafe function or method +- Access or modify a mutable static variable +- Implement an unsafe trait +- Access fields of a `union` It’s important to understand that `unsafe` doesn’t turn off the borrow checker or disable any other of Rust’s safety checks: if you use a reference in unsafe @@ -69,20 +69,20 @@ some abstractions that provide a safe interface to unsafe code. In Chapter 4, in the [“Dangling References”][dangling-references] section, we mentioned that the compiler ensures references are always -valid. Unsafe Rust has two new types called *raw pointers* that are similar to +valid. Unsafe Rust has two new types called _raw pointers_ that are similar to references. As with references, raw pointers can be immutable or mutable and are written as `*const T` and `*mut T`, respectively. The asterisk isn’t the dereference operator; it’s part of the type name. In the context of raw -pointers, *immutable* means that the pointer can’t be directly assigned to +pointers, _immutable_ means that the pointer can’t be directly assigned to after being dereferenced. Different from references and smart pointers, raw pointers: -* Are allowed to ignore the borrowing rules by having both immutable and +- Are allowed to ignore the borrowing rules by having both immutable and mutable pointers or multiple mutable pointers to the same location -* Aren’t guaranteed to point to valid memory -* Are allowed to be null -* Don’t implement any automatic cleanup +- Aren’t guaranteed to point to valid memory +- Are allowed to be null +- Don’t implement any automatic cleanup By opting out of having Rust enforce these guarantees, you can give up guaranteed safety in exchange for greater performance or the ability to @@ -125,7 +125,7 @@ where you can use a raw borrow operator instead, but it is possible.
-Recall that we can create raw pointers in safe code, but we can’t *dereference* +Recall that we can create raw pointers in safe code, but we can’t _dereference_ raw pointers and read the data being pointed to. In Listing 20-3, we use the dereference operator `*` on a raw pointer that requires an `unsafe` block. @@ -305,7 +305,7 @@ that the slice this code creates contains valid `i32` values. Attempting to use Sometimes, your Rust code might need to interact with code written in another language. For this, Rust has the keyword `extern` that facilitates the creation -and use of a *Foreign Function Interface (FFI)*. An FFI is a way for a +and use of a _Foreign Function Interface (FFI)_. An FFI is a way for a programming language to define functions and enable a different (foreign) programming language to call those functions. @@ -326,7 +326,7 @@ safety. Within the `unsafe extern "C"` block, we list the names and signatures of external functions from another language we want to call. The `"C"` part defines -which *application binary interface (ABI)* the external function uses: the ABI +which _application binary interface (ABI)_ the external function uses: the ABI defines how to call the function at the assembly level. The `"C"` ABI is the most common and follows the C programming language’s ABI. @@ -345,7 +345,7 @@ it no longer requires an `unsafe` block, as shown in Listing 20-9.
Marking a function as `safe` does not inherently make it safe! Instead, it is -like a promise you are making to Rust that it *is* safe. It is still your +like a promise you are making to Rust that it _is_ safe. It is still your responsibility to make sure that promise is kept! > #### Calling Rust Functions from Other Languages @@ -354,7 +354,7 @@ responsibility to make sure that promise is kept! > call Rust functions. Instead of creating a whole `extern` block, we add the > `extern` keyword and specify the ABI to use just before the `fn` keyword for > the relevant function. We also need to add a `#[unsafe(no_mangle)]` annotation -> to tell the Rust compiler not to mangle the name of this function. *Mangling* +> to tell the Rust compiler not to mangle the name of this function. _Mangling_ > is when a compiler changes the name we’ve given a function to a different name > that contains more information for other parts of the compilation process to > consume but is less human readable. Every programming language compiler @@ -378,11 +378,11 @@ responsibility to make sure that promise is kept! ### Accessing or Modifying a Mutable Static Variable -In this book, we’ve not yet talked about *global variables*, which Rust does +In this book, we’ve not yet talked about _global variables_, which Rust does support but can be problematic with Rust’s ownership rules. If two threads are accessing the same mutable global variable, it can cause a data race. -In Rust, global variables are called *static* variables. Listing 20-10 shows an +In Rust, global variables are called _static_ variables. Listing 20-10 shows an example declaration and use of a static variable with a string slice as a value. @@ -408,7 +408,7 @@ values in a static variable have a fixed address in memory. Using the value will always access the same data. Constants, on the other hand, are allowed to duplicate their data whenever they’re used. Another difference is that static variables can be mutable. Accessing and modifying mutable static variables is -*unsafe*. Listing 20-11 shows how to declare, access, and modify a mutable +_unsafe_. Listing 20-11 shows how to declare, access, and modify a mutable static variable named `COUNTER`. @@ -472,7 +472,7 @@ those checks manually and indicate as such with `unsafe`. ### Accessing Fields of a Union The final action that works only with `unsafe` is accessing fields of a -*union*. A `union` is similar to a `struct`, but only one declared field is +_union_. A `union` is similar to a `struct`, but only one declared field is used in a particular instance at one time. Unions are primarily used to interface with unions in C code. Accessing union fields is unsafe because Rust can’t guarantee the type of the data currently being stored in the union @@ -483,8 +483,8 @@ instance. You can learn more about unions in [the Rust Reference][reference]. When writing unsafe code, you might want to check that what you have written actually is safe and correct. One of the best ways to do that is to use [Miri][miri], an official Rust tool for detecting undefined behavior. Whereas -the borrow checker is a *static* tool which works at compile time, Miri is a -*dynamic* tool which works at runtime. It checks your code by running your +the borrow checker is a _static_ tool which works at compile time, Miri is a +_dynamic_ tool which works at runtime. It checks your code by running your program, or its test suite, and detecting when you violate the rules it understands about how Rust should work. @@ -507,15 +507,15 @@ It helpfully and correctly notices that we have shared references to mutable data, and warns about it. In this case, it does not tell us how to fix the problem, but it means that we know there is a possible issue and can think about how to make sure it is safe. In other cases, it can actually tell us that some -code is *sure* to be wrong and make recommendations about how to fix it. +code is _sure_ to be wrong and make recommendations about how to fix it. -Miri doesn’t catch *everything* you might get wrong when writing unsafe code. +Miri doesn’t catch _everything_ you might get wrong when writing unsafe code. For one thing, since it is a dynamic check, it only catches problems with code that actually gets run. That means you will need to use it in conjunction with good testing techniques to increase your confidence about the unsafe code you have written. For another thing, it does not cover every possible way your code -can be unsound. If Miri *does* catch a problem, you know there’s a bug, but just -because Miri *doesn’t* catch a bug doesn’t mean there isn’t a problem. Miri can +can be unsound. If Miri _does_ catch a problem, you know there’s a bug, but just +because Miri _doesn’t_ catch a bug doesn’t mean there isn’t a problem. Miri can catch a lot, though. Try running it on the other examples of unsafe code in this chapter and see what it says! @@ -529,12 +529,9 @@ annotation makes it easier to track down the source of problems when they occur. Whenever you write unsafe code, you can use Miri to help you be more confident that the code you have written upholds Rust’s rules. -[dangling-references]: -ch04-02-references-and-borrowing.html#dangling-references -[differences-between-variables-and-constants]: -ch03-01-variables-and-mutability.html#constants -[extensible-concurrency-with-the-sync-and-send-traits]: -ch16-04-extensible-concurrency-sync-and-send.html#extensible-concurrency-with-the-sync-and-send-traits +[dangling-references]: ch04-02-references-and-borrowing.html#dangling-references +[differences-between-variables-and-constants]: ch03-01-variables-and-mutability.html#constants +[extensible-concurrency-with-the-sync-and-send-traits]: ch16-04-extensible-concurrency-sync-and-send.html#extensible-concurrency-with-the-sync-and-send-traits [the-slice-type]: ch04-03-slices.html#the-slice-type [reference]: ../reference/items/unions.html [miri]: https://github.com/rust-lang/miri diff --git a/src/ch20-03-advanced-traits.md b/src/ch20-03-advanced-traits.md index d95b1d9b94..3b5b80728b 100644 --- a/src/ch20-03-advanced-traits.md +++ b/src/ch20-03-advanced-traits.md @@ -7,7 +7,7 @@ about Rust, we can get into the nitty-gritty. ### Specifying Placeholder Types in Trait Definitions with Associated Types -*Associated types* connect a type placeholder with a trait such that the trait +_Associated types_ connect a type placeholder with a trait such that the trait method definitions can use these placeholder types in their signatures. The implementor of a trait will specify the concrete type to be used instead of the placeholder type for the particular implementation. That way, we can define a @@ -91,8 +91,8 @@ the generic type. This eliminates the need for implementors of the trait to specify a concrete type if the default type works. You specify a default type when declaring a generic type with the `` syntax. -A great example of a situation where this technique is useful is with *operator -overloading*, in which you customize the behavior of an operator (such as `+`) +A great example of a situation where this technique is useful is with _operator +overloading_, in which you customize the behavior of an operator (such as `+`) in particular situations. Rust doesn’t allow you to create your own operators or overload arbitrary @@ -127,8 +127,8 @@ trait Add { ``` This code should look generally familiar: a trait with one method and an -associated type. The new part is `Rhs=Self`: this syntax is called *default -type parameters*. The `Rhs` generic type parameter (short for “right hand +associated type. The new part is `Rhs=Self`: this syntax is called _default +type parameters_. The `Rhs` generic type parameter (short for “right hand side”) defines the type of the `rhs` parameter in the `add` method. If we don’t specify a concrete type for `Rhs` when we implement the `Add` trait, the type of `Rhs` will default to `Self`, which will be the type we’re implementing @@ -141,7 +141,7 @@ default. We have two structs, `Millimeters` and `Meters`, holding values in different units. This thin wrapping of an existing type in another struct is known as the -*newtype pattern*, which we describe in more detail in the [“Using the Newtype +_newtype pattern_, which we describe in more detail in the [“Using the Newtype Pattern to Implement External Traits on External Types”][newtype] section. We want to add values in millimeters to values in meters and have the implementation of `Add` do the conversion correctly. We can implement `Add` @@ -160,8 +160,8 @@ value of the `Rhs` type parameter instead of using the default of `Self`. You’ll use default type parameters in two main ways: -* To extend a type without breaking existing code -* To allow customization in specific cases most users won’t need +- To extend a type without breaking existing code +- To allow customization in specific cases most users won’t need The standard library’s `Add` trait is an example of the second purpose: usually, you’ll add two like types, but the `Add` trait provides the ability to @@ -234,15 +234,15 @@ Running this code prints the following: {{#include ../listings/ch20-advanced-features/listing-20-19/output.txt}} ``` -Because the `fly` method takes a `self` parameter, if we had two *types* that -both implement one *trait*, Rust could figure out which implementation of a +Because the `fly` method takes a `self` parameter, if we had two _types_ that +both implement one _trait_, Rust could figure out which implementation of a trait to use based on the type of `self`. However, associated functions that are not methods don’t have a `self` parameter. When there are multiple types or traits that define non-method functions with the same function name, Rust doesn't always know which type you -mean unless you use *fully qualified syntax*. For example, in Listing 20-20 we -create a trait for an animal shelter that wants to name all baby dogs *Spot*. +mean unless you use _fully qualified syntax_. For example, in Listing 20-20 we +create a trait for an animal shelter that wants to name all baby dogs _Spot_. We make an `Animal` trait with an associated non-method function `baby_name`. The `Animal` trait is implemented for the struct `Dog`, on which we also provide an associated non-method function `baby_name` directly. @@ -332,7 +332,7 @@ Sometimes, you might write a trait definition that depends on another trait: for a type to implement the first trait, you want to require that type to also implement the second trait. You would do this so that your trait definition can make use of the associated items of the second trait. The trait your trait -definition is relying on is called a *supertrait* of your trait. +definition is relying on is called a _supertrait_ of your trait. For example, let’s say we want to make an `OutlinePrint` trait with an `outline_print` method that will print a given value formatted so that it's @@ -410,13 +410,13 @@ In Chapter 10 in the [“Implementing a Trait on a Type”][implementing-a-trait-on-a-type] section, we mentioned the orphan rule that states we’re only allowed to implement a trait on a type if either the trait or the type are local to our crate. It’s possible to get -around this restriction using the *newtype pattern*, which involves creating a +around this restriction using the _newtype pattern_, which involves creating a new type in a tuple struct. (We covered tuple structs in the [“Using Tuple Structs without Named Fields to Create Different Types”][tuple-structs] section of Chapter 5.) The tuple struct will have one field and be a thin wrapper around the type we want to implement a trait for. Then the wrapper type is local to our crate, and we can implement the trait on the wrapper. -*Newtype* is a term that originates from the Haskell programming language. +_Newtype_ is a term that originates from the Haskell programming language. There is no runtime performance penalty for using this pattern, and the wrapper type is elided at compile time. @@ -454,9 +454,7 @@ This newtype pattern is also useful even when traits are not involved. Let’s switch focus and look at some advanced ways to interact with Rust’s type system. [newtype]: ch20-03-advanced-traits.html#using-the-newtype-pattern-to-implement-external-traits-on-external-types -[implementing-a-trait-on-a-type]: -ch10-02-traits.html#implementing-a-trait-on-a-type -[traits-defining-shared-behavior]: -ch10-02-traits.html#traits-defining-shared-behavior +[implementing-a-trait-on-a-type]: ch10-02-traits.html#implementing-a-trait-on-a-type +[traits-defining-shared-behavior]: ch10-02-traits.html#traits-defining-shared-behavior [smart-pointer-deref]: ch15-02-deref.html#treating-smart-pointers-like-regular-references-with-the-deref-trait [tuple-structs]: ch05-01-defining-structs.html#using-tuple-structs-without-named-fields-to-create-different-types diff --git a/src/ch20-04-advanced-types.md b/src/ch20-04-advanced-types.md index a3f1f43207..498a3c36b6 100644 --- a/src/ch20-04-advanced-types.md +++ b/src/ch20-04-advanced-types.md @@ -38,7 +38,7 @@ section of Chapter 18. ### Creating Type Synonyms with Type Aliases -Rust provides the ability to declare a *type alias* to give an existing type +Rust provides the ability to declare a _type alias_ to give an existing type another name. For this we use the `type` keyword. For example, we can create the alias `Kilometers` to `i32` like so: @@ -46,7 +46,7 @@ the alias `Kilometers` to `i32` like so: {{#rustdoc_include ../listings/ch20-advanced-features/no-listing-04-kilometers-alias/src/main.rs:here}} ``` -Now, the alias `Kilometers` is a *synonym* for `i32`; unlike the `Millimeters` +Now, the alias `Kilometers` is a _synonym_ for `i32`; unlike the `Millimeters` and `Meters` types we created in Listing 20-16, `Kilometers` is not a separate, new type. Values that have the type `Kilometers` will be treated the same as values of type `i32`: @@ -94,7 +94,7 @@ can replace all uses of the type with the shorter alias `Thunk`. This code is much easier to read and write! Choosing a meaningful name for a -type alias can help communicate your intent as well (*thunk* is a word for code +type alias can help communicate your intent as well (_thunk_ is a word for code to be evaluated at a later time, so it’s an appropriate name for a closure that gets stored). @@ -126,7 +126,7 @@ looking like this: {{#rustdoc_include ../listings/ch20-advanced-features/no-listing-06-result-alias/src/lib.rs:there}} ``` -The type alias helps in two ways: it makes code easier to write *and* it gives +The type alias helps in two ways: it makes code easier to write _and_ it gives us a consistent interface across all of `std::io`. Because it’s an alias, it’s just another `Result`, which means we can use any methods that work on `Result` with it, as well as special syntax like the `?` operator. @@ -134,7 +134,7 @@ just another `Result`, which means we can use any methods that work on ### The Never Type that Never Returns Rust has a special type named `!` that’s known in type theory lingo as the -*empty type* because it has no values. We prefer to call it the *never type* +_empty type_ because it has no values. We prefer to call it the _never type_ because it stands in the place of the return type when a function will never return. Here is an example: @@ -143,7 +143,7 @@ return. Here is an example: ``` This code is read as “the function `bar` returns never.” Functions that return -never are called *diverging functions*. We can’t create values of the type `!` +never are called _diverging functions_. We can’t create values of the type `!` so `bar` can never possibly return. But what use is a type you can never create values for? Recall the code from @@ -167,7 +167,7 @@ example, the following code doesn’t work: {{#rustdoc_include ../listings/ch20-advanced-features/no-listing-08-match-arms-different-types/src/main.rs:here}} ``` -The type of `guess` in this code would have to be an integer *and* a string, +The type of `guess` in this code would have to be an integer _and_ a string, and Rust requires that `guess` have only one type. So what does `continue` return? How were we allowed to return a `u32` from one arm and have another arm that ends with `continue` in Listing 20-27? @@ -211,8 +211,8 @@ when it got to the `break`. Rust needs to know certain details about its types, such as how much space to allocate for a value of a particular type. This leaves one corner of its type -system a little confusing at first: the concept of *dynamically sized types*. -Sometimes referred to as *DSTs* or *unsized types*, these types let us write +system a little confusing at first: the concept of _dynamically sized types_. +Sometimes referred to as _DSTs_ or _unsized types_, these types let us write code using values whose size we can know only at runtime. Let’s dig into the details of a dynamically sized type called `str`, which @@ -237,7 +237,7 @@ of `s1` and `s2` a `&str` rather than a `str`. Recall from the [“String Slices”][string-slices] section of Chapter 4 that the slice data structure just stores the starting position and the length of the slice. So although a `&T` is a single value that stores the memory address of where the -`T` is located, a `&str` is *two* values: the address of the `str` and its +`T` is located, a `&str` is _two_ values: the address of the `str` and its length. As such, we can know the size of a `&str` value at compile time: it’s twice the length of a `usize`. That is, we always know the size of a `&str`, no matter how long the string it refers to is. In general, this is the way in @@ -291,11 +291,8 @@ pointer. In this case, we’ve chosen a reference. Next, we’ll talk about functions and closures! -[encapsulation-that-hides-implementation-details]: -ch18-01-what-is-oo.html#encapsulation-that-hides-implementation-details +[encapsulation-that-hides-implementation-details]: ch18-01-what-is-oo.html#encapsulation-that-hides-implementation-details [string-slices]: ch04-03-slices.html#string-slices -[the-match-control-flow-operator]: -ch06-02-match.html#the-match-control-flow-operator -[using-trait-objects-that-allow-for-values-of-different-types]: -ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types +[the-match-control-flow-operator]: ch06-02-match.html#the-match-control-flow-operator +[using-trait-objects-that-allow-for-values-of-different-types]: ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types [using-the-newtype-pattern]: ch20-03-advanced-traits.html#using-the-newtype-pattern-to-implement-external-traits-on-external-types diff --git a/src/ch20-05-advanced-functions-and-closures.md b/src/ch20-05-advanced-functions-and-closures.md index 618568d0d1..9f04892b0a 100644 --- a/src/ch20-05-advanced-functions-and-closures.md +++ b/src/ch20-05-advanced-functions-and-closures.md @@ -9,7 +9,7 @@ We’ve talked about how to pass closures to functions; you can also pass regula functions to functions! This technique is useful when you want to pass a function you’ve already defined rather than defining a new closure. Functions coerce to the type `fn` (with a lowercase f), not to be confused with the `Fn` -closure trait. The `fn` type is called a *function pointer*. Passing functions +closure trait. The `fn` type is called a _function pointer_. Passing functions with function pointers will allow you to use functions as arguments to other functions. @@ -122,8 +122,6 @@ ignore --> in Chapter 19. Next, let’s look at macros! -[advanced-traits]: -ch20-03-advanced-traits.html#advanced-traits +[advanced-traits]: ch20-03-advanced-traits.html#advanced-traits [enum-values]: ch06-01-defining-an-enum.html#enum-values -[using-trait-objects-that-allow-for-values-of-different-types]: -ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types +[using-trait-objects-that-allow-for-values-of-different-types]: ch18-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types diff --git a/src/ch20-06-macros.md b/src/ch20-06-macros.md index cd4ded07d8..c687c8b614 100644 --- a/src/ch20-06-macros.md +++ b/src/ch20-06-macros.md @@ -1,14 +1,14 @@ ## Macros We’ve used macros like `println!` throughout this book, but we haven’t fully -explored what a macro is and how it works. The term *macro* refers to a family -of features in Rust: *declarative* macros with `macro_rules!` and three kinds -of *procedural* macros: +explored what a macro is and how it works. The term _macro_ refers to a family +of features in Rust: _declarative_ macros with `macro_rules!` and three kinds +of _procedural_ macros: -* Custom `#[derive]` macros that specify code added with the `derive` attribute +- Custom `#[derive]` macros that specify code added with the `derive` attribute used on structs and enums -* Attribute-like macros that define custom attributes usable on any item -* Function-like macros that look like function calls but operate on the tokens +- Attribute-like macros that define custom attributes usable on any item +- Function-like macros that look like function calls but operate on the tokens specified as their argument We’ll talk about each of these in turn, but first, let’s look at why we even @@ -17,10 +17,10 @@ need macros when we already have functions. ### The Difference Between Macros and Functions Fundamentally, macros are a way of writing code that writes other code, which -is known as *metaprogramming*. In Appendix C, we discuss the `derive` +is known as _metaprogramming_. In Appendix C, we discuss the `derive` attribute, which generates an implementation of various traits for you. We’ve also used the `println!` and `vec!` macros throughout the book. All of these -macros *expand* to produce more code than the code you’ve written manually. +macros _expand_ to produce more code than the code you’ve written manually. Metaprogramming is useful for reducing the amount of code you have to write and maintain, which is also one of the roles of functions. However, macros have @@ -41,12 +41,12 @@ generally more difficult to read, understand, and maintain than function definitions. Another important difference between macros and functions is that you must -define macros or bring them into scope *before* you call them in a file, as +define macros or bring them into scope _before_ you call them in a file, as opposed to functions you can define anywhere and call anywhere. ### Declarative Macros with `macro_rules!` for General Metaprogramming -The most widely used form of macros in Rust is the *declarative macro*. These +The most widely used form of macros in Rust is the _declarative macro_. These are also sometimes referred to as “macros by example,” “`macro_rules!` macros,” or just plain “macros.” At their core, declarative macros allow you to write something similar to a Rust `match` expression. As discussed in Chapter 6, @@ -92,7 +92,7 @@ available whenever the crate in which the macro is defined is brought into scope. Without this annotation, the macro can’t be brought into scope. We then start the macro definition with `macro_rules!` and the name of the -macro we’re defining *without* the exclamation mark. The name, in this case +macro we’re defining _without_ the exclamation mark. The name, in this case `vec`, is followed by curly brackets denoting the body of the macro definition. The structure in the `vec!` body is similar to the structure of a `match` @@ -150,7 +150,7 @@ Daniel Keep and continued by Lukas Wirth. ### Procedural Macros for Generating Code from Attributes -The second form of macros is the *procedural macro*, which acts more like a +The second form of macros is the _procedural macro_, which acts more like a function (and is a type of procedure). Procedural macros accept some code as an input, operate on that code, and produce some code as an output rather than matching against patterns and replacing the code with other code as declarative @@ -266,7 +266,7 @@ possible for programmers to use `hello_macro` even if they don’t want the We need to declare the `hello_macro_derive` crate as a procedural macro crate. We’ll also need functionality from the `syn` and `quote` crates, as you’ll see in a moment, so we need to add them as dependencies. Add the following to the -*Cargo.toml* file for `hello_macro_derive`: +_Cargo.toml_ file for `hello_macro_derive`: @@ -277,7 +277,7 @@ in a moment, so we need to add them as dependencies. Add the following to the To start defining the procedural macro, place the code in Listing 20-32 into -your *src/lib.rs* file for the `hello_macro_derive` crate. Note that this code +your _src/lib.rs_ file for the `hello_macro_derive` crate. Note that this code won’t compile until we add a definition for the `impl_hello_macro` function. @@ -299,7 +299,7 @@ depending on your procedural macro’s purpose. We’ve introduced three new crates: `proc_macro`, [`syn`], and [`quote`]. The `proc_macro` crate comes with Rust, so we didn’t need to add that to the -dependencies in *Cargo.toml*. The `proc_macro` crate is the compiler’s API that +dependencies in _Cargo.toml_. The `proc_macro` crate is the compiler’s API that allows us to read and manipulate Rust code from our code. The `syn` crate parses Rust code from a string into a data structure that we @@ -413,9 +413,9 @@ saves an allocation by converting `#name` to a string literal at compile time. At this point, `cargo build` should complete successfully in both `hello_macro` and `hello_macro_derive`. Let’s hook up these crates to the code in Listing 20-31 to see the procedural macro in action! Create a new binary project in -your *projects* directory using `cargo new pancakes`. We need to add +your _projects_ directory using `cargo new pancakes`. We need to add `hello_macro` and `hello_macro_derive` as dependencies in the `pancakes` -crate’s *Cargo.toml*. If you’re publishing your versions of `hello_macro` and +crate’s _Cargo.toml_. If you’re publishing your versions of `hello_macro` and `hello_macro_derive` to [crates.io](https://crates.io/), they would be regular dependencies; if not, you can specify them as `path` dependencies as follows: @@ -423,7 +423,7 @@ dependencies; if not, you can specify them as `path` dependencies as follows: {{#include ../listings/ch20-advanced-features/no-listing-21-pancakes/pancakes/Cargo.toml:7:9}} ``` -Put the code in Listing 20-31 into *src/main.rs*, and run `cargo run`: it +Put the code in Listing 20-31 into _src/main.rs_, and run `cargo run`: it should print `Hello, Macro! My name is Pancakes!` The implementation of the `HelloMacro` trait from the procedural macro was included without the `pancakes` crate needing to implement it; the `#[derive(HelloMacro)]` added the diff --git a/src/ch21-01-single-threaded.md b/src/ch21-01-single-threaded.md index 9712b69a41..813a352474 100644 --- a/src/ch21-01-single-threaded.md +++ b/src/ch21-01-single-threaded.md @@ -5,10 +5,10 @@ let’s look at a quick overview of the protocols involved in building web servers. The details of these protocols are beyond the scope of this book, but a brief overview will give you the information you need. -The two main protocols involved in web servers are *Hypertext Transfer -Protocol* *(HTTP)* and *Transmission Control Protocol* *(TCP)*. Both protocols -are *request-response* protocols, meaning a *client* initiates requests and a -*server* listens to the requests and provides a response to the client. The +The two main protocols involved in web servers are _Hypertext Transfer +Protocol_ _(HTTP)_ and _Transmission Control Protocol_ _(TCP)_. Both protocols +are _request-response_ protocols, meaning a _client_ initiates requests and a +_server_ listens to the requests and provides a response to the client. The contents of those requests and responses are defined by the protocols. TCP is the lower-level protocol that describes the details of how information @@ -30,7 +30,7 @@ $ cargo new hello $ cd hello ``` -Now enter the code in Listing 21-1 in *src/main.rs* to start. This code will +Now enter the code in Listing 21-1 in _src/main.rs_ to start. This code will listen at the local address `127.0.0.1:7878` for incoming TCP streams. When it gets an incoming stream, it will print `Connection established!`. @@ -48,7 +48,7 @@ representing your computer (this is the same on every computer and doesn’t represent the authors’ computer specifically), and `7878` is the port. We’ve chosen this port for two reasons: HTTP isn’t normally accepted on this port so our server is unlikely to conflict with any other web server you might have -running on your machine, and 7878 is *rust* typed on a telephone. +running on your machine, and 7878 is _rust_ typed on a telephone. The `bind` function in this scenario works like the `new` function in that it will return a new `TcpListener` instance. The function is called `bind` @@ -67,8 +67,8 @@ stop the program if errors happen. The `incoming` method on `TcpListener` returns an iterator that gives us a sequence of streams (more specifically, streams of type `TcpStream`). A single -*stream* represents an open connection between the client and the server. A -*connection* is the name for the full request and response process in which a +_stream_ represents an open connection between the client and the server. A +_connection_ is the name for the full request and response process in which a client connects to the server, the server generates a response, and the server closes the connection. As such, we will read from the `TcpStream` to see what the client sent and then write our response to the stream to send data back to @@ -80,7 +80,7 @@ our program if the stream has any errors; if there aren’t any errors, the program prints a message. We’ll add more functionality for the success case in the next listing. The reason we might receive errors from the `incoming` method when a client connects to the server is that we’re not actually iterating over -connections. Instead, we’re iterating over *connection attempts*. The +connections. Instead, we’re iterating over _connection attempts_. The connection might not be successful for a number of reasons, many of them operating system specific. For example, many operating systems have a limit to the number of simultaneous open connections they can support; new connection @@ -88,7 +88,7 @@ attempts beyond that number will produce an error until some of the open connections are closed. Let’s try running this code! Invoke `cargo run` in the terminal and then load -*127.0.0.1:7878* in a web browser. The browser should show an error message +_127.0.0.1:7878_ in a web browser. The browser should show an error message like “Connection reset,” because the server isn’t currently sending back any data. But when you look at your terminal, you should see several messages that were printed when the browser connected to the server! @@ -102,7 +102,7 @@ Connection established! Sometimes, you’ll see multiple messages printed for one browser request; the reason might be that the browser is making a request for the page as well as a -request for other resources, like the *favicon.ico* icon that appears in the +request for other resources, like the _favicon.ico_ icon that appears in the browser tab. It could also be that the browser is trying to connect to the server multiple @@ -193,8 +193,8 @@ Request: [ Depending on your browser, you might get slightly different output. Now that we’re printing the request data, we can see why we get multiple connections from one browser request by looking at the path after `GET` in the first line -of the request. If the repeated connections are all requesting */*, we know the -browser is trying to fetch */* repeatedly because it’s not getting a response +of the request. If the repeated connections are all requesting _/_, we know the +browser is trying to fetch _/_ repeatedly because it’s not getting a response from our program. Let’s break down this request data to understand what the browser is asking of @@ -210,34 +210,34 @@ headers CRLF message-body ``` -The first line is the *request line* that holds information about what the -client is requesting. The first part of the request line indicates the *method* +The first line is the _request line_ that holds information about what the +client is requesting. The first part of the request line indicates the _method_ being used, such as `GET` or `POST`, which describes how the client is making this request. Our client used a `GET` request, which means it is asking for information. -The next part of the request line is */*, which indicates the *Uniform Resource -Identifier* *(URI)* the client is requesting: a URI is almost, but not quite, -the same as a *Uniform Resource Locator* *(URL)*. The difference between URIs +The next part of the request line is _/_, which indicates the _Uniform Resource +Identifier_ _(URI)_ the client is requesting: a URI is almost, but not quite, +the same as a _Uniform Resource Locator_ _(URL)_. The difference between URIs and URLs isn’t important for our purposes in this chapter, but the HTTP spec uses the term URI, so we can just mentally substitute URL for URI here. The last part is the HTTP version the client uses, and then the request line -ends in a *CRLF sequence*. (CRLF stands for *carriage return* and *line feed*, +ends in a _CRLF sequence_. (CRLF stands for _carriage return_ and _line feed_, which are terms from the typewriter days!) The CRLF sequence can also be written as `\r\n`, where `\r` is a carriage return and `\n` is a line feed. The CRLF sequence separates the request line from the rest of the request data. Note that when the CRLF is printed, we see a new line start rather than `\r\n`. Looking at the request line data we received from running our program so far, -we see that `GET` is the method, */* is the request URI, and `HTTP/1.1` is the +we see that `GET` is the method, _/_ is the request URI, and `HTTP/1.1` is the version. After the request line, the remaining lines starting from `Host:` onward are headers. `GET` requests have no body. Try making a request from a different browser or asking for a different -address, such as *127.0.0.1:7878/test*, to see how the request data changes. +address, such as _127.0.0.1:7878/test_, to see how the request data changes. Now that we know what the browser is asking for, let’s send back some data! @@ -252,7 +252,7 @@ headers CRLF message-body ``` -The first line is a *status line* that contains the HTTP version used in the +The first line is a _status line_ that contains the HTTP version used in the response, a numeric status code that summarizes the result of the request, and a reason phrase that provides a text description of the status code. After the CRLF sequence are any headers, another CRLF sequence, and the body of the @@ -288,15 +288,15 @@ application you would add error handling here. With these changes, let’s run our code and make a request. We’re no longer printing any data to the terminal, so we won’t see any output other than the -output from Cargo. When you load *127.0.0.1:7878* in a web browser, you should +output from Cargo. When you load _127.0.0.1:7878_ in a web browser, you should get a blank page instead of an error. You’ve just hand-coded receiving an HTTP request and sending a response! ### Returning Real HTML Let’s implement the functionality for returning more than a blank page. Create -the new file *hello.html* in the root of your project directory, not in the -*src* directory. You can input any HTML you want; Listing 21-4 shows one +the new file _hello.html_ in the root of your project directory, not in the +_src_ directory. You can input any HTML you want; Listing 21-4 shows one possibility. @@ -330,25 +330,25 @@ response. To ensure a valid HTTP response, we add the `Content-Length` header which is set to the size of our response body, in this case the size of `hello.html`. -Run this code with `cargo run` and load *127.0.0.1:7878* in your browser; you +Run this code with `cargo run` and load _127.0.0.1:7878_ in your browser; you should see your HTML rendered! Currently, we’re ignoring the request data in `http_request` and just sending back the contents of the HTML file unconditionally. That means if you try -requesting *127.0.0.1:7878/something-else* in your browser, you’ll still get +requesting _127.0.0.1:7878/something-else_ in your browser, you’ll still get back this same HTML response. At the moment, our server is very limited and does not do what most web servers do. We want to customize our responses depending on the request and only send back the HTML file for a well-formed -request to */*. +request to _/_. ### Validating the Request and Selectively Responding Right now, our web server will return the HTML in the file no matter what the client requested. Let’s add functionality to check that the browser is -requesting */* before returning the HTML file and return an error if the +requesting _/_ before returning the HTML file and return an error if the browser requests anything else. For this we need to modify `handle_connection`, as shown in Listing 21-6. This new code checks the content of the request -received against what we know a request for */* looks like and adds `if` and +received against what we know a request for _/_ looks like and adds `if` and `else` blocks to treat requests differently. @@ -367,16 +367,16 @@ stops the program if the iterator has no items. The second `unwrap` handles the Listing 21-2. Next, we check the `request_line` to see if it equals the request line of a GET -request to the */* path. If it does, the `if` block returns the contents of our +request to the _/_ path. If it does, the `if` block returns the contents of our HTML file. -If the `request_line` does *not* equal the GET request to the */* path, it +If the `request_line` does _not_ equal the GET request to the _/_ path, it means we’ve received some other request. We’ll add code to the `else` block in a moment to respond to all other requests. -Run this code now and request *127.0.0.1:7878*; you should get the HTML in -*hello.html*. If you make any other request, such as -*127.0.0.1:7878/something-else*, you’ll get a connection error like those you +Run this code now and request _127.0.0.1:7878_; you should get the HTML in +_hello.html_. If you make any other request, such as +_127.0.0.1:7878/something-else_, you’ll get a connection error like those you saw when running the code in Listing 21-1 and Listing 21-2. Now let’s add the code in Listing 21-7 to the `else` block to return a response @@ -393,8 +393,8 @@ indicating the response to the end user. Here, our response has a status line with status code 404 and the reason phrase -`NOT FOUND`. The body of the response will be the HTML in the file *404.html*. -You’ll need to create a *404.html* file next to *hello.html* for the error +`NOT FOUND`. The body of the response will be the HTML in the file _404.html_. +You’ll need to create a _404.html_ file next to _hello.html_ for the error page; again feel free to use any HTML you want or use the example HTML in Listing 21-8. @@ -406,9 +406,9 @@ Listing 21-8. -With these changes, run your server again. Requesting *127.0.0.1:7878* should -return the contents of *hello.html*, and any other request, like -*127.0.0.1:7878/foo*, should return the error HTML from *404.html*. +With these changes, run your server again. Requesting _127.0.0.1:7878_ should +return the contents of _hello.html_, and any other request, like +_127.0.0.1:7878/foo_, should return the error HTML from _404.html_. ### A Touch of Refactoring diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index 788ee54688..c2e7865ab5 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -12,7 +12,7 @@ this, but first, we’ll look at the problem in action. We’ll look at how a slow-processing request can affect other requests made to our current server implementation. Listing 21-10 implements handling a request -to */sleep* with a simulated slow response that will cause the server to sleep +to _/sleep_ with a simulated slow response that will cause the server to sleep for 5 seconds before responding. @@ -29,7 +29,7 @@ string literal values; `match` doesn’t do automatic referencing and dereferencing like the equality method does. The first arm is the same as the `if` block from Listing 21-9. The second arm -matches a request to */sleep*. When that request is received, the server will +matches a request to _/sleep_. When that request is received, the server will sleep for 5 seconds before rendering the successful HTML page. The third arm is the same as the `else` block from Listing 21-9. @@ -37,9 +37,9 @@ You can see how primitive our server is: real libraries would handle the recognition of multiple requests in a much less verbose way! Start the server using `cargo run`. Then open two browser windows: one for -*http://127.0.0.1:7878/* and the other for *http://127.0.0.1:7878/sleep*. If -you enter the */* URI a few times, as before, you’ll see it respond quickly. -But if you enter */sleep* and then load */*, you’ll see that */* waits until +_http://127.0.0.1:7878/_ and the other for _http://127.0.0.1:7878/sleep_. If +you enter the _/_ URI a few times, as before, you’ll see it respond quickly. +But if you enter _/sleep_ and then load _/_, you’ll see that _/_ waits until `sleep` has slept for its full 5 seconds before loading. There are multiple techniques we could use to avoid requests backing up behind @@ -48,7 +48,7 @@ implement is a thread pool. ### Improving Throughput with a Thread Pool -A *thread pool* is a group of spawned threads that are waiting and ready to +A _thread pool_ is a group of spawned threads that are waiting and ready to handle a task. When the program receives a new task, it assigns one of the threads in the pool to the task, and that thread will process the task. The remaining threads in the pool are available to handle any other tasks that come @@ -74,8 +74,8 @@ back up in the queue, but we’ve increased the number of long-running requests we can handle before reaching that point. This technique is just one of many ways to improve the throughput of a web -server. Other options you might explore are the *fork/join model*, the -*single-threaded async I/O model*, or the *multi-threaded async I/O model*. If +server. Other options you might explore are the _fork/join model_, the +_single-threaded async I/O model_, or the _multi-threaded async I/O model_. If you’re interested in this topic, you can read more about other solutions and try to implement them; with a low-level language like Rust, all of these options are possible. @@ -94,6 +94,7 @@ what we should change next to get the code to work. Before we do that, however, we’ll explore the technique we’re not going to use as a starting point. + #### Spawning a Thread for Each Request @@ -116,8 +117,8 @@ to handle each stream within the `for` loop. As you learned in Chapter 16, `thread::spawn` will create a new thread and then run the code in the closure in the new thread. If you run this code and load -*/sleep* in your browser, then */* in two more browser tabs, you’ll indeed see -that the requests to */* don’t have to wait for */sleep* to finish. However, as +_/sleep_ in your browser, then _/_ in two more browser tabs, you’ll indeed see +that the requests to _/_ don’t have to wait for _/sleep_ to finish. However, as we mentioned, this will eventually overwhelm the system because you’d be making new threads without any limit. @@ -126,6 +127,7 @@ where async and await really shine! Keep that in mind as we build the thread pool and think about how things would look different or the same with async. + #### Creating a Finite Number of Threads @@ -151,11 +153,12 @@ closure and gives it to a thread in the pool to run. This code won’t yet compile, but we’ll try so the compiler can guide us in how to fix it. + #### Building `ThreadPool` Using Compiler Driven Development -Make the changes in Listing 21-12 to *src/main.rs*, and then let’s use the +Make the changes in Listing 21-12 to _src/main.rs_, and then let’s use the compiler errors from `cargo check` to drive our development. Here is the first error we get: @@ -171,7 +174,7 @@ we change to a library crate, we could also use the separate thread pool library for any work we want to do using a thread pool, not just for serving web requests. -Create a *src/lib.rs* that contains the following, which is the simplest +Create a _src/lib.rs_ that contains the following, which is the simplest definition of a `ThreadPool` struct that we can have for now: @@ -182,8 +185,8 @@ definition of a `ThreadPool` struct that we can have for now: -Then edit *main.rs* file to bring `ThreadPool` into scope from the library -crate by adding the following code to the top of *src/main.rs*: +Then edit _main.rs_ file to bring `ThreadPool` into scope from the library +crate by adding the following code to the top of _src/main.rs_: @@ -293,10 +296,10 @@ yet! > Haskell and Rust, is “if the code compiles, it works.” But this saying is not > universally true. Our project compiles, but it does absolutely nothing! If we > were building a real, complete project, this would be a good time to start -> writing unit tests to check that the code compiles *and* has the behavior we +> writing unit tests to check that the code compiles _and_ has the behavior we > want. -Consider: what would be different here if we were going to execute a *future* +Consider: what would be different here if we were going to execute a _future_ instead of a closure? #### Validating the Number of Threads in `new` @@ -389,13 +392,13 @@ threads. Here, we’ll look at how we actually create threads. The standard library provides `thread::spawn` as a way to create threads, and `thread::spawn` expects to get some code the thread should run as soon as the thread is created. However, in our case, we want to create the threads and have -them *wait* for code that we’ll send later. The standard library’s +them _wait_ for code that we’ll send later. The standard library’s implementation of threads doesn’t include any way to do that; we have to implement it manually. We’ll implement this behavior by introducing a new data structure between the `ThreadPool` and the threads that will manage this new behavior. We’ll call -this data structure *Worker*, which is a common term in pooling +this data structure _Worker_, which is a common term in pooling implementations. The Worker picks up code that needs to be run and runs the code in the Worker’s thread. Think of people working in the kitchen at a restaurant: the workers wait until orders come in from customers, and then @@ -438,7 +441,7 @@ because it’s now holding `Worker` instances instead of `JoinHandle<()>` instances. We use the counter in the `for` loop as an argument to `Worker::new`, and we store each new `Worker` in the vector named `workers`. -External code (like our server in *src/main.rs*) doesn’t need to know the +External code (like our server in _src/main.rs_) doesn’t need to know the implementation details regarding using a `Worker` struct within `ThreadPool`, so we make the `Worker` struct and its `new` function private. The `Worker::new` function uses the `id` we give it and stores a `JoinHandle<()>` @@ -453,7 +456,7 @@ instance that is created by spawning a new thread using an empty closure. > [`spawn`][builder-spawn] method that returns `Result` instead. This code will compile and will store the number of `Worker` instances we -specified as an argument to `ThreadPool::new`. But we’re *still* not processing +specified as an argument to `ThreadPool::new`. But we’re _still_ not processing the closure that we get in `execute`. Let’s look at how to do that next. #### Sending Requests to Threads via Channels @@ -520,7 +523,7 @@ When we try to check this code, we get this error: The code is trying to pass `receiver` to multiple `Worker` instances. This won’t work, as you’ll recall from Chapter 16: the channel implementation that -Rust provides is multiple *producer*, single *consumer*. This means we can’t +Rust provides is multiple _producer_, single _consumer_. This means we can’t just clone the consuming end of the channel to fix this code. We also don’t want to send a message multiple times to multiple consumers; we want one list of messages with multiple workers such that each message gets processed once. @@ -576,7 +579,7 @@ reason we use `unwrap` is that we know the failure case won’t happen, but the compiler doesn’t know that. But we’re not quite done yet! In the worker, our closure being passed to -`thread::spawn` still only *references* the receiving end of the channel. +`thread::spawn` still only _references_ the receiving end of the channel. Instead, we need the closure to loop forever, asking the receiving end of the channel for a job and running the job when it gets one. Let’s make the change shown in Listing 21-20 to `Worker::new`. @@ -591,7 +594,7 @@ shown in Listing 21-20 to `Worker::new`. Here, we first call `lock` on the `receiver` to acquire the mutex, and then we call `unwrap` to panic on any errors. Acquiring a lock might fail if the mutex -is in a *poisoned* state, which can happen if some other thread panicked while +is in a _poisoned_ state, which can happen if some other thread panicked while holding the lock rather than releasing the lock. In this situation, calling `unwrap` to have this thread panic is the correct action to take. Feel free to change this `unwrap` to an `expect` with an error message that is meaningful to @@ -657,10 +660,10 @@ Worker 2 got a job; executing. Success! We now have a thread pool that executes connections asynchronously. There are never more than four threads created, so our system won’t get 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 +_/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. @@ -700,10 +703,8 @@ let` (and `if let` and `match`) does not drop temporary values until the end of the associated block. In Listing 21-21, the lock remains held for the duration of the call to `job()`, meaning other workers cannot receive jobs. -[creating-type-synonyms-with-type-aliases]: -ch20-04-advanced-types.html#creating-type-synonyms-with-type-aliases +[creating-type-synonyms-with-type-aliases]: ch20-04-advanced-types.html#creating-type-synonyms-with-type-aliases [integer-types]: ch03-02-data-types.html#integer-types -[fn-traits]: -ch13-01-closures.html#moving-captured-values-out-of-the-closure-and-the-fn-traits +[fn-traits]: ch13-01-closures.html#moving-captured-values-out-of-the-closure-and-the-fn-traits [builder]: ../std/thread/struct.Builder.html [builder-spawn]: ../std/thread/struct.Builder.html#method.spawn diff --git a/src/ch21-03-graceful-shutdown-and-cleanup.md b/src/ch21-03-graceful-shutdown-and-cleanup.md index b60278240a..36e85f32b3 100644 --- a/src/ch21-03-graceful-shutdown-and-cleanup.md +++ b/src/ch21-03-graceful-shutdown-and-cleanup.md @@ -238,11 +238,11 @@ Here’s the full code for reference: We could do more here! If you want to continue enhancing this project, here are some ideas: -* Add more documentation to `ThreadPool` and its public methods. -* Add tests of the library’s functionality. -* Change calls to `unwrap` to more robust error handling. -* Use `ThreadPool` to perform some task other than serving web requests. -* Find a thread pool crate on [crates.io](https://crates.io/) and implement a +- Add more documentation to `ThreadPool` and its public methods. +- Add tests of the library’s functionality. +- Change calls to `unwrap` to more robust error handling. +- Use `ThreadPool` to perform some task other than serving web requests. +- Find a thread pool crate on [crates.io](https://crates.io/) and implement a similar web server using the crate instead. Then compare its API and robustness to the thread pool we implemented. diff --git a/src/foreword.md b/src/foreword.md index 2265e27142..f108b65a67 100644 --- a/src/foreword.md +++ b/src/foreword.md @@ -1,7 +1,7 @@ # Foreword It wasn’t always so clear, but the Rust programming language is fundamentally -about *empowerment*: no matter what kind of code you are writing now, Rust +about _empowerment_: no matter what kind of code you are writing now, Rust empowers you to reach farther, to program with confidence in a wider variety of domains than you did before. diff --git a/src/title-page.md b/src/title-page.md index daaf01a3d7..7301493201 100644 --- a/src/title-page.md +++ b/src/title-page.md @@ -1,7 +1,7 @@ # The Rust Programming Language -*by Steve Klabnik, Carol Nichols, and Chris Krycho, with contributions from the -Rust Community* +_by Steve Klabnik, Carol Nichols, and Chris Krycho, with contributions from the +Rust Community_ This version of the text assumes you’re using Rust 1.82.0 (released 2024-10-17) or later. See the [“Installation” section of Chapter 1][install] diff --git a/style-guide.md b/style-guide.md index 56677811f4..04dc805ca5 100644 --- a/style-guide.md +++ b/style-guide.md @@ -2,33 +2,33 @@ ## Prose -* Prefer title case for chapter/section headings, ex: `## Generating a Secret +- Prefer title case for chapter/section headings, ex: `## Generating a Secret Number` rather than `## Generating a secret number`. -* Prefer italics over single quotes when calling out a term, ex: `is an +- Prefer italics over single quotes when calling out a term, ex: `is an *associated function* of` rather than `is an ‘associated function’ of`. -* When talking about a method in prose, DO NOT include the parentheses, ex: +- When talking about a method in prose, DO NOT include the parentheses, ex: `read_line` rather than `read_line()`. -* Hard wrap at 80 chars -* Prefer not mixing code and not-code in one word, ex: ``Remember when we wrote +- Hard wrap at 80 chars +- Prefer not mixing code and not-code in one word, ex: ``Remember when we wrote `use std::io`?`` rather than ``Remember when we `use`d `std::io`?`` ## Code -* Add the file name before markdown blocks to make it clear which file we're +- Add the file name before markdown blocks to make it clear which file we're talking about, when applicable. -* When making changes to code, make it clear which parts of the code changed +- When making changes to code, make it clear which parts of the code changed and which stayed the same... not sure how to do this yet -* Split up long lines as appropriate to keep them under 80 chars if possible -* Use `bash` syntax highlighting for command line output code blocks +- Split up long lines as appropriate to keep them under 80 chars if possible +- Use `bash` syntax highlighting for command line output code blocks ## Links Once all the scripts are done: -* If a link shouldn't be printed, mark it to be ignored - * This includes all "Chapter XX" intra-book links, which *should* be links +- If a link shouldn't be printed, mark it to be ignored + - This includes all "Chapter XX" intra-book links, which _should_ be links for the HTML version -* Make intra-book links and stdlib API doc links relative so they work whether +- Make intra-book links and stdlib API doc links relative so they work whether the book is read offline or on docs.rust-lang.org -* Use markdown links and keep in mind that they will be changed into `text at +- Use markdown links and keep in mind that they will be changed into `text at *url*` in print, so word them in a way that it reads well in that format diff --git a/theme/2018-edition.css b/theme/2018-edition.css index b1dcf93641..2276ccbe3e 100644 --- a/theme/2018-edition.css +++ b/theme/2018-edition.css @@ -1,9 +1,9 @@ span.caption { - font-size: .8em; - font-weight: 600; + font-size: 0.8em; + font-weight: 600; } span.caption code { - font-size: 0.875em; - font-weight: 400; + font-size: 0.875em; + font-weight: 400; } diff --git a/theme/listing.css b/theme/listing.css index 5998d39f3b..40ae35a5fb 100644 --- a/theme/listing.css +++ b/theme/listing.css @@ -1,8 +1,8 @@ figure.listing { - margin: 0; + margin: 0; } .listing figcaption { - font-size: .8em; - font-weight: 600; + font-size: 0.8em; + font-weight: 600; } diff --git a/theme/semantic-notes.css b/theme/semantic-notes.css index 7e68eb371d..b6852a0994 100644 --- a/theme/semantic-notes.css +++ b/theme/semantic-notes.css @@ -4,10 +4,10 @@ identical while updating the presentation. */ .note { - margin: 20px 0; - padding: 0 20px; - color: var(--fg); - background-color: var(--quote-bg); - border-block-start: 0.1em solid var(--quote-border); - border-block-end: 0.1em solid var(--quote-border); + margin: 20px 0; + padding: 0 20px; + color: var(--fg); + background-color: var(--quote-bg); + border-block-start: 0.1em solid var(--quote-border); + border-block-end: 0.1em solid var(--quote-border); } From 587b3e40b463780fb37c07469be4f815bf79b382 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 2 Dec 2024 16:15:22 -0700 Subject: [PATCH 696/720] infra: add .git-blame-ignore-revs file w/the formatting commit --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000000..2bcb162313 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Ran dprint fmt on the repo +3a30e4c1 From 951cbf6f2a2dfa041feb7d21a250540f3f60899f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 3 Dec 2024 07:05:20 -0700 Subject: [PATCH 697/720] infra: ignore VS Code and Zed settings --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 17127d1142..6bd6995e09 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ target tmp .nova +.vscode +.zed From 1611a39557e5bea77fad140e900d286f1cd208e3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 3 Dec 2024 11:41:50 -0700 Subject: [PATCH 698/720] =?UTF-8?q?Ch.=2018:=20use=20=E2=80=9Cdyn=20compat?= =?UTF-8?q?ibility=E2=80=9D=20instead=20of=20=E2=80=9Cobject=20safety?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduce the concept at the end of 18.2 when discussing the tradeoffs of dynamic dispatch, with a link to the reference. The link is not currently valid, because of the versioning timeline, but it will be when this stabilizes! - In 18.3, simply replace “object safe” with “dyn compatible”. There is still probably not enough discussion of it, but with the introduction and link in 18.2, it is *probably* enough for now? --- src/ch18-02-trait-objects.md | 9 ++++++--- src/ch18-03-oo-design-patterns.md | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ch18-02-trait-objects.md b/src/ch18-02-trait-objects.md index 4fba9656c9..99e1e73900 100644 --- a/src/ch18-02-trait-objects.md +++ b/src/ch18-02-trait-objects.md @@ -239,9 +239,12 @@ so it doesn’t know which method implemented on which type to call. Instead, at runtime, Rust uses the pointers inside the trait object to know which method to call. This lookup incurs a runtime cost that doesn’t occur with static dispatch. Dynamic dispatch also prevents the compiler from choosing to inline a -method’s code, which in turn prevents some optimizations. However, we did get -extra flexibility in the code that we wrote in Listing 18-5 and were able to -support in Listing 18-9, so it’s a trade-off to consider. +method’s code, which in turn prevents some optimizations, and Rust has some +rules about where you can and cannot use dynamic dispatch, called [_dyn +compatibility_][dyn-compatibility]. However, we did get extra flexibility in the code +that we wrote in Listing 18-5 and were able to support in Listing 18-9, so it’s +a trade-off to consider. [performance-of-code-using-generics]: ch10-01-syntax.html#performance-of-code-using-generics [dynamically-sized]: ch20-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait +[dyn-compatibility]: https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility diff --git a/src/ch18-03-oo-design-patterns.md b/src/ch18-03-oo-design-patterns.md index 625aef3027..8f50a56fdb 100644 --- a/src/ch18-03-oo-design-patterns.md +++ b/src/ch18-03-oo-design-patterns.md @@ -349,9 +349,9 @@ another design pattern. Another downside is that we’ve duplicated some logic. To eliminate some of the duplication, we might try to make default implementations for the `request_review` and `approve` methods on the `State` trait that return `self`; -however, this would violate object safety, because the trait doesn’t know what +however, this would not be dyn compatible, because the trait doesn’t know what the concrete `self` will be exactly. We want to be able to use `State` as a -trait object, so we need its methods to be object safe. +trait object, so we need its methods to be dyn compatible. Other duplication includes the similar implementations of the `request_review` and `approve` methods on `Post`. Both methods delegate to the implementation of From d10bac898c1f9a14be7dff04ff2ea42e004e576e Mon Sep 17 00:00:00 2001 From: Dahuage Date: Wed, 4 Dec 2024 10:44:16 +0800 Subject: [PATCH 699/720] fix: fix a garden-path expression that can be confusing. Fix a garden-path expression that can be confusing for those who are familiar with referring to packages using dots, especially when English is a second language for the reader. --- src/ch21-01-single-threaded.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch21-01-single-threaded.md b/src/ch21-01-single-threaded.md index 813a352474..8eb293fa5d 100644 --- a/src/ch21-01-single-threaded.md +++ b/src/ch21-01-single-threaded.md @@ -141,7 +141,7 @@ 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 reference to the `stream`. `BufReader` adds buffering by managing calls +wraps a reference to the `stream`. And `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 From b6ef8eb6b5ce259adbad39ac332c6b3e5c729456 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 4 Dec 2024 12:09:09 -0700 Subject: [PATCH 700/720] Update src/ch21-01-single-threaded.md --- src/ch21-01-single-threaded.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch21-01-single-threaded.md b/src/ch21-01-single-threaded.md index 8eb293fa5d..2c35b25b59 100644 --- a/src/ch21-01-single-threaded.md +++ b/src/ch21-01-single-threaded.md @@ -141,7 +141,7 @@ 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 reference to the `stream`. And `BufReader` adds buffering by managing calls +wraps a reference to the `stream`. The `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 From 303918057a3f28663aff9725fa7fd867c94dab92 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 21 Nov 2024 12:35:13 -0700 Subject: [PATCH 701/720] Ch. 17: ignore internal links --- src/ch17-01-futures-and-syntax.md | 16 +++++++++------- src/ch17-02-concurrency-with-async.md | 2 -- src/ch17-03-more-futures.md | 10 +++++----- src/ch17-04-streams.md | 2 +- src/ch17-05-traits-for-async.md | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ch17-01-futures-and-syntax.md b/src/ch17-01-futures-and-syntax.md index 11089811bb..81975f3a7c 100644 --- a/src/ch17-01-futures-and-syntax.md +++ b/src/ch17-01-futures-and-syntax.md @@ -44,8 +44,8 @@ everything you need to know as we go. To keep this chapter focused on learning async, rather than juggling parts of the ecosystem, we have created the `trpl` crate (`trpl` is short for “The Rust Programming Language”). It re-exports all the types, traits, and functions -you’ll need, primarily from the [`futures`][futures-crate] and [`tokio`][tokio] -crates. +you’ll need, primarily from the [`futures`][futures-crate] and +[`tokio`][tokio] crates. - The `futures` crate is an official home for Rust experimentation for async code, and is actually where the `Future` type was originally designed. @@ -57,9 +57,10 @@ crates. In some cases, `trpl` also renames or wraps the original APIs to let us stay focused on the details relevant to this chapter. If you want to understand what -the crate does, we encourage you to check out [its source code][crate-source]. -You’ll be able to see what crate each re-export comes from, and we’ve left -extensive comments explaining what the crate does. +the crate does, we encourage you to check out [its source +code][crate-source]. You’ll be able to see what crate each +re-export comes from, and we’ve left extensive comments explaining what the +crate does. Create a new binary project named `hello-async` and add the `trpl` crate as a dependency: @@ -101,7 +102,8 @@ also async. We have to explicitly await both of these futures, because futures in Rust are _lazy_: they don’t do anything until you ask them to with `await`. (In fact, Rust will show a compiler warning if you don’t use a future.) This should -remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. +remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. Iterators do nothing unless you call their `next` method—whether directly, or using `for` loops or methods such as `map` which use `next` under the hood. With futures, the same basic idea applies: they do nothing unless you explicitly ask @@ -174,7 +176,7 @@ fn page_title(url: &str) -> impl Future> + '_ { Let’s walk through each part of the transformed version: - It uses the `impl Trait` syntax we discussed back in the [“Traits as - Parameters”][impl-trait] section in Chapter 10. + Parameters”][impl-trait] section in Chapter 10. - The returned trait is a `Future`, with an associated type of `Output`. Notice that the `Output` type is `Option`, which is the same as the the original return type from the `async fn` version of `page_title`. diff --git a/src/ch17-02-concurrency-with-async.md b/src/ch17-02-concurrency-with-async.md index 522b84092b..2348144d6d 100644 --- a/src/ch17-02-concurrency-with-async.md +++ b/src/ch17-02-concurrency-with-async.md @@ -380,5 +380,3 @@ received 'you' This is a good start, but it limits us to just a handful of futures: two with `join`, or three with `join3`. Let’s see how we might work with more futures. - -[streams]: ch17-05-streams.html diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index aaf8e9084b..c850ffc2f4 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -71,7 +71,7 @@ structs in a `Vec`, and the same thing applies to the different structs generated by the compiler. To make this work, we need to use _trait objects_, just as we did in [“Returning -Errors from the run function”][dyn] in Chapter 12. (We’ll cover trait objects +Errors from the run function”][dyn] in Chapter 12. (We’ll cover trait objects in detail in Chapter 18.) Using trait objects lets us treat each of the anonymous futures produced by these types as the same type, because all of them implement the `Future` trait. @@ -330,9 +330,9 @@ In Listing 17-21, we once again use `trpl::race` to run two futures, `slow` and pauses for some amount of time by calling and awaiting `sleep`, and then prints another message when it finishes. Then we pass both to `trpl::race` and wait for one of them to finish. (The outcome here won’t be too surprising: `fast` wins!) -Unlike when we used `race` back in [Our First Async Program][async-program], we -just ignore the `Either` instance it returns here, because all of the -interesting behavior happens in the body of the async blocks. +Unlike when we used `race` back in [“Our First Async Program”][async-program], we just ignore the `Either` instance it returns here, because all of +the interesting behavior happens in the body of the async blocks. @@ -351,7 +351,7 @@ to poll first. Regardless of whether the implementation of race we’re using is fair, though, _one_ of the futures will run up to the first `await` in its body before another task can start. -Recall from [Our First Async Program][async-program] that at each await point, +Recall from [Our First Async Program][async-program] that at each await point, Rust gives a runtime a chance to pause the task and switch to another one if the future being awaited isn’t ready. The inverse is also true: Rust _only_ pauses async blocks and hands control back to a runtime at an await point. Everything diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 11b4a04fd4..e205e77add 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -2,7 +2,7 @@ So far in this chapter, we have mostly stuck to individual futures. The one big exception was the async channel we used. Recall how we used the receiver for our -async channel in the [“Message Passing”][17-02-messages] earlier in the chapter. +async channel in the [“Message Passing”][17-02-messages] earlier in the chapter. The async `recv` method produces a sequence of items over time. This is an instance of a much more general pattern, often called a _stream_. diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index b5cc800ce8..0aed567cdd 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -10,9 +10,9 @@ still leaving the _really_ deep dive for other documentation! ### Future -Back in [Futures and the Async Syntax][futures-syntax], we noted that `Future` -is a trait. Let’s start by taking a closer look at how it works. Here is how -Rust defines a `Future`: +Back in [“Futures and the Async Syntax”][futures-syntax], we +noted that `Future` is a trait. Let’s start by taking a closer look at how it +works. Here is how Rust defines a `Future`: ```rust use std::pin::Pin; From 69f7761152ee738d7a1f404329d3966587b1ea89 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 4 Dec 2024 17:00:40 -0700 Subject: [PATCH 702/720] infra: `dprint fmt` dprint config itself --- dprint.jsonc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dprint.jsonc b/dprint.jsonc index 3d48ade517..bf34e5b4de 100644 --- a/dprint.jsonc +++ b/dprint.jsonc @@ -22,12 +22,12 @@ "second-edition", "redirects", // has empty list items which look like headings to a formatter - ".github/ISSUE_TEMPLATE/bug_report.md" + ".github/ISSUE_TEMPLATE/bug_report.md", ], "plugins": [ "https://plugins.dprint.dev/typescript-0.93.3.wasm", "https://plugins.dprint.dev/json-0.19.4.wasm", "https://plugins.dprint.dev/markdown-0.17.8.wasm", - "https://plugins.dprint.dev/g-plane/malva-v0.11.0.wasm" - ] + "https://plugins.dprint.dev/g-plane/malva-v0.11.0.wasm", + ], } From 8ab103d510eda7825ecf469ed3b6fd59b1f807d5 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 8 Nov 2024 08:57:41 -0700 Subject: [PATCH 703/720] Add Chris Krycho (me!) to the nostarch book.toml authors --- nostarch/book.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nostarch/book.toml b/nostarch/book.toml index ce0abdc510..4886d0ae8e 100644 --- a/nostarch/book.toml +++ b/nostarch/book.toml @@ -1,6 +1,6 @@ [book] title = "The Rust Programming Language" -authors = ["Steve Klabnik", "Carol Nichols", "Contributions from the Rust Community"] +authors = ["Steve Klabnik", "Carol Nichols", "Chris Krycho", "Contributions from the Rust Community"] src = "../src" # needs to be explicit (it is implicit in `/book.toml`). [output.html] From bf43b7a5162e8ccd60267a5b0cb90ad344e95b2c Mon Sep 17 00:00:00 2001 From: Dane Harrigan <72265290+dane@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:32:50 -0500 Subject: [PATCH 704/720] Revise sentence to not refer to two subjects as it --- src/ch04-02-references-and-borrowing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index cb4d172e85..22ceb2bdb1 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -45,8 +45,8 @@ Let’s take a closer look at the function call here: ``` The `&s1` syntax lets us create a reference that _refers_ to the value of `s1` -but does not own it. Because it does not own it, the value it points to will -not be dropped when the reference stops being used. +but does not own it. Because the reference does not own it, the value it points +to will not be dropped when the reference stops being used. Likewise, the signature of the function uses `&` to indicate that the type of the parameter `s` is a reference. Let’s add some explanatory annotations: From d65bd3cc316ce9c59f91c549be70c69b2384f018 Mon Sep 17 00:00:00 2001 From: Dane Harrigan <72265290+dane@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:43:51 -0500 Subject: [PATCH 705/720] Revise annotations to not refer to subjects as it --- .../no-listing-08-reference-with-annotations/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs index 964fd233f7..e9894fab67 100644 --- a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs @@ -9,6 +9,6 @@ fn main() { // ANCHOR: here fn calculate_length(s: &String) -> usize { // s is a reference to a String s.len() -} // Here, s goes out of scope. But because it does not have ownership of what - // it refers to, it is not dropped. +} // Here, s goes out of scope. But because s does not have ownership of what + // it refers to, the value is not dropped. // ANCHOR_END: here From 9e2673a008a02f05fd994fe1c37c55df0f3064b1 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 8 Nov 2024 09:23:13 -0700 Subject: [PATCH 706/720] infra: share infrastructure for mdbook preprocessors - Create an `mdbook_trpl` library package which hosts shared concerns for the packages, e.g. error and config handling. - Move `mdbook-trpl-note` and `mdbook-trpl-listing` into the new shared package, with binaries at `src/bin/(note|listing)/main.rs` and the existing libraries at `src/note/mod.rs` and `src/listing/mod.rs` with their associated tests. - Extract their actual shared pieces into the crate root. - Update `tools/nostarch.sh` to build all the bins in `mdbook_trpl` at one time. At the moment, this doesn't do a lot except trim down the number of packages in the repository, but it sets things up nicely to support more preprocessors (which I am going to add shortly). --- .github/workflows/main.yml | 14 +- README.md | 3 +- packages/mdbook-trpl-note/Cargo.lock | 1087 ----------------- packages/mdbook-trpl-note/Cargo.toml | 21 - packages/mdbook-trpl-note/src/lib.rs | 346 ------ .../tests/integration/main.rs | 22 - .../Cargo.lock | 484 ++++---- .../Cargo.toml | 19 +- packages/mdbook-trpl/README.md | 13 + .../src/bin/README - mdbook-trpl-note.md} | 0 packages/mdbook-trpl/src/bin/figure.rs | 42 + .../src/bin/listing.rs} | 9 +- .../main.rs => mdbook-trpl/src/bin/note.rs} | 8 +- packages/mdbook-trpl/src/config/mod.rs | 71 ++ .../src/config/tests.rs} | 180 +-- packages/mdbook-trpl/src/figure/mod.rs | 252 ++++ packages/mdbook-trpl/src/figure/tests.rs | 60 + packages/mdbook-trpl/src/lib.rs | 35 + .../lib.rs => mdbook-trpl/src/listing/mod.rs} | 311 +++-- .../src/listing/tests.rs} | 25 +- packages/mdbook-trpl/src/note/mod.rs | 145 +++ packages/mdbook-trpl/src/note/tests.rs | 195 +++ .../mdbook-trpl/tests/integration/main.rs | 20 + tools/nostarch.sh | 8 +- 24 files changed, 1354 insertions(+), 2016 deletions(-) delete mode 100644 packages/mdbook-trpl-note/Cargo.lock delete mode 100644 packages/mdbook-trpl-note/Cargo.toml delete mode 100644 packages/mdbook-trpl-note/src/lib.rs delete mode 100644 packages/mdbook-trpl-note/tests/integration/main.rs rename packages/{mdbook-trpl-listing => mdbook-trpl}/Cargo.lock (67%) rename packages/{mdbook-trpl-listing => mdbook-trpl}/Cargo.toml (67%) create mode 100644 packages/mdbook-trpl/README.md rename packages/{mdbook-trpl-note/README.md => mdbook-trpl/src/bin/README - mdbook-trpl-note.md} (100%) create mode 100644 packages/mdbook-trpl/src/bin/figure.rs rename packages/{mdbook-trpl-listing/src/main.rs => mdbook-trpl/src/bin/listing.rs} (75%) rename packages/{mdbook-trpl-note/src/main.rs => mdbook-trpl/src/bin/note.rs} (84%) create mode 100644 packages/mdbook-trpl/src/config/mod.rs rename packages/{mdbook-trpl-listing/src/tests/config.rs => mdbook-trpl/src/config/tests.rs} (62%) create mode 100644 packages/mdbook-trpl/src/figure/mod.rs create mode 100644 packages/mdbook-trpl/src/figure/tests.rs create mode 100644 packages/mdbook-trpl/src/lib.rs rename packages/{mdbook-trpl-listing/src/lib.rs => mdbook-trpl/src/listing/mod.rs} (56%) rename packages/{mdbook-trpl-listing/src/tests/mod.rs => mdbook-trpl/src/listing/tests.rs} (93%) create mode 100644 packages/mdbook-trpl/src/note/mod.rs create mode 100644 packages/mdbook-trpl/src/note/tests.rs create mode 100644 packages/mdbook-trpl/tests/integration/main.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 727f1d1312..34fc9ae0a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,12 +52,8 @@ jobs: - name: Run `tools` package tests run: | cargo test - - name: Run `mdbook-trpl-note` package tests - working-directory: packages/mdbook-trpl-note - run: | - cargo test - - name: Run `mdbook-trpl-listing` package tests - working-directory: packages/mdbook-trpl-listing + - name: Run `mdbook-trpl` package tests + working-directory: packages/mdbook-trpl run: | cargo test lint: @@ -77,10 +73,8 @@ jobs: mkdir bin curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.21/mdbook-v0.4.21-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin echo "$(pwd)/bin" >> "${GITHUB_PATH}" - - name: Install mdbook-trpl-note - run: cargo install --path packages/mdbook-trpl-note - - name: Install mdbook-trpl-listing - run: cargo install --path packages/mdbook-trpl-listing + - name: Install mdbook-trpl binaries + run: cargo install --path packages/mdbook-trpl - name: Install aspell run: sudo apt-get install aspell - name: Install shellcheck diff --git a/README.md b/README.md index 9935bd46f7..a632402385 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,7 @@ 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 +$ cargo install --locked --path packages/mdbook_trpl ``` ## Building diff --git a/packages/mdbook-trpl-note/Cargo.lock b/packages/mdbook-trpl-note/Cargo.lock deleted file mode 100644 index 25a63dab12..0000000000 --- a/packages/mdbook-trpl-note/Cargo.lock +++ /dev/null @@ -1,1087 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anstream" -version = "0.6.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" - -[[package]] -name = "anstyle-parse" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - -[[package]] -name = "anyhow" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - -[[package]] -name = "assert_cmd" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" -dependencies = [ - "anstyle", - "bstr", - "doc-comment", - "predicates", - "predicates-core", - "predicates-tree", - "wait-timeout", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bstr" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" -dependencies = [ - "memchr", - "regex-automata", - "serde", -] - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "cc" -version = "1.0.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "num-traits", - "windows-targets 0.52.5", -] - -[[package]] -name = "clap" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", - "terminal_size", -] - -[[package]] -name = "clap_complete" -version = "4.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" -dependencies = [ - "clap", -] - -[[package]] -name = "clap_derive" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" - -[[package]] -name = "colorchoice" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" - -[[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - -[[package]] -name = "cpufeatures" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "dbus" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" -dependencies = [ - "libc", - "libdbus-sys", - "winapi", -] - -[[package]] -name = "difflib" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "doc-comment" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" - -[[package]] -name = "env_filter" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getopts" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "handlebars" -version = "5.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" -dependencies = [ - "log", - "pest", - "pest_derive", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "iana-time-zone" -version = "0.1.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "libdbus-sys" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" -dependencies = [ - "cc", - "pkg-config", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "mdbook" -version = "0.4.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45a38e19bd200220ef07c892b0157ad3d2365e5b5a267ca01ad12182491eea5" -dependencies = [ - "anyhow", - "chrono", - "clap", - "clap_complete", - "env_logger", - "handlebars", - "log", - "memchr", - "once_cell", - "opener", - "pulldown-cmark", - "regex", - "serde", - "serde_json", - "shlex", - "tempfile", - "toml", - "topological-sort", -] - -[[package]] -name = "mdbook-trpl-note" -version = "1.0.0" -dependencies = [ - "assert_cmd", - "clap", - "mdbook", - "pulldown-cmark", - "pulldown-cmark-to-cmark", - "serde_json", -] - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - -[[package]] -name = "normpath" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "opener" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8df34be653210fbe9ffaff41d3b92721c56ce82dfee58ee684f9afb5e3a90c0" -dependencies = [ - "bstr", - "dbus", - "normpath", - "windows-sys 0.52.0", -] - -[[package]] -name = "pest" -version = "2.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" -dependencies = [ - "memchr", - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" -dependencies = [ - "once_cell", - "pest", - "sha2", -] - -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - -[[package]] -name = "predicates" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" -dependencies = [ - "anstyle", - "difflib", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" - -[[package]] -name = "predicates-tree" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" -dependencies = [ - "predicates-core", - "termtree", -] - -[[package]] -name = "proc-macro2" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "pulldown-cmark" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" -dependencies = [ - "bitflags", - "getopts", - "memchr", - "pulldown-cmark-escape", - "unicase", -] - -[[package]] -name = "pulldown-cmark-escape" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" - -[[package]] -name = "pulldown-cmark-to-cmark" -version = "13.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" -dependencies = [ - "pulldown-cmark", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex" -version = "1.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" - -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "serde" -version = "1.0.202" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.202" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.117" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "syn" -version = "2.0.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - -[[package]] -name = "terminal_size" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" -dependencies = [ - "rustix", - "windows-sys 0.48.0", -] - -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - -[[package]] -name = "thiserror" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - -[[package]] -name = "topological-sort" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "ucd-trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" - -[[package]] -name = "unicase" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-width" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" - -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wait-timeout" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" -dependencies = [ - "libc", -] - -[[package]] -name = "wasm-bindgen" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/packages/mdbook-trpl-note/Cargo.toml b/packages/mdbook-trpl-note/Cargo.toml deleted file mode 100644 index 4fde2fd878..0000000000 --- a/packages/mdbook-trpl-note/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "mdbook-trpl-note" -version = "1.0.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -clap = { version = "4", features = ["derive"] } -mdbook = { version = "0.4", default-features = false } # only need the library -pulldown-cmark = { version = "0.10", features = ["simd"] } -pulldown-cmark-to-cmark = "13" -serde_json = "1" - -[dev-dependencies] -assert_cmd = "2" - -# This package is used as a path dependency in `rust-lang/rust`, not published -# to crates.io, so it cannot be part of the `rust-lang/book` workspace, because -# path dependencies do not get built as a crate within the hosting workspace. -[workspace] diff --git a/packages/mdbook-trpl-note/src/lib.rs b/packages/mdbook-trpl-note/src/lib.rs deleted file mode 100644 index 115641bac2..0000000000 --- a/packages/mdbook-trpl-note/src/lib.rs +++ /dev/null @@ -1,346 +0,0 @@ -use mdbook::{ - book::Book, - errors::Result, - preprocess::{Preprocessor, PreprocessorContext}, - utils::new_cmark_parser, - BookItem, -}; -use pulldown_cmark::{ - Event::{self, *}, - Tag, TagEnd, -}; -use pulldown_cmark_to_cmark::cmark; - -/// A simple preprocessor for semantic notes in _The Rust Programming Language_. -/// -/// Takes in Markdown like this: -/// -/// ```markdown -/// > Note: This is a note. -/// ``` -/// -/// Spits out Markdown like this: -/// -/// ```markdown -///
-/// -/// This is a note. -/// -///
-/// ``` -pub struct TrplNote; - -impl Preprocessor for TrplNote { - fn name(&self) -> &str { - "simple-note-preprocessor" - } - - fn run( - &self, - _ctx: &PreprocessorContext, - mut book: Book, - ) -> Result { - book.for_each_mut(|item| { - if let BookItem::Chapter(ref mut chapter) = item { - chapter.content = rewrite(&chapter.content); - } - }); - Ok(book) - } - - fn supports_renderer(&self, renderer: &str) -> bool { - renderer == "html" || renderer == "markdown" || renderer == "test" - } -} - -pub fn rewrite(text: &str) -> String { - let parser = new_cmark_parser(text, true); - - let mut events = Vec::new(); - let mut state = Default; - - for event in parser { - match (&mut state, event) { - (Default, Start(Tag::BlockQuote)) => { - state = StartingBlockquote(vec![Start(Tag::BlockQuote)]); - } - - (StartingBlockquote(blockquote_events), Text(content)) => { - if content.starts_with("Note: ") { - // This needs the "extra" `SoftBreak`s so that when the final rendering pass - // happens, it does not end up treating the internal content as inline *or* - // treating the HTML tags as inline tags: - // - // - Content inside HTML blocks is only rendered as Markdown when it is - // separated from the block HTML elements: otherwise it gets treated as inline - // HTML and *not* rendered. - // - Along the same lines, an HTML tag that happens to be directly adjacent to - // the end of a previous Markdown block will end up being rendered as part of - // that block. - events.extend([ - SoftBreak, - SoftBreak, - Html( - r#"
"#.into(), - ), - SoftBreak, - SoftBreak, - Start(Tag::Paragraph), - Text(content), - ]); - state = InNote; - } else { - events.append(blockquote_events); - events.push(Text(content)); - state = Default; - } - } - - ( - StartingBlockquote(_blockquote_events), - heading @ Start(Tag::Heading { .. }), - ) => { - events.extend([ - SoftBreak, - SoftBreak, - Html(r#"
"#.into()), - SoftBreak, - SoftBreak, - heading, - ]); - state = InNote; - } - - (StartingBlockquote(ref mut events), Start(tag)) => { - events.push(Start(tag)); - } - - (InNote, End(TagEnd::BlockQuote)) => { - // As with the start of the block HTML, the closing HTML must be - // separated from the Markdown text by two newlines. - events.extend([ - SoftBreak, - SoftBreak, - Html("
".into()), - ]); - state = Default; - } - - (_, event) => { - events.push(event); - } - } - } - - let mut buf = String::new(); - cmark(events.into_iter(), &mut buf).unwrap(); - buf -} - -use State::*; - -#[derive(Debug)] -enum State<'e> { - Default, - StartingBlockquote(Vec>), - InNote, -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn no_note() { - let text = "Hello, world.\n\nThis is some text."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "

Hello, world.

\n

This is some text.

\n" - ); - } - - #[test] - fn with_note() { - let text = "> Note: This is some text.\n> It keeps going."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Note: This is some text.\nIt keeps going.

\n
" - ); - } - - #[test] - fn regular_blockquote() { - let text = "> This is some text.\n> It keeps going."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

This is some text.\nIt keeps going.

\n
\n" - ); - } - - #[test] - fn combined() { - let text = "> Note: This is some text.\n> It keeps going.\n\nThis is regular text.\n\n> This is a blockquote.\n"; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Note: This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" - ); - } - - #[test] - fn blockquote_then_note() { - let text = "> This is quoted.\n\n> Note: This is noted."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

This is quoted.

\n
\n
\n

Note: This is noted.

\n
" - ); - } - - #[test] - fn note_then_blockquote() { - let text = "> Note: This is noted.\n\n> This is quoted."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Note: This is noted.

\n
\n
\n

This is quoted.

\n
\n" - ); - } - - #[test] - fn with_h1_note() { - let text = "> # Header\n > And then some note content."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
" - ); - } - - #[test] - fn with_h2_note() { - let text = "> ## Header\n > And then some note content."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
" - ); - } - - #[test] - fn with_h3_note() { - let text = "> ### Header\n > And then some note content."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
" - ); - } - - #[test] - fn with_h4_note() { - let text = "> #### Header\n > And then some note content."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
" - ); - } - - #[test] - fn with_h5_note() { - let text = "> ##### Header\n > And then some note content."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n
Header
\n

And then some note content.

\n
" - ); - } - - #[test] - fn with_h6_note() { - let text = "> ###### Header\n > And then some note content."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n
Header
\n

And then some note content.

\n
" - ); - } - - #[test] - fn h1_then_blockquote() { - let text = - "> # Header\n > And then some note content.\n\n> This is quoted."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Header

\n

And then some note content.

\n
\n
\n

This is quoted.

\n
\n" - ); - } - - #[test] - fn blockquote_then_h1_note() { - let text = - "> This is quoted.\n\n> # Header\n > And then some note content."; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

This is quoted.

\n
\n
\n

Header

\n

And then some note content.

\n
" - ); - } - - #[test] - fn blockquote_with_strong() { - let text = "> **Bold text in a paragraph.**"; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

Bold text in a paragraph.

\n
\n" - ); - } - - #[test] - fn normal_table() { - let text = "| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; - let processed = rewrite(text); - - assert_eq!( - processed, - "|Header 1|Header 2|\n|--------|--------|\n|Text 123|More 456|", - "It strips some whitespace but otherwise leaves the table intact." - ); - } - - #[test] - fn table_in_note() { - let text = "> Note: table stuff.\n\n| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; - let processed = rewrite(text); - - assert_eq!( - processed, - "\n\n
\n\nNote: table stuff.\n\n
\n\n|Header 1|Header 2|\n|--------|--------|\n|Text 123|More 456|", - "It adds the note markup but leaves the table untouched, to be rendered as Markdown." - ); - } - - #[test] - fn table_in_quote() { - let text = "> A table.\n\n| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; - let processed = rewrite(text); - assert_eq!( - render_markdown(&processed), - "
\n

A table.

\n
\n\n\n
Header 1Header 2
Text 123More 456
\n", - "It renders blockquotes with nested tables as expected." - ); - } - - fn render_markdown(text: &str) -> String { - let parser = new_cmark_parser(text, true); - let mut buf = String::new(); - pulldown_cmark::html::push_html(&mut buf, parser); - buf - } -} diff --git a/packages/mdbook-trpl-note/tests/integration/main.rs b/packages/mdbook-trpl-note/tests/integration/main.rs deleted file mode 100644 index 6944fae693..0000000000 --- a/packages/mdbook-trpl-note/tests/integration/main.rs +++ /dev/null @@ -1,22 +0,0 @@ -use assert_cmd::Command; - -#[test] -fn supports_html_renderer() { - let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) - .unwrap() - .args(["supports", "html"]) - .ok(); - assert!(cmd.is_ok()); -} - -#[test] -fn errors_for_other_renderers() { - let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) - .unwrap() - .args(["supports", "total-nonsense"]) - .ok(); - assert!(cmd.is_err()); -} - -// It would be nice to add an actual fixture for an mdbook, but doing *that* is -// going to be a bit of a pain, and what I have should cover it for now. diff --git a/packages/mdbook-trpl-listing/Cargo.lock b/packages/mdbook-trpl/Cargo.lock similarity index 67% rename from packages/mdbook-trpl-listing/Cargo.lock rename to packages/mdbook-trpl/Cargo.lock index c61da8a7f4..e096e4cd67 100644 --- a/packages/mdbook-trpl-listing/Cargo.lock +++ b/packages/mdbook-trpl/Cargo.lock @@ -28,9 +28,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -43,53 +43,54 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.3" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "assert_cmd" -version = "2.0.14" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" +checksum = "dc1835b7f27878de8525dc71410b5a31cdcc5f230aed5ba5df968e09c201b23d" dependencies = [ "anstyle", "bstr", "doc-comment", + "libc", "predicates", "predicates-core", "predicates-tree", @@ -98,15 +99,15 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "block-buffer" @@ -119,9 +120,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.9.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" dependencies = [ "memchr", "regex-automata", @@ -136,9 +137,12 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "cc" -version = "1.0.98" +version = "1.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -155,14 +159,14 @@ dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "windows-targets 0.52.5", + "windows-targets", ] [[package]] name = "clap" -version = "4.5.4" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -170,9 +174,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -183,18 +187,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.2" +version = "4.5.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +checksum = "11611dca53440593f38e6b25ec629de50b14cdfa63adc0fb856115a2c6d97595" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.5.4" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck", "proc-macro2", @@ -204,27 +208,27 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -274,9 +278,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "env_filter" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" dependencies = [ "log", "regex", @@ -284,9 +288,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" dependencies = [ "anstream", "anstyle", @@ -313,9 +317,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "generic-array" @@ -338,11 +342,12 @@ dependencies = [ [[package]] name = "handlebars" -version = "5.1.2" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +checksum = "fd4ccde012831f9a071a637b0d4e31df31c0f6c525784b35ae76a9ac6bc1e315" dependencies = [ "log", + "num-order", "pest", "pest_derive", "serde", @@ -352,9 +357,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.5" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" [[package]] name = "heck" @@ -385,9 +390,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -408,9 +413,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown", @@ -418,9 +423,9 @@ dependencies = [ [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" @@ -430,18 +435,18 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.155" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libdbus-sys" @@ -461,15 +466,15 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "mdbook" -version = "0.4.40" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45a38e19bd200220ef07c892b0157ad3d2365e5b5a267ca01ad12182491eea5" +checksum = "7624879735513024d323e7267a0b3a7176aceb0db537939beb4ee31d9e8945e3" dependencies = [ "anyhow", "chrono", @@ -481,7 +486,7 @@ dependencies = [ "memchr", "once_cell", "opener", - "pulldown-cmark", + "pulldown-cmark 0.10.3", "regex", "serde", "serde_json", @@ -492,33 +497,49 @@ dependencies = [ ] [[package]] -name = "mdbook-trpl-listing" +name = "mdbook-trpl" version = "0.1.0" dependencies = [ + "anyhow", "assert_cmd", "clap", "html_parser", "mdbook", - "pulldown-cmark", + "pulldown-cmark 0.12.2", "pulldown-cmark-to-cmark", "serde_json", "thiserror", - "toml 0.8.13", + "toml 0.8.19", ] [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "normpath" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8911957c4b1549ac0dc74e30db9c8b0e66ddcd6d7acc33098f4c63a64a6d7ed" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "num-modular" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17bb261bf36fa7d83f4c294f834e91256769097b3cb505d44831e0a179ac647f" + +[[package]] +name = "num-order" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +checksum = "537b596b97c40fcf8056d153049eb22f481c17ebce72a513ec9286e4986d1bb6" dependencies = [ - "windows-sys 0.52.0", + "num-modular", ] [[package]] @@ -532,27 +553,27 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "opener" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8df34be653210fbe9ffaff41d3b92721c56ce82dfee58ee684f9afb5e3a90c0" +checksum = "d0812e5e4df08da354c851a3376fead46db31c2214f849d3de356d774d057681" dependencies = [ "bstr", "dbus", "normpath", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "pest" -version = "2.7.10" +version = "2.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" dependencies = [ "memchr", "thiserror", @@ -561,9 +582,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.10" +version = "2.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +checksum = "d214365f632b123a47fd913301e14c946c61d1c183ee245fa76eb752e59a02dd" dependencies = [ "pest", "pest_generator", @@ -571,9 +592,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.10" +version = "2.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +checksum = "eb55586734301717aea2ac313f50b2eb8f60d2fc3dc01d190eefa2e625f60c4e" dependencies = [ "pest", "pest_meta", @@ -584,9 +605,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.10" +version = "2.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +checksum = "b75da2a70cf4d9cb76833c990ac9cd3923c9a8905a8929789ce347c84564d03d" dependencies = [ "once_cell", "pest", @@ -595,15 +616,15 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "predicates" -version = "3.1.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" dependencies = [ "anstyle", "difflib", @@ -612,15 +633,15 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" +checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" [[package]] name = "predicates-tree" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" dependencies = [ "predicates-core", "termtree", @@ -628,9 +649,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.83" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -640,11 +661,23 @@ name = "pulldown-cmark" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags", + "memchr", + "pulldown-cmark-escape 0.10.1", + "unicase", +] + +[[package]] +name = "pulldown-cmark" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86ba2052aebccc42cbbb3ed234b8b13ce76f75c3551a303cb2bcffcff12bb14" dependencies = [ "bitflags", "getopts", "memchr", - "pulldown-cmark-escape", + "pulldown-cmark-escape 0.11.0", "unicase", ] @@ -654,29 +687,35 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" +[[package]] +name = "pulldown-cmark-escape" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" + [[package]] name = "pulldown-cmark-to-cmark" -version = "13.0.0" +version = "19.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f609795c8d835f79dcfcf768415b9fb57ef1b74891e99f86e73f43a7a257163b" +checksum = "7d742adcc7b655dba3e9ebab47954ca229fc0fa1df01fdc94349b6f3a2e6d257" dependencies = [ - "pulldown-cmark", + "pulldown-cmark 0.12.2", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.10.4" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -686,9 +725,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -697,15 +736,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" dependencies = [ "bitflags", "errno", @@ -722,18 +761,18 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.202" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.202" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", @@ -742,20 +781,21 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] [[package]] name = "serde_spanned" -version = "0.6.6" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -785,9 +825,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.65" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -796,24 +836,25 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.10.1" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", + "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "terminal_size" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +checksum = "4f599bd7ca042cfdf8f4512b277c02ba102247820f9d9d4a9f521f496751a6ef" dependencies = [ "rustix", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -824,18 +865,18 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" dependencies = [ "proc-macro2", "quote", @@ -853,9 +894,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.13" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", @@ -865,18 +906,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.6" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.13" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "serde", @@ -899,42 +940,39 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" [[package]] name = "unicase" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] +checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-width" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wait-timeout" @@ -947,19 +985,20 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", @@ -972,9 +1011,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -982,9 +1021,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", @@ -995,9 +1034,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "winapi" @@ -1027,16 +1066,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", + "windows-targets", ] [[package]] @@ -1045,135 +1075,87 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets", ] [[package]] -name = "windows-targets" -version = "0.48.5" +name = "windows-sys" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.8" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] diff --git a/packages/mdbook-trpl-listing/Cargo.toml b/packages/mdbook-trpl/Cargo.toml similarity index 67% rename from packages/mdbook-trpl-listing/Cargo.toml rename to packages/mdbook-trpl/Cargo.toml index 4b90001e23..170a708605 100644 --- a/packages/mdbook-trpl-listing/Cargo.toml +++ b/packages/mdbook-trpl/Cargo.toml @@ -1,16 +1,27 @@ [package] -name = "mdbook-trpl-listing" +name = "mdbook-trpl" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name = "mdbook-trpl-note" +path = "src/bin/note.rs" + +[[bin]] +name = "mdbook-trpl-listing" +path = "src/bin/listing.rs" + +[[bin]] +name = "mdbook-trpl-figure" +path = "src/bin/figure.rs" [dependencies] +anyhow = "1" clap = { version = "4", features = ["derive"] } html_parser = "0.7.0" mdbook = { version = "0.4", default-features = false } # only need the library -pulldown-cmark = { version = "0.10", features = ["simd"] } -pulldown-cmark-to-cmark = "13" +pulldown-cmark = { version = "0.12", features = ["simd"] } +pulldown-cmark-to-cmark = "19" serde_json = "1" thiserror = "1.0.60" toml = "0.8.12" diff --git a/packages/mdbook-trpl/README.md b/packages/mdbook-trpl/README.md new file mode 100644 index 0000000000..15aacced0d --- /dev/null +++ b/packages/mdbook-trpl/README.md @@ -0,0 +1,13 @@ +# mdbook_trpl + +A shared package for [mdbook][mdbook] [preprocessors][pre] used in [_The Rust +Programming Language_][trpl]. + +Supplies the following preprocessor binaries: + +- [mdbook-trpl-note](./src/bin/note) +- [mdbook-trpl-listing](./src/bin/listing) + +[mdbook]: https://crates.io/crates/mdbook +[pre]: https://rust-lang.github.io/mdBook/format/configuration/preprocessors.html +[trpl]: https://doc.rust-lang.org/book/ diff --git a/packages/mdbook-trpl-note/README.md b/packages/mdbook-trpl/src/bin/README - mdbook-trpl-note.md similarity index 100% rename from packages/mdbook-trpl-note/README.md rename to packages/mdbook-trpl/src/bin/README - mdbook-trpl-note.md diff --git a/packages/mdbook-trpl/src/bin/figure.rs b/packages/mdbook-trpl/src/bin/figure.rs new file mode 100644 index 0000000000..e780cbd4e7 --- /dev/null +++ b/packages/mdbook-trpl/src/bin/figure.rs @@ -0,0 +1,42 @@ +use std::io; + +use clap::{self, Parser, Subcommand}; + +use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; +use mdbook_trpl::Figure; + +fn main() -> Result<(), String> { + match Cli::parse().command { + Some(Command::Supports { renderer }) => { + if Figure.supports_renderer(&renderer) { + Ok(()) + } else { + Err(format!("Renderer '{renderer}' is unsupported")) + } + } + None => { + let (ctx, book) = CmdPreprocessor::parse_input(io::stdin()) + .map_err(|e| format!("{e}"))?; + let processed = + Figure.run(&ctx, book).map_err(|e| format!("{e}"))?; + serde_json::to_writer(io::stdout(), &processed) + .map_err(|e| format!("{e}")) + } + } +} + +/// A simple preprocessor for handling figures with images in _The Rust +/// Programming Language_ book. +#[derive(Parser, Debug)] +struct Cli { + #[command(subcommand)] + command: Option, +} + +#[derive(Subcommand, Debug)] +enum Command { + /// Is the renderer supported? + /// + /// Supported renderers are `'html'`, `'markdown'`, and `'test'`. + Supports { renderer: String }, +} diff --git a/packages/mdbook-trpl-listing/src/main.rs b/packages/mdbook-trpl/src/bin/listing.rs similarity index 75% rename from packages/mdbook-trpl-listing/src/main.rs rename to packages/mdbook-trpl/src/bin/listing.rs index 3792b46fa4..ed3f7226db 100644 --- a/packages/mdbook-trpl-listing/src/main.rs +++ b/packages/mdbook-trpl/src/bin/listing.rs @@ -3,20 +3,21 @@ use std::io; use clap::{self, Parser, Subcommand}; use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; -use mdbook_trpl_listing::TrplListing; +use mdbook_trpl::Listing; fn main() -> Result<(), String> { let cli = Cli::parse(); if let Some(Command::Supports { renderer }) = cli.command { - return if TrplListing.supports_renderer(&renderer) { + return if Listing.supports_renderer(&renderer) { Ok(()) } else { Err(format!("Renderer '{renderer}' is unsupported")) }; } - let (ctx, book) = CmdPreprocessor::parse_input(io::stdin()).map_err(|e| format!("{e}"))?; - let processed = TrplListing.run(&ctx, book).map_err(|e| format!("{e}"))?; + let (ctx, book) = CmdPreprocessor::parse_input(io::stdin()) + .map_err(|e| format!("{e}"))?; + let processed = Listing.run(&ctx, book).map_err(|e| format!("{e}"))?; serde_json::to_writer(io::stdout(), &processed).map_err(|e| format!("{e}")) } diff --git a/packages/mdbook-trpl-note/src/main.rs b/packages/mdbook-trpl/src/bin/note.rs similarity index 84% rename from packages/mdbook-trpl-note/src/main.rs rename to packages/mdbook-trpl/src/bin/note.rs index 8649432f82..8af222b8d2 100644 --- a/packages/mdbook-trpl-note/src/main.rs +++ b/packages/mdbook-trpl/src/bin/note.rs @@ -3,11 +3,11 @@ use std::io; use clap::{self, Parser, Subcommand}; use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; -use mdbook_trpl_note::TrplNote; +use mdbook_trpl::Note; fn main() -> Result<(), String> { let cli = Cli::parse(); - let simple_note = TrplNote; + let simple_note = Note; if let Some(Command::Supports { renderer }) = cli.command { return if simple_note.supports_renderer(&renderer) { Ok(()) @@ -16,8 +16,8 @@ fn main() -> Result<(), String> { }; } - let (ctx, book) = - CmdPreprocessor::parse_input(io::stdin()).map_err(|e| format!("blah: {e}"))?; + let (ctx, book) = CmdPreprocessor::parse_input(io::stdin()) + .map_err(|e| format!("blah: {e}"))?; let processed = simple_note.run(&ctx, book).map_err(|e| format!("{e}"))?; serde_json::to_writer(io::stdout(), &processed).map_err(|e| format!("{e}")) } diff --git a/packages/mdbook-trpl/src/config/mod.rs b/packages/mdbook-trpl/src/config/mod.rs new file mode 100644 index 0000000000..1be61e9dba --- /dev/null +++ b/packages/mdbook-trpl/src/config/mod.rs @@ -0,0 +1,71 @@ +//! Get any `preprocessor.trpl-*` config. + +use mdbook::preprocess::PreprocessorContext; + +#[derive(Debug, Clone, Copy)] +pub enum Mode { + Default, + Simple, +} + +impl Mode { + pub fn from_context( + ctx: &PreprocessorContext, + preprocessor_name: &str, + ) -> Result { + let config = ctx + .config + .get_preprocessor(preprocessor_name) + .ok_or_else(|| Error::NoConfig(preprocessor_name.into()))?; + + let key = String::from("output-mode"); + let mode = config + .get(&key) + .map(|value| match value.as_str() { + Some(s) => Mode::try_from(s).map_err(|_| Error::BadValue { + key, + value: value.to_string(), + }), + None => Err(Error::BadValue { + key, + value: value.to_string(), + }), + }) + .transpose()? + .unwrap_or(Mode::Default); + + Ok(mode) + } +} + +/// Trivial marker struct to indicate an internal error. +/// +/// The caller has enough info to do what it needs without passing data around. +pub struct ParseErr; + +impl TryFrom<&str> for Mode { + type Error = ParseErr; + + fn try_from(value: &str) -> Result { + match value { + "default" => Ok(Mode::Default), + "simple" => Ok(Mode::Simple), + _ => Err(ParseErr), + } + } +} + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error(transparent)] + Mdbook(#[from] mdbook::errors::Error), + + #[error("No config for '{0}'")] + NoConfig(String), + + #[error("Bad config value '{value}' for key '{key}'")] + BadValue { key: String, value: String }, +} + +#[cfg(test)] +mod tests; diff --git a/packages/mdbook-trpl-listing/src/tests/config.rs b/packages/mdbook-trpl/src/config/tests.rs similarity index 62% rename from packages/mdbook-trpl-listing/src/tests/config.rs rename to packages/mdbook-trpl/src/config/tests.rs index d44004b3e2..0795595abc 100644 --- a/packages/mdbook-trpl-listing/src/tests/config.rs +++ b/packages/mdbook-trpl/src/config/tests.rs @@ -6,96 +6,118 @@ //! more complex in the future, it would be good to revisit and integrate //! the same kinds of tests as the unit tests above here. -use super::*; +use mdbook::{ + book::Book, + errors::Result, + preprocess::{Preprocessor, PreprocessorContext}, + BookItem, +}; + +use crate::config::Mode; + +/// Dummy preprocessor for testing purposes to exercise config. +struct TestPreprocessor; + +impl Preprocessor for TestPreprocessor { + fn name(&self) -> &str { + "test-preprocessor" + } + + fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result { + let mode = Mode::from_context(ctx, self.name())?; + book.push_item(BookItem::PartTitle(format!("{mode:?}"))); + Ok(book) + } +} -// TODO: what *should* the behavior here be? I *think* it should error, -// in that there is a problem if it is invoked without that info. #[test] fn no_config() { let input_json = r##"[ - { - "root": "/path/to/book", - "config": { - "book": { - "authors": ["AUTHOR"], - "language": "en", - "multilingual": false, - "src": "src", - "title": "TITLE" - }, - "preprocessor": {} - }, - "renderer": "html", - "mdbook_version": "0.4.21" + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" }, + "preprocessor": {} + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ { - "sections": [ - { - "Chapter": { - "name": "Chapter 1", - "content": "# Chapter 1\n", - "number": [1], - "sub_items": [], - "path": "chapter_1.md", - "source_path": "chapter_1.md", - "parent_names": [] - } - } - ], - "__non_exhaustive": null + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } } - ]"##; + ], + "__non_exhaustive": null + } + ]"##; let input_json = input_json.as_bytes(); let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); - let result = TrplListing.run(&ctx, book); + let result = TestPreprocessor.run(&ctx, book); assert!(result.is_err()); let err = result.unwrap_err(); - assert_eq!(format!("{err}"), "No config for trpl-listing"); + assert_eq!(format!("{err}"), "No config for 'test-preprocessor'"); } #[test] fn empty_config() { let input_json = r##"[ - { - "root": "/path/to/book", - "config": { - "book": { - "authors": ["AUTHOR"], - "language": "en", - "multilingual": false, - "src": "src", - "title": "TITLE" - }, - "preprocessor": { - "trpl-listing": {} - } - }, - "renderer": "html", - "mdbook_version": "0.4.21" + { + "root": "/path/to/book", + "config": { + "book": { + "authors": ["AUTHOR"], + "language": "en", + "multilingual": false, + "src": "src", + "title": "TITLE" }, + "preprocessor": { + "test-preprocessor": {} + } + }, + "renderer": "html", + "mdbook_version": "0.4.21" + }, + { + "sections": [ { - "sections": [ - { - "Chapter": { - "name": "Chapter 1", - "content": "# Chapter 1\n", - "number": [1], - "sub_items": [], - "path": "chapter_1.md", - "source_path": "chapter_1.md", - "parent_names": [] - } - } - ], - "__non_exhaustive": null + "Chapter": { + "name": "Chapter 1", + "content": "# Chapter 1\n", + "number": [1], + "sub_items": [], + "path": "chapter_1.md", + "source_path": "chapter_1.md", + "parent_names": [] + } } - ]"##; + ], + "__non_exhaustive": null + } + ]"##; let input_json = input_json.as_bytes(); let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_ok()); + let book = TestPreprocessor.run(&ctx, book).unwrap(); + assert!(book.iter().any( + |item| matches!(item, BookItem::PartTitle(title) if title == &format!("{:?}", Mode::Default)) + )) } #[test] @@ -112,7 +134,7 @@ fn specify_default() { "title": "TITLE" }, "preprocessor": { - "trpl-listing": { + "test-preprocessor": { "output-mode": "default" } } @@ -140,8 +162,10 @@ fn specify_default() { let input_json = input_json.as_bytes(); let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_ok()); + let book = TestPreprocessor.run(&ctx, book).unwrap(); + assert!(book.iter().any( + |item| matches!(item, BookItem::PartTitle(title) if title == &format!("{:?}", Mode::Default)) + )); } #[test] @@ -158,7 +182,7 @@ fn specify_simple() { "title": "TITLE" }, "preprocessor": { - "trpl-listing": { + "test-preprocessor": { "output-mode": "simple" } } @@ -186,8 +210,10 @@ fn specify_simple() { let input_json = input_json.as_bytes(); let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_ok()); + let book = TestPreprocessor.run(&ctx, book).unwrap(); + assert!(book.iter().any( + |item| matches!(item, BookItem::PartTitle(title) if title == &format!("{:?}", Mode::Simple)) + )) } #[test] @@ -204,7 +230,7 @@ fn specify_invalid() { "title": "TITLE" }, "preprocessor": { - "trpl-listing": { + "test-preprocessor": { "output-mode": "nonsense" } } @@ -232,11 +258,9 @@ fn specify_invalid() { let input_json = input_json.as_bytes(); let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap(); - let result = TrplListing.run(&ctx, book); - assert!(result.is_err()); - let err = result.unwrap_err(); + let result = TestPreprocessor.run(&ctx, book).unwrap_err(); assert_eq!( - format!("{err}"), + format!("{result}"), "Bad config value '\"nonsense\"' for key 'output-mode'" ); } diff --git a/packages/mdbook-trpl/src/figure/mod.rs b/packages/mdbook-trpl/src/figure/mod.rs new file mode 100644 index 0000000000..169475f658 --- /dev/null +++ b/packages/mdbook-trpl/src/figure/mod.rs @@ -0,0 +1,252 @@ +use anyhow::{anyhow, Result}; +use html_parser::{Dom, Node}; +use mdbook::{book::Book, preprocess::Preprocessor, BookItem}; + +use pulldown_cmark::Event; +use pulldown_cmark_to_cmark::cmark; + +use crate::config::Mode; + +/// A simple preprocessor to rewrite `
`s with ``s. +/// +/// This is a no-op by default; it only operates on the book chapters when the +/// `[preprocessor.trpl-figure]` has `output-mode = "simple"`. +/// +/// Takes in Markdown containing like this: +/// +/// ```markdown +///
+/// +/// +/// +///
Figure 1-2: A description of the image
+/// +///
+/// ``` +/// +/// Spits out Markdown like this: +/// +/// ```markdown +/// +/// +/// +/// Figure 1-2: A description of the image +/// +/// ``` +pub struct TrplFigure; + +impl TrplFigure { + pub fn supports_renderer(&self, renderer: &str) -> bool { + renderer == "html" || renderer == "markdown" || renderer == "test" + } +} + +impl Preprocessor for TrplFigure { + fn name(&self) -> &str { + "trpl-figure" + } + + fn run( + &self, + ctx: &mdbook::preprocess::PreprocessorContext, + mut book: Book, + ) -> Result { + // The `
`-based output is only replaced in the `Simple` mode. + let Mode::Simple = Mode::from_context(ctx, self.name())? else { + return Ok(book); + }; + + let mut errors = vec![]; + book.for_each_mut(|item| { + if let BookItem::Chapter(ref mut chapter) = item { + match rewrite_figure(&chapter.content) { + Ok(rewritten) => chapter.content = rewritten, + Err(reason) => errors.push(reason), + } + } + }); + + if errors.is_empty() { + Ok(book) + } else { + Err(CompositeError(errors).into()) + } + } +} + +#[derive(Debug, thiserror::Error)] +struct CompositeError(Vec); + +impl std::fmt::Display for CompositeError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Error(s) rewriting input: {}", + self.0.iter().map(|e| format!("{e:?}")).collect::() + ) + } +} + +const OPEN_FIGURE: &'static str = "
"; +const CLOSE_FIGURE: &'static str = "
"; + +const OPEN_CAPTION: &'static str = "
"; +const CLOSE_CAPTION: &'static str = "
"; + +fn rewrite_figure(text: &str) -> Result { + let final_state = crate::parser(text).try_fold( + State { + current: None, + events: Vec::new(), + }, + |mut state, event| { + match (event, &mut state.current) { + // -- Open figure + (Event::Html(tag), None) if tag.starts_with(OPEN_FIGURE) => { + let mut figure = Figure::new(); + figure.events.push(Event::Text("\n".into())); + state.current.replace(figure); + } + + (Event::Html(tag), Some(_)) if tag.starts_with(OPEN_FIGURE) => { + return Err(anyhow!( + "Opening `
` when already in a `
`" + )) + } + + // -- Close figure + (Event::Html(tag), Some(figure)) + if tag.starts_with(CLOSE_FIGURE) => + { + if figure.in_caption { + return Err(anyhow!("Unclosed `
`")); + } + + state.events.append(&mut figure.events); + state.events.push(Event::Text("\n".into())); + let _ = state.current.take(); + } + + (Event::Html(tag), None) if tag.trim() == CLOSE_FIGURE => { + return Err(anyhow!(bad_close(CLOSE_FIGURE, OPEN_CAPTION))); + } + + // -- Start captions + // We do not allow nested captions, but if we have not yet + // started a caption, it is legal to start one, and we + // intentionally ignore that event entirely other than tracking + // that we have started a caption. We will push the body of the + // caption into the figure’s events when we hit them. + // + // Note: this does not support `
`. + (Event::Html(tag), Some(fig)) + if tag.starts_with(OPEN_CAPTION) => + { + if fig.in_caption { + return Err(anyhow!(bad_open(OPEN_CAPTION))); + } else { + if tag.trim().ends_with(CLOSE_CAPTION) { + let text = Dom::parse(tag.as_ref())? + .children + .into_iter() + .filter_map(text_of) + .collect::(); + + if text.is_empty() { + return Err(anyhow!( + "Missing caption in `
`" + )); + } + + fig.events.push(Event::Text(text.into())); + } else { + fig.events.push(Event::Text("\n".into())); + fig.in_caption = true; + } + } + } + + (Event::Html(tag), None) if tag.starts_with(OPEN_CAPTION) => { + return Err(anyhow!(bad_open(OPEN_CAPTION))) + } + + // -- Close captions + (Event::Html(tag), Some(fig)) + if tag.trim() == CLOSE_CAPTION => + { + if fig.in_caption { + fig.events.push(Event::Text("\n".into())); + fig.in_caption = false; + } else { + return Err(anyhow!(bad_close( + CLOSE_CAPTION, + OPEN_CAPTION + ))); + } + } + + (Event::Html(tag), None) if tag.trim() == CLOSE_CAPTION => { + return Err(anyhow!(bad_close(CLOSE_CAPTION, OPEN_FIGURE))); + } + + // Otherwise, if in the body of a figure, push whatever other + // events without modification into the figure state. + (ev, Some(ref mut figure)) => figure.events.push(ev), + + // And if not in a figure, no modifications whatsoever. + (ev, None) => state.events.push(ev), + } + Ok(state) + }, + )?; + + if final_state.current.is_some() { + return Err(anyhow!("Unclosed `
`")); + } + + let mut rewritten = String::new(); + cmark(final_state.events.into_iter(), &mut rewritten)?; + Ok(rewritten) +} + +fn text_of(node: Node) -> Option { + match node { + Node::Text(text) => Some(text), + Node::Element(element) => { + Some(element.children.into_iter().filter_map(text_of).collect()) + } + Node::Comment(_) => None, + } +} + +fn bad_open(tag: &str) -> String { + format!("Opening `<{tag}>` while not in a `
`.") +} + +fn bad_close(close: &str, required_open: &str) -> String { + format!("Closing `<{close}>` while not in a `<{required_open}>`.") +} + +#[derive(Debug)] +struct State<'e> { + current: Option>, + events: Vec>, +} + +#[derive(Debug)] +struct Figure<'e> { + events: Vec>, + in_caption: bool, +} + +impl<'e> Figure<'e> { + fn new() -> Figure<'e> { + Figure { + events: vec![], + in_caption: false, + } + } +} + +#[cfg(test)] +mod tests; diff --git a/packages/mdbook-trpl/src/figure/tests.rs b/packages/mdbook-trpl/src/figure/tests.rs new file mode 100644 index 0000000000..d99eb6d43e --- /dev/null +++ b/packages/mdbook-trpl/src/figure/tests.rs @@ -0,0 +1,60 @@ +use super::*; + +#[test] +fn text_without_figures_is_ignored() { + let actual = rewrite_figure("This is some basic text.").unwrap(); + assert_eq!(actual, "This is some basic text."); +} + +#[test] +fn text_with_figure_replaces_it_with_simple_text() { + let actual = rewrite_figure( + r#"
+ + + +
Figure 12-34: Look at this cool picture!
+ +
"#, + ) + .unwrap(); + + let expected = r#" + + + +Figure 12-34: Look at this cool picture! + +"#; + + assert_eq!(actual, expected); +} + +#[test] +fn unclosed_figure() { + let result = rewrite_figure("
"); + let actual = format!("{:?}", result.unwrap_err()); + assert_eq!(actual, "Unclosed `
`"); +} + +#[test] +fn empty_caption() { + let result = rewrite_figure( + "
+
+
", + ); + let actual = format!("{:?}", result.unwrap_err()); + assert_eq!(actual, "Missing caption in `
`"); +} + +#[test] +fn unclosed_caption() { + let result = rewrite_figure( + "
+
+
", + ); + let actual = format!("{:?}", result.unwrap_err()); + assert_eq!(actual, "Unclosed `
`"); +} diff --git a/packages/mdbook-trpl/src/lib.rs b/packages/mdbook-trpl/src/lib.rs new file mode 100644 index 0000000000..04e446eba2 --- /dev/null +++ b/packages/mdbook-trpl/src/lib.rs @@ -0,0 +1,35 @@ +mod config; +mod figure; +mod listing; +mod note; + +pub use config::Mode; +pub use figure::TrplFigure as Figure; +pub use listing::TrplListing as Listing; +pub use note::TrplNote as Note; +use pulldown_cmark::{Options, Parser}; + +/// Convenience function to get a parser matching `mdbook::new_cmark_parser`. +/// +/// This is implemented separately so we are decoupled from mdbook's dependency +/// versions and can update at will (albeit with care to stay aligned with what +/// mdbook does!) to later versions of `pulldown-cmark` and related tools. +/// +/// Notes: +/// +/// - `mdbook::new_cmark_parser` has an additional parameter which allows smart +/// punctuation to be enabled or disabled; we always enable it. +/// - We do not use footnotes in the text at present, but this goes out of its +/// way to match this up to the old footnotes behavior just to make sure the +/// parsing etc. is all the same. +pub fn parser(text: &str) -> Parser<'_> { + let mut opts = Options::empty(); + opts.insert(Options::ENABLE_TABLES); + opts.insert(Options::ENABLE_FOOTNOTES); + opts.insert(Options::ENABLE_OLD_FOOTNOTES); + opts.insert(Options::ENABLE_STRIKETHROUGH); + opts.insert(Options::ENABLE_TASKLISTS); + opts.insert(Options::ENABLE_HEADING_ATTRIBUTES); + opts.insert(Options::ENABLE_SMART_PUNCTUATION); + Parser::new_ext(text, opts) +} diff --git a/packages/mdbook-trpl-listing/src/lib.rs b/packages/mdbook-trpl/src/listing/mod.rs similarity index 56% rename from packages/mdbook-trpl-listing/src/lib.rs rename to packages/mdbook-trpl/src/listing/mod.rs index c4ff14e447..b118234494 100644 --- a/packages/mdbook-trpl-listing/src/lib.rs +++ b/packages/mdbook-trpl/src/listing/mod.rs @@ -3,12 +3,13 @@ use mdbook::{ book::Book, errors::Result, preprocess::{Preprocessor, PreprocessorContext}, - utils::new_cmark_parser, BookItem, }; use pulldown_cmark::{html, Event}; use pulldown_cmark_to_cmark::cmark; +use crate::config::Mode; + /// A preprocessor for rendering listings more elegantly. /// /// Given input like this: @@ -59,28 +60,9 @@ impl Preprocessor for TrplListing { } fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result { - let config = ctx - .config - .get_preprocessor(self.name()) - .ok_or(Error::NoConfig)?; - - let key = String::from("output-mode"); - let mode = config - .get(&key) - .map(|value| match value.as_str() { - Some(s) => Mode::try_from(s).map_err(|_| Error::BadValue { - key, - value: value.to_string(), - }), - None => Err(Error::BadValue { - key, - value: value.to_string(), - }), - }) - .transpose()? - .unwrap_or(Mode::Default); + let mode = Mode::from_context(ctx, self.name())?; - let mut errors: Vec = vec![]; + let mut errors = vec![]; book.for_each_mut(|item| { if let BookItem::Chapter(ref mut chapter) = item { match rewrite_listing(&chapter.content, mode) { @@ -102,153 +84,114 @@ impl Preprocessor for TrplListing { } } -#[derive(Debug, thiserror::Error)] -enum Error { - #[error("No config for trpl-listing")] - NoConfig, - - #[error("Bad config value '{value}' for key '{key}'")] - BadValue { key: String, value: String }, -} - #[derive(Debug, thiserror::Error)] #[error("Error(s) rewriting input: {0}")] struct CompositeError(String); -#[derive(Debug, Clone, Copy)] -enum Mode { - Default, - Simple, -} +fn rewrite_listing(src: &str, mode: Mode) -> Result { + match mode { + Mode::Default => { + let final_state = crate::parser(src).try_fold( + RewriteState { + current: None, + events: vec![], + }, + |mut state, ev| { + match ev { + Event::Html(tag) => { + if tag.starts_with("") { + state.close_listing(tag); + } else { + state.events.push(Ok(Event::Html(tag))); + } + } + ev => state.events.push(Ok(ev)), + }; + Ok::, String>(state) + }, + )?; + + if final_state.current.is_some() { + return Err("Unclosed listing".into()); + } -/// Trivial marker struct to indicate an internal error. -/// -/// The caller has enough info to do what it needs without passing data around. -struct ParseErr; + let (events, errors): (Vec<_>, Vec<_>) = + final_state.events.into_iter().partition(|e| e.is_ok()); + + if !errors.is_empty() { + return Err(errors + .into_iter() + .map(|e| e.unwrap_err()) + .collect::>() + .join("\n")); + } -impl TryFrom<&str> for Mode { - type Error = ParseErr; + let mut buf = String::with_capacity(src.len() * 2); + cmark(events.into_iter().map(|ok| ok.unwrap()), &mut buf) + .map_err(|e| format!("{e}"))?; - fn try_from(value: &str) -> std::prelude::v1::Result { - match value { - "default" => Ok(Mode::Default), - "simple" => Ok(Mode::Simple), - _ => Err(ParseErr), + Ok(buf) } - } -} - -fn rewrite_listing(src: &str, mode: Mode) -> Result { - let final_state = new_cmark_parser(src, true).try_fold( - ListingState { - current: None, - events: vec![], - }, - |mut state, ev| { - match ev { - Event::Html(tag) => { - if tag.starts_with("") { - state.close_listing(tag, mode); - } else { - state.events.push(Ok(Event::Html(tag))); - } + Mode::Simple => { + // The output text should be very slightly *shorter* than the input, + // so we know this is a reasonable size for the buffer. + let mut rewritten = String::with_capacity(src.len()); + let mut current_closing = None; + for line in src.lines() { + if line.starts_with("")) { + let listing = + ListingBuilder::from_tag(&line)?.build(Mode::Simple); + rewritten.push_str(&listing.opening_text()); + current_closing = Some(listing.closing_text("\n")); + } else if line == "
" { + let closing = + current_closing.as_ref().ok_or_else(|| { + String::from( + "Closing `
` without opening tag.", + ) + })?; + rewritten.push_str(closing); + } else { + rewritten.push_str(line); + rewritten.push('\n'); } - ev => state.events.push(Ok(ev)), - }; - Ok::, String>(state) - }, - )?; - - if final_state.current.is_some() { - return Err("Unclosed listing".into()); - } + } - let (events, errors): (Vec<_>, Vec<_>) = - final_state.events.into_iter().partition(|e| e.is_ok()); + // Since we always push a `'\n'` onto the end of the new string and + // `.lines()` does not tell us whether there *was* such a character, + // this makes the output match the input, and thus avoids adding new + // newlines after conversion. + if !src.ends_with('\n') { + rewritten.pop(); + } - if !errors.is_empty() { - return Err(errors - .into_iter() - .map(|e| e.unwrap_err()) - .collect::>() - .join("\n")); + Ok(rewritten) + } } - - let mut buf = String::with_capacity(src.len() * 2); - cmark(events.into_iter().map(|ok| ok.unwrap()), &mut buf) - .map_err(|e| format!("{e}"))?; - Ok(buf) } -struct ListingState<'e> { +struct RewriteState<'e> { current: Option, events: Vec, String>>, } -impl<'e> ListingState<'e> { +impl<'e> RewriteState<'e> { fn open_listing( &mut self, tag: pulldown_cmark::CowStr<'_>, mode: Mode, ) -> Result<(), String> { - // We do not *keep* the version constructed here, just temporarily - // construct it so the HTML parser, which expects properly closed tags - // to parse it as a *tag* rather than a *weird text node*, will accept - // it and provide a useful view of it. - let to_parse = tag.to_owned().to_string() + ""; - let listing = Dom::parse(&to_parse) - .map_err(|e| e.to_string())? - .children - .into_iter() - .filter_map(|node| match node { - html_parser::Node::Element(element) => Some(element.attributes), - html_parser::Node::Text(_) | html_parser::Node::Comment(_) => { - None - } - }) - .flatten() - .try_fold(ListingBuilder::new(), |builder, (key, maybe_value)| { - match (key.as_str(), maybe_value) { - ("number", Some(value)) => Ok(builder.with_number(value)), - - ("caption", Some(value)) => Ok(builder.with_caption(value)), - - ("file-name", Some(value)) => { - Ok(builder.with_file_name(value)) - } - - (attr @ "file-name", None) - | (attr @ "caption", None) - | (attr @ "number", None) => { - Err(format!("Missing value for attribute: '{attr}'")) - } - - (attr, _) => { - Err(format!("Unsupported attribute name: '{attr}'")) - } - } - })? - .build(); - - let opening_event = match mode { - Mode::Default => { - let opening_html = listing.opening_html(); - Event::Html(opening_html.into()) - } - Mode::Simple => { - let opening_text = listing.opening_text(); - Event::Text(opening_text.into()) - } - }; + let listing = ListingBuilder::from_tag(&tag)?.build(mode); + let opening_event = Event::Html(listing.opening_html().into()); self.current = Some(listing); self.events.push(Ok(opening_event)); Ok(()) } - fn close_listing(&mut self, tag: pulldown_cmark::CowStr<'_>, mode: Mode) { + fn close_listing(&mut self, tag: pulldown_cmark::CowStr<'_>) { let trailing = if !tag.ends_with('>') { tag.replace("
", "") } else { @@ -257,16 +200,8 @@ impl<'e> ListingState<'e> { match &self.current { Some(listing) => { - let closing_event = match mode { - Mode::Default => { - let closing_html = listing.closing_html(&trailing); - Event::Html(closing_html.into()) - } - Mode::Simple => { - let closing_text = listing.closing_text(&trailing); - Event::Text(closing_text.into()) - } - }; + let closing_event = + Event::Html(listing.closing_html(&trailing).into()); self.current = None; self.events.push(Ok(closing_event)); @@ -320,7 +255,7 @@ impl Listing { fn opening_text(&self) -> String { self.file_name .as_ref() - .map(|file_name| format!("\nFilename: {file_name}\n")) + .map(|file_name| format!("Filename: {file_name}\n")) .unwrap_or_default() } @@ -336,6 +271,9 @@ impl Listing { } } +/// Note: Although this has the same structure as [`Listing`], it does not have +/// the same *semantics*. In particular, this has the *source* for the `caption` +/// while `Listing` has the *rendered* version. struct ListingBuilder { number: Option, caption: Option, @@ -343,12 +281,46 @@ struct ListingBuilder { } impl ListingBuilder { - fn new() -> ListingBuilder { - ListingBuilder { - number: None, - caption: None, - file_name: None, - } + fn from_tag(tag: &str) -> Result { + let to_parse = format!("{tag}
"); + Dom::parse(&to_parse) + .map_err(|e| e.to_string())? + .children + .into_iter() + .filter_map(|node| match node { + html_parser::Node::Element(element) => Some(element.attributes), + html_parser::Node::Text(_) | html_parser::Node::Comment(_) => { + None + } + }) + .flatten() + .try_fold( + ListingBuilder { + number: None, + caption: None, + file_name: None, + }, + |builder, (key, maybe_value)| match (key.as_str(), maybe_value) + { + ("number", Some(value)) => Ok(builder.with_number(value)), + + ("caption", Some(value)) => Ok(builder.with_caption(value)), + + ("file-name", Some(value)) => { + Ok(builder.with_file_name(value)) + } + + (attr @ "file-name", None) + | (attr @ "caption", None) + | (attr @ "number", None) => { + Err(format!("Missing value for attribute: '{attr}'")) + } + + (attr, _) => { + Err(format!("Unsupported attribute name: '{attr}'")) + } + }, + ) } fn with_number(mut self, value: String) -> Self { @@ -366,17 +338,20 @@ impl ListingBuilder { self } - fn build(self) -> Listing { - let caption = self.caption.map(|caption_source| { - let events = new_cmark_parser(&caption_source, true); - let mut buf = String::with_capacity(caption_source.len() * 2); - html::push_html(&mut buf, events); - - // This is not particularly principled, but since the only - // place it is used is here, for caption source handling, it - // is “fine”. - buf.replace("

", "").replace("

", "").replace('\n', "") - }); + fn build(self, mode: Mode) -> Listing { + let caption = match mode { + Mode::Default => self.caption.map(|caption_source| { + let events = crate::parser(&caption_source); + let mut buf = String::with_capacity(caption_source.len() * 2); + html::push_html(&mut buf, events); + + // This is not particularly principled, but since the only + // place it is used is here, for caption source handling, it + // is “fine”. + buf.replace("

", "").replace("

", "").replace('\n', "") + }), + Mode::Simple => self.caption, + }; Listing { number: self.number.map(String::from), diff --git a/packages/mdbook-trpl-listing/src/tests/mod.rs b/packages/mdbook-trpl/src/listing/tests.rs similarity index 93% rename from packages/mdbook-trpl-listing/src/tests/mod.rs rename to packages/mdbook-trpl/src/listing/tests.rs index 224b14fe50..4efb24748d 100644 --- a/packages/mdbook-trpl-listing/src/tests/mod.rs +++ b/packages/mdbook-trpl/src/listing/tests.rs @@ -33,26 +33,33 @@ fn main() {} #[test] fn simple_mode_works() { let result = rewrite_listing( - r#"+ r#"Leading text. + + ```rust fn main() {} ``` -"#, + + +Trailing text."#, Mode::Simple, ); assert_eq!( &result.unwrap(), - r#" + r#"Leading text. + Filename: src/main.rs -````rust +```rust fn main() {} -```` +``` -Listing 1-2: A write-up which might include inline Markdown like code etc."# +Listing 1-2: A write-up which *might* include inline Markdown like `code` etc. + +Trailing text."# ); } @@ -287,9 +294,3 @@ fn main() {} ) } } - -#[test] -fn missing_value() {} - -#[cfg(test)] -mod config; diff --git a/packages/mdbook-trpl/src/note/mod.rs b/packages/mdbook-trpl/src/note/mod.rs new file mode 100644 index 0000000000..12528a1f2e --- /dev/null +++ b/packages/mdbook-trpl/src/note/mod.rs @@ -0,0 +1,145 @@ +use mdbook::{ + book::Book, + errors::Result, + preprocess::{Preprocessor, PreprocessorContext}, + BookItem, +}; +use pulldown_cmark::{ + Event::{self, *}, + Tag, TagEnd, +}; +use pulldown_cmark_to_cmark::cmark; + +/// A simple preprocessor for semantic notes in _The Rust Programming Language_. +/// +/// Takes in Markdown like this: +/// +/// ```markdown +/// > Note: This is a note. +/// ``` +/// +/// Spits out Markdown like this: +/// +/// ```markdown +///
+/// +/// This is a note. +/// +///
+/// ``` +pub struct TrplNote; + +impl Preprocessor for TrplNote { + fn name(&self) -> &str { + "simple-note-preprocessor" + } + + fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result { + book.for_each_mut(|item| { + if let BookItem::Chapter(ref mut chapter) = item { + chapter.content = rewrite(&chapter.content); + } + }); + Ok(book) + } + + fn supports_renderer(&self, renderer: &str) -> bool { + renderer == "html" || renderer == "markdown" || renderer == "test" + } +} + +pub fn rewrite(text: &str) -> String { + let parser = crate::parser(text); + + let mut events = Vec::new(); + let mut state = Default; + + for event in parser { + match (&mut state, event) { + (Default, Start(Tag::BlockQuote(_))) => { + state = StartingBlockquote(vec![Start(Tag::BlockQuote(None))]); + } + + (StartingBlockquote(blockquote_events), Text(content)) => { + if content.starts_with("Note: ") { + // This needs the "extra" `SoftBreak`s so that when the final rendering pass + // happens, it does not end up treating the internal content as inline *or* + // treating the HTML tags as inline tags: + // + // - Content inside HTML blocks is only rendered as Markdown when it is + // separated from the block HTML elements: otherwise it gets treated as inline + // HTML and *not* rendered. + // - Along the same lines, an HTML tag that happens to be directly adjacent to + // the end of a previous Markdown block will end up being rendered as part of + // that block. + events.extend([ + SoftBreak, + SoftBreak, + Html( + r#"
"#.into(), + ), + SoftBreak, + SoftBreak, + Start(Tag::Paragraph), + Text(content), + ]); + state = InNote; + } else { + events.append(blockquote_events); + events.push(Text(content)); + state = Default; + } + } + + ( + StartingBlockquote(_blockquote_events), + heading @ Start(Tag::Heading { .. }), + ) => { + events.extend([ + SoftBreak, + SoftBreak, + Html(r#"
"#.into()), + SoftBreak, + SoftBreak, + heading, + ]); + state = InNote; + } + + (StartingBlockquote(ref mut events), Start(tag)) => { + events.push(Start(tag)); + } + + (InNote, End(TagEnd::BlockQuote(_))) => { + // As with the start of the block HTML, the closing HTML must be + // separated from the Markdown text by two newlines. + events.extend([ + SoftBreak, + SoftBreak, + Html("
".into()), + ]); + state = Default; + } + + (_, event) => { + events.push(event); + } + } + } + + let mut buf = String::new(); + cmark(events.into_iter(), &mut buf).unwrap(); + buf +} + +use State::*; + +#[derive(Debug)] +enum State<'e> { + Default, + StartingBlockquote(Vec>), + InNote, +} + +#[cfg(test)] +mod tests; diff --git a/packages/mdbook-trpl/src/note/tests.rs b/packages/mdbook-trpl/src/note/tests.rs new file mode 100644 index 0000000000..c67d2ec9dc --- /dev/null +++ b/packages/mdbook-trpl/src/note/tests.rs @@ -0,0 +1,195 @@ +use super::*; + +#[test] +fn no_note() { + let text = "Hello, world.\n\nThis is some text."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "

Hello, world.

\n

This is some text.

\n" + ); +} + +#[test] +fn with_note() { + let text = "> Note: This is some text.\n> It keeps going."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Note: This is some text.\nIt keeps going.

\n
" + ); +} + +#[test] +fn regular_blockquote() { + let text = "> This is some text.\n> It keeps going."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

This is some text.\nIt keeps going.

\n
\n" + ); +} + +#[test] +fn combined() { + let text = "> Note: This is some text.\n> It keeps going.\n\nThis is regular text.\n\n> This is a blockquote.\n"; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Note: This is some text.\nIt keeps going.

\n
\n

This is regular text.

\n
\n

This is a blockquote.

\n
\n" + ); +} + +#[test] +fn blockquote_then_note() { + let text = "> This is quoted.\n\n> Note: This is noted."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

This is quoted.

\n
\n
\n

Note: This is noted.

\n
" + ); +} + +#[test] +fn note_then_blockquote() { + let text = "> Note: This is noted.\n\n> This is quoted."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Note: This is noted.

\n
\n
\n

This is quoted.

\n
\n" + ); +} + +#[test] +fn with_h1_note() { + let text = "> # Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
" + ); +} + +#[test] +fn with_h2_note() { + let text = "> ## Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
" + ); +} + +#[test] +fn with_h3_note() { + let text = "> ### Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
" + ); +} + +#[test] +fn with_h4_note() { + let text = "> #### Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
" + ); +} + +#[test] +fn with_h5_note() { + let text = "> ##### Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n
Header
\n

And then some note content.

\n
" + ); +} + +#[test] +fn with_h6_note() { + let text = "> ###### Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n
Header
\n

And then some note content.

\n
" + ); +} + +#[test] +fn h1_then_blockquote() { + let text = + "> # Header\n > And then some note content.\n\n> This is quoted."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Header

\n

And then some note content.

\n
\n
\n

This is quoted.

\n
\n" + ); +} + +#[test] +fn blockquote_then_h1_note() { + let text = + "> This is quoted.\n\n> # Header\n > And then some note content."; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

This is quoted.

\n
\n
\n

Header

\n

And then some note content.

\n
" + ); +} + +#[test] +fn blockquote_with_strong() { + let text = "> **Bold text in a paragraph.**"; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

Bold text in a paragraph.

\n
\n" + ); +} + +#[test] +fn normal_table() { + let text = "| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; + let processed = rewrite(text); + + assert_eq!( + processed, + "|Header 1|Header 2|\n|--------|--------|\n|Text 123|More 456|", + "It strips some whitespace but otherwise leaves the table intact." + ); +} + +#[test] +fn table_in_note() { + let text = "> Note: table stuff.\n\n| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; + let processed = rewrite(text); + + assert_eq!( + processed, + "\n\n
\n\nNote: table stuff.\n\n
\n\n|Header 1|Header 2|\n|--------|--------|\n|Text 123|More 456|", + "It adds the note markup but leaves the table untouched, to be rendered as Markdown." + ); +} + +#[test] +fn table_in_quote() { + let text = "> A table.\n\n| Header 1 | Header 2 |\n| -------- | -------- |\n| Text 123 | More 456 |"; + let processed = rewrite(text); + assert_eq!( + render_markdown(&processed), + "
\n

A table.

\n
\n\n\n
Header 1Header 2
Text 123More 456
\n", + "It renders blockquotes with nested tables as expected." + ); +} + +fn render_markdown(text: &str) -> String { + let parser = crate::parser(text); + let mut buf = String::new(); + pulldown_cmark::html::push_html(&mut buf, parser); + buf +} diff --git a/packages/mdbook-trpl/tests/integration/main.rs b/packages/mdbook-trpl/tests/integration/main.rs new file mode 100644 index 0000000000..bc081a1204 --- /dev/null +++ b/packages/mdbook-trpl/tests/integration/main.rs @@ -0,0 +1,20 @@ +mod note { + use assert_cmd::Command; + #[test] + fn supports_html_renderer() { + let cmd = Command::cargo_bin("mdbook-trpl-note") + .unwrap() + .args(["supports", "html"]) + .ok(); + assert!(cmd.is_ok()); + } + + #[test] + fn errors_for_other_renderers() { + let cmd = Command::cargo_bin("mdbook-trpl-note") + .unwrap() + .args(["supports", "total-nonsense"]) + .ok(); + assert!(cmd.is_err()); + } +} diff --git a/tools/nostarch.sh b/tools/nostarch.sh index a9dd12d4d3..086b8545b9 100755 --- a/tools/nostarch.sh +++ b/tools/nostarch.sh @@ -4,13 +4,7 @@ set -eu cargo build --release -cd packages/mdbook-trpl-listing -cargo install --locked --path . - -cd ../mdbook-trpl-note -cargo install --locked --path . - -cd ../.. +cargo install --locked --path ./packages/mdbook_trpl mkdir -p tmp rm -rf tmp/*.md From 901627b9b42cca44ad8f254b8dec07f7f57f4e4f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 8 Nov 2024 12:07:36 -0700 Subject: [PATCH 707/720] infra: use anyhow for error reporting mdbook already does this, and anyhow has nice error reporting. From 902612b6d24b24b1763e621dab2fcbd3b0409bc9 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 8 Nov 2024 12:07:36 -0700 Subject: [PATCH 708/720] infra: create mdbook-trpl-figure preprocessor Building on the shared infra from `mdbook_trpl`, this preprocessor takes nicely accessible and semantic HTML input like this:
Figure 12-34: An illustration of something
It produces output like this: Figure 12-34: An illustration of something This matches what we need for the nostarch output. Accordingly, wire up the `nostarch/book.toml` to use this. There is no need to worry about ordering of the two preprocessors, because in `Simple` mode the listing preprocessor emits plain text output for listings (much as this does for figures). --- nostarch/book.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nostarch/book.toml b/nostarch/book.toml index 4886d0ae8e..169a02be0f 100644 --- a/nostarch/book.toml +++ b/nostarch/book.toml @@ -14,5 +14,10 @@ build-dir = "../tmp" [preprocessor.trpl-listing] output-mode = "simple" +# Only used in this version, *not* in the root `book.toml`, because its job is +# to remove `
` and `
` markup from the version we send them. +[preprocessor.trpl-figure] +output-mode = "simple" + [rust] edition = "2021" From 7dafbb65072792d32f3d5696213453f780438195 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 8 Nov 2024 08:57:41 -0700 Subject: [PATCH 709/720] infra: decouple preprocessors from current mdbook version Instead of using `mdbook:new_cmark_parser`, provide our own utility function which does the same thing. This allows us to preprocess the text using versions of `pulldown-cmark` and `pulldown-cmark-to-cmark` different from those used by `mdbook` itself so long as we take care that the configuration continues to match. From 2e8392d29709e00fe42010440a54b3543c12669f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 22 Jul 2024 07:39:12 -0600 Subject: [PATCH 710/720] infra: update dependencies for mdbook preprocessors This (in principle) lets us get better support for round-tripping and therefore less hoop-jumping to get the desired Markdown output after preprocessing some text. This intentionally keeps the rendering the same as it was on previous versions. From 1882cfbb1290ea4dd51bbc5f35bfd699f6a3d773 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 12 Nov 2024 17:04:04 -0700 Subject: [PATCH 711/720] infra: remove extra leading `>` in simple preprocessor output Preprocessors using `pulldown-cmark-to-cmark` do not yet perform round trips 100% correctly, and insert leading spaces and an extra initial `>` for block quotes, so strip those. Once that is fixed upstream, this will become a no-op, and can be removed then. --- packages/tools/Cargo.toml | 5 + packages/tools/src/bin/cleanup_blockquotes.rs | 147 ++++++++++++++++++ tools/nostarch.sh | 9 +- 3 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 packages/tools/src/bin/cleanup_blockquotes.rs diff --git a/packages/tools/Cargo.toml b/packages/tools/Cargo.toml index 95dda7a18b..a24a8d74e5 100644 --- a/packages/tools/Cargo.toml +++ b/packages/tools/Cargo.toml @@ -36,6 +36,11 @@ path = "src/bin/remove_links.rs" name = "remove_markup" path = "src/bin/remove_markup.rs" +[[bin]] +name = "cleanup_blockquotes" +path = "src/bin/cleanup_blockquotes.rs" + + [dependencies] walkdir = { workspace = true } docopt = { workspace = true } diff --git a/packages/tools/src/bin/cleanup_blockquotes.rs b/packages/tools/src/bin/cleanup_blockquotes.rs new file mode 100644 index 0000000000..41c31b653c --- /dev/null +++ b/packages/tools/src/bin/cleanup_blockquotes.rs @@ -0,0 +1,147 @@ +//! Fix incorrect round-tripping of block quotes in `pulldown-cmark-to-cmark`: +//! +//! - Eliminate extraneous leading `>` +//! - Eliminate extraneous indent. +//! +//! Note: later versions of `pulldown-cmark-to-cmark` will likely fix this, so +//! check when upgrading it if it is still necessary! + +use std::io::{self, Read}; + +use lazy_static::lazy_static; +use regex::Regex; + +fn main() { + let input = { + let mut buffer = String::new(); + io::stdin() + .read_to_string(&mut buffer) + .unwrap_or_else(|e| panic!("{e}")); + buffer + }; + + let fixed = cleanup_blockquotes(input); + print!("{fixed}"); +} + +fn cleanup_blockquotes(input: String) -> String { + let normal_start = EXTRA_SPACE.replace_all(&input, ">"); + let sans_empty_leading = EMPTY_LEADING.replace_all(&normal_start, "\n\n"); + sans_empty_leading.to_string() +} + +lazy_static! { + static ref EXTRA_SPACE: Regex = Regex::new("(?m)^ >").unwrap(); + static ref EMPTY_LEADING: Regex = Regex::new("\n\n> ?\n").unwrap(); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn extra_space() { + let input = " > Hello".to_string(); + let actual = cleanup_blockquotes(input); + assert_eq!(actual, "> Hello"); + } + + #[test] + fn empty_leading() { + let input = "\n\n>\n> Hello".into(); + let actual = cleanup_blockquotes(input); + assert_eq!(actual, "\n\n> Hello"); + } + + #[test] + fn leading_after_extra_space_cleaned_up() { + let input = r#"Start + +> +> Note: Hey. + +Wrap."# + .into(); + + let actual = cleanup_blockquotes(input); + assert_eq!( + actual, + r#"Start + +> Note: Hey. + +Wrap."# + ); + } + + /// This particular input was the result of running any of the mdbook + /// preprocessors which use `pulldown-cmark-to-cmark@<=18.0.0`. + #[test] + fn regression_ch17_example() { + // This is an example of the original motivating input which we are fixing. + let input = r#" +We have to explicitly await both of these futures, because futures in Rust are +*lazy*: they don’t do anything until you ask them to with `await`. (In fact, +Rust will show a compiler warning if you don’t use a future.) This should +remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. +Iterators do nothing unless you call their `next` method—whether directly, or +using `for` loops or methods such as `map` which use `next` under the hood. With +futures, the same basic idea applies: they do nothing unless you explicitly ask +them to. This laziness allows Rust to avoid running async code until it’s +actually needed. + + > + > Note: This is different from the behavior we saw when using `thread::spawn` in + > the previous chapter, where the closure we passed to another thread started + > running immediately. It’s also different from how many other languages + > approach async! But it’s important for Rust. We’ll see why that is later. + +Once we have `response_text`, we can then parse it into an instance of the +`Html` type using `Html::parse`. Instead of a raw string, we now have a data +type we can use to work with the HTML as a richer data structure. In particular, +we can use the `select_first` method to find the first instance of a given CSS +selector. By passing the string `"title"`, we’ll get the first `` +element in the document, if there is one. Because there may not be any matching +element, `select_first` returns an `Option<ElementRef>`. Finally, we use the +`Option::map` method, which lets us work with the item in the `Option` if it’s +present, and do nothing if it isn’t. (We could also use a `match` expression +here, but `map` is more idiomatic.) In the body of the function we supply to +`map`, we call `inner_html` on the `title_element` to get its content, which is +a `String`. When all is said and done, we have an `Option<String>`. +"#.to_string(); + + let actual = cleanup_blockquotes(input); + assert_eq!( + actual, + r#" +We have to explicitly await both of these futures, because futures in Rust are +*lazy*: they don’t do anything until you ask them to with `await`. (In fact, +Rust will show a compiler warning if you don’t use a future.) This should +remind you of our discussion of iterators [back in Chapter 13][iterators-lazy]. +Iterators do nothing unless you call their `next` method—whether directly, or +using `for` loops or methods such as `map` which use `next` under the hood. With +futures, the same basic idea applies: they do nothing unless you explicitly ask +them to. This laziness allows Rust to avoid running async code until it’s +actually needed. + +> Note: This is different from the behavior we saw when using `thread::spawn` in +> the previous chapter, where the closure we passed to another thread started +> running immediately. It’s also different from how many other languages +> approach async! But it’s important for Rust. We’ll see why that is later. + +Once we have `response_text`, we can then parse it into an instance of the +`Html` type using `Html::parse`. Instead of a raw string, we now have a data +type we can use to work with the HTML as a richer data structure. In particular, +we can use the `select_first` method to find the first instance of a given CSS +selector. By passing the string `"title"`, we’ll get the first `<title>` +element in the document, if there is one. Because there may not be any matching +element, `select_first` returns an `Option<ElementRef>`. Finally, we use the +`Option::map` method, which lets us work with the item in the `Option` if it’s +present, and do nothing if it isn’t. (We could also use a `match` expression +here, but `map` is more idiomatic.) In the body of the function we supply to +`map`, we call `inner_html` on the `title_element` to get its content, which is +a `String`. When all is said and done, we have an `Option<String>`. +"# + ); + } +} diff --git a/tools/nostarch.sh b/tools/nostarch.sh index 086b8545b9..9123c7f29d 100755 --- a/tools/nostarch.sh +++ b/tools/nostarch.sh @@ -4,7 +4,7 @@ set -eu cargo build --release -cargo install --locked --path ./packages/mdbook_trpl +cargo install --locked --path ./packages/mdbook_trpl --offline mkdir -p tmp rm -rf tmp/*.md @@ -14,7 +14,9 @@ rm -rf tmp/markdown MDBOOK_OUTPUT__MARKDOWN=1 mdbook build nostarch # Get all the Markdown files -find tmp/markdown -name "${1:-\"\"}*.md" -print0 | \ +# TODO: what was this doing and why?!? +# find tmp/markdown -name "${1:-\"\"}*.md" -print0 | \ +find tmp/markdown -name "*.md" -print0 | \ # Extract just the filename so we can reuse it easily. xargs -0 basename | \ # Remove all links followed by `<!-- ignore -->``, then @@ -23,7 +25,8 @@ while IFS= read -r filename; do < "tmp/markdown/$filename" ./target/release/remove_links \ | ./target/release/link2print \ | ./target/release/remove_markup \ - | ./target/release/remove_hidden_lines > "tmp/$filename" + | ./target/release/remove_hidden_lines \ + | ./target/release/cleanup_blockquotes > "tmp/$filename" done # Concatenate the files into the `nostarch` dir. ./target/release/concat_chapters tmp nostarch From a523b611e95a43015790c9f284e58933c2d0fe7f Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Tue, 12 Nov 2024 17:04:04 -0700 Subject: [PATCH 712/720] infra: fix output for `simple` mode preprocessors Stop using the `pulldown-cmark` parser to rewrite the listings. Instead, find the tags and parse them with the DOM parser, and then rewrite the lines of the string directly. From 7435e9f4871f11339042b040810cc2ff1dc14242 Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Wed, 20 Nov 2024 17:03:26 -0700 Subject: [PATCH 713/720] infra: use new version of pulldown-cmark-to-cmark This fixes escaping of `|` in a table. Bonus trivia: comment formatting in the Cargo.toml for `mdbook_trpl`. From ec5b76b8b0e7b02349dc8e095be095ccbc1b5d95 Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Thu, 5 Dec 2024 12:27:08 -0700 Subject: [PATCH 714/720] tools: fix nostarch build reference to mdbook-trpl Note that this is not urgent to land upstream because the script in question is one only we run. --- tools/nostarch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/nostarch.sh b/tools/nostarch.sh index 9123c7f29d..f209b306dd 100755 --- a/tools/nostarch.sh +++ b/tools/nostarch.sh @@ -4,7 +4,7 @@ set -eu cargo build --release -cargo install --locked --path ./packages/mdbook_trpl --offline +cargo install --locked --path ./packages/mdbook-trpl --offline mkdir -p tmp rm -rf tmp/*.md From 18ef30b08799fdb3e30eef29ae725f41bc1699ac Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Thu, 5 Dec 2024 13:57:02 -0700 Subject: [PATCH 715/720] Document use of rustfmt and dprint for formatting --- CONTRIBUTING.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bba1a19a22..68a2dc0c28 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,35 @@ of the print version. The snapshot files reflect what has been sent or not, so they only get updated when edits are sent to No Starch. **Do not submit pull requests changing files in the `nostarch` directory, they will be closed.** +We use [`rustfmt`][rustfmt] to apply standard formatting to Rust code in the +repo and [`dprint`][dprint] to apply standing formatting to the Markdown source +and the non-Rust code in the project. + +[rustfmt]: https://github.com/rust-lang/rustfmt +[dprint]: https://dprint.dev + +You will normally have `rustfmt` installed if you have a Rust toolchain +installed; if for some reason you do not have a copy of `rustfmt`, you can add +it by running the following command: + +```sh +rustup component add rustfmt +``` + +To install `dprint`, you can run the following command: + +```sh +cargo install dprint +``` + +Or follow the [instructions][install-dprint] on the `dprint` website. + +[install-dprint]: https://dprint.dev/install/ + +To format Rust code, you can run `rustfmt <path to file>`, and to format other +files, you can pass `dprint <path to file>`. Many text editors also have native +support or extensions for both `rustfmt` and `dprint`. + ## Checking for Fixes The book rides the Rust release trains. Therefore, if you see a problem on From d8f0f5b450d4acc879f84c94de7a1367a67b103d Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Fri, 6 Dec 2024 16:44:00 -0700 Subject: [PATCH 716/720] Ch. 15.5: account for improved error message Previously, the error message from the compiler only suggested changing the `impl` to use `&mut self`, but a (very helpful!) update to the error message suggests changing both the `impl` and the `trait` definitions, which is much better in the general case since changing one without the other will just produce a new error message: a point the original text points to with its suggestion to try and see what happens. Account for the new error message by keeping the framing of the reason as avoiding breaking the trait contract, but now explicitly in terms of good testing habits. Fixes #4140 --- src/ch15-05-interior-mutability.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index f1d5547c7e..77180db94d 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -189,9 +189,10 @@ However, there’s one problem with this test, as shown here: We can’t modify the `MockMessenger` to keep track of the messages, because the `send` method takes an immutable reference to `self`. We also can’t take the -suggestion from the error text to use `&mut self` instead, because then the -signature of `send` wouldn’t match the signature in the `Messenger` trait -definition (feel free to try and see what error message you get). +suggestion from the error text to use `&mut self` in both the `impl` method and +the `trait` definition. We do not want to change the `Messenger` trait solely +for the sake of testing. Instead, we need to find a way to make our test code +work correctly with our existing design. This is a situation in which interior mutability can help! We’ll store the `sent_messages` within a `RefCell<T>`, and then the `send` method will be From fa5eb0061a170c8020a427db058d688f0bd28a42 Mon Sep 17 00:00:00 2001 From: Xheldon <c1006044256@gmail.com> Date: Sun, 8 Dec 2024 18:38:25 +0800 Subject: [PATCH 717/720] Update README.md typo It's should be `packages/mdbook-trpl`, not `packages/mdbook_trpl` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a632402385..2ff16818b5 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ 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 +$ cargo install --locked --path packages/mdbook-trpl ``` ## Building From 6f0d1f8f41dc897ad748f7ceadc5a5ac13a320f5 Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 9 Dec 2024 10:47:39 -0700 Subject: [PATCH 718/720] Rust 2024: distinguish `unsafe fn` vs. `unsafe` blocks The former is no longer always treated as an unsafe block (without a warning, anyway), as implementation of [RFC #2585][rfc] progresses; the `unsafe fn` declares an obligation and the `unsafe` block upholds it. Fixes #4147 [rfc]: https://rust-lang.github.io/rfcs/2585-unsafe-block-in-unsafe-fn.html --- src/ch20-01-unsafe-rust.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 3e6147fe97..8796483a4b 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -186,9 +186,14 @@ With the `unsafe` block, we’re asserting to Rust that we’ve read the functio documentation, we understand how to use it properly, and we’ve verified that we’re fulfilling the contract of the function. -Bodies of unsafe functions are effectively `unsafe` blocks, so to perform other -unsafe operations within an unsafe function, we don’t need to add another -`unsafe` block. +> Note: In earlier versions of Rust, the body of an unsafe function was treated +> as an `unsafe` block, so you could perform any unsafe operation within the +> body of an `unsafe` function. In later versions of Rust, the compiler will +> warn you that you need to use an `unsafe` block to perform unsafe operations +> in the body of an unsafe function. This is because Rust now distinguishes +> between `unsafe fn`, which defines what you need to do to call the function +> safely, and an `unsafe` block, where you actually uphold that “contract” the +> function establishes. #### Creating a Safe Abstraction over Unsafe Code From bd576349dae597d775a5a38bbeead19ad2ac55dd Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 9 Dec 2024 14:40:04 -0700 Subject: [PATCH 719/720] Fix `.git-blame-ignore-revs` file It seems to need a full SHA! --- .git-blame-ignore-revs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 2bcb162313..3c71ce4186 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +1,2 @@ # Ran dprint fmt on the repo -3a30e4c1 +3a30e4c1fbe641afc066b3af9eb01dcdf5ed8b24 From 2186da27a85c487ffd3fa6ef5250b8ac557ca570 Mon Sep 17 00:00:00 2001 From: Chris Krycho <hello@chriskrycho.com> Date: Mon, 9 Dec 2024 15:16:52 -0700 Subject: [PATCH 720/720] Remove emphasis on four-space indents I suspect this one goes *allllll* the way back to Rust for Rubyists. Fixes #3759 --- src/ch01-02-hello-world.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index 600401d4d8..5779360b11 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -121,18 +121,16 @@ println!("Hello, world!"); This line does all the work in this little program: it prints text to the screen. There are four important details to notice here. -First, Rust style is to indent with four spaces, not a tab. - -Second, `println!` calls a Rust macro. If it had called a function instead, it +First, `println!` calls a Rust macro. If it had called a function instead, it would be entered as `println` (without the `!`). We’ll discuss Rust macros in more detail in Chapter 20. For now, you just need to know that using a `!` means that you’re calling a macro instead of a normal function and that macros don’t always follow the same rules as functions. -Third, you see the `"Hello, world!"` string. We pass this string as an argument +Second, you see the `"Hello, world!"` string. We pass this string as an argument to `println!`, and the string is printed to the screen. -Fourth, we end the line with a semicolon (`;`), which indicates that this +Third, we end the line with a semicolon (`;`), which indicates that this expression is over and the next one is ready to begin. Most lines of Rust code end with a semicolon.